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