From 2c5904a59b1bc3a7fca0fd75bc5770b4d1f7da63 Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Wed, 9 May 2012 23:12:06 -0500 Subject: Generalized link-modifier!, implemented chmod,setuid,setgid,setatime,setmtime. --- src/clojure/foofs/filesystem.clj | 25 +++++-------- src/clojure/foofs/fuse/jna.clj | 1 + src/clojure/foofs/fuse/protocol.clj | 10 ++---- src/clojure/foofs/memorybackend.clj | 71 +++++++++++++++++++++++++++---------- 4 files changed, 64 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/clojure/foofs/filesystem.clj b/src/clojure/foofs/filesystem.clj index fbd6e3d..7f21c3b 100644 --- a/src/clojure/foofs/filesystem.clj +++ b/src/clojure/foofs/filesystem.clj @@ -158,8 +158,8 @@ (.reference backend (:nodeid request) (fn [link] - (if (nil? link) - (continuation! errno-noent) + (if (integer? link) + (continuation! link) (continuation! {:handle 0 :flags 0}))))) (readfile [this request continuation!] @@ -183,12 +183,7 @@ :namelen 255 :frsize 0})) (release [this request continuation!] - (.dereference - backend (:nodeid request) - (fn [link] - (if (nil? link) - (continuation! errno-noent) - (continuation! 0))))) + (.dereference backend (:nodeid request) continuation!)) (init [this request] (.println *err* "init called") (send @@ -199,8 +194,8 @@ (.reference backend (:nodeid request) (fn [link] - (if (nil? link) - (continuation! errno-noent) + (if (integer? link) + (continuation! link) (send readdir-agent (fn [state] @@ -247,9 +242,7 @@ (.dereference backend (:nodeid request) (fn [link] - (if (nil? link) - (continuation! errno-noent) - (continuation! 0)) + (continuation! link) (send readdir-agent (fn [state] @@ -265,9 +258,9 @@ (continuation! attr) (.reference backend (:inode attr) - (fn [result] - (if (nil? result) - (continuation! errno-noent) + (fn [link] + (if (integer? link) + (continuation! link) (continuation! (assoc (fill-entry attr) :handle 0 diff --git a/src/clojure/foofs/fuse/jna.clj b/src/clojure/foofs/fuse/jna.clj index dce885e..fc98f62 100644 --- a/src/clojure/foofs/fuse/jna.clj +++ b/src/clojure/foofs/fuse/jna.clj @@ -207,6 +207,7 @@ (def stat-type-socket 0140000) (def stat-type-whiteout 0160000) (def stat-type-mask 0170000) +(def stat-mode-mask 0007777) ;; TODO: Figure out how to subclass com.sun.jna.Structure in Clojure or wimp ;; out and write it in Java. diff --git a/src/clojure/foofs/fuse/protocol.clj b/src/clojure/foofs/fuse/protocol.clj index 2ba3fc9..e799d1e 100644 --- a/src/clojure/foofs/fuse/protocol.clj +++ b/src/clojure/foofs/fuse/protocol.clj @@ -383,13 +383,6 @@ :nop) ] nil)) -(defn process-releasedir! - [fuse request] - (.releasedir - (:filesystem fuse) - request - (partial reply-error! fuse request))) - (defn process-destroy! [fuse request] (.destroy (:filesystem fuse) request) @@ -443,7 +436,8 @@ :processor! (partial process-generic! #(.readdir %1 %2 %3) write-bytes)} op-releasedir {:arg-parser parse-release-in - :processor! process-releasedir!} + :processor! (partial process-generic! + #(.releasedir %1 %2 %3) write-skip)} op-create {:arg-parser parse-create-in :processor! (partial process-generic! #(.create %1 %2 %3) write-create-out)} diff --git a/src/clojure/foofs/memorybackend.clj b/src/clojure/foofs/memorybackend.clj index 9878d3b..47dab4a 100644 --- a/src/clojure/foofs/memorybackend.clj +++ b/src/clojure/foofs/memorybackend.clj @@ -33,20 +33,29 @@ :gid 0 :rdev 0}) -(defn link-modifier! - [state-agent f inode continuation! state] - (let [attr-table (:attr-table state) - attr (get attr-table inode)] - (if (nil? attr) - (do - (continuation! nil) - state) - (let [link (f (:nlink attr))] - (send state-agent - (fn [state] - (continuation! link) - state)) - (assoc-deep state link :attr-table inode :nlink))))) +(defn attr-modifier! + [state-agent inode f continuation!] + (send + state-agent + (fn [state] + (let [attr-table (:attr-table state) + attr (get attr-table inode)] + (if (nil? attr) + (do (continuation! errno-noent) state) + (let [new-attr (f attr)] + (send state-agent + (fn [state] + (continuation! new-attr) + state)) + (assoc-deep state new-attr :attr-table inode))))))) + +;; TODO rename s/attr/attrs/ almost everywhere +(defn attr-attribute-modifier! + [state-agent inode f attribute continuation!] + (attr-modifier! state-agent inode + (fn [attr] + (assoc attr attribute (f (get attr attribute)))) + continuation!)) (defrecord MemoryBackend [^clojure.lang.Agent state-agent] @@ -66,11 +75,9 @@ (continuation! nil) (continuation! (assoc attr :inode inode))))) (reference [this inode continuation!] - (send state-agent - (partial link-modifier! state-agent inc inode continuation!))) + (attr-attribute-modifier! state-agent inode inc :nlink continuation!)) (dereference [this inode continuation!] - (send state-agent - (partial link-modifier! state-agent dec inode continuation!))) + (attr-attribute-modifier! state-agent inode dec :nlink continuation!)) (clonedir [this inode continuation!] (let [state (deref state-agent) lookup-table (:lookup-table state) @@ -208,4 +215,30 @@ (assoc attr-table child-inode (assoc child-attr - :nlink nlink))))))))))))))) + :nlink nlink)))))))))))))) + (chmod [this inode mode continuation!] + (attr-attribute-modifier! state-agent inode + #(bit-or (bit-and stat-type-mask %) + (bit-and stat-mode-mask mode)) + :mode continuation!)) + (setuid [this inode uid continuation!] + (attr-attribute-modifier! state-agent inode + (fn [_] uid) + :uid continuation!)) + (setgid [this inode gid continuation!] + (attr-attribute-modifier! state-agent inode + (fn [_] gid) + :gid continuation!)) + (truncate [this inode size continuation!] + ;; TODO + (continuation! errno-nosys)) + (setatime [this inode seconds nseconds continuation!] + (attr-modifier! state-agent inode + (fn [attr] + (assoc attr :atime seconds :atimensec nseconds)) + continuation!)) + (setmtime [this inode seconds nseconds continuation!] + (attr-modifier! state-agent inode + (fn [attr] + (assoc attr :mtime seconds :mtimensec nseconds)) + continuation!))) -- cgit v1.2.3-18-g5258