ntfs_vfsops.c revision 1.97 1 1.97 hannken /* $NetBSD: ntfs_vfsops.c,v 1.97 2014/11/13 16:51:53 hannken Exp $ */
2 1.1 jdolecek
3 1.1 jdolecek /*-
4 1.1 jdolecek * Copyright (c) 1998, 1999 Semen Ustimenko
5 1.1 jdolecek * All rights reserved.
6 1.1 jdolecek *
7 1.1 jdolecek * Redistribution and use in source and binary forms, with or without
8 1.1 jdolecek * modification, are permitted provided that the following conditions
9 1.1 jdolecek * are met:
10 1.1 jdolecek * 1. Redistributions of source code must retain the above copyright
11 1.1 jdolecek * notice, this list of conditions and the following disclaimer.
12 1.1 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jdolecek * notice, this list of conditions and the following disclaimer in the
14 1.1 jdolecek * documentation and/or other materials provided with the distribution.
15 1.1 jdolecek *
16 1.1 jdolecek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 jdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 jdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 jdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jdolecek * SUCH DAMAGE.
27 1.1 jdolecek *
28 1.1 jdolecek * Id: ntfs_vfsops.c,v 1.7 1999/05/31 11:28:30 phk Exp
29 1.1 jdolecek */
30 1.1 jdolecek
31 1.1 jdolecek #include <sys/cdefs.h>
32 1.97 hannken __KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.97 2014/11/13 16:51:53 hannken Exp $");
33 1.1 jdolecek
34 1.1 jdolecek #include <sys/param.h>
35 1.1 jdolecek #include <sys/systm.h>
36 1.1 jdolecek #include <sys/namei.h>
37 1.1 jdolecek #include <sys/proc.h>
38 1.1 jdolecek #include <sys/kernel.h>
39 1.1 jdolecek #include <sys/vnode.h>
40 1.1 jdolecek #include <sys/mount.h>
41 1.1 jdolecek #include <sys/buf.h>
42 1.1 jdolecek #include <sys/fcntl.h>
43 1.1 jdolecek #include <sys/malloc.h>
44 1.15 atatat #include <sys/sysctl.h>
45 1.1 jdolecek #include <sys/device.h>
46 1.1 jdolecek #include <sys/conf.h>
47 1.41 elad #include <sys/kauth.h>
48 1.70 rumble #include <sys/module.h>
49 1.1 jdolecek
50 1.1 jdolecek #include <uvm/uvm_extern.h>
51 1.1 jdolecek
52 1.62 dholland #include <miscfs/genfs/genfs.h>
53 1.1 jdolecek #include <miscfs/specfs/specdev.h>
54 1.1 jdolecek
55 1.1 jdolecek #include <fs/ntfs/ntfs.h>
56 1.1 jdolecek #include <fs/ntfs/ntfs_inode.h>
57 1.1 jdolecek #include <fs/ntfs/ntfs_subr.h>
58 1.1 jdolecek #include <fs/ntfs/ntfs_vfsops.h>
59 1.1 jdolecek #include <fs/ntfs/ntfs_ihash.h>
60 1.1 jdolecek #include <fs/ntfs/ntfsmount.h>
61 1.1 jdolecek
62 1.70 rumble MODULE(MODULE_CLASS_VFS, ntfs, NULL);
63 1.70 rumble
64 1.50 pooka MALLOC_JUSTDEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure");
65 1.50 pooka MALLOC_JUSTDEFINE(M_NTFSNTNODE,"NTFS ntnode", "NTFS ntnode information");
66 1.50 pooka MALLOC_JUSTDEFINE(M_NTFSDIR,"NTFS dir", "NTFS dir buffer");
67 1.1 jdolecek
68 1.59 pooka static int ntfs_mount(struct mount *, const char *, void *, size_t *);
69 1.33 xtraeme static int ntfs_root(struct mount *, struct vnode **);
70 1.59 pooka static int ntfs_start(struct mount *, int);
71 1.59 pooka static int ntfs_statvfs(struct mount *, struct statvfs *);
72 1.59 pooka static int ntfs_sync(struct mount *, int, kauth_cred_t);
73 1.59 pooka static int ntfs_unmount(struct mount *, int);
74 1.33 xtraeme static int ntfs_vget(struct mount *mp, ino_t ino,
75 1.33 xtraeme struct vnode **vpp);
76 1.97 hannken static int ntfs_loadvnode(struct mount *, struct vnode *,
77 1.97 hannken const void *, size_t, const void **);
78 1.33 xtraeme static int ntfs_mountfs(struct vnode *, struct mount *,
79 1.36 christos struct ntfs_args *, struct lwp *);
80 1.42 martin static int ntfs_vptofh(struct vnode *, struct fid *, size_t *);
81 1.1 jdolecek
82 1.56 pooka static void ntfs_init(void);
83 1.56 pooka static void ntfs_reinit(void);
84 1.56 pooka static void ntfs_done(void);
85 1.56 pooka static int ntfs_fhtovp(struct mount *, struct fid *,
86 1.56 pooka struct vnode **);
87 1.56 pooka static int ntfs_mountroot(void);
88 1.1 jdolecek
89 1.31 yamt static const struct genfs_ops ntfs_genfsops = {
90 1.31 yamt .gop_write = genfs_compat_gop_write,
91 1.1 jdolecek };
92 1.1 jdolecek
93 1.72 rumble static struct sysctllog *ntfs_sysctl_log;
94 1.1 jdolecek
95 1.1 jdolecek static int
96 1.76 cegger ntfs_mountroot(void)
97 1.1 jdolecek {
98 1.1 jdolecek struct mount *mp;
99 1.36 christos struct lwp *l = curlwp; /* XXX */
100 1.1 jdolecek int error;
101 1.1 jdolecek struct ntfs_args args;
102 1.1 jdolecek
103 1.37 thorpej if (device_class(root_device) != DV_DISK)
104 1.1 jdolecek return (ENODEV);
105 1.1 jdolecek
106 1.1 jdolecek if ((error = vfs_rootmountalloc(MOUNT_NTFS, "root_device", &mp))) {
107 1.1 jdolecek vrele(rootvp);
108 1.1 jdolecek return (error);
109 1.1 jdolecek }
110 1.1 jdolecek
111 1.1 jdolecek args.flag = 0;
112 1.1 jdolecek args.uid = 0;
113 1.1 jdolecek args.gid = 0;
114 1.1 jdolecek args.mode = 0777;
115 1.1 jdolecek
116 1.36 christos if ((error = ntfs_mountfs(rootvp, mp, &args, l)) != 0) {
117 1.67 ad vfs_unbusy(mp, false, NULL);
118 1.69 ad vfs_destroy(mp);
119 1.1 jdolecek return (error);
120 1.1 jdolecek }
121 1.1 jdolecek
122 1.90 christos mountlist_append(mp);
123 1.59 pooka (void)ntfs_statvfs(mp, &mp->mnt_stat);
124 1.67 ad vfs_unbusy(mp, false, NULL);
125 1.1 jdolecek return (0);
126 1.1 jdolecek }
127 1.1 jdolecek
128 1.1 jdolecek static void
129 1.76 cegger ntfs_init(void)
130 1.1 jdolecek {
131 1.50 pooka
132 1.5 christos malloc_type_attach(M_NTFSMNT);
133 1.5 christos malloc_type_attach(M_NTFSNTNODE);
134 1.5 christos malloc_type_attach(M_NTFSDIR);
135 1.6 christos malloc_type_attach(M_NTFSNTVATTR);
136 1.7 christos malloc_type_attach(M_NTFSRDATA);
137 1.7 christos malloc_type_attach(M_NTFSDECOMP);
138 1.7 christos malloc_type_attach(M_NTFSRUN);
139 1.1 jdolecek ntfs_nthashinit();
140 1.1 jdolecek ntfs_toupper_init();
141 1.1 jdolecek }
142 1.1 jdolecek
143 1.1 jdolecek static void
144 1.76 cegger ntfs_reinit(void)
145 1.1 jdolecek {
146 1.1 jdolecek ntfs_nthashreinit();
147 1.1 jdolecek }
148 1.1 jdolecek
149 1.1 jdolecek static void
150 1.76 cegger ntfs_done(void)
151 1.1 jdolecek {
152 1.1 jdolecek ntfs_nthashdone();
153 1.5 christos malloc_type_detach(M_NTFSMNT);
154 1.5 christos malloc_type_detach(M_NTFSNTNODE);
155 1.5 christos malloc_type_detach(M_NTFSDIR);
156 1.6 christos malloc_type_detach(M_NTFSNTVATTR);
157 1.7 christos malloc_type_detach(M_NTFSRDATA);
158 1.7 christos malloc_type_detach(M_NTFSDECOMP);
159 1.7 christos malloc_type_detach(M_NTFSRUN);
160 1.1 jdolecek }
161 1.1 jdolecek
162 1.1 jdolecek static int
163 1.29 perry ntfs_mount (
164 1.1 jdolecek struct mount *mp,
165 1.1 jdolecek const char *path,
166 1.1 jdolecek void *data,
167 1.59 pooka size_t *data_len)
168 1.1 jdolecek {
169 1.59 pooka struct lwp *l = curlwp;
170 1.28 mycroft int err = 0, flags;
171 1.1 jdolecek struct vnode *devvp;
172 1.51 dsl struct ntfs_args *args = data;
173 1.51 dsl
174 1.94 maxv if (args == NULL)
175 1.94 maxv return EINVAL;
176 1.51 dsl if (*data_len < sizeof *args)
177 1.51 dsl return EINVAL;
178 1.1 jdolecek
179 1.1 jdolecek if (mp->mnt_flag & MNT_GETARGS) {
180 1.1 jdolecek struct ntfsmount *ntmp = VFSTONTFS(mp);
181 1.1 jdolecek if (ntmp == NULL)
182 1.1 jdolecek return EIO;
183 1.51 dsl args->fspec = NULL;
184 1.51 dsl args->uid = ntmp->ntm_uid;
185 1.51 dsl args->gid = ntmp->ntm_gid;
186 1.51 dsl args->mode = ntmp->ntm_mode;
187 1.51 dsl args->flag = ntmp->ntm_flag;
188 1.51 dsl *data_len = sizeof *args;
189 1.51 dsl return 0;
190 1.1 jdolecek }
191 1.1 jdolecek /*
192 1.1 jdolecek ***
193 1.1 jdolecek * Mounting non-root file system or updating a file system
194 1.1 jdolecek ***
195 1.1 jdolecek */
196 1.1 jdolecek
197 1.1 jdolecek /*
198 1.1 jdolecek * If updating, check whether changing from read-only to
199 1.1 jdolecek * read/write; if there is no device name, that's all we do.
200 1.1 jdolecek */
201 1.1 jdolecek if (mp->mnt_flag & MNT_UPDATE) {
202 1.1 jdolecek printf("ntfs_mount(): MNT_UPDATE not supported\n");
203 1.28 mycroft return (EINVAL);
204 1.1 jdolecek }
205 1.1 jdolecek
206 1.1 jdolecek /*
207 1.1 jdolecek * Not an update, or updating the name: look up the name
208 1.1 jdolecek * and verify that it refers to a sensible block device.
209 1.1 jdolecek */
210 1.78 dholland err = namei_simple_user(args->fspec,
211 1.78 dholland NSM_FOLLOW_NOEMULROOT, &devvp);
212 1.1 jdolecek if (err) {
213 1.1 jdolecek /* can't get devvp!*/
214 1.28 mycroft return (err);
215 1.1 jdolecek }
216 1.1 jdolecek
217 1.1 jdolecek if (devvp->v_type != VBLK) {
218 1.1 jdolecek err = ENOTBLK;
219 1.28 mycroft goto fail;
220 1.1 jdolecek }
221 1.1 jdolecek if (bdevsw_lookup(devvp->v_rdev) == NULL) {
222 1.1 jdolecek err = ENXIO;
223 1.28 mycroft goto fail;
224 1.1 jdolecek }
225 1.1 jdolecek if (mp->mnt_flag & MNT_UPDATE) {
226 1.1 jdolecek #if 0
227 1.1 jdolecek /*
228 1.1 jdolecek ********************
229 1.1 jdolecek * UPDATE
230 1.1 jdolecek ********************
231 1.1 jdolecek */
232 1.1 jdolecek
233 1.28 mycroft if (devvp != ntmp->um_devvp) {
234 1.1 jdolecek err = EINVAL; /* needs translation */
235 1.28 mycroft goto fail;
236 1.28 mycroft }
237 1.28 mycroft
238 1.1 jdolecek /*
239 1.1 jdolecek * Update device name only on success
240 1.1 jdolecek */
241 1.51 dsl err = set_statvfs_info(NULL, UIO_USERSPACE, args->fspec,
242 1.52 pooka UIO_USERSPACE, mp->mnt_op->vfs_name, mp, p);
243 1.28 mycroft if (err)
244 1.28 mycroft goto fail;
245 1.28 mycroft
246 1.28 mycroft vrele(devvp);
247 1.1 jdolecek #endif
248 1.1 jdolecek } else {
249 1.1 jdolecek /*
250 1.1 jdolecek ********************
251 1.1 jdolecek * NEW MOUNT
252 1.1 jdolecek ********************
253 1.1 jdolecek */
254 1.1 jdolecek
255 1.1 jdolecek /*
256 1.1 jdolecek * Since this is a new mount, we want the names for
257 1.1 jdolecek * the device and the mount point copied in. If an
258 1.1 jdolecek * error occurs, the mountpoint is discarded by the
259 1.1 jdolecek * upper level code.
260 1.1 jdolecek */
261 1.28 mycroft
262 1.1 jdolecek /* Save "last mounted on" info for mount point (NULL pad)*/
263 1.51 dsl err = set_statvfs_info(path, UIO_USERSPACE, args->fspec,
264 1.52 pooka UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
265 1.28 mycroft if (err)
266 1.28 mycroft goto fail;
267 1.28 mycroft
268 1.28 mycroft if (mp->mnt_flag & MNT_RDONLY)
269 1.28 mycroft flags = FREAD;
270 1.28 mycroft else
271 1.28 mycroft flags = FREAD|FWRITE;
272 1.87 hannken vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
273 1.59 pooka err = VOP_OPEN(devvp, flags, FSCRED);
274 1.87 hannken VOP_UNLOCK(devvp);
275 1.28 mycroft if (err)
276 1.28 mycroft goto fail;
277 1.51 dsl err = ntfs_mountfs(devvp, mp, args, l);
278 1.28 mycroft if (err) {
279 1.28 mycroft vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
280 1.59 pooka (void)VOP_CLOSE(devvp, flags, NOCRED);
281 1.81 hannken VOP_UNLOCK(devvp);
282 1.28 mycroft goto fail;
283 1.4 christos }
284 1.1 jdolecek }
285 1.1 jdolecek
286 1.1 jdolecek /*
287 1.1 jdolecek * Initialize FS stat information in mount struct; uses both
288 1.1 jdolecek * mp->mnt_stat.f_mntonname and mp->mnt_stat.f_mntfromname
289 1.1 jdolecek *
290 1.1 jdolecek * This code is common to root and non-root mounts
291 1.1 jdolecek */
292 1.59 pooka (void)VFS_STATVFS(mp, &mp->mnt_stat);
293 1.28 mycroft return (err);
294 1.1 jdolecek
295 1.28 mycroft fail:
296 1.1 jdolecek vrele(devvp);
297 1.28 mycroft return (err);
298 1.1 jdolecek }
299 1.1 jdolecek
300 1.1 jdolecek /*
301 1.1 jdolecek * Common code for mount and mountroot
302 1.1 jdolecek */
303 1.1 jdolecek int
304 1.75 dsl ntfs_mountfs(struct vnode *devvp, struct mount *mp, struct ntfs_args *argsp, struct lwp *l)
305 1.1 jdolecek {
306 1.1 jdolecek struct buf *bp;
307 1.1 jdolecek struct ntfsmount *ntmp;
308 1.1 jdolecek dev_t dev = devvp->v_rdev;
309 1.89 christos int error, i;
310 1.1 jdolecek struct vnode *vp;
311 1.1 jdolecek
312 1.39 xtraeme ntmp = NULL;
313 1.39 xtraeme
314 1.1 jdolecek /*
315 1.1 jdolecek * Flush out any old buffers remaining from a previous use.
316 1.1 jdolecek */
317 1.28 mycroft vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
318 1.43 ad error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0);
319 1.81 hannken VOP_UNLOCK(devvp);
320 1.1 jdolecek if (error)
321 1.1 jdolecek return (error);
322 1.1 jdolecek
323 1.1 jdolecek bp = NULL;
324 1.1 jdolecek
325 1.71 hannken error = bread(devvp, BBLOCK, BBSIZE, NOCRED, 0, &bp);
326 1.1 jdolecek if (error)
327 1.1 jdolecek goto out;
328 1.74 cegger ntmp = malloc( sizeof *ntmp, M_NTFSMNT, M_WAITOK|M_ZERO);
329 1.77 cegger memcpy( &ntmp->ntm_bootfile, bp->b_data, sizeof(struct bootfile) );
330 1.57 ad brelse( bp , 0 );
331 1.1 jdolecek bp = NULL;
332 1.1 jdolecek
333 1.1 jdolecek if (strncmp(ntmp->ntm_bootfile.bf_sysid, NTFS_BBID, NTFS_BBIDLEN)) {
334 1.1 jdolecek error = EINVAL;
335 1.1 jdolecek dprintf(("ntfs_mountfs: invalid boot block\n"));
336 1.1 jdolecek goto out;
337 1.1 jdolecek }
338 1.1 jdolecek
339 1.1 jdolecek {
340 1.1 jdolecek int8_t cpr = ntmp->ntm_mftrecsz;
341 1.1 jdolecek if( cpr > 0 )
342 1.1 jdolecek ntmp->ntm_bpmftrec = ntmp->ntm_spc * cpr;
343 1.1 jdolecek else
344 1.1 jdolecek ntmp->ntm_bpmftrec = (1 << (-cpr)) / ntmp->ntm_bps;
345 1.1 jdolecek }
346 1.1 jdolecek dprintf(("ntfs_mountfs(): bps: %d, spc: %d, media: %x, mftrecsz: %d (%d sects)\n",
347 1.1 jdolecek ntmp->ntm_bps,ntmp->ntm_spc,ntmp->ntm_bootfile.bf_media,
348 1.1 jdolecek ntmp->ntm_mftrecsz,ntmp->ntm_bpmftrec));
349 1.1 jdolecek dprintf(("ntfs_mountfs(): mftcn: 0x%x|0x%x\n",
350 1.1 jdolecek (u_int32_t)ntmp->ntm_mftcn,(u_int32_t)ntmp->ntm_mftmirrcn));
351 1.1 jdolecek
352 1.1 jdolecek ntmp->ntm_mountp = mp;
353 1.1 jdolecek ntmp->ntm_dev = dev;
354 1.1 jdolecek ntmp->ntm_devvp = devvp;
355 1.1 jdolecek ntmp->ntm_uid = argsp->uid;
356 1.1 jdolecek ntmp->ntm_gid = argsp->gid;
357 1.1 jdolecek ntmp->ntm_mode = argsp->mode;
358 1.1 jdolecek ntmp->ntm_flag = argsp->flag;
359 1.1 jdolecek mp->mnt_data = ntmp;
360 1.1 jdolecek
361 1.1 jdolecek /* set file name encode/decode hooks XXX utf-8 only for now */
362 1.1 jdolecek ntmp->ntm_wget = ntfs_utf8_wget;
363 1.1 jdolecek ntmp->ntm_wput = ntfs_utf8_wput;
364 1.1 jdolecek ntmp->ntm_wcmp = ntfs_utf8_wcmp;
365 1.1 jdolecek
366 1.1 jdolecek dprintf(("ntfs_mountfs(): case-%s,%s uid: %d, gid: %d, mode: %o\n",
367 1.1 jdolecek (ntmp->ntm_flag & NTFS_MFLAG_CASEINS)?"insens.":"sens.",
368 1.1 jdolecek (ntmp->ntm_flag & NTFS_MFLAG_ALLNAMES)?" allnames,":"",
369 1.1 jdolecek ntmp->ntm_uid, ntmp->ntm_gid, ntmp->ntm_mode));
370 1.1 jdolecek
371 1.1 jdolecek /*
372 1.29 perry * We read in some system nodes to do not allow
373 1.1 jdolecek * reclaim them and to have everytime access to them.
374 1.29 perry */
375 1.1 jdolecek {
376 1.1 jdolecek int pi[3] = { NTFS_MFTINO, NTFS_ROOTINO, NTFS_BITMAPINO };
377 1.1 jdolecek for (i=0; i<3; i++) {
378 1.9 thorpej error = VFS_VGET(mp, pi[i], &(ntmp->ntm_sysvn[pi[i]]));
379 1.1 jdolecek if(error)
380 1.1 jdolecek goto out1;
381 1.58 ad ntmp->ntm_sysvn[pi[i]]->v_vflag |= VV_SYSTEM;
382 1.80 pooka vref(ntmp->ntm_sysvn[pi[i]]);
383 1.1 jdolecek vput(ntmp->ntm_sysvn[pi[i]]);
384 1.1 jdolecek }
385 1.1 jdolecek }
386 1.1 jdolecek
387 1.1 jdolecek /* read the Unicode lowercase --> uppercase translation table,
388 1.1 jdolecek * if necessary */
389 1.1 jdolecek if ((error = ntfs_toupper_use(mp, ntmp)))
390 1.1 jdolecek goto out1;
391 1.1 jdolecek
392 1.1 jdolecek /*
393 1.1 jdolecek * Scan $BitMap and count free clusters
394 1.1 jdolecek */
395 1.1 jdolecek error = ntfs_calccfree(ntmp, &ntmp->ntm_cfree);
396 1.1 jdolecek if(error)
397 1.1 jdolecek goto out1;
398 1.1 jdolecek
399 1.1 jdolecek /*
400 1.1 jdolecek * Read and translate to internal format attribute
401 1.29 perry * definition file.
402 1.1 jdolecek */
403 1.1 jdolecek {
404 1.1 jdolecek int num,j;
405 1.1 jdolecek struct attrdef ad;
406 1.1 jdolecek
407 1.1 jdolecek /* Open $AttrDef */
408 1.10 fvdl error = VFS_VGET(mp, NTFS_ATTRDEFINO, &vp );
409 1.29 perry if(error)
410 1.1 jdolecek goto out1;
411 1.1 jdolecek
412 1.1 jdolecek /* Count valid entries */
413 1.1 jdolecek for(num=0;;num++) {
414 1.1 jdolecek error = ntfs_readattr(ntmp, VTONT(vp),
415 1.1 jdolecek NTFS_A_DATA, NULL,
416 1.1 jdolecek num * sizeof(ad), sizeof(ad),
417 1.1 jdolecek &ad, NULL);
418 1.1 jdolecek if (error)
419 1.1 jdolecek goto out1;
420 1.1 jdolecek if (ad.ad_name[0] == 0)
421 1.1 jdolecek break;
422 1.1 jdolecek }
423 1.1 jdolecek
424 1.1 jdolecek /* Alloc memory for attribute definitions */
425 1.1 jdolecek ntmp->ntm_ad = (struct ntvattrdef *) malloc(
426 1.1 jdolecek num * sizeof(struct ntvattrdef),
427 1.1 jdolecek M_NTFSMNT, M_WAITOK);
428 1.1 jdolecek
429 1.1 jdolecek ntmp->ntm_adnum = num;
430 1.1 jdolecek
431 1.1 jdolecek /* Read them and translate */
432 1.1 jdolecek for(i=0;i<num;i++){
433 1.1 jdolecek error = ntfs_readattr(ntmp, VTONT(vp),
434 1.1 jdolecek NTFS_A_DATA, NULL,
435 1.1 jdolecek i * sizeof(ad), sizeof(ad),
436 1.1 jdolecek &ad, NULL);
437 1.1 jdolecek if (error)
438 1.1 jdolecek goto out1;
439 1.1 jdolecek j = 0;
440 1.1 jdolecek do {
441 1.1 jdolecek ntmp->ntm_ad[i].ad_name[j] = ad.ad_name[j];
442 1.1 jdolecek } while(ad.ad_name[j++]);
443 1.1 jdolecek ntmp->ntm_ad[i].ad_namelen = j - 1;
444 1.1 jdolecek ntmp->ntm_ad[i].ad_type = ad.ad_type;
445 1.1 jdolecek }
446 1.1 jdolecek
447 1.1 jdolecek vput(vp);
448 1.1 jdolecek }
449 1.1 jdolecek
450 1.18 christos mp->mnt_stat.f_fsidx.__fsid_val[0] = dev;
451 1.18 christos mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_NTFS);
452 1.18 christos mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
453 1.25 jdolecek mp->mnt_stat.f_namemax = NTFS_MAXFILENAME;
454 1.1 jdolecek mp->mnt_flag |= MNT_LOCAL;
455 1.88 hannken spec_node_setmountedfs(devvp, mp);
456 1.1 jdolecek return (0);
457 1.1 jdolecek
458 1.1 jdolecek out1:
459 1.1 jdolecek for(i=0;i<NTFS_SYSNODESNUM;i++)
460 1.1 jdolecek if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
461 1.1 jdolecek
462 1.45 christos if (vflush(mp,NULLVP,0)) {
463 1.1 jdolecek dprintf(("ntfs_mountfs: vflush failed\n"));
464 1.45 christos }
465 1.1 jdolecek out:
466 1.88 hannken spec_node_setmountedfs(devvp, NULL);
467 1.1 jdolecek if (bp)
468 1.57 ad brelse(bp, 0);
469 1.1 jdolecek
470 1.38 christos if (error) {
471 1.40 christos if (ntmp) {
472 1.40 christos if (ntmp->ntm_ad)
473 1.40 christos free(ntmp->ntm_ad, M_NTFSMNT);
474 1.40 christos free(ntmp, M_NTFSMNT);
475 1.40 christos }
476 1.38 christos }
477 1.38 christos
478 1.1 jdolecek return (error);
479 1.1 jdolecek }
480 1.1 jdolecek
481 1.1 jdolecek static int
482 1.1 jdolecek ntfs_start (
483 1.47 christos struct mount *mp,
484 1.59 pooka int flags)
485 1.1 jdolecek {
486 1.1 jdolecek return (0);
487 1.1 jdolecek }
488 1.1 jdolecek
489 1.1 jdolecek static int
490 1.29 perry ntfs_unmount(
491 1.1 jdolecek struct mount *mp,
492 1.59 pooka int mntflags)
493 1.1 jdolecek {
494 1.59 pooka struct lwp *l = curlwp;
495 1.1 jdolecek struct ntfsmount *ntmp;
496 1.1 jdolecek int error, ronly = 0, flags, i;
497 1.1 jdolecek
498 1.1 jdolecek dprintf(("ntfs_unmount: unmounting...\n"));
499 1.1 jdolecek ntmp = VFSTONTFS(mp);
500 1.1 jdolecek
501 1.1 jdolecek flags = 0;
502 1.1 jdolecek if(mntflags & MNT_FORCE)
503 1.1 jdolecek flags |= FORCECLOSE;
504 1.1 jdolecek
505 1.1 jdolecek dprintf(("ntfs_unmount: vflushing...\n"));
506 1.1 jdolecek error = vflush(mp,NULLVP,flags | SKIPSYSTEM);
507 1.1 jdolecek if (error) {
508 1.1 jdolecek dprintf(("ntfs_unmount: vflush failed: %d\n",error));
509 1.1 jdolecek return (error);
510 1.1 jdolecek }
511 1.1 jdolecek
512 1.1 jdolecek /* Check if only system vnodes are rest */
513 1.1 jdolecek for(i=0;i<NTFS_SYSNODESNUM;i++)
514 1.29 perry if((ntmp->ntm_sysvn[i]) &&
515 1.1 jdolecek (ntmp->ntm_sysvn[i]->v_usecount > 1)) return (EBUSY);
516 1.1 jdolecek
517 1.1 jdolecek /* Dereference all system vnodes */
518 1.1 jdolecek for(i=0;i<NTFS_SYSNODESNUM;i++)
519 1.1 jdolecek if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
520 1.1 jdolecek
521 1.1 jdolecek /* vflush system vnodes */
522 1.1 jdolecek error = vflush(mp,NULLVP,flags);
523 1.1 jdolecek if (error) {
524 1.54 pooka panic("ntfs_unmount: vflush failed(sysnodes): %d\n",error);
525 1.1 jdolecek }
526 1.1 jdolecek
527 1.1 jdolecek /* Check if the type of device node isn't VBAD before
528 1.1 jdolecek * touching v_specinfo. If the device vnode is revoked, the
529 1.1 jdolecek * field is NULL and touching it causes null pointer derefercence.
530 1.1 jdolecek */
531 1.1 jdolecek if (ntmp->ntm_devvp->v_type != VBAD)
532 1.88 hannken spec_node_setmountedfs(ntmp->ntm_devvp, NULL);
533 1.1 jdolecek
534 1.91 christos error = vinvalbuf(ntmp->ntm_devvp, V_SAVE, NOCRED, l, 0, 0);
535 1.91 christos KASSERT(error == 0);
536 1.1 jdolecek
537 1.1 jdolecek /* lock the device vnode before calling VOP_CLOSE() */
538 1.23 yamt vn_lock(ntmp->ntm_devvp, LK_EXCLUSIVE | LK_RETRY);
539 1.1 jdolecek error = VOP_CLOSE(ntmp->ntm_devvp, ronly ? FREAD : FREAD|FWRITE,
540 1.59 pooka NOCRED);
541 1.54 pooka KASSERT(error == 0);
542 1.81 hannken VOP_UNLOCK(ntmp->ntm_devvp);
543 1.1 jdolecek
544 1.1 jdolecek vrele(ntmp->ntm_devvp);
545 1.1 jdolecek
546 1.1 jdolecek /* free the toupper table, if this has been last mounted ntfs volume */
547 1.1 jdolecek ntfs_toupper_unuse();
548 1.1 jdolecek
549 1.1 jdolecek dprintf(("ntfs_umount: freeing memory...\n"));
550 1.1 jdolecek mp->mnt_data = NULL;
551 1.1 jdolecek mp->mnt_flag &= ~MNT_LOCAL;
552 1.1 jdolecek free(ntmp->ntm_ad, M_NTFSMNT);
553 1.73 cegger free(ntmp, M_NTFSMNT);
554 1.54 pooka return (0);
555 1.1 jdolecek }
556 1.1 jdolecek
557 1.1 jdolecek static int
558 1.1 jdolecek ntfs_root(
559 1.1 jdolecek struct mount *mp,
560 1.36 christos struct vnode **vpp)
561 1.1 jdolecek {
562 1.1 jdolecek struct vnode *nvp;
563 1.1 jdolecek int error = 0;
564 1.1 jdolecek
565 1.1 jdolecek dprintf(("ntfs_root(): sysvn: %p\n",
566 1.1 jdolecek VFSTONTFS(mp)->ntm_sysvn[NTFS_ROOTINO]));
567 1.9 thorpej error = VFS_VGET(mp, (ino_t)NTFS_ROOTINO, &nvp);
568 1.1 jdolecek if(error) {
569 1.1 jdolecek printf("ntfs_root: VFS_VGET failed: %d\n",error);
570 1.1 jdolecek return (error);
571 1.1 jdolecek }
572 1.1 jdolecek
573 1.1 jdolecek *vpp = nvp;
574 1.1 jdolecek return (0);
575 1.1 jdolecek }
576 1.1 jdolecek
577 1.1 jdolecek int
578 1.1 jdolecek ntfs_calccfree(
579 1.1 jdolecek struct ntfsmount *ntmp,
580 1.1 jdolecek cn_t *cfreep)
581 1.1 jdolecek {
582 1.1 jdolecek struct vnode *vp;
583 1.1 jdolecek u_int8_t *tmp;
584 1.1 jdolecek int j, error;
585 1.16 jdolecek cn_t cfree = 0;
586 1.1 jdolecek size_t bmsize, i;
587 1.1 jdolecek
588 1.1 jdolecek vp = ntmp->ntm_sysvn[NTFS_BITMAPINO];
589 1.1 jdolecek
590 1.1 jdolecek bmsize = VTOF(vp)->f_size;
591 1.1 jdolecek
592 1.1 jdolecek tmp = (u_int8_t *) malloc(bmsize, M_TEMP, M_WAITOK);
593 1.1 jdolecek
594 1.1 jdolecek error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
595 1.1 jdolecek 0, bmsize, tmp, NULL);
596 1.1 jdolecek if (error)
597 1.1 jdolecek goto out;
598 1.1 jdolecek
599 1.1 jdolecek for(i=0;i<bmsize;i++)
600 1.1 jdolecek for(j=0;j<8;j++)
601 1.1 jdolecek if(~tmp[i] & (1 << j)) cfree++;
602 1.1 jdolecek *cfreep = cfree;
603 1.1 jdolecek
604 1.1 jdolecek out:
605 1.1 jdolecek free(tmp, M_TEMP);
606 1.1 jdolecek return(error);
607 1.1 jdolecek }
608 1.1 jdolecek
609 1.1 jdolecek static int
610 1.18 christos ntfs_statvfs(
611 1.1 jdolecek struct mount *mp,
612 1.59 pooka struct statvfs *sbp)
613 1.1 jdolecek {
614 1.1 jdolecek struct ntfsmount *ntmp = VFSTONTFS(mp);
615 1.1 jdolecek u_int64_t mftallocated;
616 1.1 jdolecek
617 1.18 christos dprintf(("ntfs_statvfs():\n"));
618 1.1 jdolecek
619 1.1 jdolecek mftallocated = VTOF(ntmp->ntm_sysvn[NTFS_MFTINO])->f_allocated;
620 1.1 jdolecek
621 1.1 jdolecek sbp->f_bsize = ntmp->ntm_bps;
622 1.18 christos sbp->f_frsize = sbp->f_bsize; /* XXX */
623 1.1 jdolecek sbp->f_iosize = ntmp->ntm_bps * ntmp->ntm_spc;
624 1.1 jdolecek sbp->f_blocks = ntmp->ntm_bootfile.bf_spv;
625 1.1 jdolecek sbp->f_bfree = sbp->f_bavail = ntfs_cntobn(ntmp->ntm_cfree);
626 1.18 christos sbp->f_ffree = sbp->f_favail = sbp->f_bfree / ntmp->ntm_bpmftrec;
627 1.1 jdolecek sbp->f_files = mftallocated / ntfs_bntob(ntmp->ntm_bpmftrec) +
628 1.18 christos sbp->f_ffree;
629 1.18 christos sbp->f_fresvd = sbp->f_bresvd = 0; /* XXX */
630 1.18 christos sbp->f_flag = mp->mnt_flag;
631 1.18 christos copy_statvfs_info(sbp, mp);
632 1.1 jdolecek return (0);
633 1.1 jdolecek }
634 1.1 jdolecek
635 1.1 jdolecek static int
636 1.1 jdolecek ntfs_sync (
637 1.47 christos struct mount *mp,
638 1.47 christos int waitfor,
639 1.59 pooka kauth_cred_t cred)
640 1.1 jdolecek {
641 1.1 jdolecek /*dprintf(("ntfs_sync():\n"));*/
642 1.1 jdolecek return (0);
643 1.1 jdolecek }
644 1.1 jdolecek
645 1.1 jdolecek /*ARGSUSED*/
646 1.1 jdolecek static int
647 1.1 jdolecek ntfs_fhtovp(
648 1.1 jdolecek struct mount *mp,
649 1.1 jdolecek struct fid *fhp,
650 1.9 thorpej struct vnode **vpp)
651 1.1 jdolecek {
652 1.42 martin struct ntfid ntfh;
653 1.1 jdolecek int error;
654 1.1 jdolecek
655 1.42 martin if (fhp->fid_len != sizeof(struct ntfid))
656 1.42 martin return EINVAL;
657 1.42 martin memcpy(&ntfh, fhp, sizeof(ntfh));
658 1.35 christos ddprintf(("ntfs_fhtovp(): %s: %llu\n", mp->mnt_stat.f_mntonname,
659 1.42 martin (unsigned long long)ntfh.ntfid_ino));
660 1.1 jdolecek
661 1.95 hannken error = ntfs_vgetex(mp, ntfh.ntfid_ino, ntfh.ntfid_attr, "",
662 1.96 hannken LK_EXCLUSIVE, vpp);
663 1.1 jdolecek if (error != 0) {
664 1.1 jdolecek *vpp = NULLVP;
665 1.1 jdolecek return (error);
666 1.1 jdolecek }
667 1.1 jdolecek
668 1.1 jdolecek /* XXX as unlink/rmdir/mkdir/creat are not currently possible
669 1.1 jdolecek * with NTFS, we don't need to check anything else for now */
670 1.1 jdolecek return (0);
671 1.1 jdolecek }
672 1.1 jdolecek
673 1.1 jdolecek static int
674 1.1 jdolecek ntfs_vptofh(
675 1.1 jdolecek struct vnode *vp,
676 1.42 martin struct fid *fhp,
677 1.42 martin size_t *fh_size)
678 1.1 jdolecek {
679 1.1 jdolecek struct ntnode *ntp;
680 1.42 martin struct ntfid ntfh;
681 1.1 jdolecek struct fnode *fn;
682 1.1 jdolecek
683 1.42 martin if (*fh_size < sizeof(struct ntfid)) {
684 1.42 martin *fh_size = sizeof(struct ntfid);
685 1.42 martin return E2BIG;
686 1.42 martin }
687 1.42 martin *fh_size = sizeof(struct ntfid);
688 1.42 martin
689 1.1 jdolecek ddprintf(("ntfs_fhtovp(): %s: %p\n", vp->v_mount->mnt_stat.f_mntonname,
690 1.1 jdolecek vp));
691 1.1 jdolecek
692 1.1 jdolecek fn = VTOF(vp);
693 1.1 jdolecek ntp = VTONT(vp);
694 1.42 martin memset(&ntfh, 0, sizeof(ntfh));
695 1.42 martin ntfh.ntfid_len = sizeof(struct ntfid);
696 1.42 martin ntfh.ntfid_ino = ntp->i_number;
697 1.42 martin ntfh.ntfid_attr = fn->f_attrtype;
698 1.1 jdolecek #ifdef notyet
699 1.42 martin ntfh.ntfid_gen = ntp->i_gen;
700 1.1 jdolecek #endif
701 1.42 martin memcpy(fhp, &ntfh, sizeof(ntfh));
702 1.1 jdolecek return (0);
703 1.1 jdolecek }
704 1.1 jdolecek
705 1.97 hannken static int
706 1.97 hannken ntfs_loadvnode(struct mount *mp, struct vnode *vp,
707 1.97 hannken const void *key, size_t key_len, const void **new_key)
708 1.1 jdolecek {
709 1.1 jdolecek int error;
710 1.97 hannken struct ntvattr *vap;
711 1.97 hannken struct ntkey small_key, *ntkey;
712 1.1 jdolecek struct ntfsmount *ntmp;
713 1.1 jdolecek struct ntnode *ip;
714 1.97 hannken struct fnode *fp = NULL;
715 1.13 christos enum vtype f_type = VBAD;
716 1.1 jdolecek
717 1.97 hannken if (key_len <= sizeof(small_key))
718 1.97 hannken ntkey = &small_key;
719 1.97 hannken else
720 1.97 hannken ntkey = kmem_alloc(key_len, KM_SLEEP);
721 1.97 hannken memcpy(ntkey, key, key_len);
722 1.97 hannken
723 1.97 hannken dprintf(("ntfs_loadvnode: ino: %llu, attr: 0x%x:%s",
724 1.97 hannken (unsigned long long)ntkey->k_ino,
725 1.97 hannken ntkey->k_attrtype, ntkey->k_attrname));
726 1.1 jdolecek
727 1.1 jdolecek ntmp = VFSTONTFS(mp);
728 1.1 jdolecek
729 1.1 jdolecek /* Get ntnode */
730 1.97 hannken error = ntfs_ntlookup(ntmp, ntkey->k_ino, &ip);
731 1.1 jdolecek if (error) {
732 1.97 hannken printf("ntfs_loadvnode: ntfs_ntget failed\n");
733 1.97 hannken goto out;
734 1.1 jdolecek }
735 1.1 jdolecek /* It may be not initialized fully, so force load it */
736 1.96 hannken if (!(ip->i_flag & IN_LOADED)) {
737 1.97 hannken error = ntfs_loadntnode(ntmp, ip);
738 1.97 hannken if(error) {
739 1.97 hannken printf("ntfs_loadvnode: CAN'T LOAD ATTRIBUTES FOR INO:"
740 1.97 hannken " %llu\n", (unsigned long long)ip->i_number);
741 1.97 hannken ntfs_ntput(ip);
742 1.97 hannken goto out;
743 1.97 hannken }
744 1.1 jdolecek }
745 1.1 jdolecek
746 1.97 hannken /* Setup fnode */
747 1.97 hannken fp = kmem_zalloc(sizeof(*fp), KM_SLEEP);
748 1.97 hannken dprintf(("%s: allocating fnode: %p\n", __func__, fp));
749 1.96 hannken
750 1.97 hannken error = ntfs_ntvattrget(ntmp, ip, NTFS_A_NAME, NULL, 0, &vap);
751 1.83 hannken if (error) {
752 1.83 hannken ntfs_ntput(ip);
753 1.97 hannken goto out;
754 1.83 hannken }
755 1.97 hannken fp->f_fflag = vap->va_a_name->n_flag;
756 1.97 hannken fp->f_pnumber = vap->va_a_name->n_pnumber;
757 1.97 hannken fp->f_times = vap->va_a_name->n_times;
758 1.97 hannken ntfs_ntvattrrele(vap);
759 1.97 hannken
760 1.97 hannken if ((ip->i_frflag & NTFS_FRFLAG_DIR) &&
761 1.97 hannken (ntkey->k_attrtype == NTFS_A_DATA &&
762 1.97 hannken strcmp(ntkey->k_attrname, "") == 0)) {
763 1.97 hannken f_type = VDIR;
764 1.97 hannken } else {
765 1.97 hannken f_type = VREG;
766 1.97 hannken error = ntfs_ntvattrget(ntmp, ip,
767 1.97 hannken ntkey->k_attrtype, ntkey->k_attrname, 0, &vap);
768 1.97 hannken if (error == 0) {
769 1.97 hannken fp->f_size = vap->va_datalen;
770 1.97 hannken fp->f_allocated = vap->va_allocated;
771 1.97 hannken ntfs_ntvattrrele(vap);
772 1.97 hannken } else if (ntkey->k_attrtype == NTFS_A_DATA &&
773 1.97 hannken strcmp(ntkey->k_attrname, "") == 0 &&
774 1.97 hannken error == ENOENT) {
775 1.97 hannken fp->f_size = 0;
776 1.97 hannken fp->f_allocated = 0;
777 1.97 hannken error = 0;
778 1.97 hannken } else
779 1.97 hannken goto out;
780 1.97 hannken }
781 1.97 hannken
782 1.97 hannken if (key_len <= sizeof(fp->f_smallkey))
783 1.97 hannken fp->f_key = &fp->f_smallkey;
784 1.97 hannken else
785 1.97 hannken fp->f_key = kmem_alloc(key_len, KM_SLEEP);
786 1.97 hannken fp->f_ip = ip;
787 1.97 hannken fp->f_ino = ip->i_number;
788 1.97 hannken strcpy(fp->f_attrname, ntkey->k_attrname);
789 1.97 hannken fp->f_attrtype = ntkey->k_attrtype;
790 1.1 jdolecek fp->f_vp = vp;
791 1.1 jdolecek vp->v_data = fp;
792 1.97 hannken
793 1.97 hannken vp->v_tag = VT_NTFS;
794 1.97 hannken vp->v_type = f_type;
795 1.97 hannken vp->v_op = ntfs_vnodeop_p;
796 1.97 hannken ntfs_ntref(ip);
797 1.97 hannken vref(ip->i_devvp);
798 1.64 pooka genfs_node_init(vp, &ntfs_genfsops);
799 1.1 jdolecek
800 1.97 hannken if (ip->i_number == NTFS_ROOTINO)
801 1.58 ad vp->v_vflag |= VV_ROOT;
802 1.1 jdolecek
803 1.97 hannken uvm_vnp_setsize(vp, fp->f_size);
804 1.83 hannken ntfs_ntput(ip);
805 1.83 hannken
806 1.97 hannken *new_key = fp->f_key;
807 1.97 hannken
808 1.97 hannken fp = NULL;
809 1.97 hannken
810 1.97 hannken out:
811 1.97 hannken if (ntkey != &small_key)
812 1.97 hannken kmem_free(ntkey, key_len);
813 1.97 hannken if (fp)
814 1.97 hannken kmem_free(fp, sizeof(*fp));
815 1.1 jdolecek
816 1.97 hannken return error;
817 1.1 jdolecek }
818 1.1 jdolecek
819 1.1 jdolecek static int
820 1.1 jdolecek ntfs_vget(
821 1.1 jdolecek struct mount *mp,
822 1.1 jdolecek ino_t ino,
823 1.29 perry struct vnode **vpp)
824 1.1 jdolecek {
825 1.96 hannken return ntfs_vgetex(mp, ino, NTFS_A_DATA, "", LK_EXCLUSIVE, vpp);
826 1.1 jdolecek }
827 1.1 jdolecek
828 1.97 hannken int
829 1.97 hannken ntfs_vgetex(
830 1.97 hannken struct mount *mp,
831 1.97 hannken ino_t ino,
832 1.97 hannken u_int32_t attrtype,
833 1.97 hannken const char *attrname,
834 1.97 hannken u_long lkflags,
835 1.97 hannken struct vnode **vpp)
836 1.97 hannken {
837 1.97 hannken const int attrlen = strlen(attrname);
838 1.97 hannken int error;
839 1.97 hannken struct ntkey small_key, *ntkey;
840 1.97 hannken
841 1.97 hannken if (NTKEY_SIZE(attrlen) <= sizeof(small_key))
842 1.97 hannken ntkey = &small_key;
843 1.97 hannken else
844 1.97 hannken ntkey = malloc(NTKEY_SIZE(attrlen), M_TEMP, M_WAITOK);
845 1.97 hannken ntkey->k_ino = ino;
846 1.97 hannken ntkey->k_attrtype = attrtype;
847 1.97 hannken strcpy(ntkey->k_attrname, attrname);
848 1.97 hannken
849 1.97 hannken error = vcache_get(mp, ntkey, NTKEY_SIZE(attrlen), vpp);
850 1.97 hannken if (error)
851 1.97 hannken goto out;
852 1.97 hannken
853 1.97 hannken if ((lkflags & (LK_SHARED | LK_EXCLUSIVE)) != 0) {
854 1.97 hannken error = vn_lock(*vpp, lkflags);
855 1.97 hannken if (error) {
856 1.97 hannken vrele(*vpp);
857 1.97 hannken *vpp = NULL;
858 1.97 hannken }
859 1.97 hannken }
860 1.97 hannken
861 1.97 hannken out:
862 1.97 hannken if (ntkey != &small_key)
863 1.97 hannken free(ntkey, M_TEMP);
864 1.97 hannken return error;
865 1.97 hannken }
866 1.97 hannken
867 1.1 jdolecek extern const struct vnodeopv_desc ntfs_vnodeop_opv_desc;
868 1.1 jdolecek
869 1.1 jdolecek const struct vnodeopv_desc * const ntfs_vnodeopv_descs[] = {
870 1.1 jdolecek &ntfs_vnodeop_opv_desc,
871 1.1 jdolecek NULL,
872 1.1 jdolecek };
873 1.1 jdolecek
874 1.1 jdolecek struct vfsops ntfs_vfsops = {
875 1.93 hannken .vfs_name = MOUNT_NTFS,
876 1.93 hannken .vfs_min_mount_data = sizeof (struct ntfs_args),
877 1.93 hannken .vfs_mount = ntfs_mount,
878 1.93 hannken .vfs_start = ntfs_start,
879 1.93 hannken .vfs_unmount = ntfs_unmount,
880 1.93 hannken .vfs_root = ntfs_root,
881 1.93 hannken .vfs_quotactl = (void *)eopnotsupp,
882 1.93 hannken .vfs_statvfs = ntfs_statvfs,
883 1.93 hannken .vfs_sync = ntfs_sync,
884 1.93 hannken .vfs_vget = ntfs_vget,
885 1.97 hannken .vfs_loadvnode = ntfs_loadvnode,
886 1.93 hannken .vfs_fhtovp = ntfs_fhtovp,
887 1.93 hannken .vfs_vptofh = ntfs_vptofh,
888 1.93 hannken .vfs_init = ntfs_init,
889 1.93 hannken .vfs_reinit = ntfs_reinit,
890 1.93 hannken .vfs_done = ntfs_done,
891 1.93 hannken .vfs_mountroot = ntfs_mountroot,
892 1.93 hannken .vfs_snapshot = (void *)eopnotsupp,
893 1.93 hannken .vfs_extattrctl = vfs_stdextattrctl,
894 1.93 hannken .vfs_suspendctl = (void *)eopnotsupp,
895 1.93 hannken .vfs_renamelock_enter = genfs_renamelock_enter,
896 1.93 hannken .vfs_renamelock_exit = genfs_renamelock_exit,
897 1.93 hannken .vfs_fsync = (void *)eopnotsupp,
898 1.93 hannken .vfs_opv_descs = ntfs_vnodeopv_descs
899 1.1 jdolecek };
900 1.70 rumble
901 1.70 rumble static int
902 1.70 rumble ntfs_modcmd(modcmd_t cmd, void *arg)
903 1.70 rumble {
904 1.72 rumble int error;
905 1.70 rumble
906 1.70 rumble switch (cmd) {
907 1.70 rumble case MODULE_CMD_INIT:
908 1.72 rumble error = vfs_attach(&ntfs_vfsops);
909 1.72 rumble if (error != 0)
910 1.72 rumble break;
911 1.72 rumble sysctl_createv(&ntfs_sysctl_log, 0, NULL, NULL,
912 1.72 rumble CTLFLAG_PERMANENT,
913 1.72 rumble CTLTYPE_NODE, "ntfs",
914 1.72 rumble SYSCTL_DESCR("NTFS file system"),
915 1.72 rumble NULL, 0, NULL, 0,
916 1.72 rumble CTL_VFS, 20, CTL_EOL);
917 1.72 rumble /*
918 1.72 rumble * XXX the "20" above could be dynamic, thereby eliminating
919 1.72 rumble * one more instance of the "number to vfs" mapping problem,
920 1.72 rumble * but "20" is the order as taken from sys/mount.h
921 1.72 rumble */
922 1.72 rumble break;
923 1.70 rumble case MODULE_CMD_FINI:
924 1.72 rumble error = vfs_detach(&ntfs_vfsops);
925 1.72 rumble if (error != 0)
926 1.72 rumble break;
927 1.72 rumble sysctl_teardown(&ntfs_sysctl_log);
928 1.72 rumble break;
929 1.70 rumble default:
930 1.72 rumble error = ENOTTY;
931 1.72 rumble break;
932 1.70 rumble }
933 1.72 rumble
934 1.72 rumble return (error);
935 1.70 rumble }
936