diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure/foofs/filesystem.clj | 2 | ||||
-rw-r--r-- | src/clojure/foofs/filesystembackend.clj | 2 | ||||
-rw-r--r-- | src/clojure/foofs/fuse/filesystem.clj | 1 | ||||
-rw-r--r-- | src/clojure/foofs/fuse/jna.clj | 1 | ||||
-rw-r--r-- | src/clojure/foofs/fuse/protocol.clj | 13 | ||||
-rw-r--r-- | src/clojure/foofs/memorybackend.clj | 32 |
6 files changed, 47 insertions, 4 deletions
diff --git a/src/clojure/foofs/filesystem.clj b/src/clojure/foofs/filesystem.clj index d8d51c5..29f6d41 100644 --- a/src/clojure/foofs/filesystem.clj +++ b/src/clojure/foofs/filesystem.clj @@ -75,6 +75,8 @@ (.link backend inode "." inode skip) (.link backend inode ".." (:nodeid request) skip) (continuation! (fill-entry attr)))))))) + (unlink [this request continuation!] + (.unlink backend (:nodeid request) (:arg request) continuation!)) (link [this request continuation!] (let [arg (:arg request)] (.link diff --git a/src/clojure/foofs/filesystembackend.clj b/src/clojure/foofs/filesystembackend.clj index dff2c23..6ba3afc 100644 --- a/src/clojure/foofs/filesystembackend.clj +++ b/src/clojure/foofs/filesystembackend.clj @@ -33,5 +33,7 @@ "Create an inode and return its attributes.") (link [this inode filename target-inode continuation!] "Create a hardlink and return the target's attributes.") + (unlink [this inode filename continuation!] + "Unlink a file.") ;; and so on ) diff --git a/src/clojure/foofs/fuse/filesystem.clj b/src/clojure/foofs/fuse/filesystem.clj index 17a6a7e..102c78c 100644 --- a/src/clojure/foofs/fuse/filesystem.clj +++ b/src/clojure/foofs/fuse/filesystem.clj @@ -22,6 +22,7 @@ (getattr [this request continuation!] "Get file attributes.") (mknod [this request continuation!] "Create node.") (mkdir [this request continuation!] "Create directory.") + (unlink [this request continuation!] "Unlink a file.") (link [this request continuation!] "Create hardlink.") (open [this request continuation!] "Open file.") (readfile [this request continuation!] "Read file.") diff --git a/src/clojure/foofs/fuse/jna.clj b/src/clojure/foofs/fuse/jna.clj index ccbe65e..ba800d9 100644 --- a/src/clojure/foofs/fuse/jna.clj +++ b/src/clojure/foofs/fuse/jna.clj @@ -142,6 +142,7 @@ (def errno-nomem 12) (def errno-exist 17) (def errno-notdir 20) + (def errno-isdir 21) (def errno-inval 22) (def errno-nosys 38) (def errno-proto 71) diff --git a/src/clojure/foofs/fuse/protocol.clj b/src/clojure/foofs/fuse/protocol.clj index 99e59c8..4aa72ba 100644 --- a/src/clojure/foofs/fuse/protocol.clj +++ b/src/clojure/foofs/fuse/protocol.clj @@ -118,8 +118,6 @@ :gid gid :pid pid})) -(def parse-lookup-in parse-utf8) - (defn write-fuse-attr [attr] (domonad @@ -236,6 +234,13 @@ (reply-error! fuse request result) (reply-ok! fuse request (write-entry-out result)))))) +(defn process-unlink! + [fuse request] + (.unlink + (:filesystem fuse) + request + (partial reply-error! fuse request))) + (def parse-link-in (domonad parser-m @@ -497,7 +502,7 @@ (c-close (:fd fuse))) (def ops - {op-lookup {:arg-parser parse-lookup-in + {op-lookup {:arg-parser parse-utf8 :processor! process-lookup!} op-forget {:arg-parser parse-forget-in :processor! process-forget!} @@ -507,6 +512,8 @@ :processor! process-mknod!} op-mkdir {:arg-parser parse-mkdir-in :processor! process-mkdir!} + op-unlink {:arg-parser parse-utf8 + :processor! process-unlink!} op-link {:arg-parser parse-link-in :processor! process-link!} op-open {:arg-parser parse-open-in diff --git a/src/clojure/foofs/memorybackend.clj b/src/clojure/foofs/memorybackend.clj index 4530dec..f08a4bd 100644 --- a/src/clojure/foofs/memorybackend.clj +++ b/src/clojure/foofs/memorybackend.clj @@ -145,4 +145,34 @@ (inc (:nlink attr)))) :lookup-table (assoc lookup-table inode (assoc children filename - target-inode)))))))))))) + target-inode))))))))))) + (unlink [this inode filename continuation!] + (send + state-agent + (fn [state] + (let [lookup-table (:lookup-table state) + attr-table (:attr-table state) + children (get lookup-table inode) + child-inode (get children filename) + dir-attr (get attr-table inode)] + (if (not (= stat-type-directory + (bit-and stat-type-mask (:mode dir-attr)))) + (do (continuation! errno-notdir) state) + (if (nil? child-inode) + (do (continuation! errno-noent) state) + (let [child-attr (get attr-table child-inode) + nlink (dec (:nlink child-attr))] + (if (= stat-type-directory + (bit-and stat-type-mask (:mode child-attr))) + (do (continuation! errno-isdir) state) + (do + (continuation! 0) + (assoc state + :lookup-table (assoc lookup-table inode + (dissoc children filename)) + :attr-table (if (zero? nlink) + (dissoc attr-table child-inode) + (assoc + attr-table child-inode + (assoc child-attr + :nlink nlink)))))))))))))) |