xref: /haiku/src/add-ons/kernel/file_systems/ntfs/kernel_interface.cpp (revision be3db2942c0e8dda63cdd226ec3c99309d3eab0c)
1 /* kernel_interface - file system interface to Haiku's vnode layer
2  *
3  * Copyright (c) 2006 Troeglazov Gerasim (3dEyes**)
4  *
5  * This program/include file is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program/include file is distributed in the hope that it will be
11  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program (in the main directory of the Linux-NTFS
17  * distribution in the file COPYING); if not, write to the Free Software
18  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 
21 
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <errno.h>
26 #include <string.h>
27 #include <ctype.h>
28 #include <stdio.h>
29 #include <dirent.h>
30 #include <sys/stat.h>
31 #include <time.h>
32 #include <lock.h>
33 #include <malloc.h>
34 #include <stdio.h>
35 
36 #include <ByteOrder.h>
37 #include <fs_info.h>
38 #include <KernelExport.h>
39 
40 #include <NodeMonitor.h>
41 
42 #include <fs_interface.h>
43 #include <fs_cache.h>
44 #include <fs_attr.h>
45 #include <fs_info.h>
46 #include <fs_index.h>
47 #include <fs_query.h>
48 #include <fs_volume.h>
49 
50 #include <util/kernel_cpp.h>
51 
52 
53 extern "C"{
54 
55  status_t	fs_mount( mount_id nsid, const char *device, ulong flags, const char *args, void **data, vnode_id *vnid );
56  status_t	fs_unmount(void *_ns);
57  status_t	fs_rfsstat(void *_ns, struct fs_info *);
58  status_t  	fs_wfsstat(void *_vol, const struct fs_info *fss, uint32 mask);
59  status_t 	fs_sync(void *_ns);
60  status_t	fs_walk(void *_ns, void *_base, const char *file, vnode_id *vnid,int *_type);
61  status_t	fs_get_vnode_name(void *_ns, void *_node, char *buffer, size_t bufferSize);
62  status_t	fs_read_vnode(void *_ns, vnode_id vnid, void **_node, bool reenter);
63  status_t	fs_write_vnode(void *_ns, void *_node, bool reenter);
64  status_t   fs_remove_vnode( void *_ns, void *_node, bool reenter );
65  status_t	fs_access( void *ns, void *node, int mode );
66  status_t	fs_rstat(void *_ns, void *_node, struct stat *st);
67  status_t 	fs_wstat(void *_vol, void *_node, const struct stat *st, uint32 mask);
68  status_t   fs_create(void *_ns, void *_dir, const char *name, int omode, int perms, void **_cookie, vnode_id *_vnid);
69  status_t	fs_open(void *_ns, void *_node, int omode, void **cookie);
70  status_t	fs_close(void *ns, void *node, void *cookie);
71  status_t	fs_free_cookie(void *ns, void *node, void *cookie);
72  status_t	fs_read(void *_ns, void *_node, void *cookie, off_t pos, void *buf, size_t *len);
73  status_t	fs_write(void *ns, void *node, void *cookie, off_t pos, const void *buf, size_t *len);
74  status_t	fs_mkdir(void *_ns, void *_node, const char *name,	int perms, vnode_id *_vnid);
75  status_t 	fs_rmdir(void *_ns, void *dir, const char *name);
76  status_t	fs_opendir(void* _ns, void* _node, void** cookie);
77  status_t   fs_readdir( void *_ns, void *_node, void *_cookie, struct dirent *buf, size_t bufsize, uint32 *num );
78  status_t	fs_rewinddir(void *_ns, void *_node, void *cookie);
79  status_t	fs_closedir(void *_ns, void *_node, void *cookie);
80  status_t	fs_free_dircookie(void *_ns, void *_node, void *cookie);
81  status_t 	fs_readlink(void *_ns, void *_node, char *buf, size_t *bufsize);
82  status_t 	fs_fsync(void *_ns, void *_node);
83 
84  status_t   fs_rename(void *_ns, void *_odir, const char *oldname, void *_ndir, const char *newname);
85  status_t   fs_unlink(void *_ns, void *_node, const char *name);
86  status_t	fs_create_symlink(void *_ns, void *_dir, const char *name, const char *target, int mode);
87 
88  status_t 	fs_open_attrib_dir(void *_vol, void *_node, void **_cookie);
89  status_t 	fs_close_attrib_dir(void *_vol, void *_node, void *_cookie);
90  status_t 	fs_free_attrib_dir_cookie(void *_vol, void *_node, void *_cookie);
91  status_t 	fs_rewind_attrib_dir(void *_vol, void *_node, void *_cookie);
92  status_t 	fs_read_attrib_dir(void *_vol, void *_node, void *_cookie, struct dirent *buf, size_t bufsize, uint32 *num);
93  status_t 	fs_open_attrib(void *_vol, void *_node, const char *name, int openMode,fs_cookie *_cookie);
94  status_t 	fs_close_attrib(void *_vol, void *_node, fs_cookie cookie);
95  status_t 	fs_free_attrib_cookie(void *_vol, void *_node, fs_cookie cookie);
96  status_t 	fs_read_attrib_stat(void *_vol, void *_node, fs_cookie _cookie, struct stat *stat);
97  status_t 	fs_read_attrib(void *_vol, void *_node, fs_cookie _cookie, off_t pos,void *buffer, size_t *_length);
98  status_t 	fs_write_attrib(void *_vol, void *_node, fs_cookie _cookie, off_t pos,	const void *buffer, size_t *_length);
99 
100  void 		fs_free_identify_partition_cookie(partition_data *partition, void *_cookie);
101  status_t	fs_scan_partition(int fd, partition_data *partition, void *_cookie);
102  float		fs_identify_partition(int fd, partition_data *partition, void **_cookie);
103 };
104 
105 
106 static status_t
107 ntfs_std_ops(int32 op, ...)
108 {
109 	switch (op) {
110 		case B_MODULE_INIT:
111 			return B_OK;
112 		case B_MODULE_UNINIT:
113 			return B_OK;
114 		default:
115 			return B_ERROR;
116 	}
117 }
118 
119 
120 static file_system_module_info sNTFSFileSystem = {
121 	{
122 		"file_systems/ntfs" B_CURRENT_FS_API_VERSION,
123 		0,
124 		ntfs_std_ops,
125 	},
126 
127 	"ntfs File System",
128 
129 	// scanning
130 	fs_identify_partition,
131 	fs_scan_partition,
132 	fs_free_identify_partition_cookie,
133 	NULL,	// free_partition_content_cookie()
134 
135 	&fs_mount,
136 	&fs_unmount,
137 	&fs_rfsstat,
138 #ifdef _READ_ONLY_
139 	NULL,
140 #else
141 	&fs_wfsstat,
142 #endif
143 	NULL,
144 
145 	/* vnode operations */
146 	&fs_walk,
147 	&fs_get_vnode_name,
148 	&fs_read_vnode,
149 	&fs_write_vnode,
150 #ifdef _READ_ONLY_
151 	NULL,
152 #else
153 	&fs_remove_vnode,
154 #endif
155 
156 	/* VM file access */
157 	NULL, 	// &fs_can_page
158 	NULL,	// &fs_read_pages
159 	NULL, 	// &fs_write_pages
160 
161 	NULL,	// &fs_get_file_map
162 
163 	NULL, 	// &fs_ioctl
164 	NULL, 	// &fs_set_flags
165 	NULL,	// &fs_select
166 	NULL,	// &fs_deselect
167 
168 #ifdef _READ_ONLY_
169 	NULL,
170 #else
171 	&fs_fsync,
172 #endif
173 
174 	&fs_readlink,
175 
176 #ifdef _READ_ONLY_
177 	NULL,
178 	NULL,
179 	NULL,
180 	NULL,
181 	NULL,
182 #else
183 	NULL,	// write link
184 	&fs_create_symlink,
185 	NULL, 	// &fs_link,
186 	&fs_unlink,
187 	&fs_rename,
188 #endif
189 
190 	&fs_access,
191 	&fs_rstat,
192 #ifdef _READ_ONLY_
193 	NULL,
194 #else
195 	&fs_wstat,
196 #endif
197 
198 	/* file operations */
199 #ifdef _READ_ONLY_
200 	NULL,
201 #else
202 	&fs_create,
203 #endif
204 	&fs_open,
205 	&fs_close,
206 	&fs_free_cookie,
207 	&fs_read,
208 #ifdef _READ_ONLY_
209 	NULL,
210 #else
211 	&fs_write,
212 #endif
213 
214 	/* directory operations */
215 #ifdef _READ_ONLY_
216 	NULL,
217 	NULL,
218 #else
219 	&fs_mkdir,
220 	&fs_rmdir,
221 #endif
222 	&fs_opendir,
223 	&fs_closedir,
224 	&fs_free_dircookie,
225 	&fs_readdir,
226 	&fs_rewinddir,
227 
228 	/* attribute directory operations */
229 	&fs_open_attrib_dir,
230 	&fs_close_attrib_dir,
231 	&fs_free_attrib_dir_cookie,
232 	&fs_read_attrib_dir,
233 	&fs_rewind_attrib_dir,
234 
235 	/* attribute operations */
236 	NULL,	//&fs_create_attr,
237 	&fs_open_attrib,
238 	&fs_close_attrib,
239 	&fs_free_attrib_cookie,
240 	&fs_read_attrib,
241 	&fs_write_attrib,
242 
243 	&fs_read_attrib_stat,
244 	NULL,	//&fs_write_attr_stat,
245 	NULL,	//&fs_rename_attr,
246 	NULL,	//&fs_remove_attr,
247 
248 	/* index directory & index operations */
249 	NULL,	// &fs_open_index_dir
250 	NULL,	// &fs_close_index_dir
251 	NULL,	// &fs_free_index_dir_cookie
252 	NULL,	// &fs_read_index_dir
253 	NULL,	// &fs_rewind_index_dir
254 
255 	NULL,	// &fs_create_index
256 	NULL,	// &fs_remove_index
257 	NULL,	// &fs_stat_index
258 
259 	/* query operations */
260 	NULL,	// &fs_open_query
261 	NULL,	// &fs_close_query
262 	NULL,	// &fs_free_query_cookie
263 	NULL,	// &fs_read_query
264 	NULL,	// &fs_rewind_query
265 };
266 
267 module_info *modules[] = {
268 	(module_info *)&sNTFSFileSystem,
269 	NULL,
270 };
271