Skip to content

Commit

Permalink
Some work on writefile.
Browse files Browse the repository at this point in the history
  • Loading branch information
amatus committed Jun 27, 2012
1 parent bbfc99a commit a7fe798
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/clojure/foofs/localbackend.clj
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,32 @@
executor
#(continuation! (read-file scheduler salt file offset size)))))))
(writefile [_ nodeid offset size data continuation!]
;; TODO: Write out all the complete blocks before bothering the state agent
(send
state-agent
(fn [state]
(let [inode-table (:inode-table state)
file-table (:file-table state)
inode (get inode-table nodeid)
file (get file-table nodeid empty-file)]
inode (get inode-table nodeid)]
(if (nil? inode)
(do (continuation! errno-noent) state)
;; XXX read partial blocks, do write, store new blocks
state)))))
(let [file-table (:file-table state)
file (get file-table nodeid empty-file)
block-list (:block-list file)
block-size (:block-size file)
first-blockid (quot offset block-size)
last-blockid (quot (+ size offset) block-size)
;; write zero blocks until first-blockid
blocks (if (< first-blockid (count block-list))
block-list
(let [zeros (byte-array block-size)
zero-block (write-block zeros)]
(take first-blockid
(concat block-list
(repeat zero-block)))))
;; get overlapping blocks
;; XXX
]
state))))))
(mknod [_ nodeid filename mode continuation!]
(send
state-agent
Expand Down

0 comments on commit a7fe798

Please sign in to comment.