diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2012-06-25 20:43:54 -0500 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2012-06-25 20:43:54 -0500 |
commit | d437b509e75970089d5d9cdd853cdcda0dc7024e (patch) | |
tree | 66b473659c6b38954b29c0127fe78e81a8cdc2ab /src | |
parent | 8d35fb5b10ea2697975e4dc23d5c0c206ff4a6bd (diff) |
Implemented read-block.
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure/foofs/fuse/jna.clj | 2 | ||||
-rw-r--r-- | src/clojure/foofs/localbackend.clj | 24 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/clojure/foofs/fuse/jna.clj b/src/clojure/foofs/fuse/jna.clj index fc98f62..d4b0bdd 100644 --- a/src/clojure/foofs/fuse/jna.clj +++ b/src/clojure/foofs/fuse/jna.clj @@ -139,6 +139,7 @@ (when (Platform/isLinux) (do (def errno-noent 2) + (def errno-io 5) (def errno-nomem 12) (def errno-exist 17) (def errno-notdir 20) @@ -163,6 +164,7 @@ (when (Platform/isFreeBSD) (do (def errno-noent 2) + (def errno-io 5) (def errno-nomem 12) (def errno-exist 17) (def errno-notdir 20) diff --git a/src/clojure/foofs/localbackend.clj b/src/clojure/foofs/localbackend.clj index 4dd0b58..4f7537a 100644 --- a/src/clojure/foofs/localbackend.clj +++ b/src/clojure/foofs/localbackend.clj @@ -15,10 +15,11 @@ (ns foofs.localbackend (:use [foofs.filesystembackend :only [FilesystemBackend]] - foofs.storage.scheduler + [foofs.storage.scheduler :only [Scheduler]] [foofs.fuse bytebuffer jna] [foofs crypto util]) - (:import [java.util.concurrent Executor LinkedBlockingQueue])) + (:import java.io.FileInputStream + [java.util.concurrent Executor LinkedBlockingQueue])) (def empty-inode {:size 0 @@ -66,6 +67,21 @@ (assoc inode attribute (f (get inode attribute)))) continuation!)) +(defn read-block + [e-hash block-size n k] + (let [hash-chars (base32-encode e-hash) + dir-name (String. (into-array Character/TYPE (take 2 hash-chars))) + file-name (String. (into-array Character/TYPE (drop 2 hash-chars))) + path (str "/tmp/foofs/" dir-name "/" file-name)] + (try + (let [file-in (FileInputStream. path) + block-bytes (byte-array block-size) + size (.read file-in block-bytes)] + (if (= size block-size) + block-bytes + nil)) + (catch Exception _)))) + (defn read-file "Execute a synchronous read of a file." [scheduler salt {:keys [block-list block-size n k] :as file} offset size] @@ -93,8 +109,8 @@ ;; in local files. (defrecord LocalBackend [^clojure.lang.Agent state-agent - ^Scheduler scheduler - ^Executor executor] + ^foofs.storage.scheduler.Scheduler scheduler + ^java.util.concurrent.Executor executor] FilesystemBackend (lookup [_ nodeid child continuation!] (let [lookup-table (:lookup-table (deref state-agent))] |