blob: abdb45b139027a1f7496433d93140224796110f6 [file] [log] [blame]
Miklos Szeredi85c74fc2001-10-28 19:44:14 +00001/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001 Miklos Szeredi (mszeredi@inf.bme.hu)
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
9/* This file defines the library interface of FUSE */
10
11#include <sys/types.h>
12#include <sys/stat.h>
Miklos Szeredi5e183482001-10-31 14:52:35 +000013#include <utime.h>
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000014
Miklos Szeredi2df1c042001-11-06 15:07:17 +000015/** Handle for a FUSE filesystem */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000016struct fuse;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000017
18/** Handle for a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000019typedef struct fuse_dirhandle *fuse_dirh_t;
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000020
Miklos Szeredi2df1c042001-11-06 15:07:17 +000021/** Function to add an entry in a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000022typedef int (*fuse_dirfil_t) (fuse_dirh_t, const char *, int type);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000023
Miklos Szeredi2df1c042001-11-06 15:07:17 +000024/**
25 * The file system operations:
26 *
27 * Most of these should work very similarly to the well known UNIX
28 * file system operations. Exceptions are:
29 *
Miklos Szeredi2df1c042001-11-06 15:07:17 +000030 * - All operations should return the negated error value (-errno) on
31 * error.
32 *
Miklos Szeredi05033042001-11-13 16:11:35 +000033 * - Getattr() doesn't need to fill in the following fields:
34 * st_ino
35 * st_dev
36 * st_blksize
37 *
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000038 * - readlink() should fill the buffer with a null terminated string. The
39 * buffer size argument includes the space for the terminating null
40 * character. If the linkname is too long to fit in the buffer, it should
41 * be truncated. The return value should be 0 for success.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000042 *
43 * - getdir() is the opendir(), readdir(), ..., closedir() sequence
44 * in one call. For each directory entry the filldir parameter should
45 * be called.
46 *
47 * - There is no create() operation, mknod() will be called for
48 * creation of all non directory, non symlink nodes.
49 *
50 * - open() should not return a filehandle, but 0 on success. No
51 * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be
52 * passed to open(). Open should only check if the operation is
53 * permitted for the given flags.
54 *
55 * - read(), write() are not passed a filehandle, but rather a
56 * pathname. The offset of the read and write is passed as the last
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000057 * argument, like the pread() and pwrite() system calls.
58 */
Miklos Szeredia181e612001-11-06 12:03:23 +000059struct fuse_operations {
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000060 int (*getattr) (const char *, struct stat *);
61 int (*readlink) (const char *, char *, size_t);
62 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
63 int (*mknod) (const char *, mode_t, dev_t);
64 int (*mkdir) (const char *, mode_t);
65 int (*unlink) (const char *);
66 int (*rmdir) (const char *);
67 int (*symlink) (const char *, const char *);
68 int (*rename) (const char *, const char *);
69 int (*link) (const char *, const char *);
70 int (*chmod) (const char *, mode_t);
71 int (*chown) (const char *, uid_t, gid_t);
72 int (*truncate) (const char *, off_t);
73 int (*utime) (const char *, struct utimbuf *);
74 int (*open) (const char *, int);
75 int (*read) (const char *, char *, size_t, off_t);
76 int (*write) (const char *, const char *, size_t, off_t);
Miklos Szeredia181e612001-11-06 12:03:23 +000077};
78
Miklos Szeredi2df1c042001-11-06 15:07:17 +000079/* FUSE flags: */
Miklos Szeredic0938ea2001-11-07 12:35:06 +000080
Miklos Szeredic0938ea2001-11-07 12:35:06 +000081/** Enable debuging output */
82#define FUSE_DEBUG (1 << 1)
83
Miklos Szeredi2df1c042001-11-06 15:07:17 +000084/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +000085 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000086 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +000087 * @param fd the control file descriptor
Miklos Szeredi2df1c042001-11-06 15:07:17 +000088 * @param flags any combination of the FUSE flags defined above, or 0
Miklos Szeredi2df1c042001-11-06 15:07:17 +000089 * @return the created FUSE handle
90 */
Miklos Szeredi8cffdb92001-11-09 14:49:18 +000091struct fuse *fuse_new(int fd, int flags);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000092
Miklos Szeredi2df1c042001-11-06 15:07:17 +000093/**
94 * Set the filesystem operations.
95 *
96 * Operations which are initialised to NULL will return ENOSYS to the
Miklos Szeredi8cffdb92001-11-09 14:49:18 +000097 * calling process.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000098 *
99 * @param f the FUSE handle
100 * @param op the operations
101 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000102void fuse_set_operations(struct fuse *f, const struct fuse_operations *op);
103
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000104/**
105 * FUSE event loop.
106 *
107 * Requests from the kernel are processed, and the apropriate
108 * operations are called.
109 *
110 * @param f the FUSE handle
111 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000112void fuse_loop(struct fuse *f);
113
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000114/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000115 * FUSE event loop with multiple threads
116 *
117 * Requests from the kernel are processed, and the apropriate
118 * operations are called. Request are processed in parallel by
119 * distributing them between multiple threads.
120 *
121 * Calling this function requires the pthreads library to be linked to
122 * the application.
123 *
124 * @param f the FUSE handle
125 */
126void fuse_loop_mt(struct fuse *f);
127
128/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000129 * Destroy the FUSE handle.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000130 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000131 * The filesystem is not unmounted.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000132 *
133 * @param f the FUSE handle
134 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000135void fuse_destroy(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000136
137
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000138/* ----------------------------------------------------------- *
139 * Advanced API for event handling, don't worry about this... *
140 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000141
142struct fuse_cmd;
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000143typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000144struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000145void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000146void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
147