xref: /haiku/headers/os/drivers/fs_interface.h (revision 80a9c4f4c3c4b5e4b42c8309d174fdaf3b04b129)
1 /* File System Interface Layer Definition
2 **
3 ** Distributed under the terms of the OpenBeOS License.
4 */
5 
6 #ifndef _FS_INTERFACE_H
7 #define _FS_INTERFACE_H
8 
9 #include <ktypes.h>
10 #include <vfs_types.h>
11 #include <OS.h>
12 
13 struct dirent;
14 struct stat;
15 struct fs_info;
16 
17 typedef dev_t mount_id;
18 typedef ino_t vnode_id;
19 
20 /* the file system's private data structures */
21 typedef void *fs_volume;
22 typedef void *fs_cookie;
23 typedef void *fs_vnode;
24 
25 /* passed to write_stat() */
26 enum write_stat_mask {
27 	FS_WRITE_STAT_MODE		= 0x0001,
28 	FS_WRITE_STAT_UID		= 0x0002,
29 	FS_WRITE_STAT_GID		= 0x0004,
30 	FS_WRITE_STAT_SIZE		= 0x0008,
31 	FS_WRITE_STAT_ATIME		= 0x0010,
32 	FS_WRITE_STAT_MTIME		= 0x0020,
33 	FS_WRITE_STAT_CRTIME	= 0x0040
34 };
35 
36 /* passed to write_fs_info() */
37 #define	FS_WRITE_FSINFO_NAME	0x0001
38 
39 #define	B_CURRENT_FS_API_VERSION 1
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 typedef struct fs_ops {
46 	/* general operations */
47 	status_t (*mount)(mount_id id, const char *device, void *args, fs_volume *_fs, vnode_id *_rootVnodeID);
48 	status_t (*unmount)(fs_volume fs);
49 
50 	status_t (*read_fs_info)(fs_volume fs, struct fs_info *info);
51 	status_t (*write_fs_info)(fs_volume fs, const struct fs_info *info, int mask);
52 	status_t (*sync)(fs_volume fs);
53 
54 	/* vnode operations */
55 	status_t (*lookup)(fs_volume fs, fs_vnode dir, const char *name, vnode_id *_id, int *_type);
56 	status_t (*get_vnode_name)(fs_volume fs, fs_vnode vnode, char *buffer, size_t bufferSize);
57 
58 	status_t (*get_vnode)(fs_volume fs, vnode_id id, fs_vnode *_vnode, bool reenter);
59 	status_t (*put_vnode)(fs_volume fs, fs_vnode vnode, bool reenter);
60 	status_t (*remove_vnode)(fs_volume fs, fs_vnode vnode, bool reenter);
61 
62 	/* VM file access */
63 	status_t (*can_page)(fs_volume fs, fs_vnode v);
64 	ssize_t (*read_pages)(fs_volume fs, fs_vnode v, iovecs *vecs, off_t pos);
65 	ssize_t (*write_pages)(fs_volume fs, fs_vnode v, iovecs *vecs, off_t pos);
66 
67 	/* common operations */
68 	status_t (*ioctl)(fs_volume fs, fs_vnode v, fs_cookie cookie, ulong op, void *buffer, size_t length);
69 	status_t (*fsync)(fs_volume fs, fs_vnode v);
70 
71 	status_t (*read_link)(fs_volume fs, fs_vnode link, char *buffer, size_t bufferSize);
72 	status_t (*write_link)(fs_volume fs, fs_vnode link, char *toPath);
73 	status_t (*create_symlink)(fs_volume fs, fs_vnode dir, const char *name, const char *path, int mode);
74 
75 	status_t (*link)(fs_volume fs, fs_vnode dir, const char *name, fs_vnode vnode);
76 	status_t (*unlink)(fs_volume fs, fs_vnode dir, const char *name);
77 	status_t (*rename)(fs_volume fs, fs_vnode fromDir, const char *fromName, fs_vnode toDir, const char *toName);
78 
79 	status_t (*access)(fs_volume fs, fs_vnode vnode, int mode);
80 	status_t (*read_stat)(fs_volume fs, fs_vnode vnode, struct stat *stat);
81 	status_t (*write_stat)(fs_volume fs, fs_vnode vnode, const struct stat *stat, int statMask);
82 
83 	/* file operations */
84 	status_t (*create)(fs_volume fs, fs_vnode dir, const char *name, int openMode, int perms, fs_cookie *_cookie, vnode_id *_newVnodeID);
85 	status_t (*open)(fs_volume fs, fs_vnode v, int openMode, fs_cookie *_cookie);
86 	status_t (*close)(fs_volume fs, fs_vnode v, fs_cookie cookie);
87 	status_t (*free_cookie)(fs_volume fs, fs_vnode v, fs_cookie cookie);
88 	ssize_t (*read)(fs_volume fs, fs_vnode v, fs_cookie cookie, off_t pos, void *buffer, size_t *length);
89 	ssize_t (*write)(fs_volume fs, fs_vnode v, fs_cookie cookie, off_t pos, const void *buffer, size_t *length);
90 
91 	/* directory operations */
92 	status_t (*create_dir)(fs_volume fs, fs_vnode parent, const char *name, int perms, vnode_id *_newVnodeID);
93 	status_t (*remove_dir)(fs_volume fs, fs_vnode parent, const char *name);
94 	status_t (*open_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie);
95 	status_t (*close_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
96 	status_t (*free_dir_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
97 	status_t (*read_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
98 	status_t (*rewind_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
99 
100 	/* attribute directory operations */
101 	status_t (*open_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie);
102 	status_t (*close_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
103 	status_t (*free_attr_dir_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
104 	status_t (*read_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
105 	status_t (*rewind_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
106 
107 	/* attribute operations */
108 	status_t (*create_attr)(fs_volume fs, fs_vnode file, const char *name, uint32 type, int openMode, fs_cookie *_cookie);
109 	status_t (*open_attr)(fs_volume fs, fs_vnode file, const char *name, int openMode, fs_cookie *_cookie);
110 	status_t (*close_attr)(fs_volume fs, fs_vnode file, fs_cookie cookie);
111 	status_t (*free_attr_cookie)(fs_volume fs, fs_vnode file, fs_cookie cookie);
112 	ssize_t (*read_attr)(fs_volume fs, fs_vnode file, fs_cookie cookie, off_t pos, void *buffer, size_t *len);
113 	ssize_t (*write_attr)(fs_volume fs, fs_vnode file, fs_cookie cookie, off_t pos, const void *buffer, size_t *len);
114 
115 	status_t (*read_attr_stat)(fs_volume fs, fs_vnode file, fs_cookie cookie, struct stat *stat);
116 	status_t (*write_attr_stat)(fs_volume fs, fs_vnode file, fs_cookie cookie, const struct stat *stat, int statMask);
117 	status_t (*rename_attr)(fs_volume fs, fs_vnode fromFile, const char *fromName, fs_vnode toFile, const char *toName);
118 	status_t (*remove_attr)(fs_volume fs, fs_vnode file, const char *name);
119 
120 	/* index directory & index operations */
121 	status_t (*open_index_dir)(fs_volume fs, fs_cookie *cookie);
122 	status_t (*close_index_dir)(fs_volume fs, fs_cookie cookie);
123 	status_t (*free_index_dir_cookie)(fs_volume fs, fs_cookie cookie);
124 	status_t (*read_index_dir)(fs_volume fs, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
125 	status_t (*rewind_index_dir)(fs_volume fs, fs_cookie cookie);
126 
127 	status_t (*create_index)(fs_volume fs, const char *name, uint32 type, uint32 flags);
128 	status_t (*remove_index)(fs_volume fs, const char *name);
129 	status_t (*read_index_stat)(fs_volume fs, const char *name, struct stat *stat);
130 
131 	/* query operations */
132 	status_t (*open_query)(fs_volume fs, const char *query, uint32 flags, port_id port, uint32 token, fs_cookie *_cookie);
133 	status_t (*close_query)(fs_volume fs, fs_cookie cookie);
134 	status_t (*free_query_cookie)(fs_volume fs, fs_cookie cookie);
135 	status_t (*read_query)(fs_volume fs, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
136 	status_t (*rewind_query)(fs_volume fs, fs_cookie cookie);
137 } fs_ops;
138 
139 
140 /* variables exported by the file system add-on */
141 extern fs_ops	fs_entry;
142 extern int32	api_version;
143 
144 /* file system add-ons only prototypes */
145 extern status_t notify_listener(int op, mount_id device, vnode_id parentNode,
146 					vnode_id toParentNode, vnode_id node, const char *name);
147 extern status_t send_notification(port_id port, long token, ulong what, long op,
148 					mount_id device, mount_id toDevice, vnode_id parentNode,
149 					vnode_id toParentNode, vnode_id node, const char *name);
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
155 #endif	/* _FS_INTERFACE_H */
156