fsys-getroot.lisp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. (in-package :hurd-translator)
  2. (defun %must-follow-symlink-p (node user flags)
  3. (and (is-lnk-p (stat node))
  4. (link node)
  5. (not (flag-is-p flags :nolink))
  6. (not (flag-is-p flags :notrans))
  7. (allow-link-p *translator* node user)))
  8. (defun %handle-normal-file (node flags dotdot user)
  9. (cond
  10. ((allow-open-p *translator* node user flags t)
  11. (when (flag-is-p flags :trunc)
  12. (unless (file-change-size *translator* node user 0)
  13. (return-from %handle-normal-file :not-permitted)))
  14. (let* ((new-open-node (make-open-node
  15. node
  16. (disable-flags flags +open-create-flags+)
  17. :root-parent dotdot))
  18. (new (new-protid *translator*
  19. user
  20. new-open-node)))
  21. (port-deallocate dotdot)
  22. (values :retry-normal
  23. (get-right new)
  24. :make-send
  25. "")))
  26. (t :not-permitted)))
  27. (defun %handle-symlink (node dotdot)
  28. (let ((target (link node)))
  29. (cond
  30. ((eq (char target 0) #\/) ; Points to root.
  31. (port-deallocate dotdot)
  32. (values :retry-magical
  33. nil
  34. :copy-send
  35. target))
  36. (t
  37. (values :retry-reauth
  38. dotdot
  39. :move-send
  40. target)))))
  41. (defun %fsys-getroot-normal (node flags dotdot user)
  42. (cond
  43. ((%must-follow-symlink-p node user flags)
  44. (%handle-symlink node dotdot))
  45. (t (%handle-normal-file node flags dotdot user))))
  46. (defun %must-follow-translator-p (node flags)
  47. (and (not (flag-is-p flags :notrans))
  48. (box-translated-p (box node))))
  49. (%add-callback do-fsys-getroot (node flags dotdot user)
  50. "Lookup root port in 'node' with 'flags' to 'user'. 'dotdot' is the parent directory.
  51. This must return four things:
  52. Type of retry.
  53. Retry port.
  54. Retry port type.
  55. Filename to retry.
  56. "
  57. (when (%must-follow-translator-p node flags)
  58. (let* ((*current-node* node)
  59. (*current-dotdot* dotdot))
  60. (multiple-value-bind (retry retry-name port)
  61. (fetch-root (box node)
  62. dotdot flags user
  63. #'get-translator-callback
  64. (callback fetch-root-callback))
  65. (unless (eq retry :no-such-file)
  66. (return-from do-fsys-getroot (values retry port :move-send retry-name))))))
  67. (%fsys-getroot-normal node flags dotdot user))
  68. (def-fsys-interface :fsys-getroot ((fsys port)
  69. (reply port)
  70. (reply-poly msg-type-name)
  71. (dotdot port)
  72. (gen-uids :pointer)
  73. (gen-uids-count msg-type-number)
  74. (gen-gids :pointer)
  75. (gen-gids-count msg-type-number)
  76. (flags open-flags)
  77. (retry-type :pointer)
  78. (retry-name :pointer)
  79. (file port-pointer)
  80. (file-poly :pointer))
  81. (declare (ignore reply reply-poly))
  82. (with-accessors ((node root)) *translator*
  83. (block getroot
  84. (unless (and node (port-exists-p fsys))
  85. (return-from getroot nil))
  86. (let ((user (make-iouser-mem gen-uids gen-uids-count
  87. gen-gids gen-gids-count)))
  88. (multiple-value-bind (retry-type0 file0 file-poly0 retry-name0)
  89. (do-fsys-getroot *translator* node flags dotdot user)
  90. (cond
  91. ((null retry-name0) retry-type0) ; Some error ocurred
  92. (t
  93. (setf (mem-ref retry-type 'retry-type) retry-type0
  94. (mem-ref file 'port) file0
  95. (mem-ref file-poly 'msg-type-name) file-poly0)
  96. (lisp-string-to-foreign retry-name0
  97. retry-name
  98. (1+ (length retry-name0)))
  99. t)))))))