Major BUF/BIO work commit. Make I/O BIO-centric and specify the disk or
[dragonfly.git] / sys / vfs / hpfs / hpfs_vnops.c
1 /*-
2  * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  *
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.30 2006/03/24 18:35:33 dillon Exp $
28  */
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/proc.h>
34 #include <sys/time.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <sys/vnode.h>
38 #include <sys/mount.h>
39 #include <sys/namei.h>
40 #include <sys/malloc.h>
41 #include <sys/buf.h>
42 #include <sys/dirent.h>
43
44 #include <machine/limits.h>
45
46 #include <vm/vm.h>
47 #include <vm/vm_param.h>
48 #if !defined(__DragonFly__)
49 #include <vm/vm_prot.h>
50 #endif
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>
57 #endif
58 #include <vm/vm_extern.h>
59 #include <sys/buf2.h>
60
61 #if !defined(__DragonFly__)
62 #include <miscfs/specfs/specdev.h>
63 #include <miscfs/genfs/genfs.h>
64 #endif
65
66 #include <sys/unistd.h> /* for pathconf(2) constants */
67
68 #include "hpfs.h"
69 #include "hpfsmount.h"
70 #include "hpfs_subr.h"
71 #include "hpfs_ioctl.h"
72
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_open (struct vop_open_args *ap);
86 static int      hpfs_close (struct vop_close_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_getpages (struct vop_getpages_args *ap);
94 static int      hpfs_putpages (struct vop_putpages_args *);
95 static int      hpfs_fsync (struct vop_fsync_args *ap);
96 #endif
97 static int      hpfs_pathconf (struct vop_pathconf_args *ap);
98
99 #if defined(__DragonFly__)
100 int
101 hpfs_getpages(struct vop_getpages_args *ap)
102 {
103         return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
104                 ap->a_reqpage);
105 }
106
107 int
108 hpfs_putpages(struct vop_putpages_args *ap)
109 {
110         return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
111                 ap->a_sync, ap->a_rtvals);
112 }
113
114 /*
115  * hpfs_fsync(struct vnode *a_vp, struct ucred *a_cred, int a_waitfor,
116  *            struct proc *a_td)
117  */
118 static int
119 hpfs_fsync(struct vop_fsync_args *ap)
120 {
121         struct vnode *vp = ap->a_vp;
122
123         /*
124          * Flush all dirty buffers associated with a vnode.
125          */
126 #ifdef DIAGNOSTIC
127 loop:
128 #endif
129         vfsync(vp, ap->a_waitfor, 0, NOOFFSET, NULL, NULL);
130 #ifdef DIAGNOSTIC
131         if (ap->a_waitfor == MNT_WAIT && !RB_EMPTY(&vp->v_rbdirty_tree)) {
132                 vprint("hpfs_fsync: dirty", vp);
133                 goto loop;
134         }
135 #endif
136
137         /*
138          * Write out the on-disc version of the vnode.
139          */
140         return hpfs_update(VTOHP(vp));
141 }
142
143 #endif
144
145 /*
146  * hpfs_ioctl(struct vnode *a_vp, u_long a_command, caddr_t a_data,
147  *            int a_fflag, struct ucred *a_cred, struct proc *a_td)
148  */
149 static int
150 hpfs_ioctl(struct vop_ioctl_args *ap)
151 {
152         struct vnode *vp = ap->a_vp;
153         struct hpfsnode *hp = VTOHP(vp);
154         int error;
155
156         printf("hpfs_ioctl(0x%x, 0x%lx, 0x%p, 0x%x): ",
157                 hp->h_no, ap->a_command, ap->a_data, ap->a_fflag);
158
159         switch (ap->a_command) {
160         case HPFSIOCGEANUM: {
161                 u_long eanum;
162                 u_long passed;
163                 struct ea *eap;
164
165                 eanum = 0;
166
167                 if (hp->h_fn.fn_ealen > 0) {
168                         eap = (struct ea *)&(hp->h_fn.fn_int);
169                         passed = 0;
170
171                         while (passed < hp->h_fn.fn_ealen) {
172
173                                 printf("EAname: %s\n", EA_NAME(eap));
174
175                                 eanum++;
176                                 passed += sizeof(struct ea) +
177                                           eap->ea_namelen + 1 + eap->ea_vallen;
178                                 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
179                                                 passed);
180                         }
181                         error = 0;
182                 } else {
183                         error = ENOENT;
184                 }
185
186                 printf("%lu eas\n", eanum);
187
188                 *(u_long *)ap->a_data = eanum;
189
190                 break;
191         }
192         case HPFSIOCGEASZ: {
193                 u_long eanum;
194                 u_long passed;
195                 struct ea *eap;
196
197                 printf("EA%ld\n", *(u_long *)ap->a_data);
198
199                 eanum = 0;
200                 if (hp->h_fn.fn_ealen > 0) {
201                         eap = (struct ea *)&(hp->h_fn.fn_int);
202                         passed = 0;
203
204                         error = ENOENT;
205                         while (passed < hp->h_fn.fn_ealen) {
206                                 printf("EAname: %s\n", EA_NAME(eap));
207
208                                 if (eanum == *(u_long *)ap->a_data) {
209                                         *(u_long *)ap->a_data =
210                                                 eap->ea_namelen + 1 +
211                                                 eap->ea_vallen;
212
213                                         error = 0;
214                                         break;
215                                 }
216
217                                 eanum++;
218                                 passed += sizeof(struct ea) +
219                                           eap->ea_namelen + 1 + eap->ea_vallen;
220                                 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
221                                                 passed);
222                         }
223                 } else {
224                         error = ENOENT;
225                 }
226
227                 break;
228         }
229         case HPFSIOCRDEA: {
230                 u_long eanum;
231                 u_long passed;
232                 struct hpfs_rdea *rdeap;
233                 struct ea *eap;
234
235                 rdeap = (struct hpfs_rdea *)ap->a_data;
236                 printf("EA%ld\n", rdeap->ea_no);
237
238                 eanum = 0;
239                 if (hp->h_fn.fn_ealen > 0) {
240                         eap = (struct ea *)&(hp->h_fn.fn_int);
241                         passed = 0;
242
243                         error = ENOENT;
244                         while (passed < hp->h_fn.fn_ealen) {
245                                 printf("EAname: %s\n", EA_NAME(eap));
246
247                                 if (eanum == rdeap->ea_no) {
248                                         rdeap->ea_sz = eap->ea_namelen + 1 +
249                                                         eap->ea_vallen;
250                                         copyout(EA_NAME(eap),rdeap->ea_data,
251                                                 rdeap->ea_sz);
252                                         error = 0;
253                                         break;
254                                 }
255
256                                 eanum++;
257                                 passed += sizeof(struct ea) +
258                                           eap->ea_namelen + 1 + eap->ea_vallen;
259                                 eap = (struct ea *)((caddr_t)hp->h_fn.fn_int +
260                                                 passed);
261                         }
262                 } else {
263                         error = ENOENT;
264                 }
265
266                 break;
267         }
268         default:
269                 error = EOPNOTSUPP;
270                 break;
271         }
272         return (error);
273 }
274
275 /*
276  * Map file offset to disk offset.
277  *
278  * hpfs_bmap(struct vnode *a_vp, off_t a_loffset, struct vnode **a_vpp,
279  *           off_t *a_doffsetp, int *a_runp, int *a_runb)
280  */
281 int
282 hpfs_bmap(struct vop_bmap_args *ap)
283 {
284         struct hpfsnode *hp = VTOHP(ap->a_vp);
285         int error;
286         daddr_t lbn;
287         daddr_t dbn;
288
289         if (ap->a_vpp != NULL) 
290                 *ap->a_vpp = hp->h_devvp;
291         if (ap->a_runb != NULL)
292                 *ap->a_runb = 0;
293         if (ap->a_doffsetp == NULL)
294                 return (0);
295
296         dprintf(("hpfs_bmap(0x%x, 0x%x): ",hp->h_no, ap->a_bn));
297
298         lbn = ap->a_loffset >> DEV_BSHIFT;
299         KKASSERT(((int)ap->a_loffset & DEV_BMASK) == 0);
300
301         error = hpfs_hpbmap (hp, lbn, &dbn, ap->a_runp);
302         if (error || dbn == (daddr_t)-1) {
303                 *ap->a_doffsetp = NOOFFSET;
304         } else {
305                 *ap->a_doffsetp = (off_t)dbn << DEV_BSHIFT;
306         }
307         return (error);
308 }
309
310 /*
311  * hpfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
312  *           struct ucred *a_cred)
313  */
314 static int
315 hpfs_read(struct vop_read_args *ap)
316 {
317         struct vnode *vp = ap->a_vp;
318         struct hpfsnode *hp = VTOHP(vp);
319         struct uio *uio = ap->a_uio;
320         struct buf *bp;
321         u_int xfersz, toread;
322         u_int off;
323         daddr_t lbn, bn;
324         int resid;
325         int runl;
326         int error = 0;
327
328         resid = min (uio->uio_resid, hp->h_fn.fn_size - uio->uio_offset);
329
330         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));
331
332         while (resid) {
333                 lbn = uio->uio_offset >> DEV_BSHIFT;
334                 off = uio->uio_offset & (DEV_BSIZE - 1);
335                 dprintf(("hpfs_read: resid: 0x%x lbn: 0x%x off: 0x%x\n",
336                         uio->uio_resid, lbn, off));
337                 error = hpfs_hpbmap(hp, lbn, &bn, &runl);
338                 if (error)
339                         return (error);
340
341                 toread = min(off + resid, min(DFLTPHYS, (runl+1)*DEV_BSIZE));
342                 xfersz = (toread + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1);
343                 dprintf(("hpfs_read: bn: 0x%x (0x%x) toread: 0x%x (0x%x)\n",
344                         bn, runl, toread, xfersz));
345
346                 if (toread == 0) 
347                         break;
348
349                 error = bread(hp->h_devvp, dbtodoff(bn), xfersz, &bp);
350                 if (error) {
351                         brelse(bp);
352                         break;
353                 }
354
355                 error = uiomove(bp->b_data + off, toread - off, uio);
356                 if(error) {
357                         brelse(bp);
358                         break;
359                 }
360                 brelse(bp);
361                 resid -= toread;
362         }
363         dprintf(("hpfs_read: successful\n"));
364         return (error);
365 }
366
367 /*
368  * hpfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
369  *            struct ucred *a_cred)
370  */
371 static int
372 hpfs_write(struct vop_write_args *ap)
373 {
374         struct vnode *vp = ap->a_vp;
375         struct hpfsnode *hp = VTOHP(vp);
376         struct uio *uio = ap->a_uio;
377         struct buf *bp;
378         u_int xfersz, towrite;
379         u_int off;
380         daddr_t lbn, bn;
381         int runl;
382         int error = 0;
383
384         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));
385
386         if (ap->a_ioflag & IO_APPEND) {
387                 dprintf(("hpfs_write: APPEND mode\n"));
388                 uio->uio_offset = hp->h_fn.fn_size;
389         }
390         if (uio->uio_offset + uio->uio_resid > hp->h_fn.fn_size) {
391                 error = hpfs_extend (hp, uio->uio_offset + uio->uio_resid);
392                 if (error) {
393                         printf("hpfs_write: hpfs_extend FAILED %d\n", error);
394                         return (error);
395                 }
396         }
397
398         while (uio->uio_resid) {
399                 lbn = uio->uio_offset >> DEV_BSHIFT;
400                 off = uio->uio_offset & (DEV_BSIZE - 1);
401                 dprintf(("hpfs_write: resid: 0x%x lbn: 0x%x off: 0x%x\n",
402                         uio->uio_resid, lbn, off));
403                 error = hpfs_hpbmap(hp, lbn, &bn, &runl);
404                 if (error)
405                         return (error);
406
407                 towrite = min(off + uio->uio_resid, min(DFLTPHYS, (runl+1)*DEV_BSIZE));
408                 xfersz = (towrite + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1);
409                 dprintf(("hpfs_write: bn: 0x%x (0x%x) towrite: 0x%x (0x%x)\n",
410                         bn, runl, towrite, xfersz));
411
412                 if ((off == 0) && (towrite == xfersz)) {
413                         bp = getblk(hp->h_devvp, dbtodoff(bn), xfersz, 0, 0);
414                         clrbuf(bp);
415                 } else {
416                         error = bread(hp->h_devvp, dbtodoff(bn), xfersz, &bp);
417                         if (error) {
418                                 brelse(bp);
419                                 return (error);
420                         }
421                 }
422
423                 error = uiomove(bp->b_data + off, towrite - off, uio);
424                 if(error) {
425                         brelse(bp);
426                         return (error);
427                 }
428
429                 if (ap->a_ioflag & IO_SYNC)
430                         bwrite(bp);
431                 else
432                         bawrite(bp);
433         }
434
435         dprintf(("hpfs_write: successful\n"));
436         return (0);
437 }
438
439 /*
440  * XXXXX do we need hpfsnode locking inside?
441  *
442  * hpfs_getattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred,
443  *              struct proc *a_td)
444  */
445 static int
446 hpfs_getattr(struct vop_getattr_args *ap)
447 {
448         struct vnode *vp = ap->a_vp;
449         struct hpfsnode *hp = VTOHP(vp);
450         struct vattr *vap = ap->a_vap;
451         int error;
452
453         dprintf(("hpfs_getattr(0x%x):\n", hp->h_no));
454
455 #if defined(__DragonFly__)
456         vap->va_fsid = dev2udev(hp->h_dev);
457 #else /* defined(__NetBSD__) */
458         vap->va_fsid = ip->i_dev;
459 #endif
460         vap->va_fileid = hp->h_no;
461         vap->va_mode = hp->h_mode;
462         vap->va_nlink = 1;
463         vap->va_uid = hp->h_uid;
464         vap->va_gid = hp->h_gid;
465         vap->va_rdev = 0;                               /* XXX UNODEV ? */
466         vap->va_size = hp->h_fn.fn_size;
467         vap->va_bytes = ((hp->h_fn.fn_size + DEV_BSIZE-1) & ~(DEV_BSIZE-1)) +
468                         DEV_BSIZE;
469
470         if (!(hp->h_flag & H_PARVALID)) {
471                 error = hpfs_validateparent(hp);
472                 if (error) 
473                         return (error);
474         }
475         vap->va_atime = hpfstimetounix(hp->h_atime);
476         vap->va_mtime = hpfstimetounix(hp->h_mtime);
477         vap->va_ctime = hpfstimetounix(hp->h_ctime);
478
479         vap->va_flags = 0;
480         vap->va_gen = 0;
481         vap->va_blocksize = DEV_BSIZE;
482         vap->va_type = vp->v_type;
483         vap->va_filerev = 0;
484
485         return (0);
486 }
487
488 /*
489  * XXXXX do we need hpfsnode locking inside?
490  *
491  * hpfs_setattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred,
492  *              struct thread *a_td)
493  */
494 static int
495 hpfs_setattr(struct vop_setattr_args *ap)
496 {
497         struct vnode *vp = ap->a_vp;
498         struct hpfsnode *hp = VTOHP(vp);
499         struct vattr *vap = ap->a_vap;
500         struct ucred *cred = ap->a_cred;
501         struct thread *td = ap->a_td;
502         int error;
503
504         dprintf(("hpfs_setattr(0x%x):\n", hp->h_no));
505
506         /*
507          * Check for unsettable attributes.
508          */
509         if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
510             (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
511             (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
512             (vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
513                 dprintf(("hpfs_setattr: changing nonsettable attr\n"));
514                 return (EINVAL);
515         }
516
517         /* Can't change flags XXX Could be implemented */
518         if (vap->va_flags != VNOVAL) {
519                 printf("hpfs_setattr: FLAGS CANNOT BE SET\n");
520                 return (EINVAL);
521         }
522
523         /* Can't change uid/gid XXX Could be implemented */
524         if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
525                 printf("hpfs_setattr: UID/GID CANNOT BE SET\n");
526                 return (EINVAL);
527         }
528
529         /* Can't change mode XXX Could be implemented */
530         if (vap->va_mode != (mode_t)VNOVAL) {
531                 printf("hpfs_setattr: MODE CANNOT BE SET\n");
532                 return (EINVAL);
533         }
534
535         /* Update times */
536         if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
537                 if (vp->v_mount->mnt_flag & MNT_RDONLY)
538                         return (EROFS);
539                 if (cred->cr_uid != hp->h_uid &&
540                     (error = suser_cred(cred, PRISON_ROOT)) &&
541                     ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
542                     (error = VOP_ACCESS(vp, VWRITE, cred, td))))
543                         return (error);
544                 if (vap->va_atime.tv_sec != VNOVAL)
545                         hp->h_atime = vap->va_atime.tv_sec;
546                 if (vap->va_mtime.tv_sec != VNOVAL)
547                         hp->h_mtime = vap->va_mtime.tv_sec;
548
549                 hp->h_flag |= H_PARCHANGE;
550         }
551
552         if (vap->va_size != VNOVAL) {
553                 switch (vp->v_type) {
554                 case VDIR:
555                         return (EISDIR);
556                 case VREG:
557                         if (vp->v_mount->mnt_flag & MNT_RDONLY)
558                                 return (EROFS);
559                         break;
560                 default:
561                         printf("hpfs_setattr: WRONG v_type\n");
562                         return (EINVAL);
563                 }
564
565                 if (vap->va_size < hp->h_fn.fn_size) {
566 #if defined(__DragonFly__)
567                         error = vtruncbuf(vp, td, vap->va_size, DEV_BSIZE);
568                         if (error)
569                                 return (error);
570 #else /* defined(__NetBSD__) */
571 #error Need alternation for vtruncbuf()
572 #endif
573                         error = hpfs_truncate(hp, vap->va_size);
574                         if (error)
575                                 return (error);
576
577                 } else if (vap->va_size > hp->h_fn.fn_size) {
578 #if defined(__DragonFly__)
579                         vnode_pager_setsize(vp, vap->va_size);
580 #endif
581                         error = hpfs_extend(hp, vap->va_size);
582                         if (error)
583                                 return (error);
584                 }
585         }
586
587         return (0);
588 }
589
590 /*
591  * Last reference to an node.  If necessary, write or delete it.
592  *
593  * hpfs_inactive(struct vnode *a_vp)
594  */
595 int
596 hpfs_inactive(struct vop_inactive_args *ap)
597 {
598         struct vnode *vp = ap->a_vp;
599         struct hpfsnode *hp = VTOHP(vp);
600         int error;
601
602         dprintf(("hpfs_inactive(0x%x): \n", hp->h_no));
603
604         if (hp->h_flag & H_CHANGE) {
605                 dprintf(("hpfs_inactive: node changed, update\n"));
606                 error = hpfs_update (hp);
607                 if (error)
608                         return (error);
609         }
610
611         if (hp->h_flag & H_PARCHANGE) {
612                 dprintf(("hpfs_inactive: parent node changed, update\n"));
613                 error = hpfs_updateparent (hp);
614                 if (error)
615                         return (error);
616         }
617
618         if (prtactive && vp->v_usecount != 0)
619                 vprint("hpfs_inactive: pushing active", vp);
620
621         if (hp->h_flag & H_INVAL) {
622 #if defined(__DragonFly__)
623                 vrecycle(vp, ap->a_td);
624 #else /* defined(__NetBSD__) */
625                 vgone(vp);
626 #endif
627                 return (0);
628         }
629         return (0);
630 }
631
632 /*
633  * Reclaim an inode so that it can be used for other purposes.
634  *
635  * hpfs_reclaim(struct vnode *a_vp)
636  */
637 int
638 hpfs_reclaim(struct vop_reclaim_args *ap)
639 {
640         struct vnode *vp = ap->a_vp;
641         struct hpfsnode *hp = VTOHP(vp);
642
643         dprintf(("hpfs_reclaim(0x%x0): \n", hp->h_no));
644
645         hpfs_hphashrem(hp);
646
647         /* Purge old data structures associated with the inode. */
648         if (hp->h_devvp) {
649                 vrele(hp->h_devvp);
650                 hp->h_devvp = NULL;
651         }
652
653         vp->v_data = NULL;
654
655         FREE(hp, M_HPFSNO);
656
657         return (0);
658 }
659
660 /*
661  * hpfs_print(struct vnode *a_vp)
662  */
663 static int
664 hpfs_print(struct vop_print_args *ap)
665 {
666         struct vnode *vp = ap->a_vp;
667         struct hpfsnode *hp = VTOHP(vp);
668
669         printf("tag VT_HPFS, ino 0x%x",hp->h_no);
670         lockmgr_printinfo(&vp->v_lock);
671         printf("\n");
672         return (0);
673 }
674
675 /*
676  * Calculate the logical to physical mapping if not done already,
677  * then call the device strategy routine.
678  *
679  * In order to be able to swap to a file, the VOP_BMAP operation may not
680  * deadlock on memory.  See hpfs_bmap() for details. XXXXXXX (not impl)
681  *
682  * hpfs_strategy(struct vnode *a_vp, struct bio *a_bio)
683  */
684 int
685 hpfs_strategy(struct vop_strategy_args *ap)
686 {
687         struct bio *bio = ap->a_bio;
688         struct bio *nbio;
689         struct buf *bp = bio->bio_buf;
690         struct vnode *vp = ap->a_vp;
691         struct hpfsnode *hp;
692         int error;
693
694         dprintf(("hpfs_strategy(): \n"));
695
696         if (vp->v_type == VBLK || vp->v_type == VCHR)
697                 panic("hpfs_strategy: spec");
698
699         nbio = push_bio(bio);
700         if (nbio->bio_offset == NOOFFSET) {
701                 error = VOP_BMAP(vp, bio->bio_offset, NULL, &nbio->bio_offset,
702                                  NULL, NULL);
703                 if (error) {
704                         printf("hpfs_strategy: VOP_BMAP FAILED %d\n", error);
705                         bp->b_error = error;
706                         bp->b_flags |= B_ERROR;
707                         /* I/O was never started on nbio, must biodone(bio) */
708                         biodone(bio);
709                         return (error);
710                 }
711                 if (nbio->bio_offset == NOOFFSET)
712                         vfs_bio_clrbuf(bp);
713         }
714         if (nbio->bio_offset == NOOFFSET) {
715                 /* I/O was never started on nbio, must biodone(bio) */
716                 biodone(bio);
717                 return (0);
718         }
719         hp = VTOHP(ap->a_vp);
720         vn_strategy(hp->h_devvp, nbio);
721         return (0);
722 }
723
724 /*
725  * XXXXX do we need hpfsnode locking inside?
726  *
727  * hpfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
728  *             struct proc *a_td)
729  */
730 int
731 hpfs_access(struct vop_access_args *ap)
732 {
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;
737         gid_t *gp;
738         int i;
739
740         dprintf(("hpfs_access(0x%x):\n", hp->h_no));
741
742         /*
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.
746          */
747         if (mode & VWRITE) {
748                 switch ((int)vp->v_type) {
749                 case VDIR:
750                 case VLNK:
751                 case VREG:
752                         if (vp->v_mount->mnt_flag & MNT_RDONLY)
753                                 return (EROFS);
754                         break;
755                 }
756         }
757
758         /* Otherwise, user id 0 always gets access. */
759         if (cred->cr_uid == 0)
760                 return (0);
761
762         mask = 0;
763
764         /* Otherwise, check the owner. */
765         if (cred->cr_uid == hp->h_uid) {
766                 if (mode & VEXEC)
767                         mask |= S_IXUSR;
768                 if (mode & VREAD)
769                         mask |= S_IRUSR;
770                 if (mode & VWRITE)
771                         mask |= S_IWUSR;
772                 return ((hp->h_mode & mask) == mask ? 0 : EACCES);
773         }
774
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) {
778                         if (mode & VEXEC)
779                                 mask |= S_IXGRP;
780                         if (mode & VREAD)
781                                 mask |= S_IRGRP;
782                         if (mode & VWRITE)
783                                 mask |= S_IWGRP;
784                         return ((hp->h_mode & mask) == mask ? 0 : EACCES);
785                 }
786
787         /* Otherwise, check everyone else. */
788         if (mode & VEXEC)
789                 mask |= S_IXOTH;
790         if (mode & VREAD)
791                 mask |= S_IROTH;
792         if (mode & VWRITE)
793                 mask |= S_IWOTH;
794         return ((hp->h_mode & mask) == mask ? 0 : EACCES);
795 }
796
797 /*
798  * Open called.
799  *
800  * Nothing to do.
801  *
802  * hpfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
803  *           struct proc *a_td)
804  */
805 /* ARGSUSED */
806 static int
807 hpfs_open(struct vop_open_args *ap)
808 {
809 #if HPFS_DEBUG
810         struct vnode *vp = ap->a_vp;
811         struct hpfsnode *hp = VTOHP(vp);
812
813         printf("hpfs_open(0x%x):\n",hp->h_no);
814 #endif
815
816         /*
817          * Files marked append-only must be opened for appending.
818          */
819
820         return (0);
821 }
822
823 /*
824  * Close called.
825  *
826  * Update the times on the inode.
827  *
828  * hpfs_close(struct vnode *a_vp, int a_fflag, struct ucred *a_cred,
829  *            struct proc *a_td)
830  */
831 /* ARGSUSED */
832 static int
833 hpfs_close(struct vop_close_args *ap)
834 {
835 #if HPFS_DEBUG
836         struct vnode *vp = ap->a_vp;
837         struct hpfsnode *hp = VTOHP(vp);
838
839         printf("hpfs_close: %d\n",hp->h_no);
840 #endif
841
842         return (0);
843 }
844
845 static int
846 hpfs_de_uiomove(int *error, struct hpfsmount *hpmp, struct hpfsdirent *dep,
847                 struct uio *uio)
848 {
849         char convname[HPFS_MAXFILENAME + 1];
850         int i, success;
851
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));
855
856         /*strncpy(cde.d_name, dep->de_name, dep->de_namelen);*/
857         for (i=0; i<dep->de_namelen; i++) 
858                 convname[i] = hpfs_d2u(hpmp, dep->de_name[i]);
859         convname[dep->de_namelen] = '\0';
860
861         success = vop_write_dirent(error, uio, dep->de_fnode,
862                         (dep->de_flag & DE_DIR) ? DT_DIR : DT_REG,
863                         dep->de_namelen, convname);
864
865         dprintf(("[0x%x] ", uio->uio_resid));
866         return (success);
867 }
868
869
870 /*
871  * hpfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
872  *              int *a_ncookies, u_int **cookies)
873  */
874 int
875 hpfs_readdir(struct vop_readdir_args *ap)
876 {
877         struct vnode *vp = ap->a_vp;
878         struct hpfsnode *hp = VTOHP(vp);
879         struct hpfsmount *hpmp = hp->h_hpmp;
880         struct uio *uio = ap->a_uio;
881         int ncookies = 0, i, num, cnum;
882         int error = 0;
883         struct buf *bp;
884         struct dirblk *dp;
885         struct hpfsdirent *dep;
886         lsn_t olsn;
887         lsn_t lsn;
888         int level;
889
890         dprintf(("hpfs_readdir(0x%x, 0x%x, 0x%x): ",hp->h_no,(u_int32_t)uio->uio_offset,uio->uio_resid));
891
892         /*
893          * As we need to fake up . and .., and the remaining directory structure
894          * can't be expressed in one off_t as well, we just increment uio_offset
895          * by 1 for each entry.
896          *
897          * num is the entry we need to start reporting
898          * cnum is the current entry
899          */
900         if (uio->uio_offset < 0 || uio->uio_offset > INT_MAX)
901                 return(EINVAL);
902         num = uio->uio_offset;
903         cnum = 0;
904
905         if( num <= cnum ) {
906                 dprintf((". faked, "));
907                 if (vop_write_dirent(&error, uio, hp->h_no, DT_DIR, 1, "."))
908                         return (0);
909                 if(error)
910                         return (error);
911
912                 ncookies ++;
913         }
914         cnum++;
915
916         if( num <= cnum ) {
917                 dprintf((".. faked, "));
918                 if (vop_write_dirent(&error, uio, hp->h_fn.fn_parent, DT_DIR, 2, ".."))
919                         goto readdone;
920                 if(error)
921                         return (error);
922
923                 ncookies ++;
924         }
925         cnum++;
926
927         lsn = ((alleaf_t *)hp->h_fn.fn_abd)->al_lsn;
928
929         olsn = 0;
930         level = 1;
931
932 dive:
933         dprintf(("[dive 0x%x] ", lsn));
934         error = bread(hp->h_devvp, dbtodoff(lsn), D_BSIZE, &bp);
935         if (error) {
936                 brelse(bp);
937                 return (error);
938         }
939
940         dp = (struct dirblk *) bp->b_data;
941         if (dp->d_magic != D_MAGIC) {
942                 printf("hpfs_readdir: MAGIC DOESN'T MATCH\n");
943                 brelse(bp);
944                 return (EINVAL);
945         }
946
947         dep = D_DIRENT(dp);
948
949         if (olsn) {
950                 dprintf(("[restore 0x%x] ", olsn));
951
952                 while(!(dep->de_flag & DE_END) ) {
953                         if((dep->de_flag & DE_DOWN) &&
954                            (olsn == DE_DOWNLSN(dep)))
955                                          break;
956                         dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
957                 }
958
959                 if((dep->de_flag & DE_DOWN) && (olsn == DE_DOWNLSN(dep))) {
960                         if (dep->de_flag & DE_END)
961                                 goto blockdone;
962
963                         if (!(dep->de_flag & DE_SPECIAL)) {
964                                 if (num <= cnum) {
965                                         if (hpfs_de_uiomove(&error, hpmp, dep, uio)) {
966                                                 brelse(bp);
967                                                 dprintf(("[resid] "));
968                                                 goto readdone;
969                                         }
970                                         if (error) {
971                                                 brelse (bp);
972                                                 return (error);
973                                         }
974                                         ncookies++;
975                                 }
976                                 cnum++;
977                         }
978
979                         dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
980                 } else {
981                         printf("hpfs_readdir: ERROR! oLSN not found\n");
982                         brelse(bp);
983                         return (EINVAL);
984                 }
985         }
986
987         olsn = 0;
988
989         while(!(dep->de_flag & DE_END)) {
990                 if(dep->de_flag & DE_DOWN) {
991                         lsn = DE_DOWNLSN(dep);
992                         brelse(bp);
993                         level++;
994                         goto dive;
995                 }
996
997                 if (!(dep->de_flag & DE_SPECIAL)) {
998                         if (num <= cnum) {
999                                 if (hpfs_de_uiomove(&error, hpmp, dep, uio)) {
1000                                         brelse(bp);
1001                                         dprintf(("[resid] "));
1002                                         goto readdone;
1003                                 }
1004                                 if (error) {
1005                                         brelse (bp);
1006                                         return (error);
1007                                 }
1008                                 ncookies++;
1009                         }
1010                         cnum++;
1011                 }
1012
1013                 dep = (hpfsdirent_t *)((caddr_t)dep + dep->de_reclen);
1014         }
1015
1016         if(dep->de_flag & DE_DOWN) {
1017                 dprintf(("[enddive] "));
1018                 lsn = DE_DOWNLSN(dep);
1019                 brelse(bp);
1020                 level++;
1021                 goto dive;
1022         }
1023
1024 blockdone:
1025         dprintf(("[EOB] "));
1026         olsn = lsn;
1027         lsn = dp->d_parent;
1028         brelse(bp);
1029         level--;
1030
1031         dprintf(("[level %d] ", level));
1032
1033         if (level > 0)
1034                 goto dive;      /* undive really */
1035
1036         if (ap->a_eofflag) {
1037             dprintf(("[EOF] "));
1038             *ap->a_eofflag = 1;
1039         }
1040
1041 readdone:
1042         uio->uio_offset = cnum;
1043         dprintf(("[readdone]\n"));
1044         if (!error && ap->a_ncookies != NULL) {
1045 #if defined(__DragonFly__)
1046                 u_long *cookies;
1047                 u_long *cookiep;
1048 #else /* defined(__NetBSD__) */
1049                 off_t *cookies;
1050                 off_t *cookiep;
1051 #endif
1052
1053                 dprintf(("%d cookies, ",ncookies));
1054                 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1055                         panic("hpfs_readdir: unexpected uio from NFS server");
1056 #if defined(__DragonFly__)
1057                 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
1058                        M_TEMP, M_WAITOK);
1059 #else /* defined(__NetBSD__) */
1060                 MALLOC(cookies, off_t *, ncookies * sizeof(off_t),
1061                        M_TEMP, M_WAITOK);
1062 #endif
1063                 for (cookiep = cookies, i=0; i < ncookies; i++)
1064                         *cookiep++ = (u_int)++num;
1065
1066                 *ap->a_ncookies = ncookies;
1067                 *ap->a_cookies = cookies;
1068         }
1069
1070         return (0);
1071 }
1072
1073 /*
1074  * hpfs_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
1075  *              struct componentname *a_cnp)
1076  */
1077 int
1078 hpfs_lookup(struct vop_old_lookup_args *ap)
1079 {
1080         struct vnode *dvp = ap->a_dvp;
1081         struct hpfsnode *dhp = VTOHP(dvp);
1082         struct hpfsmount *hpmp = dhp->h_hpmp;
1083         struct componentname *cnp = ap->a_cnp;
1084         struct ucred *cred = cnp->cn_cred;
1085         int error;
1086         int nameiop = cnp->cn_nameiop;
1087         int flags = cnp->cn_flags;
1088         int lockparent = flags & CNP_LOCKPARENT;
1089 #if HPFS_DEBUG
1090         int wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
1091 #endif
1092         dprintf(("hpfs_lookup(0x%x, %s, %ld, %d, %d): \n",
1093                 dhp->h_no, cnp->cn_nameptr, cnp->cn_namelen,
1094                 lockparent, wantparent));
1095
1096         if (nameiop != NAMEI_CREATE && nameiop != NAMEI_DELETE && nameiop != NAMEI_LOOKUP) {
1097                 printf("hpfs_lookup: LOOKUP, DELETE and CREATE are only supported\n");
1098                 return (EOPNOTSUPP);
1099         }
1100
1101         error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_td);
1102         if(error)
1103                 return (error);
1104
1105         if( (cnp->cn_namelen == 1) &&
1106             !strncmp(cnp->cn_nameptr,".",1) ) {
1107                 dprintf(("hpfs_lookup(0x%x,...): . faked\n",dhp->h_no));
1108
1109                 vref(dvp);
1110                 *ap->a_vpp = dvp;
1111
1112                 return (0);
1113         } else if( (cnp->cn_namelen == 2) &&
1114             !strncmp(cnp->cn_nameptr,"..",2) && (flags & CNP_ISDOTDOT) ) {
1115                 dprintf(("hpfs_lookup(0x%x,...): .. faked (0x%x)\n",
1116                         dhp->h_no, dhp->h_fn.fn_parent));
1117
1118                 VOP__UNLOCK(dvp,0,cnp->cn_td);
1119
1120                 error = VFS_VGET(hpmp->hpm_mp,
1121                                  dhp->h_fn.fn_parent, ap->a_vpp); 
1122                 if (error) {
1123                         VOP__LOCK(dvp, 0, cnp->cn_td);
1124                         return(error);
1125                 }
1126
1127                 if (lockparent && (error = VOP__LOCK(dvp, 0, cnp->cn_td))) {
1128                         vput( *(ap->a_vpp) );
1129                         return (error);
1130                 }
1131                 return (error);
1132         } else {
1133                 struct buf *bp;
1134                 struct hpfsdirent *dep;
1135                 struct hpfsnode *hp;
1136
1137                 error = hpfs_genlookupbyname(dhp,
1138                                 cnp->cn_nameptr, cnp->cn_namelen, &bp, &dep);
1139                 if (error) {
1140                         if (error == ENOENT && 
1141                             (nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME)) {
1142                                 if(!lockparent)
1143                                         VOP__UNLOCK(dvp, 0, cnp->cn_td);
1144                                 return (EJUSTRETURN);
1145                         }
1146
1147                         return (error);
1148                 }
1149
1150                 dprintf(("hpfs_lookup: fnode: 0x%x, CPID: 0x%x\n",
1151                          dep->de_fnode, dep->de_cpid));
1152
1153                 if (nameiop == NAMEI_DELETE) {
1154                         error = VOP_ACCESS(dvp, VWRITE, cred, cnp->cn_td);
1155                         if (error) {
1156                                 brelse(bp);
1157                                 return (error);
1158                         }
1159                 }
1160
1161                 if (dhp->h_no == dep->de_fnode) {
1162                         brelse(bp);
1163                         vref(dvp);
1164                         *ap->a_vpp = dvp;
1165                         return (0);
1166                 }
1167
1168                 error = VFS_VGET(hpmp->hpm_mp, dep->de_fnode, ap->a_vpp);
1169                 if (error) {
1170                         printf("hpfs_lookup: VFS_VGET FAILED %d\n", error);
1171                         brelse(bp);
1172                         return(error);
1173                 }
1174
1175                 hp = VTOHP(*ap->a_vpp);
1176
1177                 hp->h_mtime = dep->de_mtime;
1178                 hp->h_ctime = dep->de_ctime;
1179                 hp->h_atime = dep->de_atime;
1180                 bcopy(dep->de_name, hp->h_name, dep->de_namelen);
1181                 hp->h_name[dep->de_namelen] = '\0';
1182                 hp->h_namelen = dep->de_namelen;
1183                 hp->h_flag |= H_PARVALID;
1184
1185                 brelse(bp);
1186
1187                 if(!lockparent)
1188                         VOP__UNLOCK(dvp, 0, cnp->cn_td);
1189         }
1190         return (error);
1191 }
1192
1193 /*
1194  * hpfs_remove(struct vnode *a_dvp, struct vnode *a_vp,
1195  *              struct componentname *a_cnp)
1196  */
1197 int
1198 hpfs_remove(struct vop_old_remove_args *ap)
1199 {
1200         int error;
1201
1202         dprintf(("hpfs_remove(0x%x, %s, %ld): \n", VTOHP(ap->a_vp)->h_no,
1203                 ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen));
1204
1205         if (ap->a_vp->v_type == VDIR)
1206                 return (EPERM);
1207
1208         error = hpfs_removefnode (ap->a_dvp, ap->a_vp, ap->a_cnp);
1209         return (error);
1210 }
1211
1212 /*
1213  * hpfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
1214  *              struct componentname *a_cnp, struct vattr *a_vap)
1215  */
1216 int
1217 hpfs_create(struct vop_old_create_args *ap)
1218 {
1219         int error;
1220
1221         dprintf(("hpfs_create(0x%x, %s, %ld): \n", VTOHP(ap->a_dvp)->h_no,
1222                 ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen));
1223
1224         error = hpfs_makefnode (ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap);
1225
1226         return (error);
1227 }
1228
1229 /*
1230  * Return POSIX pathconf information applicable to NTFS filesystem
1231  *
1232  * hpfs_pathconf(struct vnode *a_vp, int a_name, t *a_retval)
1233  */
1234 int
1235 hpfs_pathconf(struct vop_pathconf_args *ap)
1236 {
1237         switch (ap->a_name) {
1238         case _PC_LINK_MAX:
1239                 *ap->a_retval = 1;
1240                 return (0);
1241         case _PC_NAME_MAX:
1242                 *ap->a_retval = HPFS_MAXFILENAME;
1243                 return (0);
1244         case _PC_PATH_MAX:
1245                 *ap->a_retval = PATH_MAX;
1246                 return (0);
1247         case _PC_CHOWN_RESTRICTED:
1248                 *ap->a_retval = 1;
1249                 return (0);
1250         case _PC_NO_TRUNC:
1251                 *ap->a_retval = 0;
1252                 return (0);
1253 #if defined(__NetBSD__)
1254         case _PC_SYNC_IO:
1255                 *ap->a_retval = 1;
1256                 return (0);
1257         case _PC_FILESIZEBITS:
1258                 *ap->a_retval = 32;
1259                 return (0);
1260 #endif
1261         default:
1262                 return (EINVAL);
1263         }
1264         /* NOTREACHED */
1265 }
1266
1267
1268 /*
1269  * Global vfs data structures
1270  */
1271 #if defined(__DragonFly__)
1272 struct vnodeopv_entry_desc hpfs_vnodeop_entries[] = {
1273         { &vop_default_desc, (vnodeopv_entry_t)vop_defaultop },
1274
1275         { &vop_getattr_desc, (vnodeopv_entry_t)hpfs_getattr },
1276         { &vop_setattr_desc, (vnodeopv_entry_t)hpfs_setattr },
1277         { &vop_inactive_desc, (vnodeopv_entry_t)hpfs_inactive },
1278         { &vop_reclaim_desc, (vnodeopv_entry_t)hpfs_reclaim },
1279         { &vop_print_desc, (vnodeopv_entry_t)hpfs_print },
1280         { &vop_old_create_desc, (vnodeopv_entry_t)hpfs_create },
1281         { &vop_old_remove_desc, (vnodeopv_entry_t)hpfs_remove },
1282         { &vop_islocked_desc, (vnodeopv_entry_t)vop_stdislocked },
1283         { &vop_unlock_desc, (vnodeopv_entry_t)vop_stdunlock },
1284         { &vop_lock_desc, (vnodeopv_entry_t)vop_stdlock },
1285         { &vop_old_lookup_desc, (vnodeopv_entry_t)hpfs_lookup },
1286         { &vop_access_desc, (vnodeopv_entry_t)hpfs_access },
1287         { &vop_close_desc, (vnodeopv_entry_t)hpfs_close },
1288         { &vop_open_desc, (vnodeopv_entry_t)hpfs_open },
1289         { &vop_readdir_desc, (vnodeopv_entry_t)hpfs_readdir },
1290         { &vop_fsync_desc, (vnodeopv_entry_t)hpfs_fsync },
1291         { &vop_bmap_desc, (vnodeopv_entry_t)hpfs_bmap },
1292         { &vop_getpages_desc, (vnodeopv_entry_t) hpfs_getpages },
1293         { &vop_putpages_desc, (vnodeopv_entry_t) hpfs_putpages },
1294         { &vop_strategy_desc, (vnodeopv_entry_t)hpfs_strategy },
1295         { &vop_bwrite_desc, (vnodeopv_entry_t)vop_stdbwrite },
1296         { &vop_read_desc, (vnodeopv_entry_t)hpfs_read },
1297         { &vop_write_desc, (vnodeopv_entry_t)hpfs_write },
1298         { &vop_ioctl_desc, (vnodeopv_entry_t)hpfs_ioctl },
1299         { &vop_pathconf_desc, (vnodeopv_entry_t)hpfs_pathconf },
1300         { NULL, NULL }
1301 };
1302
1303 #else /* defined(__NetBSD__) */
1304 struct vnodeopv_entry_desc ntfs_vnodeop_entries[] = {
1305         { &vop_default_desc, (vnodeopv_entry_t) genfs_badop },  /* XXX */
1306         { &vop_old_lookup_desc, (vnodeopv_entry_t) hpfs_lookup }, /* lookup */
1307         { &vop_old_create_desc, genfs_eopnotsupp },             /* create */
1308         { &vop_old_mknod_desc, genfs_eopnotsupp },              /* mknod */
1309         { &vop_open_desc, (vnodeopv_entry_t) hpfs_open },       /* open */
1310         { &vop_close_desc,(vnodeopv_entry_t) hpfs_close },      /* close */
1311         { &vop_access_desc, (vnodeopv_entry_t) hpfs_access },   /* access */
1312         { &vop_getattr_desc, (vnodeopv_entry_t) hpfs_getattr }, /* getattr */
1313         { &vop_setattr_desc, genfs_eopnotsupp },        /* setattr */
1314         { &vop_read_desc, (vnodeopv_entry_t) hpfs_read },       /* read */
1315         { &vop_write_desc, (vnodeopv_entry_t) hpfs_write },     /* write */
1316         { &vop_lease_desc, genfs_lease_check },         /* lease */
1317         { &vop_fcntl_desc, genfs_fcntl },               /* fcntl */
1318         { &vop_ioctl_desc, genfs_enoioctl },            /* ioctl */
1319         { &vop_poll_desc, genfs_poll },                 /* poll */
1320         { &vop_revoke_desc, genfs_revoke },             /* revoke */
1321         { &vop_mmap_desc, genfs_eopnotsupp },           /* mmap */
1322         { &vop_fsync_desc, genfs_fsync },               /* fsync */
1323         { &vop_seek_desc, genfs_seek },                 /* seek */
1324         { &vop_old_remove_desc, genfs_eopnotsupp },     /* remove */
1325         { &vop_old_link_desc, genfs_eopnotsupp },       /* link */
1326         { &vop_old_rename_desc, genfs_eopnotsupp },     /* rename */
1327         { &vop_old_mkdir_desc, genfs_eopnotsupp },      /* mkdir */
1328         { &vop_old_rmdir_desc, genfs_eopnotsupp },      /* rmdir */
1329         { &vop_old_symlink_desc, genfs_eopnotsupp },    /* symlink */
1330         { &vop_readdir_desc, (vnodeopv_entry_t) hpfs_readdir }, /* readdir */
1331         { &vop_readlink_desc, genfs_eopnotsupp },       /* readlink */
1332         { &vop_abortop_desc, genfs_abortop },           /* abortop */
1333         { &vop_inactive_desc, (vnodeopv_entry_t) hpfs_inactive },       /* inactive */
1334         { &vop_reclaim_desc, (vnodeopv_entry_t) hpfs_reclaim }, /* reclaim */
1335         { &vop_lock_desc, genfs_lock },                 /* lock */
1336         { &vop_unlock_desc, genfs_unlock },             /* unlock */
1337         { &vop_bmap_desc, (vnodeopv_entry_t) hpfs_bmap },       /* bmap */
1338         { &vop_strategy_desc, (vnodeopv_entry_t) hpfs_strategy },       /* strategy */
1339         { &vop_print_desc, (vnodeopv_entry_t) hpfs_print },     /* print */
1340         { &vop_islocked_desc, genfs_islocked },         /* islocked */
1341         { &vop_pathconf_desc, hpfs_pathconf },          /* pathconf */
1342         { &vop_advlock_desc, genfs_nullop },            /* advlock */
1343         { &vop_blkatoff_desc, genfs_eopnotsupp },       /* blkatoff */
1344         { &vop_valloc_desc, genfs_eopnotsupp },         /* valloc */
1345         { &vop_reallocblks_desc, genfs_eopnotsupp },    /* reallocblks */
1346         { &vop_vfree_desc, genfs_eopnotsupp },          /* vfree */
1347         { &vop_truncate_desc, genfs_eopnotsupp },       /* truncate */
1348         { &vop_update_desc, genfs_eopnotsupp },         /* update */
1349         { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
1350         { NULL, NULL }
1351 };
1352
1353 #endif