Add test target for figfs_test.
[figfs.git] / fuse / Fuse.ml
blob8b4d05a9b800cfff1c538f304caf1b70f3cf4af4
1 (*
2 This file is part of the "OCamlFuse" library.
4 OCamlFuse is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation (version 2 of the License).
8 OCamlFuse is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with OCamlFuse. See the file LICENSE. If you haven't received
15 a copy of the GNU General Public License, write to:
17 Free Software Foundation, Inc.,
18 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA
21 Vincenzo Ciancia
23 applejack@users.sf.net
24 vincenzo_ml@yahoo.it
27 open Fuse_lib
29 type buffer = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
31 type context = Fuse_bindings.__fuse_context
33 let get_context : unit -> context = Fuse_bindings.fuse_get_context
35 type xattr_flags = AUTO | CREATE | REPLACE
37 type statfs =
39 f_bsize : int64;
40 f_blocks : int64;
41 f_bfree : int64;
42 f_bavail : int64;
43 f_files : int64;
44 f_ffree : int64;
45 f_namelen : int64;
48 type operations =
50 getattr : string -> Unix.LargeFile.stats;
51 readlink : string -> string;
52 readdir : string -> int -> string list;
53 opendir : string -> Unix.open_flag list -> int option;
54 releasedir : string -> Unix.open_flag list -> int -> unit;
55 fsyncdir : string -> bool -> int -> unit;
56 mknod : string -> int -> unit;
57 mkdir : string -> int -> unit;
58 unlink : string -> unit;
59 rmdir : string -> unit;
60 symlink : string -> string -> unit;
61 rename : string -> string -> unit;
62 link : string -> string -> unit;
63 chmod : string -> int -> unit;
64 chown : string -> int -> int -> unit;
65 truncate : string -> int64 -> unit;
66 utime : string -> float -> float -> unit;
67 fopen : string -> Unix.open_flag list -> int option;
68 read : string -> buffer -> int64 -> int -> int;
69 write : string -> buffer -> int64 -> int -> int;
70 release : string -> Unix.open_flag list -> int -> unit;
71 flush : string -> int -> unit;
72 statfs : string -> statfs;
73 fsync : string -> bool -> int -> unit;
74 listxattr : string -> string list;
75 getxattr : string -> string -> string;
76 setxattr : string -> string -> string -> xattr_flags -> unit;
77 removexattr : string -> string -> unit;
80 let op_names_of_operations ops =
82 Fuse_bindings.getattr = Fuse_lib.named_op ops.getattr;
83 Fuse_bindings.readlink = Fuse_lib.named_op ops.readlink;
84 Fuse_bindings.readdir = Fuse_lib.named_op_2 ops.readdir;
85 Fuse_bindings.opendir = Fuse_lib.named_op_2 ops.opendir;
86 Fuse_bindings.releasedir = Fuse_lib.named_op_3 ops.releasedir;
87 Fuse_bindings.fsyncdir = Fuse_lib.named_op_3 ops.fsyncdir;
88 Fuse_bindings.mknod = Fuse_lib.named_op_2 ops.mknod;
89 Fuse_bindings.mkdir = Fuse_lib.named_op_2 ops.mkdir;
90 Fuse_bindings.unlink = Fuse_lib.named_op ops.unlink;
91 Fuse_bindings.rmdir = Fuse_lib.named_op ops.rmdir;
92 Fuse_bindings.symlink = Fuse_lib.named_op_2 ops.symlink;
93 Fuse_bindings.rename = Fuse_lib.named_op_2 ops.rename;
94 Fuse_bindings.link = Fuse_lib.named_op_2 ops.link;
95 Fuse_bindings.chmod = Fuse_lib.named_op_2 ops.chmod;
96 Fuse_bindings.chown = Fuse_lib.named_op_3 ops.chown;
97 Fuse_bindings.truncate = Fuse_lib.named_op_2 ops.truncate;
98 Fuse_bindings.utime = Fuse_lib.named_op_3 ops.utime;
99 Fuse_bindings.fopen = Fuse_lib.named_op_2 ops.fopen;
100 Fuse_bindings.read = Fuse_lib.named_op_4 ops.read;
101 Fuse_bindings.write = Fuse_lib.named_op_4 ops.write;
102 Fuse_bindings.release = Fuse_lib.named_op_3 ops.release;
103 Fuse_bindings.flush = Fuse_lib.named_op_2 ops.flush;
104 Fuse_bindings.statfs = Fuse_lib.named_op ops.statfs;
105 Fuse_bindings.fsync = Fuse_lib.named_op_3 ops.fsync;
106 Fuse_bindings.listxattr = Fuse_lib.named_op
107 (fun path ->
108 let s = ops.listxattr path in
109 (s,List.fold_left
110 (fun acc s ->
111 acc + 1 + (String.length s))
112 0 s));
113 Fuse_bindings.getxattr = Fuse_lib.named_op_2 ops.getxattr;
114 Fuse_bindings.setxattr = Fuse_lib.named_op_4 ops.setxattr;
115 Fuse_bindings.removexattr = Fuse_lib.named_op_2 ops.removexattr;
118 let default_operations =
120 getattr = undefined;
121 readdir = undefined;
122 opendir = undefined;
123 releasedir = undefined;
124 fsyncdir = undefined;
125 readlink = undefined;
126 mknod = undefined;
127 mkdir = undefined;
128 unlink = undefined;
129 rmdir = undefined;
130 symlink = undefined;
131 rename = undefined;
132 link = undefined;
133 chmod = undefined;
134 chown = undefined;
135 truncate = undefined;
136 utime = undefined;
137 fopen = undefined;
138 read = undefined;
139 write = undefined;
140 flush = undefined;
141 release = undefined;
142 statfs = undefined;
143 fsync = undefined;
144 listxattr = undefined;
145 getxattr = undefined;
146 setxattr = undefined;
147 removexattr = undefined;
150 let main argv ops =
151 Fuse_bindings.ml_fuse_init ();
152 Fuse_bindings.set_fuse_operations (op_names_of_operations ops);
153 Fuse_bindings.ml_fuse_main argv (Fuse_bindings.get_fuse_operations ())