]>
git.saurik.com Git - apple/xnu.git/blob - bsd/ufs/ffs/ffs_vfsops.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
27 * Copyright (c) 1989, 1991, 1993, 1994
28 * The Regents of the University of California. All rights reserved.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * @(#)ffs_vfsops.c 8.31 (Berkeley) 5/20/95
61 #include <rev_endian_fs.h>
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/namei.h>
66 #include <sys/kernel.h>
67 #include <sys/vnode.h>
68 #include <sys/socket.h>
69 #include <sys/mount.h>
74 #include <sys/ioctl.h>
75 #include <sys/errno.h>
76 #include <sys/malloc.h>
78 #include <sys/quota.h>
80 #include <miscfs/specfs/specdev.h>
82 #include <ufs/ufs/quota.h>
83 #include <ufs/ufs/ufsmount.h>
84 #include <ufs/ufs/inode.h>
85 #include <ufs/ufs/ufs_extern.h>
87 #include <ufs/ffs/fs.h>
88 #include <ufs/ffs/ffs_extern.h>
90 #include <ufs/ufs/ufs_byte_order.h>
91 #include <architecture/byte_order.h>
92 #endif /* REV_ENDIAN_FS */
94 int ffs_sbupdate
__P((struct ufsmount
*, int));
96 struct vfsops ufs_vfsops
= {
111 extern u_long nextgennumber
;
114 * Called by main() when ufs is going to be mounted as root.
118 extern struct vnode
*rootvp
;
121 struct proc
*p
= current_proc(); /* XXX */
122 struct ufsmount
*ump
;
127 * Get vnode for rootdev.
129 if (error
= bdevvp(rootdev
, &rootvp
)) {
130 printf("ffs_mountroot: can't setup bdevvp");
133 if (error
= vfs_rootmountalloc("ufs", "root_device", &mp
)) {
134 vrele(rootvp
); /* release the reference from bdevvp() */
138 /* Must set the MNT_ROOTFS flag before doing the actual mount */
139 mp
->mnt_flag
|= MNT_ROOTFS
;
141 if (error
= ffs_mountfs(rootvp
, mp
, p
)) {
142 mp
->mnt_vfc
->vfc_refcount
--;
144 vrele(rootvp
); /* release the reference from bdevvp() */
145 _FREE_ZONE(mp
, sizeof (struct mount
), M_MOUNT
);
148 simple_lock(&mountlist_slock
);
149 CIRCLEQ_INSERT_TAIL(&mountlist
, mp
, mnt_list
);
150 simple_unlock(&mountlist_slock
);
153 (void) copystr(mp
->mnt_stat
.f_mntonname
, fs
->fs_fsmnt
, MNAMELEN
- 1, 0);
154 (void)ffs_statfs(mp
, &mp
->mnt_stat
, p
);
156 inittodr(fs
->fs_time
);
166 ffs_mount(mp
, path
, data
, ndp
, p
)
167 register struct mount
*mp
;
170 struct nameidata
*ndp
;
174 struct ufs_args args
;
175 struct ufsmount
*ump
;
176 register struct fs
*fs
;
183 if (error
= copyin(data
, (caddr_t
)&args
, sizeof (struct ufs_args
)))
186 * If updating, check whether changing from read-only to
187 * read/write; if there is no device name, that's all we do.
189 if (mp
->mnt_flag
& MNT_UPDATE
) {
192 if (fs
->fs_ronly
== 0 && (mp
->mnt_flag
& MNT_RDONLY
)) {
194 if (mp
->mnt_flag
& MNT_FORCE
)
196 if (error
= ffs_flushfiles(mp
, flags
, p
))
200 if (error
= ffs_sbupdate(ump
, MNT_WAIT
)) {
206 /* save fs_ronly to later use */
207 ronly
= fs
->fs_ronly
;
208 if ((mp
->mnt_flag
& MNT_RELOAD
) || ronly
)
211 (error
= ffs_reload(mp
, ndp
->ni_cnd
.cn_cred
, p
)))
213 /* replace the ronly after load */
214 fs
->fs_ronly
= ronly
;
216 * Do not update the file system if the user was in singleuser
217 * and then tries to mount -uw without fscking
219 if (!fs
->fs_clean
&& ronly
) {
220 printf("WARNING: trying to mount a dirty file system\n");
221 if (issingleuser() && (mp
->mnt_flag
& MNT_ROOTFS
)) {
222 printf("WARNING: R/W mount of %s denied. Filesystem is not clean - run fsck\n",fs
->fs_fsmnt
);
224 * Reset the readonly bit as reload might have
232 if (ronly
&& (mp
->mnt_kern_flag
& MNTK_WANTRDWR
)) {
234 * If upgrade to read-write by non-root, then verify
235 * that user has necessary permissions on the device.
237 if (p
->p_ucred
->cr_uid
!= 0) {
238 devvp
= ump
->um_devvp
;
239 vn_lock(devvp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
240 if (error
= VOP_ACCESS(devvp
, VREAD
| VWRITE
,
242 VOP_UNLOCK(devvp
, 0, p
);
245 VOP_UNLOCK(devvp
, 0, p
);
249 (void) ffs_sbupdate(ump
, MNT_WAIT
);
251 if (args
.fspec
== 0) {
253 * Process export requests.
255 return (vfs_export(mp
, &ump
->um_export
, &args
.export
));
259 * Not an update, or updating the name: look up the name
260 * and verify that it refers to a sensible block device.
262 NDINIT(ndp
, LOOKUP
, FOLLOW
, UIO_USERSPACE
, args
.fspec
, p
);
263 if (error
= namei(ndp
))
267 if (devvp
->v_type
!= VBLK
) {
271 if (major(devvp
->v_rdev
) >= nblkdev
) {
276 * If mount by non-root, then verify that user has necessary
277 * permissions on the device.
279 if (p
->p_ucred
->cr_uid
!= 0) {
281 if ((mp
->mnt_flag
& MNT_RDONLY
) == 0)
282 accessmode
|= VWRITE
;
283 vn_lock(devvp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
284 if (error
= VOP_ACCESS(devvp
, accessmode
, p
->p_ucred
, p
)) {
288 VOP_UNLOCK(devvp
, 0, p
);
290 if ((mp
->mnt_flag
& MNT_UPDATE
) == 0)
291 error
= ffs_mountfs(devvp
, mp
, p
);
293 if (devvp
!= ump
->um_devvp
)
294 error
= EINVAL
; /* needs translation */
304 (void) copyinstr(path
, fs
->fs_fsmnt
, sizeof(fs
->fs_fsmnt
) - 1, &size
);
305 bzero(fs
->fs_fsmnt
+ size
, sizeof(fs
->fs_fsmnt
) - size
);
306 bcopy((caddr_t
)fs
->fs_fsmnt
, (caddr_t
)mp
->mnt_stat
.f_mntonname
,
308 (void) copyinstr(args
.fspec
, mp
->mnt_stat
.f_mntfromname
, MNAMELEN
- 1,
310 bzero(mp
->mnt_stat
.f_mntfromname
+ size
, MNAMELEN
- size
);
311 (void)ffs_statfs(mp
, &mp
->mnt_stat
, p
);
316 * Reload all incore data for a filesystem (used after running fsck on
317 * the root filesystem and finding things to fix). The filesystem must
318 * be mounted read-only.
320 * Things to do to update the mount:
321 * 1) invalidate all cached meta-data.
322 * 2) re-read superblock from disk.
323 * 3) re-read summary information from disk.
324 * 4) invalidate all inactive vnodes.
325 * 5) invalidate all cached file data.
326 * 6) re-read inode data for all active vnodes.
328 ffs_reload(mountp
, cred
, p
)
329 register struct mount
*mountp
;
333 register struct vnode
*vp
, *nvp
, *devvp
;
337 struct fs
*fs
, *newfs
;
338 int i
, blks
, size
, error
;
339 u_int64_t maxfilesize
; /* XXX */
342 int rev_endian
= (mountp
->mnt_flag
& MNT_REVEND
);
343 #endif /* REV_ENDIAN_FS */
345 if ((mountp
->mnt_flag
& MNT_RDONLY
) == 0)
348 * Step 1: invalidate all cached meta-data.
350 devvp
= VFSTOUFS(mountp
)->um_devvp
;
351 if (vinvalbuf(devvp
, 0, cred
, p
, 0, 0))
352 panic("ffs_reload: dirty1");
354 * Step 2: re-read superblock from disk.
356 VOP_DEVBLOCKSIZE(devvp
,&size
);
358 if (error
= bread(devvp
, (ufs_daddr_t
)(SBOFF
/size
), SBSIZE
, NOCRED
,&bp
)) {
362 newfs
= (struct fs
*)bp
->b_data
;
365 byte_swap_sbin(newfs
);
367 #endif /* REV_ENDIAN_FS */
368 if (newfs
->fs_magic
!= FS_MAGIC
|| newfs
->fs_bsize
> MAXBSIZE
||
369 newfs
->fs_bsize
< sizeof(struct fs
)) {
372 byte_swap_sbout(newfs
);
373 #endif /* REV_ENDIAN_FS */
376 return (EIO
); /* XXX needs translation */
378 fs
= VFSTOUFS(mountp
)->um_fs
;
380 * Copy pointer fields back into superblock before copying in XXX
381 * new superblock. These should really be in the ufsmount. XXX
382 * Note that important parameters (eg fs_ncg) are unchanged.
384 newfs
->fs_csp
= fs
->fs_csp
;
385 newfs
->fs_maxcluster
= fs
->fs_maxcluster
;
386 bcopy(newfs
, fs
, (u_int
)fs
->fs_sbsize
);
387 if (fs
->fs_sbsize
< SBSIZE
)
388 bp
->b_flags
|= B_INVAL
;
391 byte_swap_sbout(newfs
);
392 #endif /* REV_ENDIAN_FS */
394 mountp
->mnt_maxsymlinklen
= fs
->fs_maxsymlinklen
;
396 maxfilesize
= (u_int64_t
)0x100000000; /* 4GB */
397 if (fs
->fs_maxfilesize
> maxfilesize
) /* XXX */
398 fs
->fs_maxfilesize
= maxfilesize
; /* XXX */
400 * Step 3: re-read summary information from disk.
402 blks
= howmany(fs
->fs_cssize
, fs
->fs_fsize
);
404 for (i
= 0; i
< blks
; i
+= fs
->fs_frag
) {
406 if (i
+ fs
->fs_frag
> blks
)
407 size
= (blks
- i
) * fs
->fs_fsize
;
408 if (error
= bread(devvp
, fsbtodb(fs
, fs
->fs_csaddr
+ i
), size
,
416 byte_swap_ints((int *)bp
->b_data
, size
/ sizeof(int));
418 #endif /* REV_ENDIAN_FS */
419 bcopy(bp
->b_data
, space
, (u_int
)size
);
423 byte_swap_ints((int *)bp
->b_data
, size
/ sizeof(int));
425 #endif /* REV_ENDIAN_FS */
429 * We no longer know anything about clusters per cylinder group.
431 if (fs
->fs_contigsumsize
> 0) {
432 lp
= fs
->fs_maxcluster
;
433 for (i
= 0; i
< fs
->fs_ncg
; i
++)
434 *lp
++ = fs
->fs_contigsumsize
;
438 simple_lock(&mntvnode_slock
);
439 for (vp
= mountp
->mnt_vnodelist
.lh_first
; vp
!= NULL
; vp
= nvp
) {
440 if (vp
->v_mount
!= mountp
) {
441 simple_unlock(&mntvnode_slock
);
444 nvp
= vp
->v_mntvnodes
.le_next
;
446 * Step 4: invalidate all inactive vnodes.
448 if (vrecycle(vp
, &mntvnode_slock
, p
))
451 * Step 5: invalidate all cached file data.
453 simple_lock(&vp
->v_interlock
);
454 simple_unlock(&mntvnode_slock
);
455 if (vget(vp
, LK_EXCLUSIVE
| LK_INTERLOCK
, p
)) {
458 if (vinvalbuf(vp
, 0, cred
, p
, 0, 0))
459 panic("ffs_reload: dirty2");
461 * Step 6: re-read inode data for all active vnodes.
465 bread(devvp
, fsbtodb(fs
, ino_to_fsba(fs
, ip
->i_number
)),
466 (int)fs
->fs_bsize
, NOCRED
, &bp
)) {
473 byte_swap_inode_in(((struct dinode
*)bp
->b_data
+
474 ino_to_fsbo(fs
, ip
->i_number
)), ip
);
476 #endif /* REV_ENDIAN_FS */
477 ip
->i_din
= *((struct dinode
*)bp
->b_data
+
478 ino_to_fsbo(fs
, ip
->i_number
));
481 #endif /* REV_ENDIAN_FS */
484 simple_lock(&mntvnode_slock
);
486 simple_unlock(&mntvnode_slock
);
491 * Common code for mount and mountroot
494 ffs_mountfs(devvp
, mp
, p
)
495 register struct vnode
*devvp
;
499 register struct ufsmount
*ump
;
501 register struct fs
*fs
;
505 int32_t clustersumoff
;
507 int error
, i
, blks
, size
, ronly
;
510 extern struct vnode
*rootvp
;
511 u_int64_t maxfilesize
; /* XXX */
512 u_int dbsize
= DEV_BSIZE
;
515 #endif /* REV_ENDIAN_FS */
517 cred
= p
? p
->p_ucred
: NOCRED
;
519 * Disallow multiple mounts of the same device.
520 * Disallow mounting of a device that is currently in use
521 * (except for root, which might share swap device for miniroot).
522 * Flush out any old buffers remaining from a previous use.
524 if (error
= vfs_mountedon(devvp
))
526 if (vcount(devvp
) > 1 && devvp
!= rootvp
)
528 if (error
= vinvalbuf(devvp
, V_SAVE
, cred
, p
, 0, 0))
531 ronly
= (mp
->mnt_flag
& MNT_RDONLY
) != 0;
532 if (error
= VOP_OPEN(devvp
, ronly
? FREAD
: FREAD
|FWRITE
, FSCRED
, p
))
535 VOP_DEVBLOCKSIZE(devvp
,&size
);
539 if (error
= bread(devvp
, (ufs_daddr_t
)(SBOFF
/size
), SBSIZE
, cred
, &bp
))
541 fs
= (struct fs
*)bp
->b_data
;
543 if (fs
->fs_magic
!= FS_MAGIC
|| fs
->fs_bsize
> MAXBSIZE
||
544 fs
->fs_bsize
< sizeof(struct fs
)) {
545 int magic
= fs
->fs_magic
;
547 byte_swap_ints(&magic
, 1);
548 if (magic
!= FS_MAGIC
) {
553 if (fs
->fs_magic
!= FS_MAGIC
|| fs
->fs_bsize
> MAXBSIZE
||
554 fs
->fs_bsize
< sizeof(struct fs
)) {
556 error
= EINVAL
; /* XXX needs translation */
561 #endif /* REV_ENDIAN_FS */
562 if (fs
->fs_magic
!= FS_MAGIC
|| fs
->fs_bsize
> MAXBSIZE
||
563 fs
->fs_bsize
< sizeof(struct fs
)) {
567 #endif /* REV_ENDIAN_FS */
568 error
= EINVAL
; /* XXX needs translation */
574 * Buffer cache does not handle multiple pages in a buf when
575 * invalidating incore buffer in pageout. There are no locks
576 * in the pageout path. So there is a danger of loosing data when
577 * block allocation happens at the same time a pageout of buddy
578 * page occurs. incore() returns buf with both
579 * pages, this leads vnode-pageout to incorrectly flush of entire.
580 * buf. Till the low level ffs code is modified to deal with these
581 * do not mount any FS more than 4K size.
584 * Can't mount filesystems with a fragment size less than DIRBLKSIZ
587 * Don't mount dirty filesystems, except for the root filesystem
589 if ((fs
->fs_bsize
> PAGE_SIZE
) || (fs
->fs_fsize
< DIRBLKSIZ
) ||
590 ((!(mp
->mnt_flag
& MNT_ROOTFS
)) && (!fs
->fs_clean
))) {
594 #endif /* REV_ENDIAN_FS */
599 /* Let's figure out the devblock size the file system is with */
600 /* the device block size = fragment size / number of sectors per frag */
602 dbsize
= fs
->fs_fsize
/ NSPF(fs
);
604 kprintf("device blocksize computaion failed\n");
606 if (VOP_IOCTL(devvp
, DKIOCSETBLOCKSIZE
, &dbsize
, FWRITE
, NOCRED
,
608 kprintf("failed to set device blocksize\n");
610 /* force the specfs to reread blocksize from size() */
611 set_fsblocksize(devvp
);
614 /* cache the IO attributes */
615 error
= vfs_init_io_attributes(devvp
, mp
);
617 printf("ffs_mountfs: vfs_init_io_attributes returned %d\n",
622 /* XXX updating 4.2 FFS superblocks trashes rotational layout tables */
623 if (fs
->fs_postblformat
== FS_42POSTBLFMT
&& !ronly
) {
627 #endif /* REV_ENDIAN_FS */
628 error
= EROFS
; /* needs translation */
632 /* If we are not mounting read only, then check for overlap
633 * condition in cylinder group's free block map.
634 * If overlap exists, then force this into a read only mount
635 * to avoid further corruption. PR#2216969
638 if (error
= bread (devvp
, fsbtodb(fs
, cgtod(fs
, 0)),
639 (int)fs
->fs_cgsize
, NOCRED
, &cgbp
)) {
643 cgp
= (struct cg
*)cgbp
->b_data
;
646 byte_swap_cgin(cgp
,fs
);
647 #endif /* REV_ENDIAN_FS */
648 if (!cg_chkmagic(cgp
)){
651 byte_swap_cgout(cgp
,fs
);
652 #endif /* REV_ENDIAN_FS */
656 if (cgp
->cg_clustersumoff
!= 0) {
657 /* Check for overlap */
658 clustersumoff
= cgp
->cg_freeoff
+
659 howmany(fs
->fs_cpg
* fs
->fs_spc
/ NSPF(fs
), NBBY
);
660 clustersumoff
= roundup(clustersumoff
, sizeof(long));
661 if (cgp
->cg_clustersumoff
< clustersumoff
) {
663 mp
->mnt_flag
|= MNT_RDONLY
;
669 byte_swap_cgout(cgp
,fs
);
670 #endif /* REV_ENDIAN_FS */
674 ump
= _MALLOC(sizeof *ump
, M_UFSMNT
, M_WAITOK
);
675 bzero((caddr_t
)ump
, sizeof *ump
);
676 ump
->um_fs
= _MALLOC((u_long
)fs
->fs_sbsize
, M_UFSMNT
,
678 bcopy(bp
->b_data
, ump
->um_fs
, (u_int
)fs
->fs_sbsize
);
679 if (fs
->fs_sbsize
< SBSIZE
)
680 bp
->b_flags
|= B_INVAL
;
684 #endif /* REV_ENDIAN_FS */
688 fs
->fs_ronly
= ronly
;
689 size
= fs
->fs_cssize
;
690 blks
= howmany(size
, fs
->fs_fsize
);
691 if (fs
->fs_contigsumsize
> 0)
692 size
+= fs
->fs_ncg
* sizeof(int32_t);
693 space
= _MALLOC((u_long
)size
, M_UFSMNT
, M_WAITOK
);
695 for (i
= 0; i
< blks
; i
+= fs
->fs_frag
) {
697 if (i
+ fs
->fs_frag
> blks
)
698 size
= (blks
- i
) * fs
->fs_fsize
;
699 if (error
= bread(devvp
, fsbtodb(fs
, fs
->fs_csaddr
+ i
), size
,
701 _FREE(fs
->fs_csp
, M_UFSMNT
);
704 bcopy(bp
->b_data
, space
, (u_int
)size
);
707 byte_swap_ints((int *) space
, size
/ sizeof(int));
708 #endif /* REV_ENDIAN_FS */
709 space
= (char *)space
+ size
;
713 if (fs
->fs_contigsumsize
> 0) {
714 fs
->fs_maxcluster
= lp
= space
;
715 for (i
= 0; i
< fs
->fs_ncg
; i
++)
716 *lp
++ = fs
->fs_contigsumsize
;
718 mp
->mnt_data
= (qaddr_t
)ump
;
719 mp
->mnt_stat
.f_fsid
.val
[0] = (long)dev
;
720 mp
->mnt_stat
.f_fsid
.val
[1] = mp
->mnt_vfc
->vfc_typenum
;
721 #warning hardcoded max symlen and not "mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen;"
722 mp
->mnt_maxsymlinklen
= 60;
725 mp
->mnt_flag
|= MNT_REVEND
;
726 #endif /* REV_ENDIAN_FS */
729 ump
->um_devvp
= devvp
;
730 ump
->um_nindir
= fs
->fs_nindir
;
731 ump
->um_bptrtodb
= fs
->fs_fsbtodb
;
732 ump
->um_seqinc
= fs
->fs_frag
;
733 for (i
= 0; i
< MAXQUOTAS
; i
++)
734 ump
->um_qfiles
[i
].qf_vp
= NULLVP
;
735 devvp
->v_specflags
|= SI_MOUNTEDON
;
737 ump
->um_savedmaxfilesize
= fs
->fs_maxfilesize
; /* XXX */
738 maxfilesize
= (u_int64_t
)0x100000000; /* 4GB */
740 maxfilesize
= (u_int64_t
)0x40000000 * fs
->fs_bsize
- 1; /* XXX */
742 if (fs
->fs_maxfilesize
> maxfilesize
) /* XXX */
743 fs
->fs_maxfilesize
= maxfilesize
; /* XXX */
746 (void) ffs_sbupdate(ump
, MNT_WAIT
);
752 (void)VOP_CLOSE(devvp
, ronly
? FREAD
: FREAD
|FWRITE
, cred
, p
);
754 _FREE(ump
->um_fs
, M_UFSMNT
);
755 _FREE(ump
, M_UFSMNT
);
756 mp
->mnt_data
= (qaddr_t
)0;
762 * Sanity checks for old file systems.
764 * XXX - goes away some day.
771 fs
->fs_npsect
= max(fs
->fs_npsect
, fs
->fs_nsect
); /* XXX */
772 fs
->fs_interleave
= max(fs
->fs_interleave
, 1); /* XXX */
773 if (fs
->fs_postblformat
== FS_42POSTBLFMT
) /* XXX */
774 fs
->fs_nrpos
= 8; /* XXX */
775 if (fs
->fs_inodefmt
< FS_44INODEFMT
) { /* XXX */
776 u_int64_t sizepb
= fs
->fs_bsize
; /* XXX */
778 fs
->fs_maxfilesize
= fs
->fs_bsize
* NDADDR
- 1; /* XXX */
779 for (i
= 0; i
< NIADDR
; i
++) { /* XXX */
780 sizepb
*= NINDIR(fs
); /* XXX */
781 fs
->fs_maxfilesize
+= sizepb
; /* XXX */
783 fs
->fs_qbmask
= ~fs
->fs_bmask
; /* XXX */
784 fs
->fs_qfmask
= ~fs
->fs_fmask
; /* XXX */
790 * unmount system call
793 ffs_unmount(mp
, mntflags
, p
)
798 register struct ufsmount
*ump
;
799 register struct fs
*fs
;
805 if (mntflags
& MNT_FORCE
) {
809 if ( (error
= ffs_flushfiles(mp
, flags
, p
)) && !force
)
813 if (fs
->fs_ronly
== 0) {
815 if (error
= ffs_sbupdate(ump
, MNT_WAIT
)) {
818 /* we can atleast cleanup ; as the media could be WP */
819 /* & during mount, we do not check for write failures */
820 /* FIXME LATER : the Correct fix would be to have */
821 /* mount detect the WP media and downgrade to readonly mount */
822 /* For now, here it is */
827 ump
->um_devvp
->v_specflags
&= ~SI_MOUNTEDON
;
828 error
= VOP_CLOSE(ump
->um_devvp
, fs
->fs_ronly
? FREAD
: FREAD
|FWRITE
,
832 vrele(ump
->um_devvp
);
834 _FREE(fs
->fs_csp
, M_UFSMNT
);
836 _FREE(ump
, M_UFSMNT
);
837 mp
->mnt_data
= (qaddr_t
)0;
839 mp
->mnt_flag
&= ~MNT_REVEND
;
840 #endif /* REV_ENDIAN_FS */
845 * Flush out all the files in a filesystem.
847 ffs_flushfiles(mp
, flags
, p
)
848 register struct mount
*mp
;
852 register struct ufsmount
*ump
;
857 if (mp
->mnt_flag
& MNT_QUOTA
) {
858 if (error
= vflush(mp
, NULLVP
, SKIPSYSTEM
|flags
))
860 for (i
= 0; i
< MAXQUOTAS
; i
++) {
861 if (ump
->um_qfiles
[i
].qf_vp
== NULLVP
)
866 * Here we fall through to vflush again to ensure
867 * that we have gotten rid of all the system vnodes.
871 error
= vflush(mp
, NULLVP
, SKIPSWAP
|flags
);
872 error
= vflush(mp
, NULLVP
, flags
);
877 * Get file system statistics.
880 ffs_statfs(mp
, sbp
, p
)
882 register struct statfs
*sbp
;
885 register struct ufsmount
*ump
;
886 register struct fs
*fs
;
890 if (fs
->fs_magic
!= FS_MAGIC
)
892 sbp
->f_bsize
= fs
->fs_fsize
;
893 sbp
->f_iosize
= fs
->fs_bsize
;
894 sbp
->f_blocks
= fs
->fs_dsize
;
895 sbp
->f_bfree
= fs
->fs_cstotal
.cs_nbfree
* fs
->fs_frag
+
896 fs
->fs_cstotal
.cs_nffree
;
897 sbp
->f_bavail
= freespace(fs
, fs
->fs_minfree
);
898 sbp
->f_files
= fs
->fs_ncg
* fs
->fs_ipg
- ROOTINO
;
899 sbp
->f_ffree
= fs
->fs_cstotal
.cs_nifree
;
900 if (sbp
!= &mp
->mnt_stat
) {
901 sbp
->f_type
= mp
->mnt_vfc
->vfc_typenum
;
902 bcopy((caddr_t
)mp
->mnt_stat
.f_mntonname
,
903 (caddr_t
)&sbp
->f_mntonname
[0], MNAMELEN
);
904 bcopy((caddr_t
)mp
->mnt_stat
.f_mntfromname
,
905 (caddr_t
)&sbp
->f_mntfromname
[0], MNAMELEN
);
911 * Go through the disk queues to initiate sandbagged IO;
912 * go through the inodes to write those that have been modified;
913 * initiate the writing of the super block if it has been modified.
915 * Note: we are always called with the filesystem marked `MPBUSY'.
918 ffs_sync(mp
, waitfor
, cred
, p
)
924 struct vnode
*nvp
, *vp
;
926 struct ufsmount
*ump
= VFSTOUFS(mp
);
928 int error
, allerror
= 0;
931 if (fs
->fs_fmod
!= 0 && fs
->fs_ronly
!= 0) { /* XXX */
932 printf("fs = %s\n", fs
->fs_fsmnt
);
933 panic("update: rofs mod");
936 * Write back each (modified) inode.
938 simple_lock(&mntvnode_slock
);
940 for (vp
= mp
->mnt_vnodelist
.lh_first
;
946 * If the vnode that we are about to sync is no longer
947 * associated with this mount point, start over.
949 if (vp
->v_mount
!= mp
)
951 simple_lock(&vp
->v_interlock
);
952 nvp
= vp
->v_mntvnodes
.le_next
;
954 if ((vp
->v_type
== VNON
) ||
955 ((ip
->i_flag
& (IN_ACCESS
| IN_CHANGE
| IN_MODIFIED
| IN_UPDATE
)) == 0 &&
956 vp
->v_dirtyblkhd
.lh_first
== NULL
&& !(vp
->v_flag
& VHASDIRTY
))) {
957 simple_unlock(&vp
->v_interlock
);
960 simple_unlock(&mntvnode_slock
);
961 error
= vget(vp
, LK_EXCLUSIVE
| LK_NOWAIT
| LK_INTERLOCK
, p
);
963 simple_lock(&mntvnode_slock
);
968 didhold
= ubc_hold(vp
);
969 if (error
= VOP_FSYNC(vp
, cred
, waitfor
, p
))
971 VOP_UNLOCK(vp
, 0, p
);
975 simple_lock(&mntvnode_slock
);
977 simple_unlock(&mntvnode_slock
);
979 * Force stale file system control information to be flushed.
981 if (error
= VOP_FSYNC(ump
->um_devvp
, cred
, waitfor
, p
))
987 * Write back modified superblock.
989 if (fs
->fs_fmod
!= 0) {
991 fs
->fs_time
= time
.tv_sec
;
992 if (error
= ffs_sbupdate(ump
, waitfor
))
999 * Look up a FFS dinode number to find its incore vnode, otherwise read it
1000 * in from disk. If it is in core, wait for the lock bit to clear, then
1001 * return the inode locked. Detection and handling of mount points must be
1002 * done by the calling routine.
1005 ffs_vget(mp
, ino
, vpp
)
1010 struct proc
*p
= current_proc(); /* XXX */
1013 struct ufsmount
*ump
;
1022 /* Check for unmount in progress */
1023 if (mp
->mnt_kern_flag
& MNTK_UNMOUNT
) {
1028 if ((*vpp
= ufs_ihashget(dev
, ino
)) != NULL
) {
1030 UBCINFOCHECK("ffs_vget", vp
);
1033 /* Allocate a new vnode/inode. */
1034 type
= ump
->um_devvp
->v_tag
== VT_MFS
? M_MFSNODE
: M_FFSNODE
; /* XXX */
1035 MALLOC_ZONE(ip
, struct inode
*, sizeof(struct inode
), type
, M_WAITOK
);
1036 bzero((caddr_t
)ip
, sizeof(struct inode
));
1037 lockinit(&ip
->i_lock
, PINOD
, "inode", 0, 0);
1038 /* lock the inode */
1039 lockmgr(&ip
->i_lock
, LK_EXCLUSIVE
, (struct slock
*)0, p
);
1041 ip
->i_fs
= fs
= ump
->um_fs
;
1044 ip
->i_flag
|= IN_ALLOC
;
1046 for (i
= 0; i
< MAXQUOTAS
; i
++)
1047 ip
->i_dquot
[i
] = NODQUOT
;
1051 * MALLOC_ZONE is blocking call. Check for race.
1053 if ((*vpp
= ufs_ihashget(dev
, ino
)) != NULL
) {
1055 FREE_ZONE(ip
, sizeof(struct inode
), type
);
1057 UBCINFOCHECK("ffs_vget", vp
);
1062 * Put it onto its hash chain locked so that other requests for
1063 * this inode will block if they arrive while we are sleeping waiting
1064 * for old data structures to be purged or for the contents of the
1065 * disk portion of this inode to be read.
1069 if (error
= getnewvnode(VT_UFS
, mp
, ffs_vnodeop_p
, &vp
)) {
1071 if (ISSET(ip
->i_flag
, IN_WALLOC
))
1073 FREE_ZONE(ip
, sizeof(struct inode
), type
);
1081 * A vnode is associated with the inode now,
1082 * vget() can deal with the serialization.
1084 CLR(ip
->i_flag
, IN_ALLOC
);
1085 if (ISSET(ip
->i_flag
, IN_WALLOC
))
1088 /* Read in the disk contents for the inode, copy into the inode. */
1089 if (error
= bread(ump
->um_devvp
, fsbtodb(fs
, ino_to_fsba(fs
, ino
)),
1090 (int)fs
->fs_bsize
, NOCRED
, &bp
)) {
1092 * The inode does not contain anything useful, so it would
1093 * be misleading to leave it on its hash chain. With mode
1094 * still zero, it will be unlinked and returned to the free
1103 if (mp
->mnt_flag
& MNT_REVEND
) {
1104 byte_swap_inode_in(((struct dinode
*)bp
->b_data
+ ino_to_fsbo(fs
, ino
)),ip
);
1106 #endif /* REV_ENDIAN_FS */
1107 ip
->i_din
= *((struct dinode
*)bp
->b_data
+ ino_to_fsbo(fs
, ino
));
1110 #endif /* REV_ENDIAN_FS */
1114 * Initialize the vnode from the inode, check for aliases.
1115 * Note that the underlying vnode may have changed.
1117 if (error
= ufs_vinit(mp
, ffs_specop_p
, FFS_FIFOOPS
, &vp
)) {
1123 * Finish inode initialization now that aliasing has been resolved.
1125 ip
->i_devvp
= ump
->um_devvp
;
1128 * Set up a generation number for this inode if it does not
1129 * already have one. This should only happen on old filesystems.
1131 if (ip
->i_gen
== 0) {
1132 if (++nextgennumber
< (u_long
)time
.tv_sec
)
1133 nextgennumber
= time
.tv_sec
;
1134 ip
->i_gen
= nextgennumber
;
1135 if ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
) == 0)
1136 ip
->i_flag
|= IN_MODIFIED
;
1139 * Ensure that uid and gid are correct. This is a temporary
1140 * fix until fsck has been changed to do the update.
1142 if (fs
->fs_inodefmt
< FS_44INODEFMT
) { /* XXX */
1143 ip
->i_uid
= ip
->i_din
.di_ouid
; /* XXX */
1144 ip
->i_gid
= ip
->i_din
.di_ogid
; /* XXX */
1148 if (UBCINFOMISSING(vp
) || UBCINFORECLAIMED(vp
))
1154 * File handle to vnode
1156 * Have to be really careful about stale file handles:
1157 * - check that the inode number is valid
1158 * - call ffs_vget() to get the locked inode
1159 * - check for an unallocated inode (i_mode == 0)
1160 * - check that the given client host has export rights and return
1161 * those rights via. exflagsp and credanonp
1164 ffs_fhtovp(mp
, fhp
, nam
, vpp
, exflagsp
, credanonp
)
1165 register struct mount
*mp
;
1170 struct ucred
**credanonp
;
1172 register struct ufid
*ufhp
;
1175 ufhp
= (struct ufid
*)fhp
;
1176 fs
= VFSTOUFS(mp
)->um_fs
;
1177 if (ufhp
->ufid_ino
< ROOTINO
||
1178 ufhp
->ufid_ino
>= fs
->fs_ncg
* fs
->fs_ipg
)
1180 return (ufs_check_export(mp
, ufhp
, nam
, vpp
, exflagsp
, credanonp
));
1184 * Vnode pointer to File handle
1191 register struct inode
*ip
;
1192 register struct ufid
*ufhp
;
1195 ufhp
= (struct ufid
*)fhp
;
1196 ufhp
->ufid_len
= sizeof(struct ufid
);
1197 ufhp
->ufid_ino
= ip
->i_number
;
1198 ufhp
->ufid_gen
= ip
->i_gen
;
1203 * Initialize the filesystem; just use ufs_init.
1207 struct vfsconf
*vfsp
;
1210 return (ufs_init(vfsp
));
1214 * fast filesystem related variables.
1216 ffs_sysctl(name
, namelen
, oldp
, oldlenp
, newp
, newlen
, p
)
1225 extern int doclusterread
, doclusterwrite
, doreallocblks
, doasyncfree
;
1227 /* all sysctl names at this level are terminal */
1229 return (ENOTDIR
); /* overloaded */
1232 case FFS_CLUSTERREAD
:
1233 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
1235 case FFS_CLUSTERWRITE
:
1236 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
1238 case FFS_REALLOCBLKS
:
1239 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
1242 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
, &doasyncfree
));
1244 return (EOPNOTSUPP
);
1250 * Write a superblock and associated information back to disk.
1253 ffs_sbupdate(mp
, waitfor
)
1254 struct ufsmount
*mp
;
1257 register struct fs
*dfs
, *fs
= mp
->um_fs
;
1258 register struct buf
*bp
;
1261 int i
, size
, error
, allerror
= 0;
1264 int rev_endian
=(mp
->um_mountp
->mnt_flag
& MNT_REVEND
);
1265 #endif /* REV_ENDIAN_FS */
1268 * First write back the summary information.
1270 blks
= howmany(fs
->fs_cssize
, fs
->fs_fsize
);
1272 for (i
= 0; i
< blks
; i
+= fs
->fs_frag
) {
1273 size
= fs
->fs_bsize
;
1274 if (i
+ fs
->fs_frag
> blks
)
1275 size
= (blks
- i
) * fs
->fs_fsize
;
1276 bp
= getblk(mp
->um_devvp
, fsbtodb(fs
, fs
->fs_csaddr
+ i
),
1277 size
, 0, 0, BLK_META
);
1278 bcopy(space
, bp
->b_data
, (u_int
)size
);
1281 byte_swap_ints((int *)bp
->b_data
, size
/ sizeof(int));
1283 #endif /* REV_ENDIAN_FS */
1284 space
= (char *)space
+ size
;
1285 if (waitfor
!= MNT_WAIT
)
1287 else if (error
= bwrite(bp
))
1291 * Now write back the superblock itself. If any errors occurred
1292 * up to this point, then fail so that the superblock avoids
1293 * being written out as clean.
1297 VOP_DEVBLOCKSIZE(mp
->um_devvp
,&devBlockSize
);
1298 bp
= getblk(mp
->um_devvp
, (SBOFF
/devBlockSize
), (int)fs
->fs_sbsize
, 0, 0, BLK_META
);
1299 bcopy((caddr_t
)fs
, bp
->b_data
, (u_int
)fs
->fs_sbsize
);
1300 /* Restore compatibility to old file systems. XXX */
1301 dfs
= (struct fs
*)bp
->b_data
; /* XXX */
1302 if (fs
->fs_postblformat
== FS_42POSTBLFMT
) /* XXX */
1303 dfs
->fs_nrpos
= -1; /* XXX */
1306 * Swapping bytes here ; so that in case
1307 * of inode format < FS_44INODEFMT appropriate
1311 byte_swap_sbout((struct fs
*)bp
->b_data
);
1313 #endif /* REV_ENDIAN_FS */
1314 if (fs
->fs_inodefmt
< FS_44INODEFMT
) { /* XXX */
1315 int32_t *lp
, tmp
; /* XXX */
1317 lp
= (int32_t *)&dfs
->fs_qbmask
; /* XXX */
1318 tmp
= lp
[4]; /* XXX */
1319 for (i
= 4; i
> 0; i
--) /* XXX */
1320 lp
[i
] = lp
[i
-1]; /* XXX */
1321 lp
[0] = tmp
; /* XXX */
1324 /* Note that dfs is already swapped so swap the filesize
1328 dfs
->fs_maxfilesize
= NXSwapLongLong(mp
->um_savedmaxfilesize
); /* XXX */
1330 #endif /* REV_ENDIAN_FS */
1331 dfs
->fs_maxfilesize
= mp
->um_savedmaxfilesize
; /* XXX */
1334 #endif /* REV_ENDIAN_FS */
1335 if (waitfor
!= MNT_WAIT
)
1337 else if (error
= bwrite(bp
))