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.22 2005/02/15 08:32:18 joerg 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>
45 #include <vm/vm_param.h>
46 #if !defined(__DragonFly__)
47 #include <vm/vm_prot.h>
49 #include <vm/vm_page.h>
50 #include <vm/vm_object.h>
51 #include <vm/vm_pager.h>
52 #include <vm/vm_zone.h>
53 #if defined(__DragonFly__)
54 #include <vm/vnode_pager.h>
56 #include <vm/vm_extern.h>
59 #if !defined(__DragonFly__)
60 #include <miscfs/specfs/specdev.h>
61 #include <miscfs/genfs/genfs.h>
64 #include <sys/unistd.h> /* for pathconf(2) constants */
67 #include "hpfsmount.h"
68 #include "hpfs_subr.h"
69 #include "hpfs_ioctl.h"
71 static int hpfs_de_uiomove (struct hpfsmount *, struct hpfsdirent *,
73 static int hpfs_ioctl (struct vop_ioctl_args *ap);
74 static int hpfs_read (struct vop_read_args *);
75 static int hpfs_write (struct vop_write_args *ap);
76 static int hpfs_getattr (struct vop_getattr_args *ap);
77 static int hpfs_setattr (struct vop_setattr_args *ap);
78 static int hpfs_inactive (struct vop_inactive_args *ap);
79 static int hpfs_print (struct vop_print_args *ap);
80 static int hpfs_reclaim (struct vop_reclaim_args *ap);
81 static int hpfs_strategy (struct vop_strategy_args *ap);
82 static int hpfs_access (struct vop_access_args *ap);
83 static int hpfs_open (struct vop_open_args *ap);
84 static int hpfs_close (struct vop_close_args *ap);
85 static int hpfs_readdir (struct vop_readdir_args *ap);
86 static int hpfs_lookup (struct vop_lookup_args *ap);
87 static int hpfs_create (struct vop_create_args *);
88 static int hpfs_remove (struct vop_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, struct ucred *a_cred, int a_waitfor,
117 hpfs_fsync(struct vop_fsync_args *ap)
119 struct vnode *vp = ap->a_vp;
121 struct buf *bp, *nbp;
124 * Flush all dirty buffers associated with a vnode.
128 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
129 nbp = TAILQ_NEXT(bp, b_vnbufs);
130 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT))
132 if ((bp->b_flags & B_DELWRI) == 0)
133 panic("hpfs_fsync: not dirty");
139 while (vp->v_numoutput) {
140 vp->v_flag |= VBWAIT;
141 (void) tsleep((caddr_t)&vp->v_numoutput, 0, "hpfsn", 0);
144 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
145 vprint("hpfs_fsync: dirty", vp);
152 * Write out the on-disc version of the vnode.
154 return hpfs_update(VTOHP(vp));
160 * hpfs_ioctl(struct vnode *a_vp, u_long a_command, caddr_t a_data,
161 * int a_fflag, struct ucred *a_cred, struct proc *a_td)
164 hpfs_ioctl(struct vop_ioctl_args *ap)
166 struct vnode *vp = ap->a_vp;
167 struct hpfsnode *hp = VTOHP(vp);
170 printf("hpfs_ioctl(0x%x, 0x%lx, 0x%p, 0x%x): ",
171 hp->h_no, ap->a_command, ap->a_data, ap->a_fflag);
173 switch (ap->a_command) {
174 case HPFSIOCGEANUM: {
181 if (hp->h_fn.fn_ealen > 0) {
182 eap = (struct ea *)&(hp->h_fn.fn_int);
185 while (passed < hp->h_fn.fn_ealen) {
187 printf("EAname: %s\n", EA_NAME(eap));
190 passed += sizeof(struct ea) +
191 eap->ea_namelen + 1 + eap->ea_vallen;
192 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
200 printf("%lu eas\n", eanum);
202 *(u_long *)ap->a_data = eanum;
211 printf("EA%ld\n", *(u_long *)ap->a_data);
214 if (hp->h_fn.fn_ealen > 0) {
215 eap = (struct ea *)&(hp->h_fn.fn_int);
219 while (passed < hp->h_fn.fn_ealen) {
220 printf("EAname: %s\n", EA_NAME(eap));
222 if (eanum == *(u_long *)ap->a_data) {
223 *(u_long *)ap->a_data =
224 eap->ea_namelen + 1 +
232 passed += sizeof(struct ea) +
233 eap->ea_namelen + 1 + eap->ea_vallen;
234 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
246 struct hpfs_rdea *rdeap;
249 rdeap = (struct hpfs_rdea *)ap->a_data;
250 printf("EA%ld\n", rdeap->ea_no);
253 if (hp->h_fn.fn_ealen > 0) {
254 eap = (struct ea *)&(hp->h_fn.fn_int);
258 while (passed < hp->h_fn.fn_ealen) {
259 printf("EAname: %s\n", EA_NAME(eap));
261 if (eanum == rdeap->ea_no) {
262 rdeap->ea_sz = eap->ea_namelen + 1 +
264 copyout(EA_NAME(eap),rdeap->ea_data,
271 passed += sizeof(struct ea) +
272 eap->ea_namelen + 1 + eap->ea_vallen;
273 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
290 * Map file offset to disk offset.
292 * hpfs_bmap(struct vnode *a_vp, daddr_t a_bn, struct vnode **a_vpp,
293 * daddr_t *a_bnp, int *a_runp, int *a_runb)
296 hpfs_bmap(struct vop_bmap_args *ap)
298 struct hpfsnode *hp = VTOHP(ap->a_vp);
301 if (ap->a_vpp != NULL)
302 *ap->a_vpp = hp->h_devvp;
303 #if defined(__DragonFly__)
304 if (ap->a_runb != NULL)
307 if (ap->a_bnp == NULL)
310 dprintf(("hpfs_bmap(0x%x, 0x%x): ",hp->h_no, ap->a_bn));
312 error = hpfs_hpbmap (hp, ap->a_bn, ap->a_bnp, ap->a_runp);
318 * hpfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
319 * struct ucred *a_cred)
322 hpfs_read(struct vop_read_args *ap)
324 struct vnode *vp = ap->a_vp;
325 struct hpfsnode *hp = VTOHP(vp);
326 struct uio *uio = ap->a_uio;
328 u_int xfersz, toread;
335 resid = min (uio->uio_resid, hp->h_fn.fn_size - uio->uio_offset);
337 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));
340 lbn = uio->uio_offset >> DEV_BSHIFT;
341 off = uio->uio_offset & (DEV_BSIZE - 1);
342 dprintf(("hpfs_read: resid: 0x%x lbn: 0x%x off: 0x%x\n",
343 uio->uio_resid, lbn, off));
344 error = hpfs_hpbmap(hp, lbn, &bn, &runl);
348 toread = min(off + resid, min(DFLTPHYS, (runl+1)*DEV_BSIZE));
349 xfersz = (toread + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1);
350 dprintf(("hpfs_read: bn: 0x%x (0x%x) toread: 0x%x (0x%x)\n",
351 bn, runl, toread, xfersz));
356 error = bread(hp->h_devvp, bn, xfersz, &bp);
362 error = uiomove(bp->b_data + off, toread - off, uio);
370 dprintf(("hpfs_read: successful\n"));
375 * hpfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
376 * struct ucred *a_cred)
379 hpfs_write(struct vop_write_args *ap)
381 struct vnode *vp = ap->a_vp;
382 struct hpfsnode *hp = VTOHP(vp);
383 struct uio *uio = ap->a_uio;
385 u_int xfersz, towrite;
391 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));
393 if (ap->a_ioflag & IO_APPEND) {
394 dprintf(("hpfs_write: APPEND mode\n"));
395 uio->uio_offset = hp->h_fn.fn_size;
397 if (uio->uio_offset + uio->uio_resid > hp->h_fn.fn_size) {
398 error = hpfs_extend (hp, uio->uio_offset + uio->uio_resid);
400 printf("hpfs_write: hpfs_extend FAILED %d\n", error);
405 while (uio->uio_resid) {
406 lbn = uio->uio_offset >> DEV_BSHIFT;
407 off = uio->uio_offset & (DEV_BSIZE - 1);
408 dprintf(("hpfs_write: resid: 0x%x lbn: 0x%x off: 0x%x\n",
409 uio->uio_resid, lbn, off));
410 error = hpfs_hpbmap(hp, lbn, &bn, &runl);
414 towrite = min(off + uio->uio_resid, min(DFLTPHYS, (runl+1)*DEV_BSIZE));
415 xfersz = (towrite + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1);
416 dprintf(("hpfs_write: bn: 0x%x (0x%x) towrite: 0x%x (0x%x)\n",
417 bn, runl, towrite, xfersz));
419 if ((off == 0) && (towrite == xfersz)) {
420 bp = getblk(hp->h_devvp, bn, xfersz, 0, 0);
423 error = bread(hp->h_devvp, bn, xfersz, &bp);
430 error = uiomove(bp->b_data + off, towrite - off, uio);
436 if (ap->a_ioflag & IO_SYNC)
442 dprintf(("hpfs_write: successful\n"));
447 * XXXXX do we need hpfsnode locking inside?
449 * hpfs_getattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred,
453 hpfs_getattr(struct vop_getattr_args *ap)
455 struct vnode *vp = ap->a_vp;
456 struct hpfsnode *hp = VTOHP(vp);
457 struct vattr *vap = ap->a_vap;
460 dprintf(("hpfs_getattr(0x%x):\n", hp->h_no));
462 #if defined(__DragonFly__)
463 vap->va_fsid = dev2udev(hp->h_dev);
464 #else /* defined(__NetBSD__) */
465 vap->va_fsid = ip->i_dev;
467 vap->va_fileid = hp->h_no;
468 vap->va_mode = hp->h_mode;
470 vap->va_uid = hp->h_uid;
471 vap->va_gid = hp->h_gid;
472 vap->va_rdev = 0; /* XXX UNODEV ? */
473 vap->va_size = hp->h_fn.fn_size;
474 vap->va_bytes = ((hp->h_fn.fn_size + DEV_BSIZE-1) & ~(DEV_BSIZE-1)) +
477 if (!(hp->h_flag & H_PARVALID)) {
478 error = hpfs_validateparent(hp);
482 vap->va_atime = hpfstimetounix(hp->h_atime);
483 vap->va_mtime = hpfstimetounix(hp->h_mtime);
484 vap->va_ctime = hpfstimetounix(hp->h_ctime);
488 vap->va_blocksize = DEV_BSIZE;
489 vap->va_type = vp->v_type;
496 * XXXXX do we need hpfsnode locking inside?
498 * hpfs_setattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred,
499 * struct thread *a_td)
502 hpfs_setattr(struct vop_setattr_args *ap)
504 struct vnode *vp = ap->a_vp;
505 struct hpfsnode *hp = VTOHP(vp);
506 struct vattr *vap = ap->a_vap;
507 struct ucred *cred = ap->a_cred;
508 struct thread *td = ap->a_td;
511 dprintf(("hpfs_setattr(0x%x):\n", hp->h_no));
514 * Check for unsettable attributes.
516 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
517 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
518 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
519 (vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
520 dprintf(("hpfs_setattr: changing nonsettable attr\n"));
524 /* Can't change flags XXX Could be implemented */
525 if (vap->va_flags != VNOVAL) {
526 printf("hpfs_setattr: FLAGS CANNOT BE SET\n");
530 /* Can't change uid/gid XXX Could be implemented */
531 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
532 printf("hpfs_setattr: UID/GID CANNOT BE SET\n");
536 /* Can't change mode XXX Could be implemented */
537 if (vap->va_mode != (mode_t)VNOVAL) {
538 printf("hpfs_setattr: MODE CANNOT BE SET\n");
543 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
544 if (vp->v_mount->mnt_flag & MNT_RDONLY)
546 if (cred->cr_uid != hp->h_uid &&
547 (error = suser_cred(cred, PRISON_ROOT)) &&
548 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
549 (error = VOP_ACCESS(vp, VWRITE, cred, td))))
551 if (vap->va_atime.tv_sec != VNOVAL)
552 hp->h_atime = vap->va_atime.tv_sec;
553 if (vap->va_mtime.tv_sec != VNOVAL)
554 hp->h_mtime = vap->va_mtime.tv_sec;
556 hp->h_flag |= H_PARCHANGE;
559 if (vap->va_size != VNOVAL) {
560 switch (vp->v_type) {
564 if (vp->v_mount->mnt_flag & MNT_RDONLY)
568 printf("hpfs_setattr: WRONG v_type\n");
572 if (vap->va_size < hp->h_fn.fn_size) {
573 #if defined(__DragonFly__)
574 error = vtruncbuf(vp, td, vap->va_size, DEV_BSIZE);
577 #else /* defined(__NetBSD__) */
578 #error Need alternation for vtruncbuf()
580 error = hpfs_truncate(hp, vap->va_size);
584 } else if (vap->va_size > hp->h_fn.fn_size) {
585 #if defined(__DragonFly__)
586 vnode_pager_setsize(vp, vap->va_size);
588 error = hpfs_extend(hp, vap->va_size);
598 * Last reference to an node. If necessary, write or delete it.
600 * hpfs_inactive(struct vnode *a_vp)
603 hpfs_inactive(struct vop_inactive_args *ap)
605 struct vnode *vp = ap->a_vp;
606 struct hpfsnode *hp = VTOHP(vp);
609 dprintf(("hpfs_inactive(0x%x): \n", hp->h_no));
611 if (hp->h_flag & H_CHANGE) {
612 dprintf(("hpfs_inactive: node changed, update\n"));
613 error = hpfs_update (hp);
618 if (hp->h_flag & H_PARCHANGE) {
619 dprintf(("hpfs_inactive: parent node changed, update\n"));
620 error = hpfs_updateparent (hp);
625 if (prtactive && vp->v_usecount != 0)
626 vprint("hpfs_inactive: pushing active", vp);
628 if (hp->h_flag & H_INVAL) {
629 #if defined(__DragonFly__)
630 vrecycle(vp, ap->a_td);
631 #else /* defined(__NetBSD__) */
640 * Reclaim an inode so that it can be used for other purposes.
642 * hpfs_reclaim(struct vnode *a_vp)
645 hpfs_reclaim(struct vop_reclaim_args *ap)
647 struct vnode *vp = ap->a_vp;
648 struct hpfsnode *hp = VTOHP(vp);
650 dprintf(("hpfs_reclaim(0x%x0): \n", hp->h_no));
654 /* Purge old data structures associated with the inode. */
668 * hpfs_print(struct vnode *a_vp)
671 hpfs_print(struct vop_print_args *ap)
673 struct vnode *vp = ap->a_vp;
674 struct hpfsnode *hp = VTOHP(vp);
676 printf("tag VT_HPFS, ino 0x%x",hp->h_no);
677 lockmgr_printinfo(&vp->v_lock);
683 * Calculate the logical to physical mapping if not done already,
684 * then call the device strategy routine.
686 * In order to be able to swap to a file, the VOP_BMAP operation may not
687 * deadlock on memory. See hpfs_bmap() for details. XXXXXXX (not impl)
689 * hpfs_strategy(struct buf *a_bp)
692 hpfs_strategy(struct vop_strategy_args *ap)
694 struct buf *bp = ap->a_bp;
695 struct vnode *vp = ap->a_vp;
699 dprintf(("hpfs_strategy(): \n"));
701 if (vp->v_type == VBLK || vp->v_type == VCHR)
702 panic("hpfs_strategy: spec");
703 if (bp->b_blkno == bp->b_lblkno) {
704 error = VOP_BMAP(vp, bp->b_lblkno, &nvp, &bp->b_blkno, NULL, NULL);
706 printf("hpfs_strategy: VOP_BMAP FAILED %d\n", error);
708 bp->b_flags |= B_ERROR;
712 if ((long)bp->b_blkno == -1)
715 if ((long)bp->b_blkno == -1) {
719 bp->b_dev = nvp->v_rdev;
720 VOP_STRATEGY(nvp, bp);
725 * XXXXX do we need hpfsnode locking inside?
727 * hpfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
731 hpfs_access(struct vop_access_args *ap)
733 struct vnode *vp = ap->a_vp;
734 struct hpfsnode *hp = VTOHP(vp);
735 struct ucred *cred = ap->a_cred;
736 mode_t mask, mode = ap->a_mode;
740 dprintf(("hpfs_access(0x%x):\n", hp->h_no));
743 * Disallow write attempts on read-only file systems;
744 * unless the file is a socket, fifo, or a block or
745 * character device resident on the file system.
748 switch ((int)vp->v_type) {
752 if (vp->v_mount->mnt_flag & MNT_RDONLY)
758 /* Otherwise, user id 0 always gets access. */
759 if (cred->cr_uid == 0)
764 /* Otherwise, check the owner. */
765 if (cred->cr_uid == hp->h_uid) {
772 return ((hp->h_mode & mask) == mask ? 0 : EACCES);
775 /* Otherwise, check the groups. */
776 for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
777 if (hp->h_gid == *gp) {
784 return ((hp->h_mode & mask) == mask ? 0 : EACCES);
787 /* Otherwise, check everyone else. */
794 return ((hp->h_mode & mask) == mask ? 0 : EACCES);
802 * hpfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
807 hpfs_open(struct vop_open_args *ap)
810 struct vnode *vp = ap->a_vp;
811 struct hpfsnode *hp = VTOHP(vp);
813 printf("hpfs_open(0x%x):\n",hp->h_no);
817 * Files marked append-only must be opened for appending.
826 * Update the times on the inode.
828 * hpfs_close(struct vnode *a_vp, int a_fflag, struct ucred *a_cred,
833 hpfs_close(struct vop_close_args *ap)
836 struct vnode *vp = ap->a_vp;
837 struct hpfsnode *hp = VTOHP(vp);
839 printf("hpfs_close: %d\n",hp->h_no);
846 hpfs_de_uiomove(struct hpfsmount *hpmp, struct hpfsdirent *dep,
852 dprintf(("[no: 0x%x, size: %d, name: %2d:%.*s, flag: 0x%x] ",
853 dep->de_fnode, dep->de_size, dep->de_namelen,
854 dep->de_namelen, dep->de_name, dep->de_flag));
856 /*strncpy(cde.d_name, dep->de_name, dep->de_namelen);*/
857 for (i=0; i<dep->de_namelen; i++)
858 cde.d_name[i] = hpfs_d2u(hpmp, dep->de_name[i]);
860 cde.d_name[dep->de_namelen] = '\0';
861 cde.d_namlen = dep->de_namelen;
862 cde.d_fileno = dep->de_fnode;
863 cde.d_type = (dep->de_flag & DE_DIR) ? DT_DIR : DT_REG;
864 cde.d_reclen = sizeof(struct dirent);
866 error = uiomove((char *)&cde, sizeof(struct dirent), uio);
870 dprintf(("[0x%x] ", uio->uio_resid));
875 static struct dirent hpfs_de_dot =
876 { 0, sizeof(struct dirent), DT_DIR, 1, "." };
877 static struct dirent hpfs_de_dotdot =
878 { 0, sizeof(struct dirent), DT_DIR, 2, ".." };
881 * hpfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
882 * int *a_ncookies, u_int **cookies)
885 hpfs_readdir(struct vop_readdir_args *ap)
887 struct vnode *vp = ap->a_vp;
888 struct hpfsnode *hp = VTOHP(vp);
889 struct hpfsmount *hpmp = hp->h_hpmp;
890 struct uio *uio = ap->a_uio;
891 int ncookies = 0, i, num, cnum;
896 struct hpfsdirent *dep;
901 dprintf(("hpfs_readdir(0x%x, 0x%x, 0x%x): ",hp->h_no,(u_int32_t)uio->uio_offset,uio->uio_resid));
903 off = uio->uio_offset;
905 if( uio->uio_offset < sizeof(struct dirent) ) {
906 dprintf((". faked, "));
907 hpfs_de_dot.d_fileno = hp->h_no;
908 error = uiomove((char *)&hpfs_de_dot,sizeof(struct dirent),uio);
916 if( uio->uio_offset < 2 * sizeof(struct dirent) ) {
917 dprintf((".. faked, "));
918 hpfs_de_dotdot.d_fileno = hp->h_fn.fn_parent;
920 error = uiomove((char *)&hpfs_de_dotdot, sizeof(struct dirent),
929 num = uio->uio_offset / sizeof(struct dirent) - 2;
932 lsn = ((alleaf_t *)hp->h_fn.fn_abd)->al_lsn;
938 dprintf(("[dive 0x%x] ", lsn));
939 error = bread(hp->h_devvp, lsn, D_BSIZE, &bp);
945 dp = (struct dirblk *) bp->b_data;
946 if (dp->d_magic != D_MAGIC) {
947 printf("hpfs_readdir: MAGIC DOESN'T MATCH\n");
955 dprintf(("[restore 0x%x] ", olsn));
957 while(!(dep->de_flag & DE_END) ) {
958 if((dep->de_flag & DE_DOWN) &&
959 (olsn == DE_DOWNLSN(dep)))
961 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
964 if((dep->de_flag & DE_DOWN) && (olsn == DE_DOWNLSN(dep))) {
965 if (dep->de_flag & DE_END)
968 if (!(dep->de_flag & DE_SPECIAL)) {
970 if (uio->uio_resid < sizeof(struct dirent)) {
972 dprintf(("[resid] "));
976 error = hpfs_de_uiomove(hpmp, dep, uio);
983 if (uio->uio_resid < sizeof(struct dirent)) {
985 dprintf(("[resid] "));
992 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
994 printf("hpfs_readdir: ERROR! oLSN not found\n");
1002 while(!(dep->de_flag & DE_END)) {
1003 if(dep->de_flag & DE_DOWN) {
1004 lsn = DE_DOWNLSN(dep);
1010 if (!(dep->de_flag & DE_SPECIAL)) {
1012 if (uio->uio_resid < sizeof(struct dirent)) {
1014 dprintf(("[resid] "));
1018 error = hpfs_de_uiomove(hpmp, dep, uio);
1025 if (uio->uio_resid < sizeof(struct dirent)) {
1027 dprintf(("[resid] "));
1034 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
1037 if(dep->de_flag & DE_DOWN) {
1038 dprintf(("[enddive] "));
1039 lsn = DE_DOWNLSN(dep);
1046 dprintf(("[EOB] "));
1052 dprintf(("[level %d] ", level));
1055 goto dive; /* undive really */
1057 if (ap->a_eofflag) {
1058 dprintf(("[EOF] "));
1063 dprintf(("[readdone]\n"));
1064 if (!error && ap->a_ncookies != NULL) {
1065 struct dirent* dpStart;
1067 #if defined(__DragonFly__)
1070 #else /* defined(__NetBSD__) */
1075 dprintf(("%d cookies, ",ncookies));
1076 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1077 panic("hpfs_readdir: unexpected uio from NFS server");
1078 dpStart = (struct dirent *)
1079 ((caddr_t)uio->uio_iov->iov_base -
1080 (uio->uio_offset - off));
1081 #if defined(__DragonFly__)
1082 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
1084 #else /* defined(__NetBSD__) */
1085 MALLOC(cookies, off_t *, ncookies * sizeof(off_t),
1088 for (dp = dpStart, cookiep = cookies, i=0;
1090 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen), i++) {
1091 off += dp->d_reclen;
1092 *cookiep++ = (u_int) off;
1094 *ap->a_ncookies = ncookies;
1095 *ap->a_cookies = cookies;
1102 * hpfs_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
1103 * struct componentname *a_cnp)
1106 hpfs_lookup(struct vop_lookup_args *ap)
1108 struct vnode *dvp = ap->a_dvp;
1109 struct hpfsnode *dhp = VTOHP(dvp);
1110 struct hpfsmount *hpmp = dhp->h_hpmp;
1111 struct componentname *cnp = ap->a_cnp;
1112 struct ucred *cred = cnp->cn_cred;
1114 int nameiop = cnp->cn_nameiop;
1115 int flags = cnp->cn_flags;
1116 int lockparent = flags & CNP_LOCKPARENT;
1118 int wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
1120 dprintf(("hpfs_lookup(0x%x, %s, %ld, %d, %d): \n",
1121 dhp->h_no, cnp->cn_nameptr, cnp->cn_namelen,
1122 lockparent, wantparent));
1124 if (nameiop != NAMEI_CREATE && nameiop != NAMEI_DELETE && nameiop != NAMEI_LOOKUP) {
1125 printf("hpfs_lookup: LOOKUP, DELETE and CREATE are only supported\n");
1126 return (EOPNOTSUPP);
1129 error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_td);
1133 if( (cnp->cn_namelen == 1) &&
1134 !strncmp(cnp->cn_nameptr,".",1) ) {
1135 dprintf(("hpfs_lookup(0x%x,...): . faked\n",dhp->h_no));
1141 } else if( (cnp->cn_namelen == 2) &&
1142 !strncmp(cnp->cn_nameptr,"..",2) && (flags & CNP_ISDOTDOT) ) {
1143 dprintf(("hpfs_lookup(0x%x,...): .. faked (0x%x)\n",
1144 dhp->h_no, dhp->h_fn.fn_parent));
1146 VOP__UNLOCK(dvp,0,cnp->cn_td);
1148 error = VFS_VGET(hpmp->hpm_mp,
1149 dhp->h_fn.fn_parent, ap->a_vpp);
1151 VOP__LOCK(dvp, 0, cnp->cn_td);
1155 if (lockparent && (error = VOP__LOCK(dvp, 0, cnp->cn_td))) {
1156 vput( *(ap->a_vpp) );
1162 struct hpfsdirent *dep;
1163 struct hpfsnode *hp;
1165 error = hpfs_genlookupbyname(dhp,
1166 cnp->cn_nameptr, cnp->cn_namelen, &bp, &dep);
1168 if (error == ENOENT &&
1169 (nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME)) {
1171 VOP__UNLOCK(dvp, 0, cnp->cn_td);
1172 return (EJUSTRETURN);
1178 dprintf(("hpfs_lookup: fnode: 0x%x, CPID: 0x%x\n",
1179 dep->de_fnode, dep->de_cpid));
1181 if (nameiop == NAMEI_DELETE) {
1182 error = VOP_ACCESS(dvp, VWRITE, cred, cnp->cn_td);
1189 if (dhp->h_no == dep->de_fnode) {
1196 error = VFS_VGET(hpmp->hpm_mp, dep->de_fnode, ap->a_vpp);
1198 printf("hpfs_lookup: VFS_VGET FAILED %d\n", error);
1203 hp = VTOHP(*ap->a_vpp);
1205 hp->h_mtime = dep->de_mtime;
1206 hp->h_ctime = dep->de_ctime;
1207 hp->h_atime = dep->de_atime;
1208 bcopy(dep->de_name, hp->h_name, dep->de_namelen);
1209 hp->h_name[dep->de_namelen] = '\0';
1210 hp->h_namelen = dep->de_namelen;
1211 hp->h_flag |= H_PARVALID;
1216 VOP__UNLOCK(dvp, 0, cnp->cn_td);
1222 * hpfs_remove(struct vnode *a_dvp, struct vnode *a_vp,
1223 * struct componentname *a_cnp)
1226 hpfs_remove(struct vop_remove_args *ap)
1230 dprintf(("hpfs_remove(0x%x, %s, %ld): \n", VTOHP(ap->a_vp)->h_no,
1231 ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen));
1233 if (ap->a_vp->v_type == VDIR)
1236 error = hpfs_removefnode (ap->a_dvp, ap->a_vp, ap->a_cnp);
1241 * hpfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
1242 * struct componentname *a_cnp, struct vattr *a_vap)
1245 hpfs_create(struct vop_create_args *ap)
1249 dprintf(("hpfs_create(0x%x, %s, %ld): \n", VTOHP(ap->a_dvp)->h_no,
1250 ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen));
1252 error = hpfs_makefnode (ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap);
1258 * Return POSIX pathconf information applicable to NTFS filesystem
1260 * hpfs_pathconf(struct vnode *a_vp, int a_name, t *a_retval)
1263 hpfs_pathconf(struct vop_pathconf_args *ap)
1265 switch (ap->a_name) {
1270 *ap->a_retval = HPFS_MAXFILENAME;
1273 *ap->a_retval = PATH_MAX;
1275 case _PC_CHOWN_RESTRICTED:
1281 #if defined(__NetBSD__)
1285 case _PC_FILESIZEBITS:
1297 * Global vfs data structures
1299 #if defined(__DragonFly__)
1300 struct vnodeopv_entry_desc hpfs_vnodeop_entries[] = {
1301 { &vop_default_desc, vop_defaultop },
1303 { &vop_getattr_desc, (vnodeopv_entry_t)hpfs_getattr },
1304 { &vop_setattr_desc, (vnodeopv_entry_t)hpfs_setattr },
1305 { &vop_inactive_desc, (vnodeopv_entry_t)hpfs_inactive },
1306 { &vop_reclaim_desc, (vnodeopv_entry_t)hpfs_reclaim },
1307 { &vop_print_desc, (vnodeopv_entry_t)hpfs_print },
1308 { &vop_create_desc, (vnodeopv_entry_t)hpfs_create },
1309 { &vop_remove_desc, (vnodeopv_entry_t)hpfs_remove },
1310 { &vop_islocked_desc, vop_stdislocked },
1311 { &vop_unlock_desc, vop_stdunlock },
1312 { &vop_lock_desc, vop_stdlock },
1313 { &vop_lookup_desc, (vnodeopv_entry_t)hpfs_lookup },
1314 { &vop_access_desc, (vnodeopv_entry_t)hpfs_access },
1315 { &vop_close_desc, (vnodeopv_entry_t)hpfs_close },
1316 { &vop_open_desc, (vnodeopv_entry_t)hpfs_open },
1317 { &vop_readdir_desc, (vnodeopv_entry_t)hpfs_readdir },
1318 { &vop_fsync_desc, (vnodeopv_entry_t)hpfs_fsync },
1319 { &vop_bmap_desc, (vnodeopv_entry_t)hpfs_bmap },
1320 { &vop_getpages_desc, (vnodeopv_entry_t) hpfs_getpages },
1321 { &vop_putpages_desc, (vnodeopv_entry_t) hpfs_putpages },
1322 { &vop_strategy_desc, (vnodeopv_entry_t)hpfs_strategy },
1323 { &vop_bwrite_desc, vop_stdbwrite },
1324 { &vop_read_desc, (vnodeopv_entry_t)hpfs_read },
1325 { &vop_write_desc, (vnodeopv_entry_t)hpfs_write },
1326 { &vop_ioctl_desc, (vnodeopv_entry_t)hpfs_ioctl },
1327 { &vop_pathconf_desc, (vnodeopv_entry_t)hpfs_pathconf },
1331 #else /* defined(__NetBSD__) */
1332 struct vnodeopv_entry_desc ntfs_vnodeop_entries[] = {
1333 { &vop_default_desc, (vnodeopv_entry_t) genfs_badop }, /* XXX */
1334 { &vop_lookup_desc, (vnodeopv_entry_t) hpfs_lookup }, /* lookup */
1335 { &vop_create_desc, genfs_eopnotsupp }, /* create */
1336 { &vop_mknod_desc, genfs_eopnotsupp }, /* mknod */
1337 { &vop_open_desc, (vnodeopv_entry_t) hpfs_open }, /* open */
1338 { &vop_close_desc,(vnodeopv_entry_t) hpfs_close }, /* close */
1339 { &vop_access_desc, (vnodeopv_entry_t) hpfs_access }, /* access */
1340 { &vop_getattr_desc, (vnodeopv_entry_t) hpfs_getattr }, /* getattr */
1341 { &vop_setattr_desc, genfs_eopnotsupp }, /* setattr */
1342 { &vop_read_desc, (vnodeopv_entry_t) hpfs_read }, /* read */
1343 { &vop_write_desc, (vnodeopv_entry_t) hpfs_write }, /* write */
1344 { &vop_lease_desc, genfs_lease_check }, /* lease */
1345 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
1346 { &vop_ioctl_desc, genfs_enoioctl }, /* ioctl */
1347 { &vop_poll_desc, genfs_poll }, /* poll */
1348 { &vop_revoke_desc, genfs_revoke }, /* revoke */
1349 { &vop_mmap_desc, genfs_eopnotsupp }, /* mmap */
1350 { &vop_fsync_desc, genfs_fsync }, /* fsync */
1351 { &vop_seek_desc, genfs_seek }, /* seek */
1352 { &vop_remove_desc, genfs_eopnotsupp }, /* remove */
1353 { &vop_link_desc, genfs_eopnotsupp }, /* link */
1354 { &vop_rename_desc, genfs_eopnotsupp }, /* rename */
1355 { &vop_mkdir_desc, genfs_eopnotsupp }, /* mkdir */
1356 { &vop_rmdir_desc, genfs_eopnotsupp }, /* rmdir */
1357 { &vop_symlink_desc, genfs_eopnotsupp }, /* symlink */
1358 { &vop_readdir_desc, (vnodeopv_entry_t) hpfs_readdir }, /* readdir */
1359 { &vop_readlink_desc, genfs_eopnotsupp }, /* readlink */
1360 { &vop_abortop_desc, genfs_abortop }, /* abortop */
1361 { &vop_inactive_desc, (vnodeopv_entry_t) hpfs_inactive }, /* inactive */
1362 { &vop_reclaim_desc, (vnodeopv_entry_t) hpfs_reclaim }, /* reclaim */
1363 { &vop_lock_desc, genfs_lock }, /* lock */
1364 { &vop_unlock_desc, genfs_unlock }, /* unlock */
1365 { &vop_bmap_desc, (vnodeopv_entry_t) hpfs_bmap }, /* bmap */
1366 { &vop_strategy_desc, (vnodeopv_entry_t) hpfs_strategy }, /* strategy */
1367 { &vop_print_desc, (vnodeopv_entry_t) hpfs_print }, /* print */
1368 { &vop_islocked_desc, genfs_islocked }, /* islocked */
1369 { &vop_pathconf_desc, hpfs_pathconf }, /* pathconf */
1370 { &vop_advlock_desc, genfs_nullop }, /* advlock */
1371 { &vop_blkatoff_desc, genfs_eopnotsupp }, /* blkatoff */
1372 { &vop_valloc_desc, genfs_eopnotsupp }, /* valloc */
1373 { &vop_reallocblks_desc, genfs_eopnotsupp }, /* reallocblks */
1374 { &vop_vfree_desc, genfs_eopnotsupp }, /* vfree */
1375 { &vop_truncate_desc, genfs_eopnotsupp }, /* truncate */
1376 { &vop_update_desc, genfs_eopnotsupp }, /* update */
1377 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */