xref: /dragonfly/sys/vfs/ntfs/ntfs_vnops.c (revision d4ef6694)
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  * 3. 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: src/sys/ntfs/ntfs_vnops.c,v 1.9.2.4 2002/08/06 19:35:18 semenu Exp $
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/proc.h>
47 #include <sys/namei.h>
48 #include <sys/malloc.h>
49 #include <sys/buf.h>
50 #include <sys/dirent.h>
51 #include <machine/limits.h>
52 
53 #include <vm/vm.h>
54 #include <vm/vm_param.h>
55 #include <vm/vm_page.h>
56 #include <vm/vm_object.h>
57 #include <vm/vm_pager.h>
58 #include <vm/vnode_pager.h>
59 #include <vm/vm_extern.h>
60 
61 #include <sys/sysctl.h>
62 
63 #include <sys/buf2.h>
64 
65 #include "ntfs.h"
66 #include "ntfs_inode.h"
67 #include "ntfs_subr.h"
68 
69 #include <sys/unistd.h> /* for pathconf(2) constants */
70 
71 static int	ntfs_read (struct vop_read_args *);
72 static int	ntfs_write (struct vop_write_args *ap);
73 static int	ntfs_getattr (struct vop_getattr_args *ap);
74 static int	ntfs_inactive (struct vop_inactive_args *ap);
75 static int	ntfs_print (struct vop_print_args *ap);
76 static int	ntfs_reclaim (struct vop_reclaim_args *ap);
77 static int	ntfs_strategy (struct vop_strategy_args *ap);
78 static int	ntfs_access (struct vop_access_args *ap);
79 static int	ntfs_open (struct vop_open_args *ap);
80 static int	ntfs_close (struct vop_close_args *ap);
81 static int	ntfs_readdir (struct vop_readdir_args *ap);
82 static int	ntfs_lookup (struct vop_old_lookup_args *ap);
83 static int	ntfs_bmap (struct vop_bmap_args *ap);
84 static int	ntfs_fsync (struct vop_fsync_args *ap);
85 static int	ntfs_pathconf (struct vop_pathconf_args *);
86 
87 int	ntfs_prtactive = 1;	/* 1 => print out reclaim of active vnodes */
88 
89 /*
90  * This is a noop, simply returning what one has been given.
91  *
92  * ntfs_bmap(struct vnode *a_vp, off_t a_loffset,
93  *	     daddr_t *a_doffsetp, int *a_runp, int *a_runb)
94  */
95 int
96 ntfs_bmap(struct vop_bmap_args *ap)
97 {
98 	dprintf(("ntfs_bmap: vn: %p, blk: %u\n", ap->a_vp,
99 		(u_int32_t)ap->a_loffset));
100 	if (ap->a_doffsetp != NULL)
101 		*ap->a_doffsetp = ap->a_loffset;
102 	if (ap->a_runp != NULL)
103 		*ap->a_runp = 0;
104 	if (ap->a_runb != NULL)
105 		*ap->a_runb = 0;
106 	return (0);
107 }
108 
109 /*
110  * ntfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
111  *	     struct ucred *a_cred)
112  */
113 static int
114 ntfs_read(struct vop_read_args *ap)
115 {
116 	struct vnode *vp = ap->a_vp;
117 	struct fnode *fp = VTOF(vp);
118 	struct ntnode *ip = FTONT(fp);
119 	struct uio *uio = ap->a_uio;
120 	struct ntfsmount *ntmp = ip->i_mp;
121 	struct buf *bp;
122 	daddr_t cn;
123 	int resid, off, toread;
124 	int error;
125 
126 	dprintf(("ntfs_read: ino: %ju, off: %u resid: %zd, segflg: %d\n",
127 		(uintmax_t)ip->i_number, (uint32_t)uio->uio_offset,
128 		uio->uio_resid, uio->uio_segflg));
129 
130 	dprintf(("ntfs_read: filesize: %ju", (uintmax_t)fp->f_size));
131 
132 	/* don't allow reading after end of file */
133 	if (uio->uio_offset > fp->f_size)
134 		return (0);
135 
136 	resid = (int)szmin(uio->uio_resid, fp->f_size - uio->uio_offset);
137 
138 	dprintf((", resid: %d\n", resid));
139 
140 	error = 0;
141 	while (resid) {
142 		cn = ntfs_btocn(uio->uio_offset);
143 		off = ntfs_btocnoff(uio->uio_offset);
144 
145 		toread = min(off + resid, ntfs_cntob(1));
146 
147 		error = bread(vp, ntfs_cntodoff(cn), ntfs_cntob(1), &bp);
148 		if (error) {
149 			brelse(bp);
150 			break;
151 		}
152 
153 		error = uiomovebp(bp, bp->b_data + off, toread - off, uio);
154 		if(error) {
155 			brelse(bp);
156 			break;
157 		}
158 		brelse(bp);
159 
160 		resid -= toread - off;
161 	}
162 
163 	return (error);
164 }
165 
166 /*
167  * ntfs_getattr(struct vnode *a_vp, struct vattr *a_vap)
168  */
169 static int
170 ntfs_getattr(struct vop_getattr_args *ap)
171 {
172 	struct vnode *vp = ap->a_vp;
173 	struct fnode *fp = VTOF(vp);
174 	struct ntnode *ip = FTONT(fp);
175 	struct vattr *vap = ap->a_vap;
176 
177 	dprintf(("ntfs_getattr: %ju, flags: %d\n", (uintmax_t)ip->i_number,
178 		ip->i_flag));
179 
180 	vap->va_fsid = dev2udev(ip->i_dev);
181 	vap->va_fileid = ip->i_number;
182 	vap->va_mode = ip->i_mp->ntm_mode;
183 	vap->va_nlink = ip->i_nlink;
184 	vap->va_uid = ip->i_mp->ntm_uid;
185 	vap->va_gid = ip->i_mp->ntm_gid;
186 	vap->va_rmajor = VNOVAL;
187 	vap->va_rminor = VNOVAL;
188 	vap->va_size = fp->f_size;
189 	vap->va_bytes = fp->f_allocated;
190 	vap->va_atime = ntfs_nttimetounix(fp->f_times.t_access);
191 	vap->va_mtime = ntfs_nttimetounix(fp->f_times.t_write);
192 	vap->va_ctime = ntfs_nttimetounix(fp->f_times.t_create);
193 	vap->va_flags = ip->i_flag;
194 	vap->va_gen = 0;
195 	vap->va_blocksize = ip->i_mp->ntm_spc * ip->i_mp->ntm_bps;
196 	vap->va_type = vp->v_type;
197 	vap->va_filerev = 0;
198 	return (0);
199 }
200 
201 
202 /*
203  * Last reference to an ntnode.  If necessary, write or delete it.
204  *
205  * ntfs_inactive(struct vnode *a_vp)
206  */
207 int
208 ntfs_inactive(struct vop_inactive_args *ap)
209 {
210 	struct vnode *vp = ap->a_vp;
211 #ifdef NTFS_DEBUG
212 	struct ntnode *ip = VTONT(vp);
213 #endif
214 
215 	dprintf(("ntfs_inactive: vnode: %p, ntnode: %ju\n", vp, (uintmax_t)ip->i_number));
216 
217 	if (ntfs_prtactive && VREFCNT(vp) > 1)
218 		vprint("ntfs_inactive: pushing active", vp);
219 
220 	/*
221 	 * XXX since we don't support any filesystem changes
222 	 * right now, nothing more needs to be done
223 	 */
224 	return (0);
225 }
226 
227 /*
228  * Reclaim an fnode/ntnode so that it can be used for other purposes.
229  *
230  * ntfs_reclaim(struct vnode *a_vp)
231  */
232 int
233 ntfs_reclaim(struct vop_reclaim_args *ap)
234 {
235 	struct vnode *vp = ap->a_vp;
236 	struct fnode *fp = VTOF(vp);
237 	struct ntnode *ip = FTONT(fp);
238 	int error;
239 
240 	dprintf(("ntfs_reclaim: vnode: %p, ntnode: %ju\n", vp, (uintmax_t)ip->i_number));
241 
242 	if (ntfs_prtactive && VREFCNT(vp) > 1)
243 		vprint("ntfs_reclaim: pushing active", vp);
244 
245 	if ((error = ntfs_ntget(ip)) != 0)
246 		return (error);
247 
248 	ntfs_frele(fp);
249 	ntfs_ntput(ip);
250 	vp->v_data = NULL;
251 
252 	return (0);
253 }
254 
255 /*
256  * ntfs_print(struct vnode *a_vp)
257  */
258 static int
259 ntfs_print(struct vop_print_args *ap)
260 {
261 	return (0);
262 }
263 
264 /*
265  * Calculate the logical to physical mapping if not done already,
266  * then call the device strategy routine.
267  *
268  * ntfs_strategy(struct vnode *a_vp, struct bio *a_bio)
269  */
270 int
271 ntfs_strategy(struct vop_strategy_args *ap)
272 {
273 	struct bio *bio = ap->a_bio;
274 	struct buf *bp = bio->bio_buf;
275 	struct vnode *vp = ap->a_vp;
276 	struct fnode *fp = VTOF(vp);
277 	struct ntnode *ip = FTONT(fp);
278 	struct ntfsmount *ntmp = ip->i_mp;
279 	u_int32_t toread;
280 	u_int32_t towrite;
281 	size_t tmp;
282 	int error;
283 
284 	dprintf(("ntfs_strategy: loffset: %u, doffset: %u\n",
285 		(uint32_t)bp->b_loffset, (uint32_t)bio->bio_offset));
286 
287 	dprintf(("strategy: bcount: %u flags: 0x%x\n",
288 		bp->b_bcount, bp->b_flags));
289 
290 	bp->b_error = 0;
291 
292 	switch(bp->b_cmd) {
293 	case BUF_CMD_READ:
294 		if (bio->bio_offset >= fp->f_size) {
295 			clrbuf(bp);
296 			error = 0;
297 		} else {
298 			toread = min(bp->b_bcount,
299 				 fp->f_size - bio->bio_offset);
300 			dprintf(("ntfs_strategy: toread: %u, fsize: %ju\n",
301 				toread, (uintmax_t)fp->f_size));
302 
303 			error = ntfs_readattr(ntmp, ip, fp->f_attrtype,
304 				fp->f_attrname, bio->bio_offset,
305 				toread, bp->b_data, NULL);
306 
307 			if (error) {
308 				kprintf("ntfs_strategy: ntfs_readattr failed\n");
309 				bp->b_error = error;
310 				bp->b_flags |= B_ERROR;
311 			}
312 
313 			bzero(bp->b_data + toread, bp->b_bcount - toread);
314 		}
315 		break;
316 	case BUF_CMD_WRITE:
317 		if (bio->bio_offset + bp->b_bcount >= fp->f_size) {
318 			kprintf("ntfs_strategy: CAN'T EXTEND FILE\n");
319 			bp->b_error = error = EFBIG;
320 			bp->b_flags |= B_ERROR;
321 		} else {
322 			towrite = min(bp->b_bcount,
323 				      fp->f_size - bio->bio_offset);
324 			dprintf(("ntfs_strategy: towrite: %d, fsize: %ju\n",
325 				towrite, (uintmax_t)fp->f_size));
326 
327 			error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
328 				fp->f_attrname, bio->bio_offset,towrite,
329 				bp->b_data, &tmp, NULL);
330 
331 			if (error) {
332 				kprintf("ntfs_strategy: ntfs_writeattr fail\n");
333 				bp->b_error = error;
334 				bp->b_flags |= B_ERROR;
335 			}
336 		}
337 		break;
338 	default:
339 		panic("ntfs: bad b_cmd %d", bp->b_cmd);
340 	}
341 	biodone(bio);
342 	return (error);
343 }
344 
345 /*
346  * ntfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
347  *	      struct ucred *a_cred)
348  */
349 static int
350 ntfs_write(struct vop_write_args *ap)
351 {
352 	struct vnode *vp = ap->a_vp;
353 	struct fnode *fp = VTOF(vp);
354 	struct ntnode *ip = FTONT(fp);
355 	struct uio *uio = ap->a_uio;
356 	struct ntfsmount *ntmp = ip->i_mp;
357 	size_t towrite;
358 	size_t written;
359 	int error;
360 
361 	dprintf(("ntfs_write: ino: %ju, off: %u resid: %zd, segflg: %d\n",
362 		(uintmax_t)ip->i_number, (uint32_t)uio->uio_offset,
363 		uio->uio_resid, uio->uio_segflg));
364 	dprintf(("ntfs_write: filesize: %ju ", (uintmax_t)fp->f_size));
365 
366 	if (uio->uio_resid + uio->uio_offset > fp->f_size) {
367 		kprintf("ntfs_write: CAN'T WRITE BEYOND END OF FILE\n");
368 		return (EFBIG);
369 	}
370 	if (uio->uio_offset > fp->f_size)
371 		return (EFBIG);
372 
373 	towrite = szmin(uio->uio_resid, fp->f_size - uio->uio_offset);
374 
375 	dprintf((", towrite: %zd\n", towrite));
376 
377 	error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
378 		fp->f_attrname, uio->uio_offset, towrite, NULL, &written, uio);
379 #ifdef NTFS_DEBUG
380 	if (error)
381 		kprintf("ntfs_write: ntfs_writeattr failed: %d\n", error);
382 #endif
383 
384 	return (error);
385 }
386 
387 /*
388  * ntfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred)
389  */
390 int
391 ntfs_access(struct vop_access_args *ap)
392 {
393 	struct vnode *vp = ap->a_vp;
394 	struct ntnode *ip = VTONT(vp);
395 	struct ucred *cred = ap->a_cred;
396 	mode_t mask, mode = ap->a_mode;
397 	gid_t *gp;
398 	int i;
399 #ifdef QUOTA
400 	int error;
401 #endif
402 
403 	dprintf(("ntfs_access: %ju\n", (uintmax_t)ip->i_number));
404 
405 	/*
406 	 * Disallow write attempts on read-only file systems;
407 	 * unless the file is a socket, fifo, or a block or
408 	 * character device resident on the file system.
409 	 */
410 	if (mode & VWRITE) {
411 		switch ((int)vp->v_type) {
412 		case VDIR:
413 		case VLNK:
414 		case VREG:
415 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
416 				return (EROFS);
417 #ifdef QUOTA
418 			if (error = getinoquota(ip))
419 				return (error);
420 #endif
421 			break;
422 		}
423 	}
424 
425 	/* Otherwise, user id 0 always gets access. */
426 	if (cred->cr_uid == 0)
427 		return (0);
428 
429 	mask = 0;
430 
431 	/* Otherwise, check the owner. */
432 	if (cred->cr_uid == ip->i_mp->ntm_uid) {
433 		if (mode & VEXEC)
434 			mask |= S_IXUSR;
435 		if (mode & VREAD)
436 			mask |= S_IRUSR;
437 		if (mode & VWRITE)
438 			mask |= S_IWUSR;
439 		return ((ip->i_mp->ntm_mode & mask) == mask ? 0 : EACCES);
440 	}
441 
442 	/* Otherwise, check the groups. */
443 	for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
444 		if (ip->i_mp->ntm_gid == *gp) {
445 			if (mode & VEXEC)
446 				mask |= S_IXGRP;
447 			if (mode & VREAD)
448 				mask |= S_IRGRP;
449 			if (mode & VWRITE)
450 				mask |= S_IWGRP;
451 			return ((ip->i_mp->ntm_mode&mask) == mask ? 0 : EACCES);
452 		}
453 
454 	/* Otherwise, check everyone else. */
455 	if (mode & VEXEC)
456 		mask |= S_IXOTH;
457 	if (mode & VREAD)
458 		mask |= S_IROTH;
459 	if (mode & VWRITE)
460 		mask |= S_IWOTH;
461 	return ((ip->i_mp->ntm_mode & mask) == mask ? 0 : EACCES);
462 }
463 
464 /*
465  * Open called.
466  *
467  * Nothing to do.
468  *
469  * ntfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
470  *	     struct file *a_fp)
471  */
472 /* ARGSUSED */
473 static int
474 ntfs_open(struct vop_open_args *ap)
475 {
476 	return (vop_stdopen(ap));
477 }
478 
479 /*
480  * Close called.
481  *
482  * Update the times on the inode.
483  *
484  * ntfs_close(struct vnode *a_vp, int a_fflag)
485  */
486 /* ARGSUSED */
487 static int
488 ntfs_close(struct vop_close_args *ap)
489 {
490 #if NTFS_DEBUG
491 	struct vnode *vp = ap->a_vp;
492 	struct ntnode *ip = VTONT(vp);
493 
494 	kprintf("ntfs_close: %ju\n", (uintmax_t)ip->i_number);
495 #endif
496 
497 	return (vop_stdclose(ap));
498 }
499 
500 /*
501  * ntfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
502  *		int *a_ncookies, off_t **cookies)
503  */
504 int
505 ntfs_readdir(struct vop_readdir_args *ap)
506 {
507 	struct vnode *vp = ap->a_vp;
508 	struct fnode *fp = VTOF(vp);
509 	struct ntnode *ip = FTONT(fp);
510 	struct uio *uio = ap->a_uio;
511 	struct ntfsmount *ntmp = ip->i_mp;
512 	int i, j, error = 0;
513 	wchar c;
514 	u_int32_t faked = 0, num, off;
515 	int ncookies = 0;
516 	char convname[NTFS_MAXFILENAME + 1];
517 
518 	dprintf(("ntfs_readdir %ju off: %u resid: %zd\n",
519 		(uintmax_t)ip->i_number, (uint32_t)uio->uio_offset,
520 		uio->uio_resid));
521 
522 	if (uio->uio_offset < 0 || uio->uio_offset > INT_MAX)
523 		return (EINVAL);
524 	error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY | LK_FAILRECLAIM);
525 	if (error)
526 		return (error);
527 
528 	/*
529 	 * uio->uio_offset carries the number of the entry
530 	 * where we should start returning dirents.
531 	 *
532 	 * We fake up "." if we're not reading the FS root
533 	 * and we always fake up "..".
534 	 *
535 	 * off contains the entry we are starting at,
536 	 * num increments while we are reading.
537 	 */
538 
539 	off = num = uio->uio_offset;
540 	faked = (ip->i_number == NTFS_ROOTINO) ? 1 : 2;
541 
542 	/* Simulate . in every dir except ROOT */
543 	if (ip->i_number != NTFS_ROOTINO && num == 0) {
544 		if (vop_write_dirent(&error, uio, ip->i_number,
545 		    DT_DIR, 1, "."))
546 			goto done;
547 		if (error)
548 			goto done;
549 
550 		num++;
551 		ncookies++;
552 	}
553 
554 	/* Simulate .. in every dir including ROOT */
555 	if (num == faked - 1) {
556 		/* XXX NTFS_ROOTINO seems to be wrong here */
557 		if (vop_write_dirent(&error, uio, NTFS_ROOTINO,
558 		    DT_DIR, 2, ".."))
559 			goto readdone;
560 		if (error)
561 			goto done;
562 
563 		num++;
564 		ncookies++;
565 	}
566 
567 	for (;;) {
568 		struct attr_indexentry *iep;
569 
570 		/*
571 		 * num is the number of the entry we will return,
572 		 * but ntfs_ntreaddir takes the entry number of the
573 		 * ntfs directory listing, so subtract the faked
574 		 * . and .. entries.
575 		 */
576 		error = ntfs_ntreaddir(ntmp, fp, num - faked, &iep);
577 
578 		if (error)
579 			goto done;
580 
581 		if( NULL == iep )
582 			break;
583 
584 		for (; !(iep->ie_flag & NTFS_IEFLAG_LAST);
585 			iep = NTFS_NEXTREC(iep, struct attr_indexentry *))
586 		{
587 			if(!ntfs_isnamepermitted(ntmp,iep))
588 				continue;
589 			for(i=0, j=0; i < iep->ie_fnamelen; i++, j++) {
590 				c = NTFS_U28(iep->ie_fname[i]);
591 				if (c&0xFF00)
592 					convname[j++] = (char)(c>>8);
593 				convname[j] = (char)c&0xFF;
594 			}
595 			convname[j] = '\0';
596 			if (vop_write_dirent(&error, uio, iep->ie_number,
597 			    (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG,
598 			    j, convname))
599 				goto readdone;
600 
601 			dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, "
602 				 "flag: %d, %s\n",
603 				 ncookies, convname, iep->ie_fnametype,
604 				 iep->ie_flag,
605 				 (iep->ie_fflag & NTFS_FFLAG_DIR) ?
606 					"dir" : "reg"));
607 
608 			if (error)
609 				goto done;
610 
611 			ncookies++;
612 			num++;
613 		}
614 	}
615 
616 readdone:
617 	uio->uio_offset = num;
618 
619 	dprintf(("ntfs_readdir: %d entries (%d bytes) read\n",
620 		ncookies,(u_int)(uio->uio_offset - off)));
621 	dprintf(("ntfs_readdir: off: %u resid: %zd\n",
622 		(uint32_t)uio->uio_offset, uio->uio_resid));
623 
624 	if (!error && ap->a_ncookies != NULL) {
625 		off_t *cookies;
626 		off_t *cookiep;
627 
628 		ddprintf(("ntfs_readdir: %d cookies\n",ncookies));
629 		if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
630 			panic("ntfs_readdir: unexpected uio from NFS server");
631 		cookies = kmalloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
632 		cookiep = cookies;
633 		while (off < num)
634 			*cookiep++ = ++off;
635 
636 		*ap->a_ncookies = ncookies;
637 		*ap->a_cookies = cookies;
638 	}
639 /*
640 	if (ap->a_eofflag)
641 	    *ap->a_eofflag = VTONT(vp)->i_size <= uio->uio_offset;
642 */
643 done:
644 	vn_unlock(vp);
645 	return (error);
646 }
647 
648 /*
649  * ntfs_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
650  *		struct componentname *a_cnp)
651  */
652 int
653 ntfs_lookup(struct vop_old_lookup_args *ap)
654 {
655 	struct vnode *dvp = ap->a_dvp;
656 	struct ntnode *dip = VTONT(dvp);
657 	struct ntfsmount *ntmp = dip->i_mp;
658 	struct componentname *cnp = ap->a_cnp;
659 	int error;
660 	int lockparent = cnp->cn_flags & CNP_LOCKPARENT;
661 #if NTFS_DEBUG
662 	int wantparent = cnp->cn_flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
663 #endif
664 	dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %ju, lp: %d, wp: %d \n",
665 		(int)cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_namelen,
666 		(uintmax_t)dip->i_number, lockparent, wantparent));
667 
668 	*ap->a_vpp = NULL;
669 
670 	if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
671 		dprintf(("ntfs_lookup: faking . directory in %u\n",
672 			(uint32_t)dip->i_number));
673 
674 		vref(dvp);
675 		*ap->a_vpp = dvp;
676 		error = 0;
677 	} else if (cnp->cn_flags & CNP_ISDOTDOT) {
678 		struct ntvattr *vap;
679 
680 		dprintf(("ntfs_lookup: faking .. directory in %d\n",
681 			(uint32_t)dip->i_number));
682 
683 		error = ntfs_ntvattrget(ntmp, dip, NTFS_A_NAME, NULL, 0, &vap);
684 		if(error)
685 			return (error);
686 
687 		VOP__UNLOCK(dvp, 0);
688 		cnp->cn_flags |= CNP_PDIRUNLOCK;
689 
690 		dprintf(("ntfs_lookup: parentdir: %d\n",
691 			 vap->va_a_name->n_pnumber));
692 		error = VFS_VGET(ntmp->ntm_mountp, NULL,
693 				 vap->va_a_name->n_pnumber,ap->a_vpp);
694 		ntfs_ntvattrrele(vap);
695 		if (error) {
696 			if (VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY) == 0)
697 				cnp->cn_flags &= ~CNP_PDIRUNLOCK;
698 			return (error);
699 		}
700 
701 		if (lockparent) {
702 			error = VOP_LOCK(dvp, LK_EXCLUSIVE);
703 			if (error) {
704 				vput(*ap->a_vpp);
705 				*ap->a_vpp = NULL;
706 				return (error);
707 			}
708 			cnp->cn_flags &= ~CNP_PDIRUNLOCK;
709 		}
710 	} else {
711 		error = ntfs_ntlookupfile(ntmp, dvp, cnp, ap->a_vpp);
712 		if (error) {
713 			dprintf(("ntfs_ntlookupfile: returned %d\n", error));
714 			return (error);
715 		}
716 
717 		dprintf(("ntfs_lookup: found ino: %u\n",
718 			(uint32_t)VTONT(*ap->a_vpp)->i_number));
719 
720 		if (!lockparent) {
721 			VOP__UNLOCK(dvp, 0);
722 			cnp->cn_flags |= CNP_PDIRUNLOCK;
723 		}
724 	}
725 	return (error);
726 }
727 
728 /*
729  * Flush the blocks of a file to disk.
730  *
731  * This function is worthless for vnodes that represent directories. Maybe we
732  * could just do a sync if they try an fsync on a directory file.
733  *
734  * ntfs_fsync(struct vnode *a_vp, int a_waitfor)
735  */
736 static int
737 ntfs_fsync(struct vop_fsync_args *ap)
738 {
739 	return (0);
740 }
741 
742 /*
743  * Return POSIX pathconf information applicable to NTFS filesystem
744  */
745 int
746 ntfs_pathconf(struct vop_pathconf_args *ap)
747 {
748 	switch (ap->a_name) {
749 	case _PC_LINK_MAX:
750 		*ap->a_retval = 1;
751 		return (0);
752 	case _PC_NAME_MAX:
753 		*ap->a_retval = NTFS_MAXFILENAME;
754 		return (0);
755 	case _PC_PATH_MAX:
756 		*ap->a_retval = PATH_MAX;
757 		return (0);
758 	case _PC_CHOWN_RESTRICTED:
759 		*ap->a_retval = 1;
760 		return (0);
761 	case _PC_NO_TRUNC:
762 		*ap->a_retval = 0;
763 		return (0);
764 	default:
765 		return (EINVAL);
766 	}
767 	/* NOTREACHED */
768 }
769 
770 /*
771  * Global vfs data structures
772  */
773 struct vop_ops ntfs_vnode_vops = {
774 	.vop_default =		vop_defaultop,
775 	.vop_getattr =		ntfs_getattr,
776 	.vop_inactive =		ntfs_inactive,
777 	.vop_reclaim =		ntfs_reclaim,
778 	.vop_print =		ntfs_print,
779 	.vop_pathconf =		ntfs_pathconf,
780 	.vop_old_lookup =	ntfs_lookup,
781 	.vop_access =		ntfs_access,
782 	.vop_close =		ntfs_close,
783 	.vop_open =		ntfs_open,
784 	.vop_readdir =		ntfs_readdir,
785 	.vop_fsync =		ntfs_fsync,
786 	.vop_bmap =		ntfs_bmap,
787 	.vop_getpages =		vop_stdgetpages,
788 	.vop_putpages =		vop_stdputpages,
789 	.vop_strategy =		ntfs_strategy,
790 	.vop_read =		ntfs_read,
791 	.vop_write =		ntfs_write
792 };
793 
794