1 /* $Id: msdosfs_vnops.c,v 1.20 1995/08/02 12:59:49 dfr Exp $ */ 2 /* $NetBSD: msdosfs_vnops.c,v 1.20 1994/08/21 18:44:13 ws Exp $ */ 3 4 /*- 5 * Copyright (C) 1994 Wolfgang Solfrank. 6 * Copyright (C) 1994 TooLs GmbH. 7 * All rights reserved. 8 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by TooLs GmbH. 21 * 4. The name of TooLs GmbH may not be used to endorse or promote products 22 * derived from this software without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 /* 36 * Written by Paul Popelka (paulp@uts.amdahl.com) 37 * 38 * You can do anything you want with this software, just don't say you wrote 39 * it, and don't remove this notice. 40 * 41 * This software is provided "as is". 42 * 43 * The author supplies this software to be publicly redistributed on the 44 * understanding that the author is not responsible for the correct 45 * functioning of this software in any circumstances and is not liable for 46 * any damages caused by this software. 47 * 48 * October 1992 49 */ 50 51 #include <sys/param.h> 52 #include <sys/systm.h> 53 #include <sys/namei.h> 54 #include <sys/resourcevar.h> /* defines plimit structure in proc struct */ 55 #include <sys/kernel.h> 56 #include <sys/file.h> /* define FWRITE ... */ 57 #include <sys/stat.h> 58 #include <sys/buf.h> 59 #include <sys/proc.h> 60 #include <sys/mount.h> 61 #include <sys/vnode.h> 62 #include <miscfs/specfs/specdev.h> /* XXX */ /* defines v_rdev */ 63 #include <sys/malloc.h> 64 #include <sys/dir.h> /* defines dirent structure */ 65 #include <sys/signalvar.h> 66 67 #include <vm/vm.h> 68 69 #include <msdosfs/bpb.h> 70 #include <msdosfs/direntry.h> 71 #include <msdosfs/denode.h> 72 #include <msdosfs/msdosfsmount.h> 73 #include <msdosfs/fat.h> 74 /* 75 * Some general notes: 76 * 77 * In the ufs filesystem the inodes, superblocks, and indirect blocks are 78 * read/written using the vnode for the filesystem. Blocks that represent 79 * the contents of a file are read/written using the vnode for the file 80 * (including directories when they are read/written as files). This 81 * presents problems for the dos filesystem because data that should be in 82 * an inode (if dos had them) resides in the directory itself. Since we 83 * must update directory entries without the benefit of having the vnode 84 * for the directory we must use the vnode for the filesystem. This means 85 * that when a directory is actually read/written (via read, write, or 86 * readdir, or seek) we must use the vnode for the filesystem instead of 87 * the vnode for the directory as would happen in ufs. This is to insure we 88 * retreive the correct block from the buffer cache since the hash value is 89 * based upon the vnode address and the desired block number. 90 */ 91 92 /* 93 * Create a regular file. On entry the directory to contain the file being 94 * created is locked. We must release before we return. We must also free 95 * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or 96 * only if the SAVESTART bit in cn_flags is clear on success. 97 */ 98 int 99 msdosfs_create(ap) 100 struct vop_create_args /* { 101 struct vnode *a_dvp; 102 struct vnode **a_vpp; 103 struct componentname *a_cnp; 104 struct vattr *a_vap; 105 } */ *ap; 106 { 107 struct componentname *cnp = ap->a_cnp; 108 struct denode ndirent; 109 struct denode *dep; 110 struct denode *pdep = VTODE(ap->a_dvp); 111 struct timespec ts; 112 int error; 113 114 #ifdef MSDOSFS_DEBUG 115 printf("msdosfs_create(cnp %08x, vap %08x\n", cnp, ap->a_vap); 116 #endif 117 118 /* 119 * Create a directory entry for the file, then call createde() to 120 * have it installed. NOTE: DOS files are always executable. We 121 * use the absence of the owner write bit to make the file 122 * readonly. 123 */ 124 #ifdef DIAGNOSTIC 125 if ((cnp->cn_flags & SAVENAME) == 0) 126 panic("msdosfs_create: no name"); 127 #endif 128 bzero(&ndirent, sizeof(ndirent)); 129 TIMEVAL_TO_TIMESPEC(&time, &ts); 130 unix2dostime(&ts, &ndirent.de_Date, &ndirent.de_Time); 131 unix2dosfn((u_char *)cnp->cn_nameptr, ndirent.de_Name, cnp->cn_namelen); 132 ndirent.de_Attributes = (ap->a_vap->va_mode & VWRITE) 133 ? ATTR_ARCHIVE : ATTR_ARCHIVE | ATTR_READONLY; 134 ndirent.de_StartCluster = 0; 135 ndirent.de_FileSize = 0; 136 ndirent.de_dev = pdep->de_dev; 137 ndirent.de_devvp = pdep->de_devvp; 138 if ((error = createde(&ndirent, pdep, &dep)) == 0) { 139 *ap->a_vpp = DETOV(dep); 140 if ((cnp->cn_flags & SAVESTART) == 0) 141 free(cnp->cn_pnbuf, M_NAMEI); 142 } else { 143 free(cnp->cn_pnbuf, M_NAMEI); 144 } 145 vput(ap->a_dvp); /* release parent dir */ 146 return error; 147 } 148 149 int 150 msdosfs_mknod(ap) 151 struct vop_mknod_args /* { 152 struct vnode *a_dvp; 153 struct vnode **a_vpp; 154 struct componentname *a_cnp; 155 struct vattr *a_vap; 156 } */ *ap; 157 { 158 int error; 159 160 switch (ap->a_vap->va_type) { 161 case VDIR: 162 error = msdosfs_mkdir((struct vop_mkdir_args *)ap); 163 break; 164 165 case VREG: 166 error = msdosfs_create((struct vop_create_args *)ap); 167 break; 168 169 default: 170 error = EINVAL; 171 free(ap->a_cnp->cn_pnbuf, M_NAMEI); 172 vput(ap->a_dvp); 173 break; 174 } 175 return error; 176 } 177 178 int 179 msdosfs_open(ap) 180 struct vop_open_args /* { 181 struct vnode *a_vp; 182 int a_mode; 183 struct ucred *a_cred; 184 struct proc *a_p; 185 } */ *ap; 186 { 187 return 0; 188 } 189 190 int 191 msdosfs_close(ap) 192 struct vop_close_args /* { 193 struct vnode *a_vp; 194 int a_fflag; 195 struct ucred *a_cred; 196 struct proc *a_p; 197 } */ *ap; 198 { 199 struct vnode *vp = ap->a_vp; 200 struct denode *dep = VTODE(vp); 201 202 if (vp->v_usecount > 1 && !(dep->de_flag & DE_LOCKED)) 203 DE_TIMES(dep, &time); 204 return 0; 205 } 206 207 /* 208 * This routine will go into sys/kern/vfs_subr.c one day! 209 * 210 * Do the usual access checking. 211 * file_node, uid and gid are from the vnode in question, 212 * while acc_mode and cred are from the VOP_ACCESS parameter list. 213 */ 214 static int 215 vaccess(file_mode, uid, gid, acc_mode, cred) 216 mode_t file_mode; 217 uid_t uid; 218 gid_t gid; 219 mode_t acc_mode; 220 struct ucred *cred; 221 { 222 mode_t mask; 223 int i; 224 register gid_t *gp; 225 226 /* User id 0 always gets access. */ 227 if (cred->cr_uid == 0) 228 return 0; 229 230 mask = 0; 231 232 /* Otherwise, check the owner. */ 233 if (cred->cr_uid == uid) { 234 if (acc_mode & VEXEC) 235 mask |= S_IXUSR; 236 if (acc_mode & VREAD) 237 mask |= S_IRUSR; 238 if (acc_mode & VWRITE) 239 mask |= S_IWUSR; 240 return (file_mode & mask) == mask ? 0 : EACCES; 241 } 242 243 /* Otherwise, check the groups. */ 244 for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++) 245 if (gid == *gp) { 246 if (acc_mode & VEXEC) 247 mask |= S_IXGRP; 248 if (acc_mode & VREAD) 249 mask |= S_IRGRP; 250 if (acc_mode & VWRITE) 251 mask |= S_IWGRP; 252 return (file_mode & mask) == mask ? 0 : EACCES; 253 } 254 255 /* Otherwise, check everyone else. */ 256 if (acc_mode & VEXEC) 257 mask |= S_IXOTH; 258 if (acc_mode & VREAD) 259 mask |= S_IROTH; 260 if (acc_mode & VWRITE) 261 mask |= S_IWOTH; 262 return (file_mode & mask) == mask ? 0 : EACCES; 263 } 264 265 int 266 msdosfs_access(ap) 267 struct vop_access_args /* { 268 struct vnode *a_vp; 269 int a_mode; 270 struct ucred *a_cred; 271 struct proc *a_p; 272 } */ *ap; 273 { 274 mode_t dosmode; 275 struct denode *dep = VTODE(ap->a_vp); 276 struct msdosfsmount *pmp = dep->de_pmp; 277 278 dosmode = (S_IXUSR|S_IXGRP|S_IXOTH) | (S_IRUSR|S_IRGRP|S_IROTH) | 279 ((dep->de_Attributes & ATTR_READONLY) ? 0 : (S_IWUSR|S_IWGRP|S_IWOTH)); 280 dosmode &= pmp->pm_mask; 281 282 return vaccess(dosmode, pmp->pm_uid, pmp->pm_gid, ap->a_mode, ap->a_cred); 283 } 284 285 int 286 msdosfs_getattr(ap) 287 struct vop_getattr_args /* { 288 struct vnode *a_vp; 289 struct vattr *a_vap; 290 struct ucred *a_cred; 291 struct proc *a_p; 292 } */ *ap; 293 { 294 u_int cn; 295 struct denode *dep = VTODE(ap->a_vp); 296 struct vattr *vap = ap->a_vap; 297 298 DE_TIMES(dep, &time); 299 vap->va_fsid = dep->de_dev; 300 /* 301 * The following computation of the fileid must be the same as that 302 * used in msdosfs_readdir() to compute d_fileno. If not, pwd 303 * doesn't work. 304 */ 305 if (dep->de_Attributes & ATTR_DIRECTORY) { 306 if ((cn = dep->de_StartCluster) == MSDOSFSROOT) 307 cn = 1; 308 } else { 309 if ((cn = dep->de_dirclust) == MSDOSFSROOT) 310 cn = 1; 311 cn = (cn << 16) | (dep->de_diroffset & 0xffff); 312 } 313 vap->va_fileid = cn; 314 vap->va_mode = (S_IXUSR|S_IXGRP|S_IXOTH) | (S_IRUSR|S_IRGRP|S_IROTH) | 315 ((dep->de_Attributes & ATTR_READONLY) ? 0 : (S_IWUSR|S_IWGRP|S_IWOTH)); 316 vap->va_mode &= dep->de_pmp->pm_mask; 317 if (dep->de_Attributes & ATTR_DIRECTORY) 318 vap->va_mode |= S_IFDIR; 319 vap->va_nlink = 1; 320 vap->va_gid = dep->de_pmp->pm_gid; 321 vap->va_uid = dep->de_pmp->pm_uid; 322 vap->va_rdev = 0; 323 vap->va_size = dep->de_FileSize; 324 dos2unixtime(dep->de_Date, dep->de_Time, &vap->va_atime); 325 vap->va_mtime = vap->va_atime; 326 #if 0 327 #ifndef MSDOSFS_NODIRMOD 328 if (vap->va_mode & S_IFDIR) 329 TIMEVAL_TO_TIMESPEC(&time, &vap->va_mtime); 330 #endif 331 #endif 332 vap->va_ctime = vap->va_atime; 333 vap->va_flags = (dep->de_Attributes & ATTR_ARCHIVE) ? 0 : SF_ARCHIVED; 334 vap->va_gen = 0; 335 vap->va_blocksize = dep->de_pmp->pm_bpcluster; 336 vap->va_bytes = (dep->de_FileSize + dep->de_pmp->pm_crbomask) & 337 ~(dep->de_pmp->pm_crbomask); 338 vap->va_type = ap->a_vp->v_type; 339 vap->va_filerev = dep->de_modrev; 340 return 0; 341 } 342 343 int 344 msdosfs_setattr(ap) 345 struct vop_setattr_args /* { 346 struct vnode *a_vp; 347 struct vattr *a_vap; 348 struct ucred *a_cred; 349 struct proc *a_p; 350 } */ *ap; 351 { 352 int error = 0; 353 struct denode *dep = VTODE(ap->a_vp); 354 struct vattr *vap = ap->a_vap; 355 struct ucred *cred = ap->a_cred; 356 357 #ifdef MSDOSFS_DEBUG 358 printf("msdosfs_setattr(): vp %08x, vap %08x, cred %08x, p %08x\n", 359 ap->a_vp, vap, cred, ap->a_p); 360 #endif 361 if ((vap->va_type != VNON) || 362 (vap->va_nlink != VNOVAL) || 363 (vap->va_fsid != VNOVAL) || 364 (vap->va_fileid != VNOVAL) || 365 (vap->va_blocksize != VNOVAL) || 366 (vap->va_rdev != VNOVAL) || 367 (vap->va_bytes != VNOVAL) || 368 (vap->va_gen != VNOVAL)) { 369 #ifdef MSDOSFS_DEBUG 370 printf("msdosfs_setattr(): returning EINVAL\n"); 371 printf(" va_type %d, va_nlink %x, va_fsid %x, va_fileid %x\n", 372 vap->va_type, vap->va_nlink, vap->va_fsid, vap->va_fileid); 373 printf(" va_blocksize %x, va_rdev %x, va_bytes %x, va_gen %x\n", 374 vap->va_blocksize, vap->va_rdev, vap->va_bytes, vap->va_gen); 375 #endif 376 return EINVAL; 377 } 378 379 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (uid_t)VNOVAL) { 380 if ((cred->cr_uid != dep->de_pmp->pm_uid || 381 vap->va_uid != dep->de_pmp->pm_uid || 382 (vap->va_gid != dep->de_pmp->pm_gid && 383 !groupmember(vap->va_gid, cred))) && 384 (error = suser(cred, &ap->a_p->p_acflag))) 385 return error; 386 if (vap->va_uid != dep->de_pmp->pm_uid || 387 vap->va_gid != dep->de_pmp->pm_gid) 388 return EINVAL; 389 } 390 if (vap->va_size != VNOVAL) { 391 if (ap->a_vp->v_type == VDIR) 392 return EISDIR; 393 error = detrunc(dep, vap->va_size, 0, cred, ap->a_p); 394 if (error) 395 return error; 396 } 397 if (vap->va_mtime.ts_sec != VNOVAL) { 398 if (cred->cr_uid != dep->de_pmp->pm_uid && 399 (error = suser(cred, &ap->a_p->p_acflag)) && 400 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 || 401 (error = VOP_ACCESS(ap->a_vp, VWRITE, cred, &ap->a_p)))) 402 return error; 403 dep->de_flag |= DE_UPDATE; 404 error = deupdat(dep, &vap->va_mtime, 1); 405 if (error) 406 return error; 407 } 408 409 /* 410 * DOS files only have the ability to have their writability 411 * attribute set, so we use the owner write bit to set the readonly 412 * attribute. 413 */ 414 if (vap->va_mode != (u_short) VNOVAL) { 415 if (cred->cr_uid != dep->de_pmp->pm_uid && 416 (error = suser(cred, &ap->a_p->p_acflag))) 417 return error; 418 419 /* We ignore the read and execute bits */ 420 if (vap->va_mode & VWRITE) 421 dep->de_Attributes &= ~ATTR_READONLY; 422 else 423 dep->de_Attributes |= ATTR_READONLY; 424 dep->de_flag |= DE_MODIFIED; 425 } 426 427 if (vap->va_flags != VNOVAL) { 428 if (cred->cr_uid != dep->de_pmp->pm_uid && 429 (error = suser(cred, &ap->a_p->p_acflag))) 430 return error; 431 /* 432 * We are very inconsistent about handling unsupported 433 * attributes. We ignored the the access time and the 434 * read and execute bits. We were strict for the other 435 * attributes. 436 * 437 * Here we are strict, stricter than ufs in not allowing 438 * users to attempt to set SF_SETTABLE bits or anyone to 439 * set unsupported bits. However, we ignore attempts to 440 * set ATTR_ARCHIVE for directories `cp -pr' from a more 441 * sensible file system attempts it a lot. 442 */ 443 if (cred->cr_uid != 0) { 444 if (vap->va_flags & SF_SETTABLE) 445 return EPERM; 446 } 447 if (vap->va_flags & ~SF_ARCHIVED) 448 return EINVAL; 449 if (vap->va_flags & SF_ARCHIVED) 450 dep->de_Attributes &= ~ATTR_ARCHIVE; 451 else if (!(dep->de_Attributes & ATTR_DIRECTORY)) 452 dep->de_Attributes |= ATTR_ARCHIVE; 453 dep->de_flag |= DE_MODIFIED; 454 } 455 return error; 456 } 457 458 int 459 msdosfs_read(ap) 460 struct vop_read_args /* { 461 struct vnode *a_vp; 462 struct uio *a_uio; 463 int a_ioflag; 464 struct ucred *a_cred; 465 } */ *ap; 466 { 467 int error = 0; 468 int diff; 469 int isadir; 470 long n; 471 long on; 472 daddr_t lbn; 473 daddr_t rablock; 474 int rasize; 475 struct buf *bp; 476 struct vnode *vp = ap->a_vp; 477 struct denode *dep = VTODE(vp); 478 struct msdosfsmount *pmp = dep->de_pmp; 479 struct uio *uio = ap->a_uio; 480 481 /* 482 * If they didn't ask for any data, then we are done. 483 */ 484 if (uio->uio_resid == 0) 485 return 0; 486 if (uio->uio_offset < 0) 487 return EINVAL; 488 489 isadir = dep->de_Attributes & ATTR_DIRECTORY; 490 do { 491 lbn = uio->uio_offset >> pmp->pm_cnshift; 492 on = uio->uio_offset & pmp->pm_crbomask; 493 n = min((u_long) (pmp->pm_bpcluster - on), uio->uio_resid); 494 diff = dep->de_FileSize - uio->uio_offset; 495 if (diff <= 0) 496 return 0; 497 /* convert cluster # to block # if a directory */ 498 if (isadir) { 499 error = pcbmap(dep, lbn, &lbn, 0); 500 if (error) 501 return error; 502 } 503 if (diff < n) 504 n = diff; 505 /* 506 * If we are operating on a directory file then be sure to 507 * do i/o with the vnode for the filesystem instead of the 508 * vnode for the directory. 509 */ 510 if (isadir) { 511 error = bread(pmp->pm_devvp, lbn, pmp->pm_bpcluster, 512 NOCRED, &bp); 513 } else { 514 rablock = lbn + 1; 515 if (vp->v_lastr + 1 == lbn && 516 rablock * pmp->pm_bpcluster < dep->de_FileSize) { 517 rasize = pmp->pm_bpcluster; 518 error = breadn(vp, lbn, pmp->pm_bpcluster, 519 &rablock, &rasize, 1, 520 NOCRED, &bp); 521 } else { 522 error = bread(vp, lbn, pmp->pm_bpcluster, NOCRED, 523 &bp); 524 } 525 vp->v_lastr = lbn; 526 } 527 n = min(n, pmp->pm_bpcluster - bp->b_resid); 528 if (error) { 529 brelse(bp); 530 return error; 531 } 532 error = uiomove(bp->b_data + on, (int) n, uio); 533 /* 534 * If we have read everything from this block or have read 535 * to end of file then we are done with this block. Mark 536 * it to say the buffer can be reused if need be. 537 */ 538 #if 0 539 if (n + on == pmp->pm_bpcluster || 540 uio->uio_offset == dep->de_FileSize) 541 bp->b_flags |= B_AGE; 542 #endif 543 brelse(bp); 544 } while (error == 0 && uio->uio_resid > 0 && n != 0); 545 return error; 546 } 547 548 /* 549 * Write data to a file or directory. 550 */ 551 int 552 msdosfs_write(ap) 553 struct vop_write_args /* { 554 struct vnode *a_vp; 555 struct uio *a_uio; 556 int a_ioflag; 557 struct ucred *a_cred; 558 } */ *ap; 559 { 560 int n; 561 int isadir; 562 int croffset; 563 int resid; 564 int osize; 565 int error = 0; 566 u_long count; 567 daddr_t bn, lastcn; 568 struct buf *bp; 569 int ioflag = ap->a_ioflag; 570 struct uio *uio = ap->a_uio; 571 struct proc *p = uio->uio_procp; 572 struct vnode *vp = ap->a_vp; 573 struct vnode *thisvp; 574 struct denode *dep = VTODE(vp); 575 struct msdosfsmount *pmp = dep->de_pmp; 576 struct ucred *cred = ap->a_cred; 577 struct timespec ts; 578 579 #ifdef MSDOSFS_DEBUG 580 printf("msdosfs_write(vp %08x, uio %08x, ioflag %08x, cred %08x\n", 581 vp, uio, ioflag, cred); 582 printf("msdosfs_write(): diroff %d, dirclust %d, startcluster %d\n", 583 dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster); 584 #endif 585 586 switch (vp->v_type) { 587 case VREG: 588 if (ioflag & IO_APPEND) 589 uio->uio_offset = dep->de_FileSize; 590 isadir = 0; 591 thisvp = vp; 592 break; 593 594 case VDIR: 595 if ((ioflag & IO_SYNC) == 0) 596 panic("msdosfs_write(): non-sync directory update"); 597 isadir = 1; 598 thisvp = pmp->pm_devvp; 599 break; 600 601 default: 602 panic("msdosfs_write(): bad file type"); 603 break; 604 } 605 606 if (uio->uio_offset < 0) 607 return EINVAL; 608 609 if (uio->uio_resid == 0) 610 return 0; 611 612 /* 613 * If they've exceeded their filesize limit, tell them about it. 614 */ 615 if (vp->v_type == VREG && p && 616 ((uio->uio_offset + uio->uio_resid) > 617 p->p_rlimit[RLIMIT_FSIZE].rlim_cur)) { 618 psignal(p, SIGXFSZ); 619 return EFBIG; 620 } 621 622 /* 623 * If attempting to write beyond the end of the root directory we 624 * stop that here because the root directory can not grow. 625 */ 626 if ((dep->de_Attributes & ATTR_DIRECTORY) && 627 dep->de_StartCluster == MSDOSFSROOT && 628 (uio->uio_offset + uio->uio_resid) > dep->de_FileSize) 629 return ENOSPC; 630 631 /* 632 * If the offset we are starting the write at is beyond the end of 633 * the file, then they've done a seek. Unix filesystems allow 634 * files with holes in them, DOS doesn't so we must fill the hole 635 * with zeroed blocks. 636 */ 637 if (uio->uio_offset > dep->de_FileSize) { 638 error = deextend(dep, uio->uio_offset, cred); 639 if (error) 640 return error; 641 } 642 643 /* 644 * Remember some values in case the write fails. 645 */ 646 resid = uio->uio_resid; 647 osize = dep->de_FileSize; 648 649 650 /* 651 * If we write beyond the end of the file, extend it to its ultimate 652 * size ahead of the time to hopefully get a contiguous area. 653 */ 654 if (uio->uio_offset + resid > osize) { 655 count = de_clcount(pmp, uio->uio_offset + resid) - de_clcount(pmp, osize); 656 if ((error = extendfile(dep, count, NULL, NULL, 0)) 657 && (error != ENOSPC || (ioflag & IO_UNIT))) 658 goto errexit; 659 lastcn = dep->de_fc[FC_LASTFC].fc_frcn; 660 } else 661 lastcn = de_clcount(pmp, osize) - 1; 662 663 do { 664 bn = de_blk(pmp, uio->uio_offset); 665 if (isadir) { 666 error = pcbmap(dep, bn, &bn, 0); 667 if (error) 668 break; 669 } else if (bn > lastcn) { 670 error = ENOSPC; 671 break; 672 } 673 674 if ((uio->uio_offset & pmp->pm_crbomask) == 0 675 && (de_blk(pmp, uio->uio_offset + uio->uio_resid) > de_blk(pmp, uio->uio_offset) 676 || uio->uio_offset + uio->uio_resid >= dep->de_FileSize)) { 677 /* 678 * If either the whole cluster gets written, 679 * or we write the cluster from its start beyond EOF, 680 * then no need to read data from disk. 681 */ 682 bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0); 683 clrbuf(bp); 684 /* 685 * Do the bmap now, since pcbmap needs buffers 686 * for the fat table. (see msdosfs_strategy) 687 */ 688 if (!isadir) { 689 if (bp->b_blkno == bp->b_lblkno) { 690 error = pcbmap(dep, bp->b_lblkno, 691 &bp->b_blkno, 0); 692 if (error) 693 bp->b_blkno = -1; 694 } 695 if (bp->b_blkno == -1) { 696 brelse(bp); 697 if (!error) 698 error = EIO; /* XXX */ 699 break; 700 } 701 } 702 } else { 703 /* 704 * The block we need to write into exists, so read it in. 705 */ 706 error = bread(thisvp, bn, pmp->pm_bpcluster, cred, &bp); 707 if (error) 708 break; 709 } 710 711 croffset = uio->uio_offset & pmp->pm_crbomask; 712 n = min(uio->uio_resid, pmp->pm_bpcluster - croffset); 713 if (uio->uio_offset + n > dep->de_FileSize) { 714 dep->de_FileSize = uio->uio_offset + n; 715 vnode_pager_setsize(vp, dep->de_FileSize); /* why? */ 716 } 717 /* 718 * Should these vnode_pager_* functions be done on dir 719 * files? 720 */ 721 722 /* 723 * Copy the data from user space into the buf header. 724 */ 725 error = uiomove(bp->b_data + croffset, n, uio); 726 727 /* 728 * If they want this synchronous then write it and wait for 729 * it. Otherwise, if on a cluster boundary write it 730 * asynchronously so we can move on to the next block 731 * without delay. Otherwise do a delayed write because we 732 * may want to write somemore into the block later. 733 */ 734 if (ioflag & IO_SYNC) 735 (void) bwrite(bp); 736 else if (n + croffset == pmp->pm_bpcluster) { 737 bawrite(bp); 738 } else 739 bdwrite(bp); 740 dep->de_flag |= DE_UPDATE; 741 } while (error == 0 && uio->uio_resid > 0); 742 743 /* 744 * If the write failed and they want us to, truncate the file back 745 * to the size it was before the write was attempted. 746 */ 747 errexit: 748 if (error) { 749 if (ioflag & IO_UNIT) { 750 detrunc(dep, osize, ioflag & IO_SYNC, NOCRED, NULL); 751 uio->uio_offset -= resid - uio->uio_resid; 752 uio->uio_resid = resid; 753 } else { 754 detrunc(dep, dep->de_FileSize, ioflag & IO_SYNC, NOCRED, NULL); 755 if (uio->uio_resid != resid) 756 error = 0; 757 } 758 } else { 759 TIMEVAL_TO_TIMESPEC(&time, &ts); 760 error = deupdat(dep, &ts, 1); 761 } 762 return error; 763 } 764 765 int 766 msdosfs_ioctl(ap) 767 struct vop_ioctl_args /* { 768 struct vnode *a_vp; 769 int a_command; 770 caddr_t a_data; 771 int a_fflag; 772 struct ucred *a_cred; 773 struct proc *a_p; 774 } */ *ap; 775 { 776 return ENOTTY; 777 } 778 779 int 780 msdosfs_select(ap) 781 struct vop_select_args /* { 782 struct vnode *a_vp; 783 int a_which; 784 int a_fflags; 785 struct ucred *a_cred; 786 struct proc *a_p; 787 } */ *ap; 788 { 789 return 1; /* DOS filesystems never block? */ 790 } 791 792 int 793 msdosfs_mmap(ap) 794 struct vop_mmap_args /* { 795 struct vnode *a_vp; 796 int a_fflags; 797 struct ucred *a_cred; 798 struct proc *a_p; 799 } */ *ap; 800 { 801 return EINVAL; 802 } 803 804 /* 805 * Flush the blocks of a file to disk. 806 * 807 * This function is worthless for vnodes that represent directories. Maybe we 808 * could just do a sync if they try an fsync on a directory file. 809 */ 810 int 811 msdosfs_fsync(ap) 812 struct vop_fsync_args /* { 813 struct vnode *a_vp; 814 struct ucred *a_cred; 815 int a_waitfor; 816 struct proc *a_p; 817 } */ *ap; 818 { 819 register struct vnode *vp = ap->a_vp; 820 register struct buf *bp; 821 int wait = ap->a_waitfor == MNT_WAIT; 822 struct timespec ts; 823 struct buf *nbp; 824 int s; 825 826 /* 827 * Flush all dirty buffers associated with a vnode. 828 */ 829 loop: 830 s = splbio(); 831 for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) { 832 nbp = bp->b_vnbufs.le_next; 833 if ((bp->b_flags & B_BUSY)) 834 continue; 835 if ((bp->b_flags & B_DELWRI) == 0) 836 panic("msdosfs_fsync: not dirty"); 837 bremfree(bp); 838 bp->b_flags |= B_BUSY; 839 splx(s); 840 (void) bwrite(bp); 841 goto loop; 842 } 843 while (vp->v_numoutput) { 844 vp->v_flag |= VBWAIT; 845 (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "msdosfsn", 0); 846 } 847 #ifdef DIAGNOSTIC 848 if (vp->v_dirtyblkhd.lh_first) { 849 vprint("msdosfs_fsync: dirty", vp); 850 goto loop; 851 } 852 #endif 853 splx(s); 854 TIMEVAL_TO_TIMESPEC(&time, &ts); 855 return deupdat(VTODE(vp), &ts, wait); 856 } 857 858 /* 859 * Now the whole work of extending a file is done in the write function. 860 * So nothing to do here. 861 */ 862 int 863 msdosfs_seek(ap) 864 struct vop_seek_args /* { 865 struct vnode *a_vp; 866 off_t a_oldoff; 867 off_t a_newoff; 868 struct ucred *a_cred; 869 } */ *ap; 870 { 871 return 0; 872 } 873 874 int 875 msdosfs_remove(ap) 876 struct vop_remove_args /* { 877 struct vnode *a_dvp; 878 struct vnode *a_vp; 879 struct componentname *a_cnp; 880 } */ *ap; 881 { 882 int error; 883 struct denode *dep = VTODE(ap->a_vp); 884 struct denode *ddep = VTODE(ap->a_dvp); 885 886 error = removede(ddep,dep); 887 #ifdef MSDOSFS_DEBUG 888 printf("msdosfs_remove(), dep %08x, v_usecount %d\n", dep, ap->a_vp->v_usecount); 889 #endif 890 if (ddep == dep) 891 vrele(ap->a_vp); 892 else 893 vput(ap->a_vp); /* causes msdosfs_inactive() to be called 894 * via vrele() */ 895 vput(ap->a_dvp); 896 return error; 897 } 898 899 /* 900 * DOS filesystems don't know what links are. But since we already called 901 * msdosfs_lookup() with create and lockparent, the parent is locked so we 902 * have to free it before we return the error. 903 */ 904 int 905 msdosfs_link(ap) 906 struct vop_link_args /* { 907 struct vnode *a_tdvp; 908 struct vnode *a_vp; 909 struct componentname *a_cnp; 910 } */ *ap; 911 { 912 VOP_ABORTOP(ap->a_tdvp, ap->a_cnp); 913 vput(ap->a_tdvp); 914 return EOPNOTSUPP; 915 } 916 917 /* 918 * Renames on files require moving the denode to a new hash queue since the 919 * denode's location is used to compute which hash queue to put the file 920 * in. Unless it is a rename in place. For example "mv a b". 921 * 922 * What follows is the basic algorithm: 923 * 924 * if (file move) { 925 * if (dest file exists) { 926 * remove dest file 927 * } 928 * if (dest and src in same directory) { 929 * rewrite name in existing directory slot 930 * } else { 931 * write new entry in dest directory 932 * update offset and dirclust in denode 933 * move denode to new hash chain 934 * clear old directory entry 935 * } 936 * } else { 937 * directory move 938 * if (dest directory exists) { 939 * if (dest is not empty) { 940 * return ENOTEMPTY 941 * } 942 * remove dest directory 943 * } 944 * if (dest and src in same directory) { 945 * rewrite name in existing entry 946 * } else { 947 * be sure dest is not a child of src directory 948 * write entry in dest directory 949 * update "." and ".." in moved directory 950 * clear old directory entry for moved directory 951 * } 952 * } 953 * 954 * On entry: 955 * source's parent directory is unlocked 956 * source file or directory is unlocked 957 * destination's parent directory is locked 958 * destination file or directory is locked if it exists 959 * 960 * On exit: 961 * all denodes should be released 962 * 963 * Notes: 964 * I'm not sure how the memory containing the pathnames pointed at by the 965 * componentname structures is freed, there may be some memory bleeding 966 * for each rename done. 967 */ 968 int 969 msdosfs_rename(ap) 970 struct vop_rename_args /* { 971 struct vnode *a_fdvp; 972 struct vnode *a_fvp; 973 struct componentname *a_fcnp; 974 struct vnode *a_tdvp; 975 struct vnode *a_tvp; 976 struct componentname *a_tcnp; 977 } */ *ap; 978 { 979 u_char toname[11]; 980 int error; 981 int newparent = 0; 982 int sourceisadirectory = 0; 983 u_long cn; 984 daddr_t bn; 985 struct vnode *tvp = ap->a_tvp; 986 struct denode *fddep; /* from file's parent directory */ 987 struct denode *fdep; /* from file or directory */ 988 struct denode *tddep; /* to file's parent directory */ 989 struct denode *tdep; /* to file or directory */ 990 struct msdosfsmount *pmp; 991 struct direntry *dotdotp; 992 struct direntry *ep; 993 struct buf *bp; 994 995 fddep = VTODE(ap->a_fdvp); 996 fdep = VTODE(ap->a_fvp); 997 tddep = VTODE(ap->a_tdvp); 998 tdep = tvp ? VTODE(tvp) : NULL; 999 pmp = fddep->de_pmp; 1000 1001 /* Check for cross-device rename */ 1002 if ((ap->a_fvp->v_mount != ap->a_tdvp->v_mount) || 1003 (tvp && (ap->a_fvp->v_mount != tvp->v_mount))) { 1004 error = EXDEV; 1005 goto bad; 1006 } 1007 1008 /* 1009 * Convert the filename in tcnp into a dos filename. We copy this 1010 * into the denode and directory entry for the destination 1011 * file/directory. 1012 */ 1013 unix2dosfn((u_char *) ap->a_tcnp->cn_nameptr, 1014 toname, ap->a_tcnp->cn_namelen); 1015 1016 /* 1017 * At this point this is the lock state of the denodes: 1018 * fddep referenced 1019 * fdep referenced 1020 * tddep locked 1021 * tdep locked if it exists 1022 */ 1023 1024 /* 1025 * Be sure we are not renaming ".", "..", or an alias of ".". This 1026 * leads to a crippled directory tree. It's pretty tough to do a 1027 * "ls" or "pwd" with the "." directory entry missing, and "cd .." 1028 * doesn't work if the ".." entry is missing. 1029 */ 1030 if (fdep->de_Attributes & ATTR_DIRECTORY) { 1031 if ((ap->a_fcnp->cn_namelen == 1 1032 && ap->a_fcnp->cn_nameptr[0] == '.') 1033 || fddep == fdep 1034 || (ap->a_fcnp->cn_flags & ISDOTDOT)) { 1035 VOP_ABORTOP(ap->a_tdvp, ap->a_tcnp); 1036 vput(ap->a_tdvp); 1037 if (tvp) 1038 vput(tvp); 1039 VOP_ABORTOP(ap->a_fdvp, ap->a_fcnp); 1040 vrele(ap->a_fdvp); 1041 vrele(ap->a_fvp); 1042 return EINVAL; 1043 } 1044 sourceisadirectory = 1; 1045 } 1046 1047 /* 1048 * If we are renaming a directory, and the directory is being moved 1049 * to another directory, then we must be sure the destination 1050 * directory is not in the subtree of the source directory. This 1051 * could orphan everything under the source directory. 1052 * doscheckpath() unlocks the destination's parent directory so we 1053 * must look it up again to relock it. 1054 */ 1055 if (fddep->de_StartCluster != tddep->de_StartCluster) 1056 newparent = 1; 1057 if (sourceisadirectory && newparent) { 1058 if (tdep) { 1059 vput(ap->a_tvp); 1060 tdep = NULL; 1061 } 1062 /* doscheckpath() vput()'s tddep */ 1063 error = doscheckpath(fdep, tddep); 1064 tddep = NULL; 1065 if (error) 1066 goto bad; 1067 if ((ap->a_tcnp->cn_flags & SAVESTART) == 0) 1068 panic("msdosfs_rename(): lost to startdir"); 1069 error = relookup(ap->a_tdvp, &tvp, ap->a_tcnp); 1070 if (error) 1071 goto bad; 1072 tddep = VTODE(ap->a_tdvp); 1073 tdep = tvp ? VTODE(tvp) : NULL; 1074 } 1075 1076 /* 1077 * If the destination exists, then be sure its type (file or dir) 1078 * matches that of the source. And, if it is a directory make sure 1079 * it is empty. Then delete the destination. 1080 */ 1081 if (tdep) { 1082 if (tdep->de_Attributes & ATTR_DIRECTORY) { 1083 if (!sourceisadirectory) { 1084 error = ENOTDIR; 1085 goto bad; 1086 } 1087 if (!dosdirempty(tdep)) { 1088 error = ENOTEMPTY; 1089 goto bad; 1090 } 1091 cache_purge(DETOV(tddep)); 1092 } else { /* destination is file */ 1093 if (sourceisadirectory) { 1094 error = EISDIR; 1095 goto bad; 1096 } 1097 } 1098 error = removede(tddep,tdep); 1099 if (error) 1100 goto bad; 1101 vput(ap->a_tvp); 1102 tdep = NULL; 1103 } 1104 1105 /* 1106 * If the source and destination are in the same directory then 1107 * just read in the directory entry, change the name in the 1108 * directory entry and write it back to disk. 1109 */ 1110 if (newparent == 0) { 1111 /* tddep and fddep point to the same denode here */ 1112 VOP_LOCK(ap->a_fvp); /* ap->a_fdvp is already locked */ 1113 error = readep(fddep->de_pmp, fdep->de_dirclust, 1114 fdep->de_diroffset, &bp, &ep); 1115 if (error) { 1116 VOP_UNLOCK(ap->a_fvp); 1117 goto bad; 1118 } 1119 bcopy(toname, ep->deName, 11); 1120 error = bwrite(bp); 1121 if (error) { 1122 VOP_UNLOCK(ap->a_fvp); 1123 goto bad; 1124 } 1125 bcopy(toname, fdep->de_Name, 11); /* update denode */ 1126 /* 1127 * fdep locked fddep and tddep point to the same denode 1128 * which is locked tdep is NULL 1129 */ 1130 } else { 1131 u_long dirsize = 0L; 1132 1133 /* 1134 * If the source and destination are in different 1135 * directories, then mark the entry in the source directory 1136 * as deleted and write a new entry in the destination 1137 * directory. Then move the denode to the correct hash 1138 * chain for its new location in the filesystem. And, if 1139 * we moved a directory, then update its .. entry to point 1140 * to the new parent directory. If we moved a directory 1141 * will also insure that the directory entry on disk has a 1142 * filesize of zero. 1143 */ 1144 VOP_LOCK(ap->a_fvp); 1145 bcopy(toname, fdep->de_Name, 11); /* update denode */ 1146 if (fdep->de_Attributes & ATTR_DIRECTORY) { 1147 dirsize = fdep->de_FileSize; 1148 fdep->de_FileSize = 0; 1149 } 1150 error = createde(fdep, tddep, (struct denode **) 0); 1151 if (fdep->de_Attributes & ATTR_DIRECTORY) { 1152 fdep->de_FileSize = dirsize; 1153 } 1154 if (error) { 1155 /* should put back filename */ 1156 VOP_UNLOCK(ap->a_fvp); 1157 goto bad; 1158 } 1159 VOP_LOCK(ap->a_fdvp); 1160 error = readep(fddep->de_pmp, fddep->de_fndclust, 1161 fddep->de_fndoffset, &bp, &ep); 1162 if (error) { 1163 VOP_UNLOCK(ap->a_fvp); 1164 VOP_UNLOCK(ap->a_fdvp); 1165 goto bad; 1166 } 1167 ep->deName[0] = SLOT_DELETED; 1168 error = bwrite(bp); 1169 if (error) { 1170 VOP_UNLOCK(ap->a_fvp); 1171 VOP_UNLOCK(ap->a_fdvp); 1172 goto bad; 1173 } 1174 if (!sourceisadirectory) { 1175 fdep->de_dirclust = tddep->de_fndclust; 1176 fdep->de_diroffset = tddep->de_fndoffset; 1177 reinsert(fdep); 1178 } 1179 VOP_UNLOCK(ap->a_fdvp); 1180 } 1181 /* fdep is still locked here */ 1182 1183 /* 1184 * If we moved a directory to a new parent directory, then we must 1185 * fixup the ".." entry in the moved directory. 1186 */ 1187 if (sourceisadirectory && newparent) { 1188 cn = fdep->de_StartCluster; 1189 if (cn == MSDOSFSROOT) { 1190 /* this should never happen */ 1191 panic("msdosfs_rename(): updating .. in root directory?"); 1192 } else { 1193 bn = cntobn(pmp, cn); 1194 } 1195 error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster, 1196 NOCRED, &bp); 1197 if (error) { 1198 /* should really panic here, fs is corrupt */ 1199 VOP_UNLOCK(ap->a_fvp); 1200 goto bad; 1201 } 1202 dotdotp = (struct direntry *) bp->b_data + 1; 1203 putushort(dotdotp->deStartCluster, tddep->de_StartCluster); 1204 error = bwrite(bp); 1205 VOP_UNLOCK(ap->a_fvp); 1206 if (error) { 1207 /* should really panic here, fs is corrupt */ 1208 goto bad; 1209 } 1210 } else 1211 VOP_UNLOCK(ap->a_fvp); 1212 bad: ; 1213 vrele(DETOV(fdep)); 1214 vrele(DETOV(fddep)); 1215 if (tdep) 1216 vput(DETOV(tdep)); 1217 if (tddep) 1218 vput(DETOV(tddep)); 1219 return error; 1220 } 1221 1222 struct { 1223 struct direntry dot; 1224 struct direntry dotdot; 1225 } dosdirtemplate = { 1226 { 1227 ". ", " ", /* the . entry */ 1228 ATTR_DIRECTORY, /* file attribute */ 1229 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* resevered */ 1230 {210, 4}, {210, 4}, /* time and date */ 1231 {0, 0}, /* startcluster */ 1232 {0, 0, 0, 0}, /* filesize */ 1233 },{ 1234 ".. ", " ", /* the .. entry */ 1235 ATTR_DIRECTORY, /* file attribute */ 1236 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* resevered */ 1237 {210, 4}, {210, 4}, /* time and date */ 1238 {0, 0}, /* startcluster */ 1239 {0, 0, 0, 0}, /* filesize */ 1240 } 1241 }; 1242 1243 int 1244 msdosfs_mkdir(ap) 1245 struct vop_mkdir_args /* { 1246 struct vnode *a_dvp; 1247 struvt vnode **a_vpp; 1248 struvt componentname *a_cnp; 1249 struct vattr *a_vap; 1250 } */ *ap; 1251 { 1252 int bn; 1253 int error; 1254 u_long newcluster; 1255 struct denode *pdep; 1256 struct denode *ndep; 1257 struct direntry *denp; 1258 struct denode ndirent; 1259 struct msdosfsmount *pmp; 1260 struct buf *bp; 1261 struct timespec ts; 1262 u_short dDate, dTime; 1263 1264 pdep = VTODE(ap->a_dvp); 1265 1266 /* 1267 * If this is the root directory and there is no space left we 1268 * can't do anything. This is because the root directory can not 1269 * change size. 1270 */ 1271 if (pdep->de_StartCluster == MSDOSFSROOT && pdep->de_fndclust == (u_long)-1) { 1272 free(ap->a_cnp->cn_pnbuf, M_NAMEI); 1273 vput(ap->a_dvp); 1274 return ENOSPC; 1275 } 1276 1277 pmp = pdep->de_pmp; 1278 1279 /* 1280 * Allocate a cluster to hold the about to be created directory. 1281 */ 1282 error = clusteralloc(pmp, 0, 1, CLUST_EOFE, &newcluster, NULL); 1283 if (error) { 1284 free(ap->a_cnp->cn_pnbuf, M_NAMEI); 1285 vput(ap->a_dvp); 1286 return error; 1287 } 1288 1289 /* 1290 * Now fill the cluster with the "." and ".." entries. And write 1291 * the cluster to disk. This way it is there for the parent 1292 * directory to be pointing at if there were a crash. 1293 */ 1294 bn = cntobn(pmp, newcluster); 1295 /* always succeeds */ 1296 bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0); 1297 bzero(bp->b_data, pmp->pm_bpcluster); 1298 bcopy(&dosdirtemplate, bp->b_data, sizeof dosdirtemplate); 1299 denp = (struct direntry *) bp->b_data; 1300 putushort(denp->deStartCluster, newcluster); 1301 TIMEVAL_TO_TIMESPEC(&time, &ts); 1302 unix2dostime(&ts, &dDate, &dTime); 1303 putushort(denp->deDate, dDate); 1304 putushort(denp->deTime, dTime); 1305 denp++; 1306 putushort(denp->deStartCluster, pdep->de_StartCluster); 1307 putushort(denp->deDate, dDate); 1308 putushort(denp->deTime, dTime); 1309 error = bwrite(bp); 1310 if (error) { 1311 clusterfree(pmp, newcluster, NULL); 1312 free(ap->a_cnp->cn_pnbuf, M_NAMEI); 1313 vput(ap->a_dvp); 1314 return error; 1315 } 1316 1317 /* 1318 * Now build up a directory entry pointing to the newly allocated 1319 * cluster. This will be written to an empty slot in the parent 1320 * directory. 1321 */ 1322 ndep = &ndirent; 1323 bzero(ndep, sizeof(*ndep)); 1324 unix2dosfn((u_char *)ap->a_cnp->cn_nameptr, 1325 ndep->de_Name, ap->a_cnp->cn_namelen); 1326 TIMEVAL_TO_TIMESPEC(&time, &ts); 1327 unix2dostime(&ts, &ndep->de_Date, &ndep->de_Time); 1328 ndep->de_StartCluster = newcluster; 1329 ndep->de_Attributes = ATTR_DIRECTORY; 1330 1331 error = createde(ndep, pdep, &ndep); 1332 if (error) { 1333 clusterfree(pmp, newcluster, NULL); 1334 } else { 1335 *ap->a_vpp = DETOV(ndep); 1336 } 1337 free(ap->a_cnp->cn_pnbuf, M_NAMEI); 1338 #ifdef MSDOSFS_DEBUG 1339 printf("msdosfs_mkdir(): vput(%08x)\n", ap->a_dvp); 1340 #endif 1341 vput(ap->a_dvp); 1342 return error; 1343 } 1344 1345 int 1346 msdosfs_rmdir(ap) 1347 struct vop_rmdir_args /* { 1348 struct vnode *a_dvp; 1349 struct vnode *a_vp; 1350 struct componentname *a_cnp; 1351 } */ *ap; 1352 { 1353 struct denode *ddep; 1354 struct denode *dep; 1355 int error = 0; 1356 1357 ddep = VTODE(ap->a_dvp); /* parent dir of dir to delete */ 1358 dep = VTODE(ap->a_vp);/* directory to delete */ 1359 1360 /* 1361 * Don't let "rmdir ." go thru. 1362 */ 1363 if (ddep == dep) { 1364 vrele(ap->a_vp); 1365 vput(ap->a_vp); 1366 return EINVAL; 1367 } 1368 1369 /* 1370 * Be sure the directory being deleted is empty. 1371 */ 1372 if (dosdirempty(dep) == 0) { 1373 error = ENOTEMPTY; 1374 goto out; 1375 } 1376 1377 /* 1378 * Delete the entry from the directory. For dos filesystems this 1379 * gets rid of the directory entry on disk, the in memory copy 1380 * still exists but the de_refcnt is <= 0. This prevents it from 1381 * being found by deget(). When the vput() on dep is done we give 1382 * up access and eventually msdosfs_reclaim() will be called which 1383 * will remove it from the denode cache. 1384 */ 1385 error = removede(ddep,dep); 1386 if (error) 1387 goto out; 1388 1389 /* 1390 * This is where we decrement the link count in the parent 1391 * directory. Since dos filesystems don't do this we just purge 1392 * the name cache and let go of the parent directory denode. 1393 */ 1394 cache_purge(DETOV(ddep)); 1395 vput(ap->a_dvp); 1396 ap->a_dvp = NULL; 1397 1398 /* 1399 * Truncate the directory that is being deleted. 1400 */ 1401 error = detrunc(dep, (u_long) 0, IO_SYNC, NOCRED, NULL); 1402 cache_purge(DETOV(dep)); 1403 1404 out: ; 1405 if (ap->a_dvp) 1406 vput(ap->a_dvp); 1407 vput(ap->a_vp); 1408 return error; 1409 } 1410 1411 /* 1412 * DOS filesystems don't know what symlinks are. 1413 */ 1414 int 1415 msdosfs_symlink(ap) 1416 struct vop_symlink_args /* { 1417 struct vnode *a_dvp; 1418 struct vnode **a_vpp; 1419 struct componentname *a_cnp; 1420 struct vattr *a_vap; 1421 char *a_target; 1422 } */ *ap; 1423 { 1424 free(ap->a_cnp->cn_pnbuf, M_NAMEI); 1425 vput(ap->a_dvp); 1426 return EINVAL; 1427 } 1428 1429 /* 1430 * Dummy dirents to simulate the "." and ".." entries of the root directory 1431 * in a dos filesystem. Dos doesn't provide these. Note that each entry 1432 * must be the same size as a dos directory entry (32 bytes). 1433 */ 1434 struct dos_dirent { 1435 u_long d_fileno; 1436 u_short d_reclen; 1437 u_char d_type; 1438 u_char d_namlen; 1439 u_char d_name[24]; 1440 } rootdots[2] = { 1441 1442 { 1443 1, /* d_fileno */ 1444 sizeof(struct direntry), /* d_reclen */ 1445 DT_DIR, /* d_type */ 1446 1, /* d_namlen */ 1447 "." /* d_name */ 1448 }, 1449 { 1450 1, /* d_fileno */ 1451 sizeof(struct direntry), /* d_reclen */ 1452 DT_DIR, /* d_type */ 1453 2, /* d_namlen */ 1454 ".." /* d_name */ 1455 } 1456 }; 1457 1458 int 1459 msdosfs_readdir(ap) 1460 struct vop_readdir_args /* { 1461 struct vnode *a_vp; 1462 struct uio *a_uio; 1463 struct ucred *a_cred; 1464 int *a_eofflag; 1465 u_int *a_cookies; 1466 int a_ncookies; 1467 } */ *ap; 1468 { 1469 int error = 0; 1470 int diff; 1471 char pushout; 1472 long n; 1473 long on; 1474 long lost; 1475 long count; 1476 u_long cn; 1477 u_long fileno; 1478 long bias = 0; 1479 daddr_t bn; 1480 daddr_t lbn; 1481 struct buf *bp; 1482 struct denode *dep = VTODE(ap->a_vp); 1483 struct msdosfsmount *pmp = dep->de_pmp; 1484 struct direntry *dentp; 1485 struct dirent *prev; 1486 struct dirent *crnt; 1487 u_char dirbuf[512]; /* holds converted dos directories */ 1488 struct uio *uio = ap->a_uio; 1489 off_t off; 1490 int ncookies = 0; 1491 1492 #ifdef MSDOSFS_DEBUG 1493 printf("msdosfs_readdir(): vp %08x, uio %08x, cred %08x, eofflagp %08x\n", 1494 ap->a_vp, uio, ap->a_cred, ap->a_eofflag); 1495 #endif 1496 1497 /* 1498 * msdosfs_readdir() won't operate properly on regular files since 1499 * it does i/o only with the the filesystem vnode, and hence can 1500 * retrieve the wrong block from the buffer cache for a plain file. 1501 * So, fail attempts to readdir() on a plain file. 1502 */ 1503 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0) 1504 return ENOTDIR; 1505 1506 /* 1507 * If the user buffer is smaller than the size of one dos directory 1508 * entry or the file offset is not a multiple of the size of a 1509 * directory entry, then we fail the read. 1510 */ 1511 count = uio->uio_resid & ~(sizeof(struct direntry) - 1); 1512 lost = uio->uio_resid - count; 1513 if (count < sizeof(struct direntry) || 1514 (uio->uio_offset & (sizeof(struct direntry) - 1))) 1515 return EINVAL; 1516 uio->uio_resid = count; 1517 uio->uio_iov->iov_len = count; 1518 off = uio->uio_offset; 1519 1520 /* 1521 * If they are reading from the root directory then, we simulate 1522 * the . and .. entries since these don't exist in the root 1523 * directory. We also set the offset bias to make up for having to 1524 * simulate these entries. By this I mean that at file offset 64 we 1525 * read the first entry in the root directory that lives on disk. 1526 */ 1527 if (dep->de_StartCluster == MSDOSFSROOT) { 1528 /* 1529 * printf("msdosfs_readdir(): going after . or .. in root dir, offset %d\n", 1530 * uio->uio_offset); 1531 */ 1532 bias = 2 * sizeof(struct direntry); 1533 if (uio->uio_offset < 2 * sizeof(struct direntry)) { 1534 if (uio->uio_offset 1535 && uio->uio_offset != sizeof(struct direntry)) { 1536 error = EINVAL; 1537 goto out; 1538 } 1539 n = 1; 1540 if (!uio->uio_offset) { 1541 n = 2; 1542 ncookies++; 1543 } 1544 ncookies++; 1545 error = uiomove((char *) rootdots + uio->uio_offset, 1546 n * sizeof(struct direntry), uio); 1547 } 1548 } 1549 while (!error && uio->uio_resid > 0) { 1550 lbn = (uio->uio_offset - bias) >> pmp->pm_cnshift; 1551 on = (uio->uio_offset - bias) & pmp->pm_crbomask; 1552 n = min((u_long) (pmp->pm_bpcluster - on), uio->uio_resid); 1553 diff = dep->de_FileSize - (uio->uio_offset - bias); 1554 if (diff <= 0) { 1555 if(ap->a_eofflag) 1556 *ap->a_eofflag = 1; 1557 if(ap->a_ncookies != NULL) { 1558 u_int *cookies; 1559 1560 MALLOC(cookies, u_int *, 1 * sizeof(u_int), 1561 M_TEMP, M_WAITOK); 1562 *ap->a_ncookies = 0; 1563 *ap->a_cookies = cookies; 1564 } 1565 return 0; 1566 } 1567 if (diff < n) 1568 n = diff; 1569 error = pcbmap(dep, lbn, &bn, &cn); 1570 if (error) 1571 break; 1572 error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster, NOCRED, &bp); 1573 n = min(n, pmp->pm_bpcluster - bp->b_resid); 1574 if (error) { 1575 brelse(bp); 1576 return error; 1577 } 1578 1579 /* 1580 * code to convert from dos directory entries to ufs 1581 * directory entries 1582 */ 1583 pushout = 0; 1584 dentp = (struct direntry *)(bp->b_data + on); 1585 prev = 0; 1586 crnt = (struct dirent *) dirbuf; 1587 while ((char *) dentp < bp->b_data + on + n) { 1588 /* 1589 * printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n", 1590 * dentp, prev, crnt, dentp->deName[0], dentp->deAttributes); 1591 */ 1592 /* 1593 * If we have an empty entry or a slot from a 1594 * deleted file, or a volume label entry just 1595 * concatenate its space onto the end of the 1596 * previous entry or, manufacture an empty entry if 1597 * there is no previous entry. 1598 */ 1599 if (dentp->deName[0] == SLOT_EMPTY || 1600 dentp->deName[0] == SLOT_DELETED || 1601 (dentp->deAttributes & ATTR_VOLUME)) { 1602 if (prev) { 1603 prev->d_reclen += sizeof(struct direntry); 1604 } else { 1605 prev = crnt; 1606 prev->d_fileno = 0; 1607 prev->d_reclen = sizeof(struct direntry); 1608 prev->d_type = DT_UNKNOWN; 1609 prev->d_namlen = 0; 1610 prev->d_name[0] = 0; 1611 ncookies++; 1612 } 1613 } else { 1614 /* 1615 * this computation of d_fileno must match 1616 * the computation of va_fileid in 1617 * msdosfs_getattr 1618 */ 1619 if (dentp->deAttributes & ATTR_DIRECTORY) { 1620 /* if this is the root directory */ 1621 fileno = getushort(dentp->deStartCluster); 1622 if (fileno == MSDOSFSROOT) 1623 fileno = 1; 1624 } else { 1625 /* 1626 * if the file's dirent lives in 1627 * root dir 1628 */ 1629 if ((fileno = cn) == MSDOSFSROOT) 1630 fileno = 1; 1631 fileno = (fileno << 16) | 1632 ((dentp - (struct direntry *) bp->b_data) & 0xffff); 1633 } 1634 crnt->d_fileno = fileno; 1635 crnt->d_reclen = sizeof(struct direntry); 1636 crnt->d_type = (dentp->deAttributes & ATTR_DIRECTORY) 1637 ? DT_DIR : DT_REG; 1638 crnt->d_namlen = dos2unixfn(dentp->deName, 1639 (u_char *)crnt->d_name); 1640 /* 1641 * printf("readdir: file %s, fileno %08x, attr %02x, start %08x\n", 1642 * crnt->d_name, crnt->d_fileno, dentp->deAttributes, 1643 * dentp->deStartCluster); 1644 */ 1645 prev = crnt; 1646 ncookies++; 1647 } 1648 dentp++; 1649 1650 crnt = (struct dirent *) ((char *) crnt + sizeof(struct direntry)); 1651 pushout = 1; 1652 1653 /* 1654 * If our intermediate buffer is full then copy its 1655 * contents to user space. I would just use the 1656 * buffer the buf header points to but, I'm afraid 1657 * that when we brelse() it someone else might find 1658 * it in the cache and think its contents are 1659 * valid. Maybe there is a way to invalidate the 1660 * buffer before brelse()'ing it. 1661 */ 1662 if ((u_char *) crnt >= &dirbuf[sizeof dirbuf]) { 1663 pushout = 0; 1664 error = uiomove(dirbuf, sizeof(dirbuf), uio); 1665 if (error) 1666 break; 1667 prev = 0; 1668 crnt = (struct dirent *) dirbuf; 1669 } 1670 } 1671 if (pushout) { 1672 pushout = 0; 1673 error = uiomove(dirbuf, (char *) crnt - (char *) dirbuf, 1674 uio); 1675 } 1676 1677 #if 0 1678 /* 1679 * If we have read everything from this block or have read 1680 * to end of file then we are done with this block. Mark 1681 * it to say the buffer can be reused if need be. 1682 */ 1683 if (n + on == pmp->pm_bpcluster || 1684 (uio->uio_offset - bias) == dep->de_FileSize) 1685 bp->b_flags |= B_AGE; 1686 #endif /* if 0 */ 1687 brelse(bp); 1688 if (n == 0) 1689 break; 1690 } 1691 out: ; 1692 uio->uio_resid += lost; 1693 if (!error && ap->a_ncookies != NULL) { 1694 struct dirent* dpStart; 1695 struct dirent* dpEnd; 1696 struct dirent* dp; 1697 u_int *cookies; 1698 u_int *cookiep; 1699 1700 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) 1701 panic("msdosfs_readdir: unexpected uio from NFS server"); 1702 dpStart = (struct dirent *) 1703 (uio->uio_iov->iov_base - (uio->uio_offset - off)); 1704 dpEnd = (struct dirent *) uio->uio_iov->iov_base; 1705 MALLOC(cookies, u_int *, ncookies * sizeof(u_int), 1706 M_TEMP, M_WAITOK); 1707 for (dp = dpStart, cookiep = cookies; 1708 dp < dpEnd; 1709 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen)) { 1710 off += dp->d_reclen; 1711 *cookiep++ = (u_int) off; 1712 } 1713 *ap->a_ncookies = ncookies; 1714 *ap->a_cookies = cookies; 1715 } 1716 1717 /* 1718 * Set the eofflag (NFS uses it) 1719 */ 1720 if (ap->a_eofflag) 1721 if (dep->de_FileSize - (uio->uio_offset - bias) <= 0) 1722 *ap->a_eofflag = 1; 1723 else 1724 *ap->a_eofflag = 0; 1725 1726 return error; 1727 } 1728 1729 /* 1730 * DOS filesystems don't know what symlinks are. 1731 */ 1732 int 1733 msdosfs_readlink(ap) 1734 struct vop_readlink_args /* { 1735 struct vnode *a_vp; 1736 struct uio *a_uio; 1737 struct ucred *a_cred; 1738 } */ *ap; 1739 { 1740 return EINVAL; 1741 } 1742 1743 int 1744 msdosfs_abortop(ap) 1745 struct vop_abortop_args /* { 1746 struct vnode *a_dvp; 1747 struct componentname *a_cnp; 1748 } */ *ap; 1749 { 1750 if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF) 1751 FREE(ap->a_cnp->cn_pnbuf, M_NAMEI); 1752 return 0; 1753 } 1754 1755 int 1756 msdosfs_lock(ap) 1757 struct vop_lock_args /* { 1758 struct vnode *a_vp; 1759 } */ *ap; 1760 { 1761 struct denode *dep = VTODE(ap->a_vp); 1762 1763 while (dep->de_flag & DE_LOCKED) { 1764 dep->de_flag |= DE_WANTED; 1765 if (dep->de_lockholder == curproc->p_pid) 1766 panic("msdosfs_lock: locking against myself"); 1767 dep->de_lockwaiter = curproc->p_pid; 1768 (void) tsleep((caddr_t) dep, PINOD, "msdlck", 0); 1769 } 1770 dep->de_lockwaiter = 0; 1771 dep->de_lockholder = curproc->p_pid; 1772 dep->de_flag |= DE_LOCKED; 1773 return 0; 1774 } 1775 1776 int 1777 msdosfs_unlock(ap) 1778 struct vop_unlock_args /* { 1779 struct vnode *vp; 1780 } */ *ap; 1781 { 1782 struct denode *dep = VTODE(ap->a_vp); 1783 1784 if (!(dep->de_flag & DE_LOCKED)) 1785 panic("msdosfs_unlock: denode not locked"); 1786 dep->de_lockholder = 0; 1787 dep->de_flag &= ~DE_LOCKED; 1788 if (dep->de_flag & DE_WANTED) { 1789 dep->de_flag &= ~DE_WANTED; 1790 wakeup((caddr_t) dep); 1791 } 1792 return 0; 1793 } 1794 1795 int 1796 msdosfs_islocked(ap) 1797 struct vop_islocked_args /* { 1798 struct vnode *a_vp; 1799 } */ *ap; 1800 { 1801 return VTODE(ap->a_vp)->de_flag & DE_LOCKED ? 1 : 0; 1802 } 1803 1804 /* 1805 * vp - address of vnode file the file 1806 * bn - which cluster we are interested in mapping to a filesystem block number. 1807 * vpp - returns the vnode for the block special file holding the filesystem 1808 * containing the file of interest 1809 * bnp - address of where to return the filesystem relative block number 1810 */ 1811 int 1812 msdosfs_bmap(ap) 1813 struct vop_bmap_args /* { 1814 struct vnode *a_vp; 1815 daddr_t a_bn; 1816 struct vnode **a_vpp; 1817 daddr_t *a_bnp; 1818 int *a_runp; 1819 } */ *ap; 1820 { 1821 struct denode *dep = VTODE(ap->a_vp); 1822 1823 if (ap->a_vpp != NULL) 1824 *ap->a_vpp = dep->de_devvp; 1825 if (ap->a_bnp == NULL) 1826 return 0; 1827 if (ap->a_runp) { 1828 /* 1829 * Sequential clusters should be counted here. 1830 */ 1831 *ap->a_runp = 0; 1832 } 1833 return pcbmap(dep, ap->a_bn, ap->a_bnp, 0); 1834 } 1835 1836 int msdosfs_reallocblks(ap) 1837 struct vop_reallocblks_args /* { 1838 struct vnode *a_vp; 1839 struct cluster_save *a_buflist; 1840 } */ *ap; 1841 { 1842 /* Currently no support for clustering */ /* XXX */ 1843 return ENOSPC; 1844 } 1845 1846 int 1847 msdosfs_strategy(ap) 1848 struct vop_strategy_args /* { 1849 struct buf *a_bp; 1850 } */ *ap; 1851 { 1852 struct buf *bp = ap->a_bp; 1853 struct denode *dep = VTODE(bp->b_vp); 1854 struct vnode *vp; 1855 int error = 0; 1856 1857 if (bp->b_vp->v_type == VBLK || bp->b_vp->v_type == VCHR) 1858 panic("msdosfs_strategy: spec"); 1859 /* 1860 * If we don't already know the filesystem relative block number 1861 * then get it using pcbmap(). If pcbmap() returns the block 1862 * number as -1 then we've got a hole in the file. DOS filesystems 1863 * don't allow files with holes, so we shouldn't ever see this. 1864 */ 1865 if (bp->b_blkno == bp->b_lblkno) { 1866 error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno, 0); 1867 if (error) 1868 bp->b_blkno = -1; 1869 if (bp->b_blkno == -1) 1870 clrbuf(bp); 1871 } 1872 if (bp->b_blkno == -1) { 1873 biodone(bp); 1874 return error; 1875 } 1876 #ifdef DIAGNOSTIC 1877 #endif 1878 /* 1879 * Read/write the block from/to the disk that contains the desired 1880 * file block. 1881 */ 1882 vp = dep->de_devvp; 1883 bp->b_dev = vp->v_rdev; 1884 VOCALL(vp->v_op, VOFFSET(vop_strategy), ap); 1885 return 0; 1886 } 1887 1888 int 1889 msdosfs_print(ap) 1890 struct vop_print_args /* { 1891 struct vnode *vp; 1892 } */ *ap; 1893 { 1894 struct denode *dep = VTODE(ap->a_vp); 1895 1896 printf( 1897 "tag VT_MSDOSFS, startcluster %d, dircluster %ld, diroffset %ld ", 1898 dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset); 1899 printf(" dev %d, %d, %s\n", 1900 major(dep->de_dev), minor(dep->de_dev), 1901 dep->de_flag & DE_LOCKED ? "(LOCKED)" : ""); 1902 if (dep->de_lockholder) { 1903 printf(" owner pid %d", (int)dep->de_lockholder); 1904 if (dep->de_lockwaiter) 1905 printf(" waiting pid %d", (int)dep->de_lockwaiter); 1906 printf("\n"); 1907 } 1908 return 0; 1909 } 1910 1911 int 1912 msdosfs_advlock(ap) 1913 struct vop_advlock_args /* { 1914 struct vnode *a_vp; 1915 caddr_t a_id; 1916 int a_op; 1917 struct flock *a_fl; 1918 int a_flags; 1919 } */ *ap; 1920 { 1921 return EINVAL; /* we don't do locking yet */ 1922 } 1923 1924 int 1925 msdosfs_pathconf(ap) 1926 struct vop_pathconf_args /* { 1927 struct vnode *a_vp; 1928 int a_name; 1929 int *a_retval; 1930 } */ *ap; 1931 { 1932 switch (ap->a_name) { 1933 case _PC_LINK_MAX: 1934 *ap->a_retval = 1; 1935 return 0; 1936 case _PC_NAME_MAX: 1937 *ap->a_retval = 12; 1938 return 0; 1939 case _PC_PATH_MAX: 1940 *ap->a_retval = PATH_MAX; /* 255? */ 1941 return 0; 1942 case _PC_CHOWN_RESTRICTED: 1943 *ap->a_retval = 1; 1944 return 0; 1945 case _PC_NO_TRUNC: 1946 *ap->a_retval = 0; 1947 return 0; 1948 default: 1949 return EINVAL; 1950 } 1951 } 1952 1953 /* Global vfs data structures for msdosfs */ 1954 int (**msdosfs_vnodeop_p)(); 1955 struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = { 1956 { &vop_default_desc, vn_default_error }, 1957 { &vop_lookup_desc, msdosfs_lookup }, /* lookup */ 1958 { &vop_create_desc, msdosfs_create }, /* create */ 1959 { &vop_mknod_desc, msdosfs_mknod }, /* mknod */ 1960 { &vop_open_desc, msdosfs_open }, /* open */ 1961 { &vop_close_desc, msdosfs_close }, /* close */ 1962 { &vop_access_desc, msdosfs_access }, /* access */ 1963 { &vop_getattr_desc, msdosfs_getattr }, /* getattr */ 1964 { &vop_setattr_desc, msdosfs_setattr }, /* setattr */ 1965 { &vop_read_desc, msdosfs_read }, /* read */ 1966 { &vop_write_desc, msdosfs_write }, /* write */ 1967 { &vop_ioctl_desc, msdosfs_ioctl }, /* ioctl */ 1968 { &vop_select_desc, msdosfs_select }, /* select */ 1969 { &vop_mmap_desc, msdosfs_mmap }, /* mmap */ 1970 { &vop_fsync_desc, msdosfs_fsync }, /* fsync */ 1971 { &vop_seek_desc, msdosfs_seek }, /* seek */ 1972 { &vop_remove_desc, msdosfs_remove }, /* remove */ 1973 { &vop_link_desc, msdosfs_link }, /* link */ 1974 { &vop_rename_desc, msdosfs_rename }, /* rename */ 1975 { &vop_mkdir_desc, msdosfs_mkdir }, /* mkdir */ 1976 { &vop_rmdir_desc, msdosfs_rmdir }, /* rmdir */ 1977 { &vop_symlink_desc, msdosfs_symlink }, /* symlink */ 1978 { &vop_readdir_desc, msdosfs_readdir }, /* readdir */ 1979 { &vop_readlink_desc, msdosfs_readlink }, /* readlink */ 1980 { &vop_abortop_desc, msdosfs_abortop }, /* abortop */ 1981 { &vop_inactive_desc, msdosfs_inactive }, /* inactive */ 1982 { &vop_reclaim_desc, msdosfs_reclaim }, /* reclaim */ 1983 { &vop_lock_desc, msdosfs_lock }, /* lock */ 1984 { &vop_unlock_desc, msdosfs_unlock }, /* unlock */ 1985 { &vop_bmap_desc, msdosfs_bmap }, /* bmap */ 1986 { &vop_strategy_desc, msdosfs_strategy }, /* strategy */ 1987 { &vop_print_desc, msdosfs_print }, /* print */ 1988 { &vop_islocked_desc, msdosfs_islocked }, /* islocked */ 1989 { &vop_pathconf_desc, msdosfs_pathconf }, /* pathconf */ 1990 { &vop_advlock_desc, msdosfs_advlock }, /* advlock */ 1991 { &vop_reallocblks_desc, msdosfs_reallocblks }, /* reallocblks */ 1992 { &vop_bwrite_desc, vn_bwrite }, 1993 { (struct vnodeop_desc *)NULL, (int (*)())NULL } 1994 }; 1995 struct vnodeopv_desc msdosfs_vnodeop_opv_desc = 1996 { &msdosfs_vnodeop_p, msdosfs_vnodeop_entries }; 1997 1998 VNODEOP_SET(msdosfs_vnodeop_opv_desc); 1999