node.lisp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. (in-package :hurd-translator)
  2. ;;
  3. ;; This file implements the node class.
  4. ;; A node represents a file in the translator's file system.
  5. ;;
  6. (defclass node ()
  7. ((owner :initform 0
  8. :initarg :owner
  9. :accessor owner
  10. :documentation "The node's owner.")
  11. (stat :initform (make-stat)
  12. :initarg :stat
  13. :accessor stat
  14. :documentation "Stat information about the node.")
  15. (box :initform nil
  16. :accessor box
  17. :documentation "Node's translator box.")
  18. (nusers :initform 0
  19. :accessor num-users
  20. :documentation "Number of users using this node.")
  21. (link :initform nil
  22. :documentation "If this is symlink, this is the target file."))
  23. (:documentation "The node class."))
  24. (defmethod pre-drop-node ((node node))
  25. "Does some operations before we can drop a node."
  26. (box-drop (box node)))
  27. (defgeneric initialize-node (node))
  28. (defmethod initialize-instance :after ((node node) &key)
  29. "Set the node's transbox (note that we need the node reference to do that)."
  30. (setf (box node) (make-instance 'node-transbox :node node))
  31. (initialize-node node))
  32. (defmethod print-object ((node node) stream)
  33. "Print a node to stream."
  34. (format stream "#<node owner=~s link=~s box="
  35. (owner node)
  36. (link node))
  37. (print-object (box node) stream)
  38. (format stream ">"))
  39. (defmethod is-controller-p ((node node) (user iouser))
  40. "Specialize is-controller-p for nodes."
  41. (is-controller-p (stat node) user))
  42. (defmethod is-owner-p ((node node) (user iouser))
  43. "Specialize is-owner-p for nodes."
  44. (is-owner-p (stat node) user))
  45. (defmethod has-access-p ((node node) (user iouser) flag)
  46. "Specialize has-access-p for nodes."
  47. (has-access-p (stat node) user flag))
  48. (defmethod can-modify-dir-p ((node node) (user iouser))
  49. "Specialize can-modify-dir-p."
  50. (can-modify-dir-p (stat node) user))
  51. (defmethod set-link-node ((node node) new-link)
  52. "When defining a new link target, change stat size."
  53. (setf (stat-get (stat node) 'st-size)
  54. (if (null new-link) 0 (length new-link)))
  55. (when new-link
  56. (set-type (stat node) :lnk))
  57. (setf (slot-value node 'link) new-link))
  58. (defsetf link set-link-node)
  59. (defmethod link ((node node))
  60. "Return the file path this node links to, NIL otherwise."
  61. (cond
  62. ((is-lnk-p (stat node)) (slot-value node 'link))
  63. (t nil)))
  64. (defmethod inc-users ((node node))
  65. "Increment number of users."
  66. (incf (num-users node)))
  67. (defmethod dec-users ((node node))
  68. "Decrement number of users."
  69. (decf (num-users node)))