Permalink
Browse files

Fixed dirent offsets. Added more stuff to TestFS.

  • Loading branch information...
1 parent 984be05 commit 4339ff6fb2d63a63d5f29c45ead9d6191fc49cb9 @amatus committed Feb 7, 2012
Showing with 37 additions and 6 deletions.
  1. +13 −2 src/clojure/foofs/fuse/protocol.clj
  2. +24 −4 src/clojure/foofs/fuse/testfs.clj
View
15 src/clojure/foofs/fuse/protocol.clj
@@ -377,21 +377,32 @@
(* 8 (quot (+ x 7) 8)))
(defn encode-dirent
- [dirent]
+ [dirent offset]
(let [namebytes (.getBytes (:name dirent) "UTF-8")
namelen (count namebytes)
entsize (dirent-align (+ name-offset namelen))]
(take
entsize
(concat
(encode-int64 (:nodeid dirent))
- (encode-int64 entsize)
+ (encode-int64 (+ offset entsize))
(encode-int32 namelen)
(encode-int32 (bit-shift-right (bit-and stat-type-mask (:type dirent))
12))
namebytes
(repeat 0)))))
+(defn encode-dirents
+ [dirents]
+ (first (reduce (fn
+ [state dirent]
+ (let [[encoded-dirents offset] state
+ encoded-dirent (encode-dirent dirent offset)]
+ [(concat encoded-dirents encoded-dirent)
+ (+ offset (count encoded-dirent))]))
+ [[] 0]
+ dirents)))
+
(defn process-readdir!
[fuse request]
(.readdir
View
28 src/clojure/foofs/fuse/testfs.clj
@@ -47,9 +47,18 @@
{:inode 1
:mode stat-type-directory
:nlink 1})
- :dirents {"test" {:name "test"
+ :dirents {"." {:name "."
+ :nodeid 1
+ :type stat-type-directory}
+ ".." {:name ".."
+ :nodeid 1
+ :type stat-type-directory}
+ "test" {:name "test"
:nodeid 2
- :type stat-type-regular}}}
+ :type stat-type-regular}
+ "folder" {:name "folder"
+ :nodeid 3
+ :type stat-type-directory}}}
2 {:attr (conj
default-attr
{:inode 2
@@ -58,6 +67,18 @@
:mode stat-type-regular
:nlink 1})
:content hello-world-bytes}
+ 3 {:attr (conj
+ default-attr
+ {:inode 3
+ :mode stat-type-directory
+ :nlink 1})
+ :dirents {"." {:name "."
+ :nodeid 3
+ :type stat-type-directory}
+ ".." {:name ".."
+ :nodeid 1
+ :type stat-type-directory}
+ }}
}
)
@@ -147,8 +168,7 @@
(continuation! errno-noent)
(send (:state-agent this)
(fn [state]
- (let [dirents (mapcat
- encode-dirent
+ (let [dirents (encode-dirents
(vals (:dirents (inodes (:nodeid request)))))
handle (:next-handle state)]
;; do another send to make sure state is updated before

0 comments on commit 4339ff6

Please sign in to comment.