open.lisp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (in-package :hurd-translator)
  2. ;;
  3. ;; This file implements the open-node class.
  4. ;; A open-node refers to a node that is open.
  5. ;;
  6. (defclass open-node ()
  7. ((node :initarg :refers
  8. :accessor refers
  9. :documentation "Node this refers to.")
  10. (file-pos :initform 0
  11. :accessor file-offset
  12. :documentation "File offset.")
  13. (lock-status :initform :lock-un
  14. :accessor lock-status
  15. :documentation "Lock status.") ; /usr/include/sys/file.h
  16. (openstat :initform '()
  17. :initarg :flags
  18. :accessor flags
  19. :documentation "Open flags for this node.")
  20. (root-parent :initform nil
  21. :accessor root-parent
  22. :documentation "Port to the root parent.")
  23. (shadow-root :initform nil
  24. :accessor shadow-root
  25. :documentation "Shadow root.")
  26. (shadow-root-parent :initform nil
  27. :accessor shadow-root-parent
  28. :documentation "Shadow root parent."))
  29. (:documentation "Open node class."))
  30. (defun %set-root-shadow-parent (obj parent shadow shadow-parent)
  31. "Define the new parent, shadow and shadow parents."
  32. (when parent
  33. (setf (root-parent obj) parent))
  34. (when shadow
  35. (setf (shadow-root obj) shadow))
  36. (when shadow-parent
  37. (setf (shadow-root-parent obj) shadow-parent)))
  38. (defun make-open-node (node flags
  39. &key
  40. (copy nil)
  41. (root-parent nil)
  42. (shadow-root nil)
  43. (shadow-root-parent nil))
  44. "Creates a new open node."
  45. (let ((obj (make-instance 'open-node :refers node :flags flags)))
  46. (when copy
  47. (%set-root-shadow-parent obj
  48. (root-parent copy)
  49. (shadow-root copy)
  50. (shadow-root-parent copy)))
  51. (%set-root-shadow-parent obj
  52. root-parent
  53. shadow-root
  54. shadow-root-parent)
  55. (if (port-valid-p (root-parent obj))
  56. (port-mod-refs (root-parent obj) :right-send 1))
  57. (if (port-valid-p shadow-root-parent)
  58. (port-mod-refs shadow-root-parent :right-send 1))
  59. obj))
  60. (defmethod install-shadow-root ((node open-node) root parent)
  61. "Installs the new shadow root and shadow parents."
  62. (with-accessors ((s-r-parent shadow-root-parent)) node
  63. (when (port-valid-p s-r-parent)
  64. (port-deallocate s-r-parent)))
  65. (setf (shadow-root node) root
  66. (shadow-root-parent node) parent)
  67. t)