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