aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2012-05-24 21:48:31 -0500
committerDavid Barksdale <amatus.amongus@gmail.com>2012-05-24 21:48:31 -0500
commit37a9054b5bd833f0d44708c56da798e29063e988 (patch)
tree50a94b19fcb632db8fb583449fcbb4ce46e05e1a /src
parent6018241e1b99cfe565417bdf6cfe8b10a9eb474f (diff)
Cleaned up naming of inodes.
Diffstat (limited to 'src')
-rw-r--r--src/clojure/foofs/filesystem.clj55
-rw-r--r--src/clojure/foofs/fuse/filesystem.clj6
-rw-r--r--src/clojure/foofs/memorybackend.clj149
3 files changed, 101 insertions, 109 deletions
diff --git a/src/clojure/foofs/filesystem.clj b/src/clojure/foofs/filesystem.clj
index 75ddfe9..4171b3a 100644
--- a/src/clojure/foofs/filesystem.clj
+++ b/src/clojure/foofs/filesystem.clj
@@ -20,16 +20,15 @@
(foofs.fuse jna protocol)))
(defn fill-entry
- [attr]
- {:nodeid (:nodeid attr)
+ [inode]
+ {:nodeid (:nodeid inode)
:generation 0
:entry-valid 0
:attr-valid 0
:entry-valid-nsec 0
:attr-valid-nsec 0
- :attr attr})
+ :attr inode})
-;; TODO - rename attr(s) to inode, because that's the name of that structure.
;; TODO - the backend operations will eventually be interleaved with operations
;; from other clients. These need to be transformed to not operate on inode
;; numbers, because those will not be the same between clients. It seems like
@@ -48,19 +47,19 @@
(continuation! errno-noent)
(.getattr
backend child-nodeid
- (fn [attr]
- (if (nil? attr)
+ (fn [inode]
+ (if (nil? inode)
(continuation! errno-noent)
- (continuation! (fill-entry attr)))))))))
+ (continuation! (fill-entry inode)))))))))
(forget [_ _]
nil)
(getattr [_ {:keys [nodeid]} continuation!]
(.getattr
backend nodeid
- (fn [attr]
- (if (nil? attr)
+ (fn [inode]
+ (if (nil? inode)
(continuation! errno-noent)
- (continuation! (assoc attr :valid 0 :valid-nsec 0))))))
+ (continuation! (assoc inode :valid 0 :valid-nsec 0))))))
(setattr [this {:keys [nodeid arg] :as request} continuation!]
(let [valid (:valid arg)
set-mode! (fn [next!]
@@ -128,24 +127,24 @@
(mknod [_ {:keys [nodeid arg]} continuation!]
(.mknod
backend nodeid (:filename arg) (:mode arg)
- (fn [attr]
- (if (integer? attr)
- (continuation! attr)
- (continuation! (fill-entry attr))))))
+ (fn [inode]
+ (if (integer? inode)
+ (continuation! inode)
+ (continuation! (fill-entry inode))))))
(mkdir [_ {:keys [nodeid arg]} continuation!]
;; TODO: this probably should be a backend op. the parent dir could go
;; away before we can ref it with the .. link.
(.mknod
backend nodeid (:filename arg)
(bit-or stat-type-directory (:mode arg))
- (fn [attr]
- (if (integer? attr)
- (continuation! attr)
- (let [child-nodeid (:nodeid attr)]
+ (fn [inode]
+ (if (integer? inode)
+ (continuation! inode)
+ (let [child-nodeid (:nodeid inode)]
;; do we need to wait for these to finish?
(.link backend child-nodeid "." child-nodeid skip)
(.link backend child-nodeid ".." nodeid skip)
- (continuation! (fill-entry attr)))))))
+ (continuation! (fill-entry inode)))))))
(unlink [_ {:keys [nodeid arg]} continuation!]
(.unlink backend nodeid arg continuation!))
(rmdir [_ {:keys [nodeid arg]} continuation!]
@@ -156,10 +155,10 @@
(link [_ {:keys [nodeid arg]} continuation!]
(.link
backend nodeid (:filename arg) (:target-nodeid arg)
- (fn [attr]
- (if (integer? attr)
- (continuation! attr)
- (continuation! (fill-entry attr))))))
+ (fn [inode]
+ (if (integer? inode)
+ (continuation! inode)
+ (continuation! (fill-entry inode))))))
(open [_ {:keys [nodeid]} continuation!]
(.reference
backend nodeid
@@ -251,16 +250,16 @@
;; is create supposed to be atomic?
(.mknod
backend nodeid (:filename arg) (:mode arg)
- (fn [attr]
- (if (integer? attr)
- (continuation! attr)
+ (fn [inode]
+ (if (integer? inode)
+ (continuation! inode)
(.reference
- backend (:nodeid attr)
+ backend (:nodeid inode)
(fn [link]
(if (integer? link)
(continuation! link)
(continuation!
- (assoc (fill-entry attr)
+ (assoc (fill-entry inode)
:handle 0
:flags 0)))))))))
(destroy [_ _]
diff --git a/src/clojure/foofs/fuse/filesystem.clj b/src/clojure/foofs/fuse/filesystem.clj
index 83f0ad3..8e0ba36 100644
--- a/src/clojure/foofs/fuse/filesystem.clj
+++ b/src/clojure/foofs/fuse/filesystem.clj
@@ -19,9 +19,9 @@
"A FUSE filesystem."
(lookup [this request continuation!] "Lookup inode.")
(forget [this request] "I forget.")
- (getattr [this request continuation!] "Get file attributes.")
- (setattr [this request continuation!] "Set file attributes.")
- (mknod [this request continuation!] "Create node.")
+ (getattr [this request continuation!] "Get inode attributes.")
+ (setattr [this request continuation!] "Set inode attributes.")
+ (mknod [this request continuation!] "Create inode.")
(mkdir [this request continuation!] "Create directory.")
(unlink [this request continuation!] "Unlink a file.")
(rmdir [this request continuation!] "Remove an empty directory.")
diff --git a/src/clojure/foofs/memorybackend.clj b/src/clojure/foofs/memorybackend.clj
index 669e86a..efaf97e 100644
--- a/src/clojure/foofs/memorybackend.clj
+++ b/src/clojure/foofs/memorybackend.clj
@@ -18,7 +18,7 @@
[foofs.fuse bytebuffer jna]
foofs.util))
-(def empty-attrs
+(def empty-inode
{:size 0
:blocks 0
:atime 0
@@ -33,57 +33,53 @@
:gid 0
:rdev 0})
-(defn attrs-modifier!
+(defn inode-modifier!
[state-agent nodeid f continuation!]
(send
state-agent
(fn [state]
- (let [attrs-table (:attrs-table state)
- attrs (get attrs-table nodeid)]
- (if (nil? attrs)
+ (let [inode-table (:inode-table state)
+ inode (get inode-table nodeid)]
+ (if (nil? inode)
(do (continuation! errno-noent) state)
- (let [new-attrs (f attrs)]
- (agent-do state-agent (continuation! new-attrs))
- (assoc-deep state new-attrs :attrs-table nodeid)))))))
+ (let [new-inode (f inode)]
+ (agent-do state-agent (continuation! new-inode))
+ (assoc-deep state new-inode :inode-table nodeid)))))))
(defn attribute-modifier!
[state-agent nodeid f attribute continuation!]
- (attrs-modifier! state-agent nodeid
- (fn [attrs]
- (assoc attrs attribute (f (get attrs attribute))))
+ (inode-modifier! state-agent nodeid
+ (fn [inode]
+ (assoc inode attribute (f (get inode attribute))))
continuation!))
(defrecord MemoryBackend
[^clojure.lang.Agent state-agent]
FilesystemBackend
(lookup [_ nodeid child continuation!]
- (let [state (deref state-agent)
- lookup-table (:lookup-table state)]
+ (let [lookup-table (:lookup-table (deref state-agent))]
(if (= "" child)
(continuation! nodeid)
(continuation! (get-in lookup-table [nodeid child])))))
(getattr [_ nodeid continuation!]
- (let [attrs-table (:attrs-table (deref state-agent))
- attrs (get attrs-table nodeid)]
- (if (nil? attrs)
+ (let [inode (get-in (deref state-agent) [:inode-table nodeid])]
+ (if (nil? inode)
(continuation! nil)
- (continuation! (assoc attrs :nodeid nodeid)))))
+ (continuation! (assoc inode :nodeid nodeid)))))
(reference [_ nodeid continuation!]
(attribute-modifier! state-agent nodeid inc :nlink continuation!))
(dereference [_ nodeid continuation!]
(attribute-modifier! state-agent nodeid dec :nlink continuation!))
(clonedir [_ nodeid continuation!]
(let [state (deref state-agent)
- lookup-table (:lookup-table state)
- children (get lookup-table nodeid)
- attrs-table (:attrs-table state)]
+ inode-table (:inode-table state)]
(continuation!
(map
- (fn [[filename nodeid]]
+ (fn [[filename child-nodeid]]
{:name filename
- :nodeid nodeid
- :type (get-in attrs-table [nodeid :mode])})
- children))))
+ :nodeid child-nodeid
+ :type (get-in inode-table [child-nodeid :mode])})
+ (get-in state [:lookup-table nodeid])))))
(readfile [_ nodeid offset size continuation!]
(let [file (get-in (deref state-agent) [:file-table nodeid])]
(if (nil? file)
@@ -93,14 +89,14 @@
(send
state-agent
(fn [state]
- (let [attrs-table (:attrs-table state)
+ (let [inode-table (:inode-table state)
file-table (:file-table state)
- attrs (get attrs-table nodeid)
+ inode (get inode-table nodeid)
file (get file-table nodeid)]
- (if (nil? attrs)
+ (if (nil? inode)
(do (continuation! errno-noent) state)
(let [tail-offset (+ offset size)
- tail-size (- (max tail-offset (:size attrs)) tail-offset)
+ tail-size (- (max tail-offset (:size inode)) tail-offset)
file-extended (concat file (repeat (byte 0)))
file-written (concat
(take offset file-extended)
@@ -111,7 +107,7 @@
(agent-do state-agent
(continuation! {:size (.limit data)}))
(assoc state
- :attrs-table (assoc-deep attrs-table new-size nodeid :size)
+ :inode-table (assoc-deep inode-table new-size nodeid :size)
:file-table (assoc file-table nodeid file-written))))))))
(mknod [_ nodeid filename mode continuation!]
(send
@@ -119,20 +115,18 @@
(fn [state]
(let [lookup-table (:lookup-table state)
children (get lookup-table nodeid)
- attrs-table (:attrs-table state)]
+ inode-table (:inode-table state)]
(if (contains? children filename)
- (do
- (continuation! errno-exist)
- state)
- (let [child-nodeid (next-key attrs-table (:next-nodeid state)
+ (do (continuation! errno-exist) state)
+ (let [child-nodeid (next-key inode-table (:next-nodeid state)
Long/MIN_VALUE Long/MAX_VALUE)
- attrs (conj empty-attrs
+ inode (conj empty-inode
{:mode mode
:nlink 1})]
(agent-do state-agent
- (continuation! (assoc attrs :nodeid child-nodeid)))
+ (continuation! (assoc inode :nodeid child-nodeid)))
(assoc state
- :attrs-table (assoc attrs-table child-nodeid attrs)
+ :inode-table (assoc inode-table child-nodeid inode)
:lookup-table (assoc lookup-table nodeid
(assoc children filename
child-nodeid))
@@ -142,24 +136,26 @@
state-agent
(fn [state]
(let [lookup-table (:lookup-table state)
- attrs-table (:attrs-table state)
+ inode-table (:inode-table state)
children (get lookup-table nodeid)
- dir-attrs (get attrs-table nodeid)
- attrs (get attrs-table target-nodeid)]
+ inode (get inode-table nodeid)
+ target-inode (get inode-table target-nodeid)]
(if (contains? children filename)
(do (continuation! errno-exist) state)
(if (not (= stat-type-directory
- (bit-and stat-type-mask (:mode dir-attrs))))
+ (bit-and stat-type-mask (:mode inode))))
(do (continuation! errno-notdir) state)
- (if (nil? attrs)
+ (if (nil? target-inode)
(do (continuation! errno-noent) state)
(do
(agent-do state-agent
- (continuation! (assoc attrs :nodeid target-nodeid)))
+ (continuation! (assoc target-inode
+ :nodeid target-nodeid)))
(assoc state
- :attrs-table (assoc attrs-table target-nodeid
- (assoc attrs :nlink
- (inc (:nlink attrs))))
+ :inode-table (assoc inode-table target-nodeid
+ (assoc target-inode :nlink
+ (inc
+ (:nlink target-inode))))
:lookup-table (assoc lookup-table nodeid
(assoc children filename
target-nodeid)))))))))))
@@ -168,64 +164,64 @@
state-agent
(fn [state]
(let [lookup-table (:lookup-table state)
- attrs-table (:attrs-table state)
+ inode-table (:inode-table state)
children (get lookup-table nodeid)
child-nodeid (get children filename)
- dir-attrs (get attrs-table nodeid)]
+ inode (get inode-table nodeid)]
(if (not (= stat-type-directory
- (bit-and stat-type-mask (:mode dir-attrs))))
+ (bit-and stat-type-mask (:mode inode))))
(do (continuation! errno-notdir) state)
(if (nil? child-nodeid)
(do (continuation! errno-noent) state)
- (let [child-attrs (get attrs-table child-nodeid)]
+ (let [child-inode (get inode-table child-nodeid)]
(if (= stat-type-directory
- (bit-and stat-type-mask (:mode child-attrs)))
+ (bit-and stat-type-mask (:mode child-inode)))
(do (continuation! errno-isdir) state)
- (let [nlink (dec (:nlink child-attrs))]
+ (let [nlink (dec (:nlink child-inode))]
(continuation! 0)
(assoc state
:lookup-table (assoc lookup-table nodeid
(dissoc children filename))
- :attrs-table (if (zero? nlink)
- (dissoc attrs-table child-nodeid)
+ :inode-table (if (zero? nlink)
+ (dissoc inode-table child-nodeid)
(assoc
- attrs-table child-nodeid
- (assoc child-attrs
+ inode-table child-nodeid
+ (assoc child-inode
:nlink nlink)))))))))))))
(rmdir [_ nodeid filename continuation!]
(send
state-agent
(fn [state]
(let [lookup-table (:lookup-table state)
- attrs-table (:attrs-table state)
+ inode-table (:inode-table state)
children (get lookup-table nodeid)
child-nodeid (get children filename)
- dir-attrs (get attrs-table nodeid)]
+ inode (get inode-table nodeid)]
(if (not (= stat-type-directory
- (bit-and stat-type-mask (:mode dir-attrs))))
+ (bit-and stat-type-mask (:mode inode))))
(do (continuation! errno-notdir) state)
(if (nil? child-nodeid)
(do (continuation! errno-noent) state)
- (let [child-attrs (get attrs-table child-nodeid)
+ (let [child-inode (get inode-table child-nodeid)
child-children (get lookup-table child-nodeid)]
(if (not (= stat-type-directory
- (bit-and stat-type-mask (:mode child-attrs))))
+ (bit-and stat-type-mask (:mode child-inode))))
(do (continuation! errno-notdir) state)
(if (not (empty? (dissoc child-children "." "..")))
(do (continuation! errno-notempty) state)
;; TODO: 3 is wrong if . or .. don't exist
- (let [nlink (- (:nlink child-attrs) 3)]
+ (let [nlink (- (:nlink child-inode) 3)]
(agent-do state-agent (continuation! 0))
(assoc state
:lookup-table (dissoc
(assoc lookup-table nodeid
(dissoc children filename))
child-nodeid)
- :attrs-table (if (zero? nlink)
- (dissoc attrs-table child-nodeid)
+ :inode-table (if (zero? nlink)
+ (dissoc inode-table child-nodeid)
(assoc
- attrs-table child-nodeid
- (assoc child-attrs
+ inode-table child-nodeid
+ (assoc child-inode
:nlink nlink))))))))))))))
(chmod [_ nodeid mode continuation!]
(attribute-modifier! state-agent nodeid
@@ -244,30 +240,27 @@
(send
state-agent
(fn [state]
- (let [attrs-table (:attrs-table state)
+ (let [inode-table (:inode-table state)
file-table (:file-table state)
- attrs (get attrs-table nodeid)
file (get file-table nodeid)]
- (if (nil? attrs)
- (do (continuation! errno-noent) state)
+ (if (contains? inode-table nodeid)
(do
(agent-do state-agent (continuation! nil))
(assoc
state
- :attrs-table (assoc-deep attrs-table size nodeid :size)
+ :inode-table (assoc-deep inode-table size nodeid :size)
:file-table (assoc
file-table nodeid
(take size
- (concat file (repeat (byte 0))))))))))))
+ (concat file (repeat (byte 0)))))))
+ (do (continuation! errno-noent) state))))))
(setatime [_ nodeid seconds nseconds continuation!]
- (attrs-modifier! state-agent nodeid
- (fn [attrs]
- (assoc attrs :atime seconds :atimensec nseconds))
+ (inode-modifier! state-agent nodeid
+ #(assoc % :atime seconds :atimensec nseconds)
continuation!))
(setmtime [_ nodeid seconds nseconds continuation!]
- (attrs-modifier! state-agent nodeid
- (fn [attrs]
- (assoc attrs :mtime seconds :mtimensec nseconds))
+ (inode-modifier! state-agent nodeid
+ #(assoc % :mtime seconds :mtimensec nseconds)
continuation!))
(rename [_ nodeid target-nodeid filename target-filename continuation!]
(continuation! errno-nosys)))