1 /* $NetBSD: ntfs_vnops.c,v 1.23 1999/10/31 19:45:27 jdolecek Exp $ */
2
3 /*-
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * John Heidemann of the UCLA Ficus project.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * $FreeBSD: releng/6.1/sys/fs/ntfs/ntfs_vnops.c 156603 2006-03-12 21:50:02Z scottl $
35 *
36 */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/time.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <sys/vnode.h>
45 #include <sys/mount.h>
46 #include <sys/namei.h>
47 #include <sys/malloc.h>
48 #include <sys/bio.h>
49 #include <sys/buf.h>
50 #include <sys/dirent.h>
51
52 #include <vm/vm.h>
53 #include <vm/vm_param.h>
54 #include <vm/vm_page.h>
55 #include <vm/vm_object.h>
56 #include <vm/vm_pager.h>
57 #include <vm/vnode_pager.h>
58 #include <vm/vm_extern.h>
59
60 #include <sys/sysctl.h>
61
62 /*#define NTFS_DEBUG 1*/
63 #include <fs/ntfs/ntfs.h>
64 #include <fs/ntfs/ntfs_inode.h>
65 #include <fs/ntfs/ntfs_subr.h>
66
67 #include <sys/unistd.h> /* for pathconf(2) constants */
68
69 static vop_read_t ntfs_read;
70 static vop_write_t ntfs_write;
71 static vop_getattr_t ntfs_getattr;
72 static vop_inactive_t ntfs_inactive;
73 static vop_reclaim_t ntfs_reclaim;
74 static vop_bmap_t ntfs_bmap;
75 static vop_strategy_t ntfs_strategy;
76 static vop_access_t ntfs_access;
77 static vop_open_t ntfs_open;
78 static vop_close_t ntfs_close;
79 static vop_readdir_t ntfs_readdir;
80 static vop_cachedlookup_t ntfs_lookup;
81 static vop_fsync_t ntfs_fsync;
82 static vop_pathconf_t ntfs_pathconf;
83
84 int ntfs_prtactive = 1; /* 1 => print out reclaim of active vnodes */
85
86 /*
87 * This is a noop, simply returning what one has been given.
88 */
89 int
90 ntfs_bmap(ap)
91 struct vop_bmap_args /* {
92 struct vnode *a_vp;
93 daddr_t a_bn;
94 struct bufobj **a_bop;
95 daddr_t *a_bnp;
96 int *a_runp;
97 int *a_runb;
98 } */ *ap;
99 {
100 struct vnode *vp = ap->a_vp;
101
102 dprintf(("ntfs_bmap: vn: %p, blk: %d\n", ap->a_vp,(u_int32_t)ap->a_bn));
103 if (ap->a_bop != NULL)
104 *ap->a_bop = &vp->v_bufobj;
105 if (ap->a_bnp != NULL)
106 *ap->a_bnp = ap->a_bn;
107 if (ap->a_runp != NULL)
108 *ap->a_runp = 0;
109 if (ap->a_runb != NULL)
110 *ap->a_runb = 0;
111 return (0);
112 }
113
114 static int
115 ntfs_read(ap)
116 struct vop_read_args /* {
117 struct vnode *a_vp;
118 struct uio *a_uio;
119 int a_ioflag;
120 struct ucred *a_cred;
121 } */ *ap;
122 {
123 register struct vnode *vp = ap->a_vp;
124 register struct fnode *fp = VTOF(vp);
125 register struct ntnode *ip = FTONT(fp);
126 struct uio *uio = ap->a_uio;
127 struct ntfsmount *ntmp = ip->i_mp;
128 struct buf *bp;
129 daddr_t cn;
130 int resid, off, toread;
131 int error;
132
133 dprintf(("ntfs_read: ino: %d, off: %d resid: %d, segflg: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg));
134
135 dprintf(("ntfs_read: filesize: %d",(u_int32_t)fp->f_size));
136
137 /* don't allow reading after end of file */
138 if (uio->uio_offset > fp->f_size)
139 return (0);
140
141 resid = min(uio->uio_resid, fp->f_size - uio->uio_offset);
142
143 dprintf((", resid: %d\n", resid));
144
145 error = 0;
146 while (resid) {
147 cn = ntfs_btocn(uio->uio_offset);
148 off = ntfs_btocnoff(uio->uio_offset);
149
150 toread = min(off + resid, ntfs_cntob(1));
151
152 error = bread(vp, cn, ntfs_cntob(1), NOCRED, &bp);
153 if (error) {
154 brelse(bp);
155 break;
156 }
157
158 error = uiomove(bp->b_data + off, toread - off, uio);
159 if(error) {
160 brelse(bp);
161 break;
162 }
163 brelse(bp);
164
165 resid -= toread - off;
166 }
167
168 return (error);
169 }
170
171 static int
172 ntfs_getattr(ap)
173 struct vop_getattr_args /* {
174 struct vnode *a_vp;
175 struct vattr *a_vap;
176 struct ucred *a_cred;
177 struct thread *a_td;
178 } */ *ap;
179 {
180 register struct vnode *vp = ap->a_vp;
181 register struct fnode *fp = VTOF(vp);
182 register struct ntnode *ip = FTONT(fp);
183 register struct vattr *vap = ap->a_vap;
184
185 dprintf(("ntfs_getattr: %d, flags: %d\n",ip->i_number,ip->i_flag));
186
187 vap->va_fsid = dev2udev(ip->i_dev);
188 vap->va_fileid = ip->i_number;
189 vap->va_mode = ip->i_mp->ntm_mode;
190 vap->va_nlink = ip->i_nlink;
191 vap->va_uid = ip->i_mp->ntm_uid;
192 vap->va_gid = ip->i_mp->ntm_gid;
193 vap->va_rdev = 0; /* XXX UNODEV ? */
194 vap->va_size = fp->f_size;
195 vap->va_bytes = fp->f_allocated;
196 vap->va_atime = ntfs_nttimetounix(fp->f_times.t_access);
197 vap->va_mtime = ntfs_nttimetounix(fp->f_times.t_write);
198 vap->va_ctime = ntfs_nttimetounix(fp->f_times.t_create);
199 vap->va_flags = ip->i_flag;
200 vap->va_gen = 0;
201 vap->va_blocksize = ip->i_mp->ntm_spc * ip->i_mp->ntm_bps;
202 vap->va_type = vp->v_type;
203 vap->va_filerev = 0;
204 return (0);
205 }
206
207 /*
208 * Last reference to an ntnode. If necessary, write or delete it.
209 */
210 int
211 ntfs_inactive(ap)
212 struct vop_inactive_args /* {
213 struct vnode *a_vp;
214 } */ *ap;
215 {
216 register struct vnode *vp = ap->a_vp;
217 #ifdef NTFS_DEBUG
218 register struct ntnode *ip = VTONT(vp);
219 #endif
220
221 dprintf(("ntfs_inactive: vnode: %p, ntnode: %d\n", vp, ip->i_number));
222
223 if (ntfs_prtactive && vrefcnt(vp) != 0)
224 vprint("ntfs_inactive: pushing active", vp);
225
226 /* XXX since we don't support any filesystem changes
227 * right now, nothing more needs to be done
228 */
229 return (0);
230 }
231
232 /*
233 * Reclaim an fnode/ntnode so that it can be used for other purposes.
234 */
235 int
236 ntfs_reclaim(ap)
237 struct vop_reclaim_args /* {
238 struct vnode *a_vp;
239 } */ *ap;
240 {
241 register struct vnode *vp = ap->a_vp;
242 register struct fnode *fp = VTOF(vp);
243 register struct ntnode *ip = FTONT(fp);
244 int error;
245
246 dprintf(("ntfs_reclaim: vnode: %p, ntnode: %d\n", vp, ip->i_number));
247
248 if (ntfs_prtactive && vrefcnt(vp) != 0)
249 vprint("ntfs_reclaim: pushing active", vp);
250
251 /*
252 * Destroy the vm object and flush associated pages.
253 */
254 vnode_destroy_vobject(vp);
255
256 if ((error = ntfs_ntget(ip)) != 0)
257 return (error);
258
259 /* Purge old data structures associated with the inode. */
260 ntfs_frele(fp);
261 ntfs_ntput(ip);
262 vp->v_data = NULL;
263
264 return (0);
265 }
266
267 /*
268 * Calculate the logical to physical mapping if not done already,
269 * then call the device strategy routine.
270 */
271 int
272 ntfs_strategy(ap)
273 struct vop_strategy_args /* {
274 struct buf *a_bp;
275 } */ *ap;
276 {
277 register struct buf *bp = ap->a_bp;
278 register struct vnode *vp = ap->a_vp;
279 register struct fnode *fp = VTOF(vp);
280 register struct ntnode *ip = FTONT(fp);
281 struct ntfsmount *ntmp = ip->i_mp;
282 int error;
283
284 dprintf(("ntfs_strategy: offset: %d, blkno: %d, lblkno: %d\n",
285 (u_int32_t)bp->b_offset,(u_int32_t)bp->b_blkno,
286 (u_int32_t)bp->b_lblkno));
287
288 dprintf(("strategy: bcount: %d flags: 0x%lx\n",
289 (u_int32_t)bp->b_bcount,bp->b_flags));
290
291 if (bp->b_iocmd == BIO_READ) {
292 u_int32_t toread;
293
294 if (ntfs_cntob(bp->b_blkno) >= fp->f_size) {
295 clrbuf(bp);
296 error = 0;
297 } else {
298 toread = min(bp->b_bcount,
299 fp->f_size-ntfs_cntob(bp->b_blkno));
300 dprintf(("ntfs_strategy: toread: %d, fsize: %d\n",
301 toread,(u_int32_t)fp->f_size));
302
303 error = ntfs_readattr(ntmp, ip, fp->f_attrtype,
304 fp->f_attrname, ntfs_cntob(bp->b_blkno),
305 toread, bp->b_data, NULL);
306
307 if (error) {
308 printf("ntfs_strategy: ntfs_readattr failed\n");
309 bp->b_error = error;
310 bp->b_ioflags |= BIO_ERROR;
311 }
312
313 bzero(bp->b_data + toread, bp->b_bcount - toread);
314 }
315 } else {
316 size_t tmp;
317 u_int32_t towrite;
318
319 if (ntfs_cntob(bp->b_blkno) + bp->b_bcount >= fp->f_size) {
320 printf("ntfs_strategy: CAN'T EXTEND FILE\n");
321 bp->b_error = error = EFBIG;
322 bp->b_ioflags |= BIO_ERROR;
323 } else {
324 towrite = min(bp->b_bcount,
325 fp->f_size-ntfs_cntob(bp->b_blkno));
326 dprintf(("ntfs_strategy: towrite: %d, fsize: %d\n",
327 towrite,(u_int32_t)fp->f_size));
328
329 error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
330 fp->f_attrname, ntfs_cntob(bp->b_blkno),towrite,
331 bp->b_data, &tmp, NULL);
332
333 if (error) {
334 printf("ntfs_strategy: ntfs_writeattr fail\n");
335 bp->b_error = error;
336 bp->b_ioflags |= BIO_ERROR;
337 }
338 }
339 }
340 bufdone(bp);
341 return (error);
342 }
343
344 static int
345 ntfs_write(ap)
346 struct vop_write_args /* {
347 struct vnode *a_vp;
348 struct uio *a_uio;
349 int a_ioflag;
350 struct ucred *a_cred;
351 } */ *ap;
352 {
353 register struct vnode *vp = ap->a_vp;
354 register struct fnode *fp = VTOF(vp);
355 register struct ntnode *ip = FTONT(fp);
356 struct uio *uio = ap->a_uio;
357 struct ntfsmount *ntmp = ip->i_mp;
358 u_int64_t towrite;
359 size_t written;
360 int error;
361
362 dprintf(("ntfs_write: ino: %d, off: %d resid: %d, segflg: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg));
363 dprintf(("ntfs_write: filesize: %d",(u_int32_t)fp->f_size));
364
365 if (uio->uio_resid + uio->uio_offset > fp->f_size) {
366 printf("ntfs_write: CAN'T WRITE BEYOND END OF FILE\n");
367 return (EFBIG);
368 }
369
370 towrite = min(uio->uio_resid, fp->f_size - uio->uio_offset);
371
372 dprintf((", towrite: %d\n",(u_int32_t)towrite));
373
374 error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
375 fp->f_attrname, uio->uio_offset, towrite, NULL, &written, uio);
376 #ifdef NTFS_DEBUG
377 if (error)
378 printf("ntfs_write: ntfs_writeattr failed: %d\n", error);
379 #endif
380
381 return (error);
382 }
383
384 int
385 ntfs_access(ap)
386 struct vop_access_args /* {
387 struct vnode *a_vp;
388 int a_mode;
389 struct ucred *a_cred;
390 struct thread *a_td;
391 } */ *ap;
392 {
393 struct vnode *vp = ap->a_vp;
394 struct ntnode *ip = VTONT(vp);
395 mode_t mode = ap->a_mode;
396 #ifdef QUOTA
397 int error;
398 #endif
399
400 dprintf(("ntfs_access: %d\n",ip->i_number));
401
402 /*
403 * Disallow write attempts on read-only filesystems;
404 * unless the file is a socket, fifo, or a block or
405 * character device resident on the filesystem.
406 */
407 if (mode & VWRITE) {
408 switch ((int)vp->v_type) {
409 case VDIR:
410 case VLNK:
411 case VREG:
412 if (vp->v_mount->mnt_flag & MNT_RDONLY)
413 return (EROFS);
414 #ifdef QUOTA
415 if (error = getinoquota(ip))
416 return (error);
417 #endif
418 break;
419 }
420 }
421
422 return (vaccess(vp->v_type, ip->i_mp->ntm_mode, ip->i_mp->ntm_uid,
423 ip->i_mp->ntm_gid, ap->a_mode, ap->a_cred, NULL));
424 }
425
426 /*
427 * Open called.
428 *
429 * Nothing to do.
430 */
431 /* ARGSUSED */
432 static int
433 ntfs_open(ap)
434 struct vop_open_args /* {
435 struct vnode *a_vp;
436 int a_mode;
437 struct ucred *a_cred;
438 struct thread *a_td;
439 } */ *ap;
440 {
441 #if NTFS_DEBUG
442 register struct vnode *vp = ap->a_vp;
443 register struct ntnode *ip = VTONT(vp);
444
445 printf("ntfs_open: %d\n",ip->i_number);
446 #endif
447
448 vnode_create_vobject_off(ap->a_vp, VTOF(ap->a_vp)->f_size, ap->a_td);
449
450 /*
451 * Files marked append-only must be opened for appending.
452 */
453
454 return (0);
455 }
456
457 /*
458 * Close called.
459 *
460 * Update the times on the inode.
461 */
462 /* ARGSUSED */
463 static int
464 ntfs_close(ap)
465 struct vop_close_args /* {
466 struct vnode *a_vp;
467 int a_fflag;
468 struct ucred *a_cred;
469 struct thread *a_td;
470 } */ *ap;
471 {
472 #if NTFS_DEBUG
473 register struct vnode *vp = ap->a_vp;
474 register struct ntnode *ip = VTONT(vp);
475
476 printf("ntfs_close: %d\n",ip->i_number);
477 #endif
478
479 return (0);
480 }
481
482 int
483 ntfs_readdir(ap)
484 struct vop_readdir_args /* {
485 struct vnode *a_vp;
486 struct uio *a_uio;
487 struct ucred *a_cred;
488 int *a_ncookies;
489 u_int **cookies;
490 } */ *ap;
491 {
492 register struct vnode *vp = ap->a_vp;
493 register struct fnode *fp = VTOF(vp);
494 register struct ntnode *ip = FTONT(fp);
495 struct uio *uio = ap->a_uio;
496 struct ntfsmount *ntmp = ip->i_mp;
497 int i, j, error = 0;
498 wchar c;
499 u_int32_t faked = 0, num;
500 int ncookies = 0;
501 struct dirent cde;
502 off_t off;
503
504 dprintf(("ntfs_readdir %d off: %d resid: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid));
505
506 off = uio->uio_offset;
507
508 /* Simulate . in every dir except ROOT */
509 if( ip->i_number != NTFS_ROOTINO ) {
510 struct dirent dot = { NTFS_ROOTINO,
511 sizeof(struct dirent), DT_DIR, 1, "." };
512
513 if( uio->uio_offset < sizeof(struct dirent) ) {
514 dot.d_fileno = ip->i_number;
515 error = uiomove((char *)&dot,sizeof(struct dirent),uio);
516 if(error)
517 return (error);
518
519 ncookies ++;
520 }
521 }
522
523 /* Simulate .. in every dir including ROOT */
524 if( uio->uio_offset < 2 * sizeof(struct dirent) ) {
525 struct dirent dotdot = { NTFS_ROOTINO,
526 sizeof(struct dirent), DT_DIR, 2, ".." };
527
528 error = uiomove((char *)&dotdot,sizeof(struct dirent),uio);
529 if(error)
530 return (error);
531
532 ncookies ++;
533 }
534
535 faked = (ip->i_number == NTFS_ROOTINO) ? 1 : 2;
536 num = uio->uio_offset / sizeof(struct dirent) - faked;
537
538 while( uio->uio_resid >= sizeof(struct dirent) ) {
539 struct attr_indexentry *iep;
540
541 error = ntfs_ntreaddir(ntmp, fp, num, &iep);
542
543 if(error)
544 return (error);
545
546 if( NULL == iep )
547 break;
548
549 for(; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (uio->uio_resid >= sizeof(struct dirent));
550 iep = NTFS_NEXTREC(iep, struct attr_indexentry *))
551 {
552 if(!ntfs_isnamepermitted(ntmp,iep))
553 continue;
554
555 for(i=0, j=0; i<iep->ie_fnamelen; i++, j++) {
556 c = NTFS_U28(iep->ie_fname[i]);
557 if (c&0xFF00)
558 cde.d_name[j++] = (char)(c>>8);
559 cde.d_name[j] = (char)c&0xFF;
560 }
561 cde.d_name[j] = '\0';
562 dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",
563 num, cde.d_name, iep->ie_fnametype,
564 iep->ie_flag));
565 cde.d_namlen = j;
566 cde.d_fileno = iep->ie_number;
567 cde.d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
568 cde.d_reclen = sizeof(struct dirent);
569 dprintf(("%s\n", (cde.d_type == DT_DIR) ? "dir":"reg"));
570
571 error = uiomove((char *)&cde, sizeof(struct dirent), uio);
572 if(error)
573 return (error);
574
575 ncookies++;
576 num++;
577 }
578 }
579
580 dprintf(("ntfs_readdir: %d entries (%d bytes) read\n",
581 ncookies,(u_int)(uio->uio_offset - off)));
582 dprintf(("ntfs_readdir: off: %d resid: %d\n",
583 (u_int32_t)uio->uio_offset,uio->uio_resid));
584
585 if (!error && ap->a_ncookies != NULL) {
586 struct dirent* dpStart;
587 struct dirent* dp;
588 u_long *cookies;
589 u_long *cookiep;
590
591 ddprintf(("ntfs_readdir: %d cookies\n",ncookies));
592 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
593 panic("ntfs_readdir: unexpected uio from NFS server");
594 dpStart = (struct dirent *)
595 ((caddr_t)uio->uio_iov->iov_base -
596 (uio->uio_offset - off));
597 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
598 M_TEMP, M_WAITOK);
599 for (dp = dpStart, cookiep = cookies, i=0;
600 i < ncookies;
601 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen), i++) {
602 off += dp->d_reclen;
603 *cookiep++ = (u_int) off;
604 }
605 *ap->a_ncookies = ncookies;
606 *ap->a_cookies = cookies;
607 }
608 /*
609 if (ap->a_eofflag)
610 *ap->a_eofflag = VTONT(ap->a_vp)->i_size <= uio->uio_offset;
611 */
612 return (error);
613 }
614
615 int
616 ntfs_lookup(ap)
617 struct vop_cachedlookup_args /* {
618 struct vnode *a_dvp;
619 struct vnode **a_vpp;
620 struct componentname *a_cnp;
621 } */ *ap;
622 {
623 register struct vnode *dvp = ap->a_dvp;
624 register struct ntnode *dip = VTONT(dvp);
625 struct ntfsmount *ntmp = dip->i_mp;
626 struct componentname *cnp = ap->a_cnp;
627 struct ucred *cred = cnp->cn_cred;
628 int error;
629 dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %d\n",
630 (int)cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_namelen,
631 dip->i_number));
632
633 error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_thread);
634 if(error)
635 return (error);
636
637 if ((cnp->cn_flags & ISLASTCN) &&
638 (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
639 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
640 return (EROFS);
641
642 if(cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
643 dprintf(("ntfs_lookup: faking . directory in %d\n",
644 dip->i_number));
645
646 VREF(dvp);
647 *ap->a_vpp = dvp;
648 error = 0;
649 } else if (cnp->cn_flags & ISDOTDOT) {
650 struct ntvattr *vap;
651
652 dprintf(("ntfs_lookup: faking .. directory in %d\n",
653 dip->i_number));
654
655 error = ntfs_ntvattrget(ntmp, dip, NTFS_A_NAME, NULL, 0, &vap);
656 if(error)
657 return (error);
658
659 VOP_UNLOCK(dvp,0,cnp->cn_thread);
660 dprintf(("ntfs_lookup: parentdir: %d\n",
661 vap->va_a_name->n_pnumber));
662 error = VFS_VGET(ntmp->ntm_mountp, vap->va_a_name->n_pnumber,
663 LK_EXCLUSIVE, ap->a_vpp);
664 ntfs_ntvattrrele(vap);
665 if (error) {
666 vn_lock(dvp,LK_EXCLUSIVE|LK_RETRY,cnp->cn_thread);
667 return (error);
668 }
669 } else {
670 error = ntfs_ntlookupfile(ntmp, dvp, cnp, ap->a_vpp);
671 if (error) {
672 dprintf(("ntfs_ntlookupfile: returned %d\n", error));
673 return (error);
674 }
675
676 dprintf(("ntfs_lookup: found ino: %d\n",
677 VTONT(*ap->a_vpp)->i_number));
678 }
679
680 if (cnp->cn_flags & MAKEENTRY)
681 cache_enter(dvp, *ap->a_vpp, cnp);
682
683 return (error);
684 }
685
686 /*
687 * Flush the blocks of a file to disk.
688 *
689 * This function is worthless for vnodes that represent directories. Maybe we
690 * could just do a sync if they try an fsync on a directory file.
691 */
692 static int
693 ntfs_fsync(ap)
694 struct vop_fsync_args /* {
695 struct vnode *a_vp;
696 struct ucred *a_cred;
697 int a_waitfor;
698 struct thread *a_td;
699 } */ *ap;
700 {
701 return (0);
702 }
703
704 /*
705 * Return POSIX pathconf information applicable to NTFS filesystem
706 */
707 int
708 ntfs_pathconf(ap)
709 struct vop_pathconf_args *ap;
710 {
711
712 switch (ap->a_name) {
713 case _PC_LINK_MAX:
714 *ap->a_retval = 1;
715 return (0);
716 case _PC_NAME_MAX:
717 *ap->a_retval = NTFS_MAXFILENAME;
718 return (0);
719 case _PC_PATH_MAX:
720 *ap->a_retval = PATH_MAX;
721 return (0);
722 case _PC_CHOWN_RESTRICTED:
723 *ap->a_retval = 1;
724 return (0);
725 case _PC_NO_TRUNC:
726 *ap->a_retval = 0;
727 return (0);
728 default:
729 return (EINVAL);
730 }
731 /* NOTREACHED */
732 }
733
734 /*
735 * Global vfs data structures
736 */
737 struct vop_vector ntfs_vnodeops = {
738 .vop_default = &default_vnodeops,
739
740 .vop_access = ntfs_access,
741 .vop_bmap = ntfs_bmap,
742 .vop_cachedlookup = ntfs_lookup,
743 .vop_close = ntfs_close,
744 .vop_fsync = ntfs_fsync,
745 .vop_getattr = ntfs_getattr,
746 .vop_inactive = ntfs_inactive,
747 .vop_lookup = vfs_cache_lookup,
748 .vop_open = ntfs_open,
749 .vop_pathconf = ntfs_pathconf,
750 .vop_read = ntfs_read,
751 .vop_readdir = ntfs_readdir,
752 .vop_reclaim = ntfs_reclaim,
753 .vop_strategy = ntfs_strategy,
754 .vop_write = ntfs_write,
755 };
Cache object: cefacd004355770708b3ed27736dac76
|