zero-translator.lisp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (defpackage :zero-translator
  2. (:use :cl :hurd-common :mach
  3. :hurd :hurd-translator))
  4. (in-package :zero-translator)
  5. (defclass zero-translator (translator)
  6. ()
  7. (:documentation "The zero-translator."))
  8. (define-callback make-root-node zero-translator
  9. (underlying-node underlying-stat)
  10. (declare (ignore underlying-node))
  11. (let ((mode (make-mode :perms '((:owner :read :write)
  12. (:group :read :write)
  13. (:others :read :write))
  14. :type :chr)))
  15. (make-instance 'node
  16. :stat (make-stat underlying-stat
  17. :mode mode))))
  18. (define-callback read-file zero-translator
  19. (node user start amount stream)
  20. (declare (ignore translator start))
  21. (when (has-access-p node user :read)
  22. (loop for i from 0 below amount
  23. do (write-byte 0 stream))
  24. t))
  25. (define-callback write-file zero-translator
  26. (node user offset stream amount)
  27. (declare (ignore translator offset amount))
  28. (when (has-access-p node user :write)
  29. ; Empty the stream to look like we used it all.
  30. (loop while (read-byte stream nil))
  31. t))
  32. (defun main ()
  33. (run-translator (make-instance 'zero-translator
  34. :name "zero-translator")))
  35. (main)