2 * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/fs/hpfs/hpfs_vnops.c,v 1.2.2.2 2002/01/15 18:35:09 semenu Exp $
27 * $DragonFly: src/sys/vfs/hpfs/hpfs_vnops.c,v 1.43 2007/08/13 17:31:56 dillon Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
35 #include <sys/types.h>
37 #include <sys/vnode.h>
38 #include <sys/mount.h>
39 #include <sys/namei.h>
40 #include <sys/malloc.h>
42 #include <sys/dirent.h>
44 #include <machine/limits.h>
47 #include <vm/vm_param.h>
48 #if !defined(__DragonFly__)
49 #include <vm/vm_prot.h>
51 #include <vm/vm_page.h>
52 #include <vm/vm_object.h>
53 #include <vm/vm_pager.h>
54 #include <vm/vm_zone.h>
55 #if defined(__DragonFly__)
56 #include <vm/vnode_pager.h>
58 #include <vm/vm_extern.h>
61 #if !defined(__DragonFly__)
62 #include <miscfs/specfs/specdev.h>
63 #include <miscfs/genfs/genfs.h>
66 #include <sys/unistd.h> /* for pathconf(2) constants */
69 #include "hpfsmount.h"
70 #include "hpfs_subr.h"
71 #include "hpfs_ioctl.h"
73 static int hpfs_de_uiomove (int *, struct hpfsmount *,
74 struct hpfsdirent *, struct uio *);
75 static int hpfs_ioctl (struct vop_ioctl_args *ap);
76 static int hpfs_read (struct vop_read_args *);
77 static int hpfs_write (struct vop_write_args *ap);
78 static int hpfs_getattr (struct vop_getattr_args *ap);
79 static int hpfs_setattr (struct vop_setattr_args *ap);
80 static int hpfs_inactive (struct vop_inactive_args *ap);
81 static int hpfs_print (struct vop_print_args *ap);
82 static int hpfs_reclaim (struct vop_reclaim_args *ap);
83 static int hpfs_strategy (struct vop_strategy_args *ap);
84 static int hpfs_access (struct vop_access_args *ap);
85 static int hpfs_readdir (struct vop_readdir_args *ap);
86 static int hpfs_lookup (struct vop_old_lookup_args *ap);
87 static int hpfs_create (struct vop_old_create_args *);
88 static int hpfs_remove (struct vop_old_remove_args *);
89 static int hpfs_bmap (struct vop_bmap_args *ap);
90 #if defined(__DragonFly__)
91 static int hpfs_getpages (struct vop_getpages_args *ap);
92 static int hpfs_putpages (struct vop_putpages_args *);
93 static int hpfs_fsync (struct vop_fsync_args *ap);
95 static int hpfs_pathconf (struct vop_pathconf_args *ap);
97 #if defined(__DragonFly__)
99 hpfs_getpages(struct vop_getpages_args *ap)
101 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
106 hpfs_putpages(struct vop_putpages_args *ap)
108 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
109 ap->a_sync, ap->a_rtvals);
113 * hpfs_fsync(struct vnode *a_vp, int a_waitfor)
116 hpfs_fsync(struct vop_fsync_args *ap)
118 struct vnode *vp = ap->a_vp;
121 * Flush all dirty buffers associated with a vnode.
126 vfsync(vp, ap->a_waitfor, 0, NULL, NULL);
128 if (ap->a_waitfor == MNT_WAIT && !RB_EMPTY(&vp->v_rbdirty_tree)) {
129 vprint("hpfs_fsync: dirty", vp);
135 * Write out the on-disc version of the vnode.
137 return hpfs_update(VTOHP(vp));
143 * hpfs_ioctl(struct vnode *a_vp, u_long a_command, caddr_t a_data,
144 * int a_fflag, struct ucred *a_cred)
147 hpfs_ioctl(struct vop_ioctl_args *ap)
149 struct vnode *vp = ap->a_vp;
150 struct hpfsnode *hp = VTOHP(vp);
153 kprintf("hpfs_ioctl(0x%x, 0x%lx, 0x%p, 0x%x): ",
154 hp->h_no, ap->a_command, ap->a_data, ap->a_fflag);
156 switch (ap->a_command) {
157 case HPFSIOCGEANUM: {
164 if (hp->h_fn.fn_ealen > 0) {
165 eap = (struct ea *)&(hp->h_fn.fn_int);
168 while (passed < hp->h_fn.fn_ealen) {
170 kprintf("EAname: %s\n", EA_NAME(eap));
173 passed += sizeof(struct ea) +
174 eap->ea_namelen + 1 + eap->ea_vallen;
175 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
183 kprintf("%lu eas\n", eanum);
185 *(u_long *)ap->a_data = eanum;
194 kprintf("EA%ld\n", *(u_long *)ap->a_data);
197 if (hp->h_fn.fn_ealen > 0) {
198 eap = (struct ea *)&(hp->h_fn.fn_int);
202 while (passed < hp->h_fn.fn_ealen) {
203 kprintf("EAname: %s\n", EA_NAME(eap));
205 if (eanum == *(u_long *)ap->a_data) {
206 *(u_long *)ap->a_data =
207 eap->ea_namelen + 1 +
215 passed += sizeof(struct ea) +
216 eap->ea_namelen + 1 + eap->ea_vallen;
217 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
229 struct hpfs_rdea *rdeap;
232 rdeap = (struct hpfs_rdea *)ap->a_data;
233 kprintf("EA%ld\n", rdeap->ea_no);
236 if (hp->h_fn.fn_ealen > 0) {
237 eap = (struct ea *)&(hp->h_fn.fn_int);
241 while (passed < hp->h_fn.fn_ealen) {
242 kprintf("EAname: %s\n", EA_NAME(eap));
244 if (eanum == rdeap->ea_no) {
245 rdeap->ea_sz = eap->ea_namelen + 1 +
247 copyout(EA_NAME(eap),rdeap->ea_data,
254 passed += sizeof(struct ea) +
255 eap->ea_namelen + 1 + eap->ea_vallen;
256 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
273 * Map file offset to disk offset.
275 * hpfs_bmap(struct vnode *a_vp, off_t a_loffset,
276 * off_t *a_doffsetp, int *a_runp, int *a_runb)
279 hpfs_bmap(struct vop_bmap_args *ap)
281 struct hpfsnode *hp = VTOHP(ap->a_vp);
286 if (ap->a_runb != NULL)
288 if (ap->a_doffsetp == NULL)
291 dprintf(("hpfs_bmap(0x%x, 0x%x): ",hp->h_no, ap->a_bn));
293 lbn = ap->a_loffset >> DEV_BSHIFT;
294 KKASSERT(((int)ap->a_loffset & DEV_BMASK) == 0);
296 error = hpfs_hpbmap (hp, lbn, &dbn, ap->a_runp);
297 if (error || dbn == (daddr_t)-1) {
298 *ap->a_doffsetp = NOOFFSET;
300 *ap->a_doffsetp = (off_t)dbn << DEV_BSHIFT;
306 * hpfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
307 * struct ucred *a_cred)
310 hpfs_read(struct vop_read_args *ap)
312 struct vnode *vp = ap->a_vp;
313 struct hpfsnode *hp = VTOHP(vp);
314 struct uio *uio = ap->a_uio;
316 u_int xfersz, toread;
323 resid = min (uio->uio_resid, hp->h_fn.fn_size - uio->uio_offset);
325 dprintf(("hpfs_read(0x%x, off: %d resid: %d, segflg: %d): [resid: 0x%x]\n",hp->h_no,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg, resid));
328 lbn = uio->uio_offset >> DEV_BSHIFT;
329 off = uio->uio_offset & (DEV_BSIZE - 1);
330 dprintf(("hpfs_read: resid: 0x%x lbn: 0x%x off: 0x%x\n",
331 uio->uio_resid, lbn, off));
332 error = hpfs_hpbmap(hp, lbn, &bn, &runl);
336 toread = min(off + resid, min(DFLTPHYS, (runl+1)*DEV_BSIZE));
337 xfersz = (toread + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1);
338 dprintf(("hpfs_read: bn: 0x%x (0x%x) toread: 0x%x (0x%x)\n",
339 bn, runl, toread, xfersz));
344 error = bread(hp->h_devvp, dbtodoff(bn), xfersz, &bp);
350 error = uiomove(bp->b_data + off, toread - off, uio);
358 dprintf(("hpfs_read: successful\n"));
363 * hpfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
364 * struct ucred *a_cred)
367 hpfs_write(struct vop_write_args *ap)
369 struct vnode *vp = ap->a_vp;
370 struct hpfsnode *hp = VTOHP(vp);
371 struct uio *uio = ap->a_uio;
373 u_int xfersz, towrite;
379 dprintf(("hpfs_write(0x%x, off: %d resid: %d, segflg: %d):\n",hp->h_no,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg));
381 if (ap->a_ioflag & IO_APPEND) {
382 dprintf(("hpfs_write: APPEND mode\n"));
383 uio->uio_offset = hp->h_fn.fn_size;
385 if (uio->uio_offset + uio->uio_resid > hp->h_fn.fn_size) {
386 error = hpfs_extend (hp, uio->uio_offset + uio->uio_resid);
388 kprintf("hpfs_write: hpfs_extend FAILED %d\n", error);
393 while (uio->uio_resid) {
394 lbn = uio->uio_offset >> DEV_BSHIFT;
395 off = uio->uio_offset & (DEV_BSIZE - 1);
396 dprintf(("hpfs_write: resid: 0x%x lbn: 0x%x off: 0x%x\n",
397 uio->uio_resid, lbn, off));
398 error = hpfs_hpbmap(hp, lbn, &bn, &runl);
402 towrite = min(off + uio->uio_resid, min(DFLTPHYS, (runl+1)*DEV_BSIZE));
403 xfersz = (towrite + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1);
404 dprintf(("hpfs_write: bn: 0x%x (0x%x) towrite: 0x%x (0x%x)\n",
405 bn, runl, towrite, xfersz));
407 if ((off == 0) && (towrite == xfersz)) {
408 bp = getblk(hp->h_devvp, dbtodoff(bn), xfersz, 0, 0);
411 error = bread(hp->h_devvp, dbtodoff(bn), xfersz, &bp);
418 error = uiomove(bp->b_data + off, towrite - off, uio);
424 if (ap->a_ioflag & IO_SYNC)
430 dprintf(("hpfs_write: successful\n"));
435 * XXXXX do we need hpfsnode locking inside?
437 * hpfs_getattr(struct vnode *a_vp, struct vattr *a_vap)
440 hpfs_getattr(struct vop_getattr_args *ap)
442 struct vnode *vp = ap->a_vp;
443 struct hpfsnode *hp = VTOHP(vp);
444 struct vattr *vap = ap->a_vap;
447 dprintf(("hpfs_getattr(0x%x):\n", hp->h_no));
449 #if defined(__DragonFly__)
450 vap->va_fsid = dev2udev(hp->h_dev);
451 #else /* defined(__NetBSD__) */
452 vap->va_fsid = ip->i_dev;
454 vap->va_fileid = hp->h_no;
455 vap->va_mode = hp->h_mode;
457 vap->va_uid = hp->h_uid;
458 vap->va_gid = hp->h_gid;
459 vap->va_rmajor = VNOVAL;
460 vap->va_rminor = VNOVAL;
461 vap->va_size = hp->h_fn.fn_size;
462 vap->va_bytes = ((hp->h_fn.fn_size + DEV_BSIZE-1) & ~(DEV_BSIZE-1)) +
465 if (!(hp->h_flag & H_PARVALID)) {
466 error = hpfs_validateparent(hp);
470 vap->va_atime = hpfstimetounix(hp->h_atime);
471 vap->va_mtime = hpfstimetounix(hp->h_mtime);
472 vap->va_ctime = hpfstimetounix(hp->h_ctime);
476 vap->va_blocksize = DEV_BSIZE;
477 vap->va_type = vp->v_type;
484 * XXXXX do we need hpfsnode locking inside?
486 * hpfs_setattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred)
489 hpfs_setattr(struct vop_setattr_args *ap)
491 struct vnode *vp = ap->a_vp;
492 struct hpfsnode *hp = VTOHP(vp);
493 struct vattr *vap = ap->a_vap;
494 struct ucred *cred = ap->a_cred;
497 dprintf(("hpfs_setattr(0x%x):\n", hp->h_no));
500 * Check for unsettable attributes.
502 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
503 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
504 (vap->va_blocksize != VNOVAL) || (vap->va_rmajor != VNOVAL) ||
505 (vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
506 dprintf(("hpfs_setattr: changing nonsettable attr\n"));
510 /* Can't change flags XXX Could be implemented */
511 if (vap->va_flags != VNOVAL) {
512 kprintf("hpfs_setattr: FLAGS CANNOT BE SET\n");
516 /* Can't change uid/gid XXX Could be implemented */
517 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
518 kprintf("hpfs_setattr: UID/GID CANNOT BE SET\n");
522 /* Can't change mode XXX Could be implemented */
523 if (vap->va_mode != (mode_t)VNOVAL) {
524 kprintf("hpfs_setattr: MODE CANNOT BE SET\n");
529 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
530 if (vp->v_mount->mnt_flag & MNT_RDONLY)
532 if (cred->cr_uid != hp->h_uid &&
533 (error = suser_cred(cred, PRISON_ROOT)) &&
534 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
535 (error = VOP_ACCESS(vp, VWRITE, cred))))
537 if (vap->va_atime.tv_sec != VNOVAL)
538 hp->h_atime = vap->va_atime.tv_sec;
539 if (vap->va_mtime.tv_sec != VNOVAL)
540 hp->h_mtime = vap->va_mtime.tv_sec;
542 hp->h_flag |= H_PARCHANGE;
545 if (vap->va_size != VNOVAL) {
546 switch (vp->v_type) {
550 if (vp->v_mount->mnt_flag & MNT_RDONLY)
554 kprintf("hpfs_setattr: WRONG v_type\n");
558 if (vap->va_size < hp->h_fn.fn_size) {
559 #if defined(__DragonFly__)
560 error = vtruncbuf(vp, vap->va_size, DEV_BSIZE);
563 #else /* defined(__NetBSD__) */
564 #error Need alternation for vtruncbuf()
566 error = hpfs_truncate(hp, vap->va_size);
570 } else if (vap->va_size > hp->h_fn.fn_size) {
571 #if defined(__DragonFly__)
572 vnode_pager_setsize(vp, vap->va_size);
574 error = hpfs_extend(hp, vap->va_size);
584 * Last reference to an node. If necessary, write or delete it.
586 * hpfs_inactive(struct vnode *a_vp)
589 hpfs_inactive(struct vop_inactive_args *ap)
591 struct vnode *vp = ap->a_vp;
592 struct hpfsnode *hp = VTOHP(vp);
595 dprintf(("hpfs_inactive(0x%x): \n", hp->h_no));
597 if (hp->h_flag & H_CHANGE) {
598 dprintf(("hpfs_inactive: node changed, update\n"));
599 error = hpfs_update (hp);
604 if (hp->h_flag & H_PARCHANGE) {
605 dprintf(("hpfs_inactive: parent node changed, update\n"));
606 error = hpfs_updateparent (hp);
611 if (prtactive && vp->v_sysref.refcnt > 1)
612 vprint("hpfs_inactive: pushing active", vp);
614 if (hp->h_flag & H_INVAL) {
615 #if defined(__DragonFly__)
617 #else /* defined(__NetBSD__) */
626 * Reclaim an inode so that it can be used for other purposes.
628 * hpfs_reclaim(struct vnode *a_vp)
631 hpfs_reclaim(struct vop_reclaim_args *ap)
633 struct vnode *vp = ap->a_vp;
634 struct hpfsnode *hp = VTOHP(vp);
636 dprintf(("hpfs_reclaim(0x%x0): \n", hp->h_no));
640 /* Purge old data structures associated with the inode. */
654 * hpfs_print(struct vnode *a_vp)
657 hpfs_print(struct vop_print_args *ap)
659 struct vnode *vp = ap->a_vp;
660 struct hpfsnode *hp = VTOHP(vp);
662 kprintf("tag VT_HPFS, ino 0x%x",hp->h_no);
663 lockmgr_printinfo(&vp->v_lock);
669 * Calculate the logical to physical mapping if not done already,
670 * then call the device strategy routine.
672 * In order to be able to swap to a file, the VOP_BMAP operation may not
673 * deadlock on memory. See hpfs_bmap() for details. XXXXXXX (not impl)
675 * hpfs_strategy(struct vnode *a_vp, struct bio *a_bio)
678 hpfs_strategy(struct vop_strategy_args *ap)
680 struct bio *bio = ap->a_bio;
682 struct buf *bp = bio->bio_buf;
683 struct vnode *vp = ap->a_vp;
687 dprintf(("hpfs_strategy(): \n"));
689 if (vp->v_type == VBLK || vp->v_type == VCHR)
690 panic("hpfs_strategy: spec");
692 nbio = push_bio(bio);
693 if (nbio->bio_offset == NOOFFSET) {
694 error = VOP_BMAP(vp, bio->bio_offset, &nbio->bio_offset,
697 kprintf("hpfs_strategy: VOP_BMAP FAILED %d\n", error);
699 bp->b_flags |= B_ERROR;
700 /* I/O was never started on nbio, must biodone(bio) */
704 if (nbio->bio_offset == NOOFFSET)
707 if (nbio->bio_offset == NOOFFSET) {
708 /* I/O was never started on nbio, must biodone(bio) */
712 hp = VTOHP(ap->a_vp);
713 vn_strategy(hp->h_devvp, nbio);
718 * XXXXX do we need hpfsnode locking inside?
720 * hpfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred)
723 hpfs_access(struct vop_access_args *ap)
725 struct vnode *vp = ap->a_vp;
726 struct hpfsnode *hp = VTOHP(vp);
727 struct ucred *cred = ap->a_cred;
728 mode_t mask, mode = ap->a_mode;
732 dprintf(("hpfs_access(0x%x):\n", hp->h_no));
735 * Disallow write attempts on read-only file systems;
736 * unless the file is a socket, fifo, or a block or
737 * character device resident on the file system.
740 switch ((int)vp->v_type) {
744 if (vp->v_mount->mnt_flag & MNT_RDONLY)
750 /* Otherwise, user id 0 always gets access. */
751 if (cred->cr_uid == 0)
756 /* Otherwise, check the owner. */
757 if (cred->cr_uid == hp->h_uid) {
764 return ((hp->h_mode & mask) == mask ? 0 : EACCES);
767 /* Otherwise, check the groups. */
768 for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
769 if (hp->h_gid == *gp) {
776 return ((hp->h_mode & mask) == mask ? 0 : EACCES);
779 /* Otherwise, check everyone else. */
786 return ((hp->h_mode & mask) == mask ? 0 : EACCES);
790 hpfs_de_uiomove(int *error, struct hpfsmount *hpmp, struct hpfsdirent *dep,
793 char convname[HPFS_MAXFILENAME + 1];
796 dprintf(("[no: 0x%x, size: %d, name: %2d:%.*s, flag: 0x%x] ",
797 dep->de_fnode, dep->de_size, dep->de_namelen,
798 dep->de_namelen, dep->de_name, dep->de_flag));
800 /*strncpy(cde.d_name, dep->de_name, dep->de_namelen);*/
801 for (i=0; i<dep->de_namelen; i++)
802 convname[i] = hpfs_d2u(hpmp, dep->de_name[i]);
803 convname[dep->de_namelen] = '\0';
805 success = vop_write_dirent(error, uio, dep->de_fnode,
806 (dep->de_flag & DE_DIR) ? DT_DIR : DT_REG,
807 dep->de_namelen, convname);
809 dprintf(("[0x%x] ", uio->uio_resid));
815 * hpfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
816 * int *a_ncookies, u_int **cookies)
819 hpfs_readdir(struct vop_readdir_args *ap)
821 struct vnode *vp = ap->a_vp;
822 struct hpfsnode *hp = VTOHP(vp);
823 struct hpfsmount *hpmp = hp->h_hpmp;
824 struct uio *uio = ap->a_uio;
825 int ncookies = 0, i, num, cnum;
829 struct hpfsdirent *dep;
834 dprintf(("hpfs_readdir(0x%x, 0x%x, 0x%x): ",hp->h_no,(u_int32_t)uio->uio_offset,uio->uio_resid));
837 * As we need to fake up . and .., and the remaining directory structure
838 * can't be expressed in one off_t as well, we just increment uio_offset
839 * by 1 for each entry.
841 * num is the entry we need to start reporting
842 * cnum is the current entry
844 if (uio->uio_offset < 0 || uio->uio_offset > INT_MAX)
846 if ((error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY)) != 0)
849 num = uio->uio_offset;
853 dprintf((". faked, "));
854 if (vop_write_dirent(&error, uio, hp->h_no, DT_DIR, 1, "."))
863 dprintf((".. faked, "));
864 if (vop_write_dirent(&error, uio, hp->h_fn.fn_parent, DT_DIR, 2, ".."))
872 lsn = ((alleaf_t *)hp->h_fn.fn_abd)->al_lsn;
878 dprintf(("[dive 0x%x] ", lsn));
879 error = bread(hp->h_devvp, dbtodoff(lsn), D_BSIZE, &bp);
885 dp = (struct dirblk *) bp->b_data;
886 if (dp->d_magic != D_MAGIC) {
887 kprintf("hpfs_readdir: MAGIC DOESN'T MATCH\n");
896 dprintf(("[restore 0x%x] ", olsn));
898 while(!(dep->de_flag & DE_END) ) {
899 if((dep->de_flag & DE_DOWN) &&
900 (olsn == DE_DOWNLSN(dep)))
902 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
905 if((dep->de_flag & DE_DOWN) && (olsn == DE_DOWNLSN(dep))) {
906 if (dep->de_flag & DE_END)
909 if (!(dep->de_flag & DE_SPECIAL)) {
911 if (hpfs_de_uiomove(&error, hpmp, dep, uio)) {
913 dprintf(("[resid] "));
925 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
927 kprintf("hpfs_readdir: ERROR! oLSN not found\n");
936 while(!(dep->de_flag & DE_END)) {
937 if(dep->de_flag & DE_DOWN) {
938 lsn = DE_DOWNLSN(dep);
944 if (!(dep->de_flag & DE_SPECIAL)) {
946 if (hpfs_de_uiomove(&error, hpmp, dep, uio)) {
948 dprintf(("[resid] "));
960 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
963 if(dep->de_flag & DE_DOWN) {
964 dprintf(("[enddive] "));
965 lsn = DE_DOWNLSN(dep);
978 dprintf(("[level %d] ", level));
981 goto dive; /* undive really */
989 uio->uio_offset = cnum;
990 dprintf(("[readdone]\n"));
991 if (!error && ap->a_ncookies != NULL) {
992 #if defined(__DragonFly__)
995 #else /* defined(__NetBSD__) */
1000 dprintf(("%d cookies, ",ncookies));
1001 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1002 panic("hpfs_readdir: unexpected uio from NFS server");
1003 #if defined(__DragonFly__)
1004 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
1006 #else /* defined(__NetBSD__) */
1007 MALLOC(cookies, off_t *, ncookies * sizeof(off_t),
1010 for (cookiep = cookies, i=0; i < ncookies; i++)
1011 *cookiep++ = (u_int)++num;
1013 *ap->a_ncookies = ncookies;
1014 *ap->a_cookies = cookies;
1018 vn_unlock(ap->a_vp);
1023 * hpfs_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
1024 * struct componentname *a_cnp)
1027 hpfs_lookup(struct vop_old_lookup_args *ap)
1029 struct vnode *dvp = ap->a_dvp;
1030 struct hpfsnode *dhp = VTOHP(dvp);
1031 struct hpfsmount *hpmp = dhp->h_hpmp;
1032 struct componentname *cnp = ap->a_cnp;
1033 struct ucred *cred = cnp->cn_cred;
1035 int nameiop = cnp->cn_nameiop;
1036 int flags = cnp->cn_flags;
1037 int lockparent = flags & CNP_LOCKPARENT;
1039 int wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
1041 dprintf(("hpfs_lookup(0x%x, %s, %ld, %d, %d): \n",
1042 dhp->h_no, cnp->cn_nameptr, cnp->cn_namelen,
1043 lockparent, wantparent));
1045 if (nameiop != NAMEI_CREATE && nameiop != NAMEI_DELETE && nameiop != NAMEI_LOOKUP) {
1046 kprintf("hpfs_lookup: LOOKUP, DELETE and CREATE are only supported\n");
1047 return (EOPNOTSUPP);
1050 error = VOP_ACCESS(dvp, VEXEC, cred);
1054 if( (cnp->cn_namelen == 1) &&
1055 !strncmp(cnp->cn_nameptr,".",1) ) {
1056 dprintf(("hpfs_lookup(0x%x,...): . faked\n",dhp->h_no));
1062 } else if( (cnp->cn_namelen == 2) &&
1063 !strncmp(cnp->cn_nameptr,"..",2) && (flags & CNP_ISDOTDOT) ) {
1064 dprintf(("hpfs_lookup(0x%x,...): .. faked (0x%x)\n",
1065 dhp->h_no, dhp->h_fn.fn_parent));
1067 VOP__UNLOCK(dvp, 0);
1069 error = VFS_VGET(hpmp->hpm_mp,
1070 dhp->h_fn.fn_parent, ap->a_vpp);
1076 if (lockparent && (error = VOP__LOCK(dvp, 0))) {
1077 vput( *(ap->a_vpp) );
1083 struct hpfsdirent *dep;
1084 struct hpfsnode *hp;
1086 error = hpfs_genlookupbyname(dhp,
1087 cnp->cn_nameptr, cnp->cn_namelen, &bp, &dep);
1089 if (error == ENOENT &&
1090 (nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME)) {
1092 VOP__UNLOCK(dvp, 0);
1093 return (EJUSTRETURN);
1099 dprintf(("hpfs_lookup: fnode: 0x%x, CPID: 0x%x\n",
1100 dep->de_fnode, dep->de_cpid));
1102 if (nameiop == NAMEI_DELETE) {
1103 error = VOP_ACCESS(dvp, VWRITE, cred);
1110 if (dhp->h_no == dep->de_fnode) {
1117 error = VFS_VGET(hpmp->hpm_mp, dep->de_fnode, ap->a_vpp);
1119 kprintf("hpfs_lookup: VFS_VGET FAILED %d\n", error);
1124 hp = VTOHP(*ap->a_vpp);
1126 hp->h_mtime = dep->de_mtime;
1127 hp->h_ctime = dep->de_ctime;
1128 hp->h_atime = dep->de_atime;
1129 bcopy(dep->de_name, hp->h_name, dep->de_namelen);
1130 hp->h_name[dep->de_namelen] = '\0';
1131 hp->h_namelen = dep->de_namelen;
1132 hp->h_flag |= H_PARVALID;
1137 VOP__UNLOCK(dvp, 0);
1143 * hpfs_remove(struct vnode *a_dvp, struct vnode *a_vp,
1144 * struct componentname *a_cnp)
1147 hpfs_remove(struct vop_old_remove_args *ap)
1151 dprintf(("hpfs_remove(0x%x, %s, %ld): \n", VTOHP(ap->a_vp)->h_no,
1152 ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen));
1154 if (ap->a_vp->v_type == VDIR)
1157 error = hpfs_removefnode (ap->a_dvp, ap->a_vp, ap->a_cnp);
1162 * hpfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
1163 * struct componentname *a_cnp, struct vattr *a_vap)
1166 hpfs_create(struct vop_old_create_args *ap)
1170 dprintf(("hpfs_create(0x%x, %s, %ld): \n", VTOHP(ap->a_dvp)->h_no,
1171 ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen));
1173 error = hpfs_makefnode (ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap);
1179 * Return POSIX pathconf information applicable to NTFS filesystem
1181 * hpfs_pathconf(struct vnode *a_vp, int a_name, t *a_retval)
1184 hpfs_pathconf(struct vop_pathconf_args *ap)
1186 switch (ap->a_name) {
1191 *ap->a_retval = HPFS_MAXFILENAME;
1194 *ap->a_retval = PATH_MAX;
1196 case _PC_CHOWN_RESTRICTED:
1202 #if defined(__NetBSD__)
1206 case _PC_FILESIZEBITS:
1218 * Global vfs data structures
1221 struct vop_ops hpfs_vnode_vops = {
1222 .vop_default = vop_defaultop,
1223 .vop_getattr = hpfs_getattr,
1224 .vop_setattr = hpfs_setattr,
1225 .vop_inactive = hpfs_inactive,
1226 .vop_reclaim = hpfs_reclaim,
1227 .vop_print = hpfs_print,
1228 .vop_old_create = hpfs_create,
1229 .vop_old_remove = hpfs_remove,
1230 .vop_old_lookup = hpfs_lookup,
1231 .vop_access = hpfs_access,
1232 .vop_readdir = hpfs_readdir,
1233 .vop_fsync = hpfs_fsync,
1234 .vop_bmap = hpfs_bmap,
1235 .vop_getpages = hpfs_getpages,
1236 .vop_putpages = hpfs_putpages,
1237 .vop_strategy = hpfs_strategy,
1238 .vop_read = hpfs_read,
1239 .vop_write = hpfs_write,
1240 .vop_ioctl = hpfs_ioctl,
1241 .vop_pathconf = hpfs_pathconf