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 $
29 #include <sys/param.h>
30 #include <sys/systm.h>
32 #include <sys/kernel.h>
36 #include <sys/types.h>
38 #include <sys/vnode.h>
39 #include <sys/mount.h>
40 #include <sys/namei.h>
41 #include <sys/malloc.h>
43 #include <sys/dirent.h>
45 #include <machine/limits.h>
48 #include <vm/vm_param.h>
49 #if !defined(__DragonFly__)
50 #include <vm/vm_prot.h>
52 #include <vm/vm_page.h>
53 #include <vm/vm_object.h>
54 #include <vm/vm_pager.h>
55 #include <vm/vm_zone.h>
56 #if defined(__DragonFly__)
57 #include <vm/vnode_pager.h>
59 #include <vm/vm_extern.h>
63 #if !defined(__DragonFly__)
64 #include <miscfs/specfs/specdev.h>
65 #include <miscfs/genfs/genfs.h>
68 #include <sys/unistd.h> /* for pathconf(2) constants */
71 #include "hpfsmount.h"
72 #include "hpfs_subr.h"
73 #include "hpfs_ioctl.h"
75 static int hpfs_de_uiomove (int *, struct hpfsmount *,
76 struct hpfsdirent *, struct uio *);
77 static int hpfs_ioctl (struct vop_ioctl_args *ap);
78 static int hpfs_read (struct vop_read_args *);
79 static int hpfs_write (struct vop_write_args *ap);
80 static int hpfs_getattr (struct vop_getattr_args *ap);
81 static int hpfs_setattr (struct vop_setattr_args *ap);
82 static int hpfs_inactive (struct vop_inactive_args *ap);
83 static int hpfs_print (struct vop_print_args *ap);
84 static int hpfs_reclaim (struct vop_reclaim_args *ap);
85 static int hpfs_strategy (struct vop_strategy_args *ap);
86 static int hpfs_access (struct vop_access_args *ap);
87 static int hpfs_readdir (struct vop_readdir_args *ap);
88 static int hpfs_lookup (struct vop_old_lookup_args *ap);
89 static int hpfs_create (struct vop_old_create_args *);
90 static int hpfs_remove (struct vop_old_remove_args *);
91 static int hpfs_bmap (struct vop_bmap_args *ap);
92 #if defined(__DragonFly__)
93 static int hpfs_fsync (struct vop_fsync_args *ap);
95 static int hpfs_pathconf (struct vop_pathconf_args *ap);
97 #if defined(__DragonFly__)
100 * hpfs_fsync(struct vnode *a_vp, int a_waitfor)
103 hpfs_fsync(struct vop_fsync_args *ap)
105 struct vnode *vp = ap->a_vp;
108 * Flush all dirty buffers associated with a vnode.
113 vfsync(vp, ap->a_waitfor, 0, NULL, NULL);
115 if (ap->a_waitfor == MNT_WAIT && !RB_EMPTY(&vp->v_rbdirty_tree)) {
116 vprint("hpfs_fsync: dirty", vp);
122 * Write out the on-disc version of the vnode.
124 return hpfs_update(VTOHP(vp));
130 * hpfs_ioctl(struct vnode *a_vp, u_long a_command, caddr_t a_data,
131 * int a_fflag, struct ucred *a_cred)
134 hpfs_ioctl(struct vop_ioctl_args *ap)
136 struct vnode *vp = ap->a_vp;
137 struct hpfsnode *hp = VTOHP(vp);
140 kprintf("hpfs_ioctl(0x%x, 0x%lx, 0x%p, 0x%x): ",
141 hp->h_no, ap->a_command, ap->a_data, ap->a_fflag);
143 switch (ap->a_command) {
144 case HPFSIOCGEANUM: {
151 if (hp->h_fn.fn_ealen > 0) {
152 eap = (struct ea *)&(hp->h_fn.fn_int);
155 while (passed < hp->h_fn.fn_ealen) {
157 kprintf("EAname: %s\n", EA_NAME(eap));
160 passed += sizeof(struct ea) +
161 eap->ea_namelen + 1 + eap->ea_vallen;
162 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
170 kprintf("%lu eas\n", eanum);
172 *(u_long *)ap->a_data = eanum;
181 kprintf("EA%ld\n", *(u_long *)ap->a_data);
184 if (hp->h_fn.fn_ealen > 0) {
185 eap = (struct ea *)&(hp->h_fn.fn_int);
189 while (passed < hp->h_fn.fn_ealen) {
190 kprintf("EAname: %s\n", EA_NAME(eap));
192 if (eanum == *(u_long *)ap->a_data) {
193 *(u_long *)ap->a_data =
194 eap->ea_namelen + 1 +
202 passed += sizeof(struct ea) +
203 eap->ea_namelen + 1 + eap->ea_vallen;
204 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
216 struct hpfs_rdea *rdeap;
219 rdeap = (struct hpfs_rdea *)ap->a_data;
220 kprintf("EA%ld\n", rdeap->ea_no);
223 if (hp->h_fn.fn_ealen > 0) {
224 eap = (struct ea *)&(hp->h_fn.fn_int);
228 while (passed < hp->h_fn.fn_ealen) {
229 kprintf("EAname: %s\n", EA_NAME(eap));
231 if (eanum == rdeap->ea_no) {
232 rdeap->ea_sz = eap->ea_namelen + 1 +
234 copyout(EA_NAME(eap),rdeap->ea_data,
241 passed += sizeof(struct ea) +
242 eap->ea_namelen + 1 + eap->ea_vallen;
243 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
260 * Map file offset to disk offset.
262 * hpfs_bmap(struct vnode *a_vp, off_t a_loffset,
263 * off_t *a_doffsetp, int *a_runp, int *a_runb)
266 hpfs_bmap(struct vop_bmap_args *ap)
268 struct hpfsnode *hp = VTOHP(ap->a_vp);
273 if (ap->a_runb != NULL)
275 if (ap->a_doffsetp == NULL)
278 dprintf(("hpfs_bmap(0x%x): ", hp->h_no));
280 lbn = ap->a_loffset >> DEV_BSHIFT;
281 KKASSERT(((int)ap->a_loffset & DEV_BMASK) == 0);
283 error = hpfs_hpbmap (hp, lbn, &dbn, ap->a_runp);
284 if (error || dbn == (daddr_t)-1) {
285 *ap->a_doffsetp = NOOFFSET;
287 *ap->a_doffsetp = (off_t)dbn << DEV_BSHIFT;
293 * hpfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
294 * struct ucred *a_cred)
297 hpfs_read(struct vop_read_args *ap)
299 struct vnode *vp = ap->a_vp;
300 struct hpfsnode *hp = VTOHP(vp);
301 struct uio *uio = ap->a_uio;
303 u_int xfersz, toread;
310 resid = (int)szmin(uio->uio_resid, hp->h_fn.fn_size - uio->uio_offset);
312 dprintf(("hpfs_read(0x%x, off: %d resid: %zx, segflg: %d): "
314 hp->h_no, (u_int32_t)uio->uio_offset,
315 uio->uio_resid, uio->uio_segflg, resid));
318 lbn = uio->uio_offset >> DEV_BSHIFT;
319 off = uio->uio_offset & (DEV_BSIZE - 1);
320 dprintf(("hpfs_read: resid: 0x%zx lbn: 0x%x off: 0x%x\n",
321 uio->uio_resid, lbn, off));
322 error = hpfs_hpbmap(hp, lbn, &bn, &runl);
326 toread = min(off + resid, min(64*1024, (runl+1)*DEV_BSIZE));
327 xfersz = roundup2(toread, DEV_BSIZE);
328 dprintf(("hpfs_read: bn: 0x%x (0x%x) toread: 0x%x (0x%x)\n",
329 bn, runl, toread, xfersz));
334 error = bread(hp->h_devvp, dbtodoff(bn), xfersz, &bp);
340 error = uiomove(bp->b_data + off, (size_t)(toread - off), uio);
348 dprintf(("hpfs_read: successful\n"));
353 * hpfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
354 * struct ucred *a_cred)
357 hpfs_write(struct vop_write_args *ap)
359 struct vnode *vp = ap->a_vp;
360 struct hpfsnode *hp = VTOHP(vp);
361 struct uio *uio = ap->a_uio;
363 u_int xfersz, towrite;
369 dprintf(("hpfs_write(0x%x, off: %d resid: %zd, segflg: %d):\n",
370 hp->h_no, (u_int32_t)uio->uio_offset,
371 uio->uio_resid, uio->uio_segflg));
373 if (ap->a_ioflag & IO_APPEND) {
374 dprintf(("hpfs_write: APPEND mode\n"));
375 uio->uio_offset = hp->h_fn.fn_size;
377 if (uio->uio_offset + uio->uio_resid > hp->h_fn.fn_size) {
378 error = hpfs_extend (hp, uio->uio_offset + uio->uio_resid);
380 kprintf("hpfs_write: hpfs_extend FAILED %d\n", error);
385 while (uio->uio_resid) {
386 lbn = uio->uio_offset >> DEV_BSHIFT;
387 off = uio->uio_offset & (DEV_BSIZE - 1);
388 dprintf(("hpfs_write: resid: 0x%zx lbn: 0x%x off: 0x%x\n",
389 uio->uio_resid, lbn, off));
390 error = hpfs_hpbmap(hp, lbn, &bn, &runl);
394 towrite = szmin(off + uio->uio_resid,
395 min(64*1024, (runl+1)*DEV_BSIZE));
396 xfersz = roundup2(towrite, DEV_BSIZE);
397 dprintf(("hpfs_write: bn: 0x%x (0x%x) towrite: 0x%x (0x%x)\n",
398 bn, runl, towrite, xfersz));
401 * We do not have to issue a read-before-write if the xfer
402 * size does not cover the whole block.
404 * In the UIO_NOCOPY case, however, we are not overwriting
405 * anything and must do a read-before-write to fill in
406 * any missing pieces.
408 if (off == 0 && towrite == xfersz &&
409 uio->uio_segflg != UIO_NOCOPY) {
410 bp = getblk(hp->h_devvp, dbtodoff(bn), xfersz, 0, 0);
413 error = bread(hp->h_devvp, dbtodoff(bn), xfersz, &bp);
420 error = uiomove(bp->b_data + off, (size_t)(towrite - off), uio);
426 if (ap->a_ioflag & IO_SYNC)
432 dprintf(("hpfs_write: successful\n"));
437 * XXXXX do we need hpfsnode locking inside?
439 * hpfs_getattr(struct vnode *a_vp, struct vattr *a_vap)
442 hpfs_getattr(struct vop_getattr_args *ap)
444 struct vnode *vp = ap->a_vp;
445 struct hpfsnode *hp = VTOHP(vp);
446 struct vattr *vap = ap->a_vap;
449 dprintf(("hpfs_getattr(0x%x):\n", hp->h_no));
451 #if defined(__DragonFly__)
452 vap->va_fsid = devid_from_dev(hp->h_dev);
453 #else /* defined(__NetBSD__) */
454 vap->va_fsid = ip->i_dev;
456 vap->va_fileid = hp->h_no;
457 vap->va_mode = hp->h_mode;
459 vap->va_uid = hp->h_uid;
460 vap->va_gid = hp->h_gid;
461 vap->va_rmajor = VNOVAL;
462 vap->va_rminor = VNOVAL;
463 vap->va_size = hp->h_fn.fn_size;
464 vap->va_bytes = roundup2(hp->h_fn.fn_size, DEV_BSIZE) + DEV_BSIZE;
466 if (!(hp->h_flag & H_PARVALID)) {
467 error = hpfs_validateparent(hp);
471 vap->va_atime = hpfstimetounix(hp->h_atime);
472 vap->va_mtime = hpfstimetounix(hp->h_mtime);
473 vap->va_ctime = hpfstimetounix(hp->h_ctime);
477 vap->va_blocksize = DEV_BSIZE;
478 vap->va_type = vp->v_type;
485 * XXXXX do we need hpfsnode locking inside?
487 * hpfs_setattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred)
490 hpfs_setattr(struct vop_setattr_args *ap)
492 struct vnode *vp = ap->a_vp;
493 struct hpfsnode *hp = VTOHP(vp);
494 struct vattr *vap = ap->a_vap;
495 struct ucred *cred = ap->a_cred;
498 dprintf(("hpfs_setattr(0x%x):\n", hp->h_no));
501 * Check for unsettable attributes.
503 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
504 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
505 (vap->va_blocksize != VNOVAL) || (vap->va_rmajor != VNOVAL) ||
506 (vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
507 dprintf(("hpfs_setattr: changing nonsettable attr\n"));
511 /* Can't change flags XXX Could be implemented */
512 if (vap->va_flags != VNOVAL) {
513 kprintf("hpfs_setattr: FLAGS CANNOT BE SET\n");
517 /* Can't change uid/gid XXX Could be implemented */
518 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
519 kprintf("hpfs_setattr: UID/GID CANNOT BE SET\n");
523 /* Can't change mode XXX Could be implemented */
524 if (vap->va_mode != (mode_t)VNOVAL) {
525 kprintf("hpfs_setattr: MODE CANNOT BE SET\n");
530 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
531 if (vp->v_mount->mnt_flag & MNT_RDONLY)
533 if (cred->cr_uid != hp->h_uid &&
534 (error = priv_check_cred(cred, PRIV_VFS_SETATTR, 0)) &&
535 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
536 (error = VOP_EACCESS(vp, VWRITE, cred))))
538 if (vap->va_atime.tv_sec != VNOVAL)
539 hp->h_atime = vap->va_atime.tv_sec;
540 if (vap->va_mtime.tv_sec != VNOVAL)
541 hp->h_mtime = vap->va_mtime.tv_sec;
543 hp->h_flag |= H_PARCHANGE;
546 if (vap->va_size != VNOVAL) {
547 switch (vp->v_type) {
551 if (vp->v_mount->mnt_flag & MNT_RDONLY)
555 kprintf("hpfs_setattr: WRONG v_type\n");
559 if (vap->va_size < hp->h_fn.fn_size) {
560 #if defined(__DragonFly__)
561 error = vtruncbuf(vp, vap->va_size, DEV_BSIZE);
564 #else /* defined(__NetBSD__) */
565 #error Need alternation for vtruncbuf()
567 error = hpfs_truncate(hp, vap->va_size);
571 } else if (vap->va_size > hp->h_fn.fn_size) {
572 #if defined(__DragonFly__)
573 vnode_pager_setsize(vp, vap->va_size);
575 error = hpfs_extend(hp, vap->va_size);
585 * Last reference to an node. If necessary, write or delete it.
587 * hpfs_inactive(struct vnode *a_vp)
590 hpfs_inactive(struct vop_inactive_args *ap)
592 struct vnode *vp = ap->a_vp;
593 struct hpfsnode *hp = VTOHP(vp);
596 dprintf(("hpfs_inactive(0x%x): \n", hp->h_no));
598 if (hp->h_flag & H_CHANGE) {
599 dprintf(("hpfs_inactive: node changed, update\n"));
600 error = hpfs_update (hp);
605 if (hp->h_flag & H_PARCHANGE) {
606 dprintf(("hpfs_inactive: parent node changed, update\n"));
607 error = hpfs_updateparent (hp);
612 if (prtactive && VREFCNT(vp) > 1)
613 vprint("hpfs_inactive: pushing active", vp);
615 if (hp->h_flag & H_INVAL) {
616 #if defined(__DragonFly__)
618 #else /* defined(__NetBSD__) */
627 * Reclaim an inode so that it can be used for other purposes.
629 * hpfs_reclaim(struct vnode *a_vp)
632 hpfs_reclaim(struct vop_reclaim_args *ap)
634 struct vnode *vp = ap->a_vp;
635 struct hpfsnode *hp = VTOHP(vp);
637 dprintf(("hpfs_reclaim(0x%x0): \n", hp->h_no));
641 /* Purge old data structures associated with the inode. */
655 * hpfs_print(struct vnode *a_vp)
658 hpfs_print(struct vop_print_args *ap)
660 struct vnode *vp = ap->a_vp;
661 struct hpfsnode *hp = VTOHP(vp);
663 kprintf("tag VT_HPFS, ino 0x%x",hp->h_no);
664 lockmgr_printinfo(&vp->v_lock);
670 * Calculate the logical to physical mapping if not done already,
671 * then call the device strategy routine.
673 * In order to be able to swap to a file, the VOP_BMAP operation may not
674 * deadlock on memory. See hpfs_bmap() for details. XXXXXXX (not impl)
676 * hpfs_strategy(struct vnode *a_vp, struct bio *a_bio)
679 hpfs_strategy(struct vop_strategy_args *ap)
681 struct bio *bio = ap->a_bio;
683 struct buf *bp = bio->bio_buf;
684 struct vnode *vp = ap->a_vp;
688 dprintf(("hpfs_strategy(): \n"));
690 if (vp->v_type == VBLK || vp->v_type == VCHR)
691 panic("hpfs_strategy: spec");
693 nbio = push_bio(bio);
694 if (nbio->bio_offset == NOOFFSET) {
695 error = VOP_BMAP(vp, bio->bio_offset, &nbio->bio_offset,
696 NULL, NULL, bp->b_cmd);
698 kprintf("hpfs_strategy: VOP_BMAP FAILED %d\n", error);
700 bp->b_flags |= B_ERROR;
701 /* I/O was never started on nbio, must biodone(bio) */
705 if (nbio->bio_offset == NOOFFSET)
708 if (nbio->bio_offset == NOOFFSET) {
709 /* I/O was never started on nbio, must biodone(bio) */
713 hp = VTOHP(ap->a_vp);
714 vn_strategy(hp->h_devvp, nbio);
719 * XXXXX do we need hpfsnode locking inside?
721 * hpfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred)
724 hpfs_access(struct vop_access_args *ap)
726 struct vnode *vp = ap->a_vp;
727 struct hpfsnode *hp = VTOHP(vp);
729 dprintf(("hpfs_access(0x%x):\n", hp->h_no));
730 return (vop_helper_access(ap, hp->h_uid, hp->h_gid, hp->h_mode, 0));
734 hpfs_de_uiomove(int *error, struct hpfsmount *hpmp, struct hpfsdirent *dep,
737 char convname[HPFS_MAXFILENAME + 1];
740 dprintf(("[no: 0x%x, size: %d, name: %2d:%.*s, flag: 0x%x] ",
741 dep->de_fnode, dep->de_size, dep->de_namelen,
742 dep->de_namelen, dep->de_name, dep->de_flag));
744 /*strncpy(cde.d_name, dep->de_name, dep->de_namelen);*/
745 for (i=0; i<dep->de_namelen; i++)
746 convname[i] = hpfs_d2u(hpmp, dep->de_name[i]);
747 convname[dep->de_namelen] = '\0';
749 success = vop_write_dirent(error, uio, dep->de_fnode,
750 (dep->de_flag & DE_DIR) ? DT_DIR : DT_REG,
751 dep->de_namelen, convname);
753 dprintf(("[0x%zx] ", uio->uio_resid));
759 * hpfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
760 * int *a_ncookies, off_t **cookies)
763 hpfs_readdir(struct vop_readdir_args *ap)
765 struct vnode *vp = ap->a_vp;
766 struct hpfsnode *hp = VTOHP(vp);
767 struct hpfsmount *hpmp = hp->h_hpmp;
768 struct uio *uio = ap->a_uio;
769 int ncookies = 0, i, num, cnum;
773 struct hpfsdirent *dep;
778 dprintf(("hpfs_readdir(0x%x, 0x%x, 0x%zx): ",
779 hp->h_no, (u_int32_t)uio->uio_offset, uio->uio_resid));
782 * As we need to fake up . and .., and the remaining directory structure
783 * can't be expressed in one off_t as well, we just increment uio_offset
784 * by 1 for each entry.
786 * num is the entry we need to start reporting
787 * cnum is the current entry
789 if (uio->uio_offset < 0 || uio->uio_offset > INT_MAX)
791 error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY | LK_FAILRECLAIM);
795 num = uio->uio_offset;
799 dprintf((". faked, "));
800 if (vop_write_dirent(&error, uio, hp->h_no, DT_DIR, 1, "."))
809 dprintf((".. faked, "));
810 if (vop_write_dirent(&error, uio, hp->h_fn.fn_parent, DT_DIR, 2, ".."))
818 lsn = ((alleaf_t *)hp->h_fn.fn_abd)->al_lsn;
824 dprintf(("[dive 0x%x] ", lsn));
825 error = bread(hp->h_devvp, dbtodoff(lsn), D_BSIZE, &bp);
831 dp = (struct dirblk *) bp->b_data;
832 if (dp->d_magic != D_MAGIC) {
833 kprintf("hpfs_readdir: MAGIC DOESN'T MATCH\n");
842 dprintf(("[restore 0x%x] ", olsn));
844 while(!(dep->de_flag & DE_END) ) {
845 if((dep->de_flag & DE_DOWN) &&
846 (olsn == DE_DOWNLSN(dep)))
848 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
851 if((dep->de_flag & DE_DOWN) && (olsn == DE_DOWNLSN(dep))) {
852 if (dep->de_flag & DE_END)
855 if (!(dep->de_flag & DE_SPECIAL)) {
857 if (hpfs_de_uiomove(&error, hpmp, dep, uio)) {
859 dprintf(("[resid] "));
871 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
873 kprintf("hpfs_readdir: ERROR! oLSN not found\n");
882 while(!(dep->de_flag & DE_END)) {
883 if(dep->de_flag & DE_DOWN) {
884 lsn = DE_DOWNLSN(dep);
890 if (!(dep->de_flag & DE_SPECIAL)) {
892 if (hpfs_de_uiomove(&error, hpmp, dep, uio)) {
894 dprintf(("[resid] "));
906 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
909 if(dep->de_flag & DE_DOWN) {
910 dprintf(("[enddive] "));
911 lsn = DE_DOWNLSN(dep);
924 dprintf(("[level %d] ", level));
927 goto dive; /* undive really */
935 uio->uio_offset = cnum;
936 dprintf(("[readdone]\n"));
937 if (!error && ap->a_ncookies != NULL) {
941 dprintf(("%d cookies, ",ncookies));
942 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
943 panic("hpfs_readdir: unexpected uio from NFS server");
944 cookies = kmalloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
945 for (cookiep = cookies, i=0; i < ncookies; i++)
948 *ap->a_ncookies = ncookies;
949 *ap->a_cookies = cookies;
958 * hpfs_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
959 * struct componentname *a_cnp)
962 hpfs_lookup(struct vop_old_lookup_args *ap)
964 struct vnode *dvp = ap->a_dvp;
965 struct hpfsnode *dhp = VTOHP(dvp);
966 struct hpfsmount *hpmp = dhp->h_hpmp;
967 struct componentname *cnp = ap->a_cnp;
968 struct ucred *cred = cnp->cn_cred;
969 struct vnode **vpp = ap->a_vpp;
971 int nameiop = cnp->cn_nameiop;
972 int flags = cnp->cn_flags;
973 int lockparent = flags & CNP_LOCKPARENT;
975 int wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
978 dprintf(("hpfs_lookup(0x%x, %s, %ld, %d, %d): \n",
979 dhp->h_no, cnp->cn_nameptr, cnp->cn_namelen,
980 lockparent, wantparent));
982 if (nameiop != NAMEI_CREATE && nameiop != NAMEI_DELETE && nameiop != NAMEI_LOOKUP) {
983 kprintf("hpfs_lookup: LOOKUP, DELETE and CREATE are only supported\n");
987 error = VOP_EACCESS(dvp, VEXEC, cred);
991 if( (cnp->cn_namelen == 1) &&
992 !strncmp(cnp->cn_nameptr,".",1) ) {
993 dprintf(("hpfs_lookup(0x%x,...): . faked\n",dhp->h_no));
999 } else if( (cnp->cn_namelen == 2) &&
1000 !strncmp(cnp->cn_nameptr,"..",2) && (flags & CNP_ISDOTDOT) ) {
1001 dprintf(("hpfs_lookup(0x%x,...): .. faked (0x%x)\n",
1002 dhp->h_no, dhp->h_fn.fn_parent));
1004 VOP__UNLOCK(dvp, 0);
1006 error = VFS_VGET(hpmp->hpm_mp, NULL,
1007 dhp->h_fn.fn_parent, vpp);
1013 if (lockparent && (error = VOP__LOCK(dvp, 0))) {
1020 struct hpfsdirent *dep;
1021 struct hpfsnode *hp;
1023 error = hpfs_genlookupbyname(dhp,
1024 cnp->cn_nameptr, cnp->cn_namelen, &bp, &dep);
1026 if (error == ENOENT &&
1027 (nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME)) {
1029 cnp->cn_flags |= CNP_PDIRUNLOCK;
1030 VOP__UNLOCK(dvp, 0);
1032 return (EJUSTRETURN);
1038 dprintf(("hpfs_lookup: fnode: 0x%x, CPID: 0x%x\n",
1039 dep->de_fnode, dep->de_cpid));
1041 if (nameiop == NAMEI_DELETE) {
1042 error = VOP_EACCESS(dvp, VWRITE, cred);
1049 if (dhp->h_no == dep->de_fnode) {
1056 error = VFS_VGET(hpmp->hpm_mp, NULL, dep->de_fnode, vpp);
1058 kprintf("hpfs_lookup: VFS_VGET FAILED %d\n", error);
1065 hp->h_mtime = dep->de_mtime;
1066 hp->h_ctime = dep->de_ctime;
1067 hp->h_atime = dep->de_atime;
1068 bcopy(dep->de_name, hp->h_name, dep->de_namelen);
1069 hp->h_name[dep->de_namelen] = '\0';
1070 hp->h_namelen = dep->de_namelen;
1071 hp->h_flag |= H_PARVALID;
1076 cnp->cn_flags |= CNP_PDIRUNLOCK;
1077 VOP__UNLOCK(dvp, 0);
1084 * hpfs_remove(struct vnode *a_dvp, struct vnode *a_vp,
1085 * struct componentname *a_cnp)
1088 hpfs_remove(struct vop_old_remove_args *ap)
1092 dprintf(("hpfs_remove(0x%x, %s, %ld): \n", VTOHP(ap->a_vp)->h_no,
1093 ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen));
1095 if (ap->a_vp->v_type == VDIR)
1098 error = hpfs_removefnode (ap->a_dvp, ap->a_vp, ap->a_cnp);
1103 * hpfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
1104 * struct componentname *a_cnp, struct vattr *a_vap)
1107 hpfs_create(struct vop_old_create_args *ap)
1111 dprintf(("hpfs_create(0x%x, %s, %ld): \n", VTOHP(ap->a_dvp)->h_no,
1112 ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen));
1114 error = hpfs_makefnode (ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap);
1120 * Return POSIX pathconf information applicable to NTFS filesystem
1122 * hpfs_pathconf(struct vnode *a_vp, int a_name, t *a_retval)
1125 hpfs_pathconf(struct vop_pathconf_args *ap)
1127 switch (ap->a_name) {
1132 *ap->a_retval = HPFS_MAXFILENAME;
1135 *ap->a_retval = PATH_MAX;
1137 case _PC_CHOWN_RESTRICTED:
1143 #if defined(__NetBSD__)
1147 case _PC_FILESIZEBITS:
1159 * Global vfs data structures
1162 struct vop_ops hpfs_vnode_vops = {
1163 .vop_default = vop_defaultop,
1164 .vop_getattr = hpfs_getattr,
1165 .vop_setattr = hpfs_setattr,
1166 .vop_inactive = hpfs_inactive,
1167 .vop_reclaim = hpfs_reclaim,
1168 .vop_print = hpfs_print,
1169 .vop_old_create = hpfs_create,
1170 .vop_old_remove = hpfs_remove,
1171 .vop_old_lookup = hpfs_lookup,
1172 .vop_access = hpfs_access,
1173 .vop_readdir = hpfs_readdir,
1174 .vop_fsync = hpfs_fsync,
1175 .vop_bmap = hpfs_bmap,
1176 .vop_getpages = vop_stdgetpages,
1177 .vop_putpages = vop_stdputpages,
1178 .vop_strategy = hpfs_strategy,
1179 .vop_read = hpfs_read,
1180 .vop_write = hpfs_write,
1181 .vop_ioctl = hpfs_ioctl,
1182 .vop_pathconf = hpfs_pathconf