blob: 3ff3be62fab80144cc3a9ac3d8c6bafeccd3cbeb [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/** Credentials for an operation, these are determined by the fsuid
25 and fsgid of the calling process */
Miklos Szeredia181e612001-11-06 12:03:23 +000026struct fuse_cred {
27 uid_t uid;
28 gid_t gid;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000029 /* FIXME: supplementary groups should also be included */
Miklos Szeredi552c2812001-11-08 14:56:53 +000030 /* (And capabilities???) */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000031};
32
Miklos Szeredi2df1c042001-11-06 15:07:17 +000033/**
34 * The file system operations:
35 *
36 * Most of these should work very similarly to the well known UNIX
37 * file system operations. Exceptions are:
38 *
39 * - All operations get a fuse_cred structure by which the filesystem
40 * implementation can check, whether the operation is permitted or
41 * not.
42 *
43 * - All operations should return the negated error value (-errno) on
44 * error.
45 *
46 * - readlink() should fill the buffer with a null terminated string.
47 * The buffer size argument includes the space for the terminating
48 * null character. If the linkname is too long to fit in the buffer,
49 * it should be truncated. The return value should be 0 for success.
50 *
51 * - getdir() is the opendir(), readdir(), ..., closedir() sequence
52 * in one call. For each directory entry the filldir parameter should
53 * be called.
54 *
55 * - There is no create() operation, mknod() will be called for
56 * creation of all non directory, non symlink nodes.
57 *
58 * - open() should not return a filehandle, but 0 on success. No
59 * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be
60 * passed to open(). Open should only check if the operation is
61 * permitted for the given flags.
62 *
63 * - read(), write() are not passed a filehandle, but rather a
64 * pathname. The offset of the read and write is passed as the last
65 * argument, like the pread() and pwrite() system calls. */
Miklos Szeredia181e612001-11-06 12:03:23 +000066struct fuse_operations {
67 int (*getattr) (struct fuse_cred *, const char *, struct stat *);
68 int (*readlink) (struct fuse_cred *, const char *, char *, size_t);
69 int (*getdir) (struct fuse_cred *, const char *, fuse_dirh_t, fuse_dirfil_t);
70 int (*mknod) (struct fuse_cred *, const char *, mode_t, dev_t);
71 int (*mkdir) (struct fuse_cred *, const char *, mode_t);
72 int (*unlink) (struct fuse_cred *, const char *);
73 int (*rmdir) (struct fuse_cred *, const char *);
74 int (*symlink) (struct fuse_cred *, const char *, const char *);
75 int (*rename) (struct fuse_cred *, const char *, const char *);
76 int (*link) (struct fuse_cred *, const char *, const char *);
77 int (*chmod) (struct fuse_cred *, const char *, mode_t);
78 int (*chown) (struct fuse_cred *, const char *, uid_t, gid_t);
79 int (*truncate) (struct fuse_cred *, const char *, off_t);
80 int (*utime) (struct fuse_cred *, const char *, struct utimbuf *);
81 int (*open) (struct fuse_cred *, const char *, int);
82 int (*read) (struct fuse_cred *, const char *, char *, size_t, off_t);
83 int (*write) (struct fuse_cred *, const char *, const char *, size_t, off_t);
84};
85
Miklos Szeredi2df1c042001-11-06 15:07:17 +000086/* FUSE flags: */
Miklos Szeredic0938ea2001-11-07 12:35:06 +000087
88/** Process requests in multiple threads */
Miklos Szeredia181e612001-11-06 12:03:23 +000089#define FUSE_MULTITHREAD (1 << 0)
90
Miklos Szeredic0938ea2001-11-07 12:35:06 +000091/** Enable debuging output */
92#define FUSE_DEBUG (1 << 1)
93
Miklos Szeredi2df1c042001-11-06 15:07:17 +000094/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +000095 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000096 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +000097 * @param fd the control file descriptor
Miklos Szeredi2df1c042001-11-06 15:07:17 +000098 * @param flags any combination of the FUSE flags defined above, or 0
Miklos Szeredi2df1c042001-11-06 15:07:17 +000099 * @return the created FUSE handle
100 */
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000101struct fuse *fuse_new(int fd, int flags);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000102
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000103/**
104 * Set the filesystem operations.
105 *
106 * Operations which are initialised to NULL will return ENOSYS to the
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000107 * calling process.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000108 *
109 * @param f the FUSE handle
110 * @param op the operations
111 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000112void fuse_set_operations(struct fuse *f, const struct fuse_operations *op);
113
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000114/**
115 * FUSE event loop.
116 *
117 * Requests from the kernel are processed, and the apropriate
118 * operations are called.
119 *
120 * @param f the FUSE handle
121 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000122void fuse_loop(struct fuse *f);
123
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000124/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000125 * Destroy the FUSE handle.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000126 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000127 * The filesystem is not unmounted.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000128 *
129 * @param f the FUSE handle
130 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000131void fuse_destroy(struct fuse *f);