aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2012-03-27 23:33:45 -0500
committerDavid Barksdale <amatus.amongus@gmail.com>2012-03-27 23:33:45 -0500
commit5131b1815dfdbc95bfec19402bec1bbc4811279c (patch)
tree796844a6b1c40ff231aa757e97708608d03cc194 /src
parent6ea21d76494202f3f443ff87a0181a7ada847bc3 (diff)
Trying to get linux-mount to work, it's a bit messy.
Diffstat (limited to 'src')
-rw-r--r--src/clojure/foofs/fuse/fuse.clj42
-rw-r--r--src/clojure/foofs/fuse/jna.clj38
2 files changed, 69 insertions, 11 deletions
diff --git a/src/clojure/foofs/fuse/fuse.clj b/src/clojure/foofs/fuse/fuse.clj
index 4d42af0..74cbaf5 100644
--- a/src/clojure/foofs/fuse/fuse.clj
+++ b/src/clojure/foofs/fuse/fuse.clj
@@ -30,6 +30,18 @@
(catch Exception e
(.printStackTrace e)))))
+(defn start-filesystem
+ [filesystem fd]
+ (let [fuse {:filesystem filesystem
+ :fd fd
+ :read-thread (atom nil)
+ :connection {:proto-major (atom 0)
+ :proto-minor (atom 0)}}
+ read-thread (Thread. (partial read-loop! fuse))]
+ (reset! (:read-thread fuse) read-thread)
+ (.start read-thread)
+ fuse))
+
(defn freebsd-mount
[filesystem mountpoint]
(try
@@ -44,18 +56,30 @@
(let [stat_loc (IntByReference.)]
(waitpid (.getValue pid) stat_loc 0)
(if (== 0 (.getValue stat_loc))
- (let [fuse {:filesystem filesystem
- :fd fd
- :read-thread (atom nil)
- :connection {:proto-major (atom 0)
- :proto-minor (atom 0)}}
- read-thread (Thread. (partial read-loop! fuse))]
- (reset! (:read-thread fuse) read-thread)
- (.start read-thread)
- fuse)
+ (start-filesystem filesystem fd)
(c-close fd)))
(c-close fd)))
(catch Exception e
(.printStackTrace e)
nil)))
+(defn linux-mount
+ [filesystem mountpoint]
+ (try
+ (let [sv (Memory. 8)]
+ (socketpair pf-unix sock-stream 0 sv)
+ (let [sock0 (.getInt sv 0)
+ sock1 (.getInt sv 4)
+ _ (.println *err* (str "socket pair " sock0 " " sock1))
+ pid (IntByReference.)
+ ret (posix_spawnp pid "fusermount" nil nil
+ ["fusermount" "--" mountpoint]
+ [(str "_FUSE_COMMFD=" sock0)])]
+ (.println *err* (str "spawn " ret))
+ (when (== 0 ret)
+ (let [rv (receive-fd sock1)]
+ (.println *err* (str "got fd " rv))
+ (start-filesystem filesystem rv)))))
+ (catch Exception e
+ (.printStackTrace e)
+ nil)))
diff --git a/src/clojure/foofs/fuse/jna.clj b/src/clojure/foofs/fuse/jna.clj
index 00bfe6b..7a62be9 100644
--- a/src/clojure/foofs/fuse/jna.clj
+++ b/src/clojure/foofs/fuse/jna.clj
@@ -97,7 +97,7 @@
[(int32_t domain) (int32_t type) (int32_t protocol) sv])
(def-jna recvmsg ["c" "recvmsg" Function/THROW_LAST_ERROR]
- [sockfd, msg, flags]
+ [sockfd msg flags]
(assert-args recvmsg
(integer? sockfd) "sockfd is an integer"
(pointer? msg) "msg is a pointer"
@@ -115,6 +115,17 @@
(every? string? envp) "envp is a sequence of Strings")
[pid path file_actions attrp (into-array argv) (into-array envp)])
+(def-jna posix_spawnp ["c" "posix_spawnp"]
+ [pid file file_actions attrp argv envp]
+ (assert-args posix_spawn
+ (instance? IntByReference pid) "pid is an IntByReference"
+ (string? file) "file is a string"
+ (pointer? file_actions) "file_actions is a Pointer"
+ (pointer? attrp) "attrp is a Pointer"
+ (every? string? argv) "argv is a sequence of Strings"
+ (every? string? envp) "envp is a sequence of Strings")
+ [pid file file_actions attrp (into-array argv) (into-array envp)])
+
(def-jna waitpid ["c" "waitpid" Function/THROW_LAST_ERROR]
[pid stat_loc options]
(assert-args waitpid
@@ -128,7 +139,10 @@
(def errno-noent 2)
(def errno-inval 22)
(def errno-nosys 38)
- (def errno-proto 71)))
+ (def errno-proto 71)
+ (def pf-unix 1)
+ (def sock-stream 1)
+ (def scm-rights 1)))
(when (Platform/isFreeBSD)
(do
@@ -174,3 +188,23 @@
(def stat-type-socket 0140000)
(def stat-type-whiteout 0160000)
(def stat-type-mask 0170000)
+
+(defn receive-fd
+ [sockfd]
+ (let [msg (Memory. 28)
+ iov (Memory. 8)
+ buf (Memory. 1)
+ ccmsg (Memory. 16)]
+ (.setPointer iov 0 buf)
+ (.setInt iov 4 1)
+ (.setPointer msg 8 iov)
+ (.setInt msg 12 (.size iov))
+ (.setPointer msg 16 ccmsg)
+ (.setInt msg 20 (.size ccmsg))
+ (try
+ (recvmsg sockfd msg 0)
+ (when (== scm-rights (.getInt ccmsg 8))
+ (.getInt ccmsg 12))
+ (catch Exception e
+ (.printStackTrace e)
+ nil))))