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$
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 static vop_vptofh_t ntfs_vptofh;
84
85 int ntfs_prtactive = 1; /* 1 => print out reclaim of active vnodes */
86
87 /*
88 * This is a noop, simply returning what one has been given.
89 */
90 int
91 ntfs_bmap(ap)
92 struct vop_bmap_args /* {
93 struct vnode *a_vp;
94 daddr_t a_bn;
95 struct bufobj **a_bop;
96 daddr_t *a_bnp;
97 int *a_runp;
98 int *a_runb;
99 } */ *ap;
100 {
101 struct vnode *vp = ap->a_vp;
102
103 dprintf(("ntfs_bmap: vn: %p, blk: %d\n", ap->a_vp,(u_int32_t)ap->a_bn));
104 if (ap->a_bop != NULL)
105 *ap->a_bop = &vp->v_bufobj;
106 if (ap->a_bnp != NULL)
107 *ap->a_bnp = ap->a_bn;
108 if (ap->a_runp != NULL)
109 *ap->a_runp = 0;
110 if (ap->a_runb != NULL)
111 *ap->a_runb = 0;
112 return (0);
113 }
114
115 static int
116 ntfs_read(ap)
117 struct vop_read_args /* {
118 struct vnode *a_vp;
119 struct uio *a_uio;
120 int a_ioflag;
121 struct ucred *a_cred;
122 } */ *ap;
123 {
124 register struct vnode *vp = ap->a_vp;
125 register struct fnode *fp = VTOF(vp);
126 register struct ntnode *ip = FTONT(fp);
127 struct uio *uio = ap->a_uio;
128 struct ntfsmount *ntmp = ip->i_mp;
129 struct buf *bp;
130 daddr_t cn;
131 int resid, off, toread;
132 int error;
133
134 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));
135
136 dprintf(("ntfs_read: filesize: %d",(u_int32_t)fp->f_size));
137
138 /* don't allow reading after end of file */
139 if (uio->uio_offset > fp->f_size)
140 return (0);
141
142 resid = MIN(uio->uio_resid, fp->f_size - uio->uio_offset);
143
144 dprintf((", resid: %d\n", resid));
145
146 error = 0;
147 while (resid) {
148 cn = ntfs_btocn(uio->uio_offset);
149 off = ntfs_btocnoff(uio->uio_offset);
150
151 toread = MIN(off + resid, ntfs_cntob(1));
152
153 error = bread(vp, cn, ntfs_cntob(1), NOCRED, &bp);
154 if (error) {
155 brelse(bp);
156 break;
157 }
158
159 error = uiomove(bp->b_data + off, toread - off, uio);
160 if(error) {
161 brelse(bp);
162 break;
163 }
164 brelse(bp);
165
166 resid -= toread - off;
167 }
168
169 return (error);
170 }
171
172 static int
173 ntfs_getattr(ap)
174 struct vop_getattr_args /* {
175 struct vnode *a_vp;
176 struct vattr *a_vap;
177 struct ucred *a_cred;
178 struct thread *a_td;
179 } */ *ap;
180 {
181 register struct vnode *vp = ap->a_vp;
182 register struct fnode *fp = VTOF(vp);
183 register struct ntnode *ip = FTONT(fp);
184 register struct vattr *vap = ap->a_vap;
185
186 dprintf(("ntfs_getattr: %d, flags: %d\n",ip->i_number,ip->i_flag));
187
188 vap->va_fsid = dev2udev(ip->i_dev);
189 vap->va_fileid = ip->i_number;
190 vap->va_mode = ip->i_mp->ntm_mode;
191 vap->va_nlink = (ip->i_nlink || ip->i_flag & IN_LOADED ? ip->i_nlink : 1);
192 vap->va_uid = ip->i_mp->ntm_uid;
193 vap->va_gid = ip->i_mp->ntm_gid;
194 vap->va_rdev = 0; /* XXX UNODEV ? */
195 vap->va_size = fp->f_size;
196 vap->va_bytes = fp->f_allocated;
197 vap->va_atime = ntfs_nttimetounix(fp->f_times.t_access);
198 vap->va_mtime = ntfs_nttimetounix(fp->f_times.t_write);
199 vap->va_ctime = ntfs_nttimetounix(fp->f_times.t_create);
200 vap->va_flags = ip->i_flag;
201 vap->va_gen = 0;
202 vap->va_blocksize = ip->i_mp->ntm_spc * ip->i_mp->ntm_bps;
203 vap->va_type = vp->v_type;
204 vap->va_filerev = 0;
205 return (0);
206 }
207
208 /*
209 * Last reference to an ntnode. If necessary, write or delete it.
210 */
211 int
212 ntfs_inactive(ap)
213 struct vop_inactive_args /* {
214 struct vnode *a_vp;
215 } */ *ap;
216 {
217 register struct vnode *vp = ap->a_vp;
218 #ifdef NTFS_DEBUG
219 register struct ntnode *ip = VTONT(vp);
220 #endif
221
222 dprintf(("ntfs_inactive: vnode: %p, ntnode: %d\n", vp, ip->i_number));
223
224 if (ntfs_prtactive && vrefcnt(vp) != 0)
225 vprint("ntfs_inactive: pushing active", vp);
226
227 /* XXX since we don't support any filesystem changes
228 * right now, nothing more needs to be done
229 */
230 return (0);
231 }
232
233 /*
234 * Reclaim an fnode/ntnode so that it can be used for other purposes.
235 */
236 int
237 ntfs_reclaim(ap)
238 struct vop_reclaim_args /* {
239 struct vnode *a_vp;
240 } */ *ap;
241 {
242 register struct vnode *vp = ap->a_vp;
243 register struct fnode *fp = VTOF(vp);
244 register struct ntnode *ip = FTONT(fp);
245 int error;
246
247 dprintf(("ntfs_reclaim: vnode: %p, ntnode: %d\n", vp, ip->i_number));
248
249 if (ntfs_prtactive && vrefcnt(vp) != 0)
250 vprint("ntfs_reclaim: pushing active", vp);
251
252 /*
253 * Destroy the vm object and flush associated pages.
254 */
255 vnode_destroy_vobject(vp);
256
257 if ((error = ntfs_ntget(ip)) != 0)
258 return (error);
259
260 /* Purge old data structures associated with the inode. */
261 ntfs_frele(fp);
262 ntfs_ntput(ip);
263 vp->v_data = NULL;
264
265 return (0);
266 }
267
268 /*
269 * Calculate the logical to physical mapping if not done already,
270 * then call the device strategy routine.
271 */
272 int
273 ntfs_strategy(ap)
274 struct vop_strategy_args /* {
275 struct buf *a_bp;
276 } */ *ap;
277 {
278 register struct buf *bp = ap->a_bp;
279 register struct vnode *vp = ap->a_vp;
280 register struct fnode *fp = VTOF(vp);
281 register struct ntnode *ip = FTONT(fp);
282 struct ntfsmount *ntmp = ip->i_mp;
283 int error;
284
285 dprintf(("ntfs_strategy: offset: %d, blkno: %d, lblkno: %d\n",
286 (u_int32_t)bp->b_offset,(u_int32_t)bp->b_blkno,
287 (u_int32_t)bp->b_lblkno));
288
289 dprintf(("strategy: bcount: %d flags: 0x%x\n",
290 (u_int32_t)bp->b_bcount,bp->b_flags));
291
292 if (bp->b_iocmd == BIO_READ) {
293 u_int32_t toread;
294
295 if (ntfs_cntob(bp->b_blkno) >= fp->f_size) {
296 clrbuf(bp);
297 error = 0;
298 } else {
299 toread = MIN(bp->b_bcount,
300 fp->f_size-ntfs_cntob(bp->b_blkno));
301 dprintf(("ntfs_strategy: toread: %d, fsize: %d\n",
302 toread,(u_int32_t)fp->f_size));
303
304 error = ntfs_readattr(ntmp, ip, fp->f_attrtype,
305 fp->f_attrname, ntfs_cntob(bp->b_blkno),
306 toread, bp->b_data, NULL);
307
308 if (error) {
309 printf("ntfs_strategy: ntfs_readattr failed\n");
310 bp->b_error = error;
311 bp->b_ioflags |= BIO_ERROR;
312 }
313
314 bzero(bp->b_data + toread, bp->b_bcount - toread);
315 }
316 } else {
317 size_t tmp;
318 u_int32_t towrite;
319
320 if (ntfs_cntob(bp->b_blkno) + bp->b_bcount >= fp->f_size) {
321 printf("ntfs_strategy: CAN'T EXTEND FILE\n");
322 bp->b_error = error = EFBIG;
323 bp->b_ioflags |= BIO_ERROR;
324 } else {
325 towrite = MIN(bp->b_bcount,
326 fp->f_size-ntfs_cntob(bp->b_blkno));
327 dprintf(("ntfs_strategy: towrite: %d, fsize: %d\n",
328 towrite,(u_int32_t)fp->f_size));
329
330 error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
331 fp->f_attrname, ntfs_cntob(bp->b_blkno),towrite,
332 bp->b_data, &tmp, NULL);
333
334 if (error) {
335 printf("ntfs_strategy: ntfs_writeattr fail\n");
336 bp->b_error = error;
337 bp->b_ioflags |= BIO_ERROR;
338 }
339 }
340 }
341 bufdone(bp);
342 return (error);
343 }
344
345 static int
346 ntfs_write(ap)
347 struct vop_write_args /* {
348 struct vnode *a_vp;
349 struct uio *a_uio;
350 int a_ioflag;
351 struct ucred *a_cred;
352 } */ *ap;
353 {
354 register struct vnode *vp = ap->a_vp;
355 register struct fnode *fp = VTOF(vp);
356 register struct ntnode *ip = FTONT(fp);
357 struct uio *uio = ap->a_uio;
358 struct ntfsmount *ntmp = ip->i_mp;
359 u_int64_t towrite;
360 size_t written;
361 int error;
362
363 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));
364 dprintf(("ntfs_write: filesize: %d",(u_int32_t)fp->f_size));
365
366 if (uio->uio_resid + uio->uio_offset > fp->f_size) {
367 printf("ntfs_write: CAN'T WRITE BEYOND END OF FILE\n");
368 return (EFBIG);
369 }
370
371 towrite = MIN(uio->uio_resid, fp->f_size - uio->uio_offset);
372
373 dprintf((", towrite: %d\n",(u_int32_t)towrite));
374
375 error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
376 fp->f_attrname, uio->uio_offset, towrite, NULL, &written, uio);
377 #ifdef NTFS_DEBUG
378 if (error)
379 printf("ntfs_write: ntfs_writeattr failed: %d\n", error);
380 #endif
381
382 return (error);
383 }
384
385 int
386 ntfs_access(ap)
387 struct vop_access_args /* {
388 struct vnode *a_vp;
389 int a_mode;
390 struct ucred *a_cred;
391 struct thread *a_td;
392 } */ *ap;
393 {
394 struct vnode *vp = ap->a_vp;
395 struct ntnode *ip = VTONT(vp);
396 mode_t mode = ap->a_mode;
397 #ifdef QUOTA
398 int error;
399 #endif
400
401 dprintf(("ntfs_access: %d\n",ip->i_number));
402
403 /*
404 * Disallow write attempts on read-only filesystems;
405 * unless the file is a socket, fifo, or a block or
406 * character device resident on the filesystem.
407 */
408 if (mode & VWRITE) {
409 switch ((int)vp->v_type) {
410 case VDIR:
411 case VLNK:
412 case VREG:
413 if (vp->v_mount->mnt_flag & MNT_RDONLY)
414 return (EROFS);
415 #ifdef QUOTA
416 if (error = getinoquota(ip))
417 return (error);
418 #endif
419 break;
420 }
421 }
422
423 return (vaccess(vp->v_type, ip->i_mp->ntm_mode, ip->i_mp->ntm_uid,
424 ip->i_mp->ntm_gid, ap->a_mode, ap->a_cred, NULL));
425 }
426
427 /*
428 * Open called.
429 *
430 * Nothing to do.
431 */
432 /* ARGSUSED */
433 static int
434 ntfs_open(ap)
435 struct vop_open_args /* {
436 struct vnode *a_vp;
437 int a_mode;
438 struct ucred *a_cred;
439 struct thread *a_td;
440 } */ *ap;
441 {
442 #ifdef NTFS_DEBUG
443 register struct vnode *vp = ap->a_vp;
444 register struct ntnode *ip = VTONT(vp);
445
446 printf("ntfs_open: %d\n",ip->i_number);
447 #endif
448
449 vnode_create_vobject(ap->a_vp, VTOF(ap->a_vp)->f_size, ap->a_td);
450
451 /*
452 * Files marked append-only must be opened for appending.
453 */
454
455 return (0);
456 }
457
458 /*
459 * Close called.
460 *
461 * Update the times on the inode.
462 */
463 /* ARGSUSED */
464 static int
465 ntfs_close(ap)
466 struct vop_close_args /* {
467 struct vnode *a_vp;
468 int a_fflag;
469 struct ucred *a_cred;
470 struct thread *a_td;
471 } */ *ap;
472 {
473 #ifdef NTFS_DEBUG
474 register struct vnode *vp = ap->a_vp;
475 register struct ntnode *ip = VTONT(vp);
476
477 printf("ntfs_close: %d\n",ip->i_number);
478 #endif
479
480 return (0);
481 }
482
483 int
484 ntfs_readdir(ap)
485 struct vop_readdir_args /* {
486 struct vnode *a_vp;
487 struct uio *a_uio;
488 struct ucred *a_cred;
489 int *a_ncookies;
490 u_int **cookies;
491 } */ *ap;
492 {
493 register struct vnode *vp = ap->a_vp;
494 register struct fnode *fp = VTOF(vp);
495 register struct ntnode *ip = FTONT(fp);
496 struct uio *uio = ap->a_uio;
497 struct ntfsmount *ntmp = ip->i_mp;
498 int i, j, error = 0;
499 wchar c;
500 u_int32_t faked = 0, num;
501 int ncookies = 0;
502 struct dirent cde;
503 off_t off;
504
505 dprintf(("ntfs_readdir %d off: %d resid: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid));
506
507 off = uio->uio_offset;
508
509 /* Simulate . in every dir except ROOT */
510 if( ip->i_number != NTFS_ROOTINO ) {
511 struct dirent dot = { NTFS_ROOTINO,
512 sizeof(struct dirent), DT_DIR, 1, "." };
513
514 if( uio->uio_offset < sizeof(struct dirent) ) {
515 dot.d_fileno = ip->i_number;
516 error = uiomove((char *)&dot,sizeof(struct dirent),uio);
517 if(error)
518 return (error);
519
520 ncookies ++;
521 }
522 }
523
524 /* Simulate .. in every dir including ROOT */
525 if( uio->uio_offset < 2 * sizeof(struct dirent) ) {
526 struct dirent dotdot = { NTFS_ROOTINO,
527 sizeof(struct dirent), DT_DIR, 2, ".." };
528
529 error = uiomove((char *)&dotdot,sizeof(struct dirent),uio);
530 if(error)
531 return (error);
532
533 ncookies ++;
534 }
535
536 faked = (ip->i_number == NTFS_ROOTINO) ? 1 : 2;
537 num = uio->uio_offset / sizeof(struct dirent) - faked;
538
539 while( uio->uio_resid >= sizeof(struct dirent) ) {
540 struct attr_indexentry *iep;
541
542 error = ntfs_ntreaddir(ntmp, fp, num, &iep);
543
544 if(error)
545 return (error);
546
547 if( NULL == iep )
548 break;
549
550 for(; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (uio->uio_resid >= sizeof(struct dirent));
551 iep = NTFS_NEXTREC(iep, struct attr_indexentry *))
552 {
553 if(!ntfs_isnamepermitted(ntmp,iep))
554 continue;
555
556 for(i=0, j=0; i<iep->ie_fnamelen; i++, j++) {
557 c = NTFS_U28(iep->ie_fname[i]);
558 if (c&0xFF00)
559 cde.d_name[j++] = (char)(c>>8);
560 cde.d_name[j] = (char)c&0xFF;
561 }
562 cde.d_name[j] = '\0';
563 dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",
564 num, cde.d_name, iep->ie_fnametype,
565 iep->ie_flag));
566 cde.d_namlen = j;
567 cde.d_fileno = iep->ie_number;
568 cde.d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
569 cde.d_reclen = sizeof(struct dirent);
570 dprintf(("%s\n", (cde.d_type == DT_DIR) ? "dir":"reg"));
571
572 error = uiomove((char *)&cde, sizeof(struct dirent), uio);
573 if(error)
574 return (error);
575
576 ncookies++;
577 num++;
578 }
579 }
580
581 dprintf(("ntfs_readdir: %d entries (%d bytes) read\n",
582 ncookies,(u_int)(uio->uio_offset - off)));
583 dprintf(("ntfs_readdir: off: %d resid: %d\n",
584 (u_int32_t)uio->uio_offset,uio->uio_resid));
585
586 if (!error && ap->a_ncookies != NULL) {
587 struct dirent* dpStart;
588 struct dirent* dp;
589 u_long *cookies;
590 u_long *cookiep;
591
592 ddprintf(("ntfs_readdir: %d cookies\n",ncookies));
593 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
594 panic("ntfs_readdir: unexpected uio from NFS server");
595 dpStart = (struct dirent *)
596 ((caddr_t)uio->uio_iov->iov_base -
597 (uio->uio_offset - off));
598 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
599 M_TEMP, M_WAITOK);
600 for (dp = dpStart, cookiep = cookies, i=0;
601 i < ncookies;
602 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen), i++) {
603 off += dp->d_reclen;
604 *cookiep++ = (u_int) off;
605 }
606 *ap->a_ncookies = ncookies;
607 *ap->a_cookies = cookies;
608 }
609 /*
610 if (ap->a_eofflag)
611 *ap->a_eofflag = VTONT(ap->a_vp)->i_size <= uio->uio_offset;
612 */
613 return (error);
614 }
615
616 int
617 ntfs_lookup(ap)
618 struct vop_cachedlookup_args /* {
619 struct vnode *a_dvp;
620 struct vnode **a_vpp;
621 struct componentname *a_cnp;
622 } */ *ap;
623 {
624 register struct vnode *dvp = ap->a_dvp;
625 register struct ntnode *dip = VTONT(dvp);
626 struct ntfsmount *ntmp = dip->i_mp;
627 struct componentname *cnp = ap->a_cnp;
628 struct ucred *cred = cnp->cn_cred;
629 int error;
630 dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %d\n",
631 (int)cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_namelen,
632 dip->i_number));
633
634 error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_thread);
635 if(error)
636 return (error);
637
638 if ((cnp->cn_flags & ISLASTCN) &&
639 (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
640 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
641 return (EROFS);
642
643 if(cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
644 dprintf(("ntfs_lookup: faking . directory in %d\n",
645 dip->i_number));
646
647 VREF(dvp);
648 *ap->a_vpp = dvp;
649 error = 0;
650 } else if (cnp->cn_flags & ISDOTDOT) {
651 struct ntvattr *vap;
652
653 dprintf(("ntfs_lookup: faking .. directory in %d\n",
654 dip->i_number));
655
656 error = ntfs_ntvattrget(ntmp, dip, NTFS_A_NAME, NULL, 0, &vap);
657 if(error)
658 return (error);
659
660 VOP_UNLOCK(dvp,0,cnp->cn_thread);
661 dprintf(("ntfs_lookup: parentdir: %d\n",
662 vap->va_a_name->n_pnumber));
663 error = VFS_VGET(ntmp->ntm_mountp, vap->va_a_name->n_pnumber,
664 LK_EXCLUSIVE, ap->a_vpp);
665 ntfs_ntvattrrele(vap);
666 if (error) {
667 vn_lock(dvp,LK_EXCLUSIVE|LK_RETRY,cnp->cn_thread);
668 return (error);
669 }
670 } else {
671 error = ntfs_ntlookupfile(ntmp, dvp, cnp, ap->a_vpp);
672 if (error) {
673 dprintf(("ntfs_ntlookupfile: returned %d\n", error));
674 return (error);
675 }
676
677 dprintf(("ntfs_lookup: found ino: %d\n",
678 VTONT(*ap->a_vpp)->i_number));
679 }
680
681 if (cnp->cn_flags & MAKEENTRY)
682 cache_enter(dvp, *ap->a_vpp, cnp);
683
684 return (error);
685 }
686
687 /*
688 * Flush the blocks of a file to disk.
689 *
690 * This function is worthless for vnodes that represent directories. Maybe we
691 * could just do a sync if they try an fsync on a directory file.
692 */
693 static int
694 ntfs_fsync(ap)
695 struct vop_fsync_args /* {
696 struct vnode *a_vp;
697 struct ucred *a_cred;
698 int a_waitfor;
699 struct thread *a_td;
700 } */ *ap;
701 {
702 return (0);
703 }
704
705 /*
706 * Return POSIX pathconf information applicable to NTFS filesystem
707 */
708 int
709 ntfs_pathconf(ap)
710 struct vop_pathconf_args *ap;
711 {
712
713 switch (ap->a_name) {
714 case _PC_LINK_MAX:
715 *ap->a_retval = 1;
716 return (0);
717 case _PC_NAME_MAX:
718 *ap->a_retval = NTFS_MAXFILENAME;
719 return (0);
720 case _PC_PATH_MAX:
721 *ap->a_retval = PATH_MAX;
722 return (0);
723 case _PC_CHOWN_RESTRICTED:
724 *ap->a_retval = 1;
725 return (0);
726 case _PC_NO_TRUNC:
727 *ap->a_retval = 0;
728 return (0);
729 default:
730 return (EINVAL);
731 }
732 /* NOTREACHED */
733 }
734
735 int
736 ntfs_vptofh(ap)
737 struct vop_vptofh_args /* {
738 struct vnode *a_vp;
739 struct fid *a_fhp;
740 } */ *ap;
741 {
742 register struct ntnode *ntp;
743 register struct ntfid *ntfhp;
744
745 ddprintf(("ntfs_fhtovp(): %p\n", ap->a_vp));
746
747 ntp = VTONT(ap->a_vp);
748 ntfhp = (struct ntfid *)ap->a_fhp;
749 ntfhp->ntfid_len = sizeof(struct ntfid);
750 ntfhp->ntfid_ino = ntp->i_number;
751 /* ntfhp->ntfid_gen = ntp->i_gen; */
752 return (0);
753 }
754
755 /*
756 * Global vfs data structures
757 */
758 struct vop_vector ntfs_vnodeops = {
759 .vop_default = &default_vnodeops,
760
761 .vop_access = ntfs_access,
762 .vop_bmap = ntfs_bmap,
763 .vop_cachedlookup = ntfs_lookup,
764 .vop_close = ntfs_close,
765 .vop_fsync = ntfs_fsync,
766 .vop_getattr = ntfs_getattr,
767 .vop_inactive = ntfs_inactive,
768 .vop_lookup = vfs_cache_lookup,
769 .vop_open = ntfs_open,
770 .vop_pathconf = ntfs_pathconf,
771 .vop_read = ntfs_read,
772 .vop_readdir = ntfs_readdir,
773 .vop_reclaim = ntfs_reclaim,
774 .vop_strategy = ntfs_strategy,
775 .vop_write = ntfs_write,
776 .vop_vptofh = ntfs_vptofh,
777 };
Cache object: 7fdcc2fd7703edf4ee23f8e41e3ae13b
|