io-write.lisp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (in-package :hurd-translator)
  2. (defun %foreign-vector-to-array (data len)
  3. "Transforms a foreign vector to a lisp array."
  4. (make-array len
  5. :initial-contents (loop for i from 0 below len
  6. collect (mem-aref data :unsigned-char i))))
  7. (def-io-interface :io-write ((port port)
  8. (data :pointer)
  9. (datalen msg-type-number)
  10. (offset off-t)
  11. (amount :pointer))
  12. (with-lookup protid port
  13. (block io-write
  14. (let ((open (open-node protid))
  15. (node (get-node protid))
  16. (user (get-user protid)))
  17. (unless (flag-is-p (flags open) :write)
  18. (return-from io-write :invalid-argument))
  19. (when (= offset -1)
  20. (when (flag-is-p (flags open) :append)
  21. ;; Move file offset to the end of the file!
  22. (setf (file-offset open)
  23. (stat-get (stat node) 'st-size)))
  24. (setf offset (file-offset open)))
  25. (let ((data-array (%foreign-vector-to-array data datalen)))
  26. (with-input-from-sequence (stream data-array)
  27. (let* ((ret (write-file *translator*
  28. node
  29. user
  30. offset
  31. stream
  32. datalen))
  33. (total (file-position stream)))
  34. (cond
  35. ((eq ret nil) :not-permitted)
  36. ((eq ret t)
  37. (incf (file-offset open) total)
  38. (setf (mem-ref amount 'vm-size) total)
  39. t)
  40. (t ret)))))))))