2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1989, 1991, 1993, 1994
31 * The Regents of the University of California. All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * @(#)ffs_vfsops.c 8.31 (Berkeley) 5/20/95
64 #include <rev_endian_fs.h>
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/namei.h>
69 #include <sys/kauth.h>
70 #include <sys/kernel.h>
71 #include <sys/vnode_internal.h>
72 #include <sys/socket.h>
73 #include <sys/mount_internal.h>
74 #include <sys/mount.h>
79 #include <sys/ioctl.h>
80 #include <sys/errno.h>
81 #include <sys/malloc.h>
83 #include <sys/quota.h>
85 #include <miscfs/specfs/specdev.h>
87 #include <ufs/ufs/quota.h>
88 #include <ufs/ufs/ufsmount.h>
89 #include <ufs/ufs/inode.h>
90 #include <ufs/ufs/ufs_extern.h>
92 #include <ufs/ffs/fs.h>
93 #include <ufs/ffs/ffs_extern.h>
95 #include <ufs/ufs/ufs_byte_order.h>
96 #include <libkern/OSByteOrder.h>
97 #endif /* REV_ENDIAN_FS */
99 int ffs_sbupdate(struct ufsmount
*, int);
101 struct vfsops ufs_vfsops
= {
118 extern u_long nextgennumber
;
124 #define SETHIGH(q, h) { \
127 tmp.val[_QUAD_HIGHWORD] = (h); \
130 #define SETLOW(q, l) { \
133 tmp.val[_QUAD_LOWWORD] = (l); \
138 * Called by main() when ufs is going to be mounted as root.
141 ffs_mountroot(mount_t mp
, vnode_t rvp
, vfs_context_t context
)
143 struct proc
*p
= current_proc(); /* XXX */
146 /* Set asynchronous flag by default */
147 vfs_setflags(mp
, MNT_ASYNC
);
149 if (error
= ffs_mountfs(rvp
, mp
, context
))
152 (void)ffs_statfs(mp
, vfs_statfs(mp
), NULL
);
163 ffs_mount(struct mount
*mp
, vnode_t devvp
, __unused user_addr_t data
, vfs_context_t context
)
165 struct proc
*p
= vfs_context_proc(context
);
166 struct ufsmount
*ump
;
167 register struct fs
*fs
;
169 int error
= 0, flags
;
175 * If updating, check whether changing from read-write to
176 * read-only; if there is no device name, that's all we do.
178 if (mp
->mnt_flag
& MNT_UPDATE
) {
181 if (fs
->fs_ronly
== 0 && (mp
->mnt_flag
& MNT_RDONLY
)) {
183 * Flush any dirty data.
185 VFS_SYNC(mp
, MNT_WAIT
, context
);
187 * Check for and optionally get rid of files open
191 if (mp
->mnt_flag
& MNT_FORCE
)
193 if (error
= ffs_flushfiles(mp
, flags
, p
))
197 if (error
= ffs_sbupdate(ump
, MNT_WAIT
)) {
203 /* save fs_ronly to later use */
204 ronly
= fs
->fs_ronly
;
205 if ((mp
->mnt_flag
& MNT_RELOAD
) || ronly
)
208 (error
= ffs_reload(mp
, vfs_context_ucred(context
), p
)))
210 /* replace the ronly after load */
211 fs
->fs_ronly
= ronly
;
213 * Do not update the file system if the user was in singleuser
214 * and then tries to mount -uw without fscking
216 if (!fs
->fs_clean
&& ronly
) {
217 printf("WARNING: trying to mount a dirty file system\n");
218 if (issingleuser() && (mp
->mnt_flag
& MNT_ROOTFS
)) {
219 printf("WARNING: R/W mount of %s denied. Filesystem is not clean - run fsck\n",fs
->fs_fsmnt
);
221 * Reset the readonly bit as reload might have
229 if (ronly
&& (mp
->mnt_kern_flag
& MNTK_WANTRDWR
)) {
232 (void) ffs_sbupdate(ump
, MNT_WAIT
);
238 if ((mp
->mnt_flag
& MNT_UPDATE
) == 0)
239 error
= ffs_mountfs(devvp
, mp
, context
);
241 if (devvp
!= ump
->um_devvp
)
242 error
= EINVAL
; /* needs translation */
249 bzero(fs
->fs_fsmnt
, sizeof(fs
->fs_fsmnt
));
250 strncpy(fs
->fs_fsmnt
, (caddr_t
)mp
->mnt_vfsstat
.f_mntonname
, sizeof(fs
->fs_fsmnt
) - 1);
251 (void)ffs_statfs(mp
, &mp
->mnt_vfsstat
, p
);
256 struct ffs_reload_cargs
{
264 #endif /* REV_ENDIAN_FS */
269 ffs_reload_callback(struct vnode
*vp
, void *cargs
)
274 struct ffs_reload_cargs
*args
;
276 args
= (struct ffs_reload_cargs
*)cargs
;
279 * flush all the buffers associated with this node
281 if (buf_invalidateblks(vp
, 0, 0, 0))
282 panic("ffs_reload: dirty2");
285 * Step 6: re-read inode data
290 if (args
->error
= (int)buf_bread(args
->devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, ino_to_fsba(fs
, ip
->i_number
))),
291 (int)fs
->fs_bsize
, NOCRED
, &bp
)) {
294 return (VNODE_RETURNED_DONE
);
298 if (args
->rev_endian
) {
299 byte_swap_inode_in(((struct dinode
*)buf_dataptr(bp
) +
300 ino_to_fsbo(fs
, ip
->i_number
)), ip
);
302 #endif /* REV_ENDIAN_FS */
303 ip
->i_din
= *((struct dinode
*)buf_dataptr(bp
) +
304 ino_to_fsbo(fs
, ip
->i_number
));
307 #endif /* REV_ENDIAN_FS */
311 return (VNODE_RETURNED
);
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(struct mount
*mountp
, kauth_cred_t cred
, struct proc
*p
)
330 register struct vnode
*devvp
;
333 struct fs
*fs
, *newfs
;
334 int i
, blks
, size
, error
;
335 u_int64_t maxfilesize
; /* XXX */
337 struct ffs_reload_cargs args
;
339 int rev_endian
= (mountp
->mnt_flag
& MNT_REVEND
);
340 #endif /* REV_ENDIAN_FS */
342 if ((mountp
->mnt_flag
& MNT_RDONLY
) == 0)
345 * Step 1: invalidate all cached meta-data.
347 devvp
= VFSTOUFS(mountp
)->um_devvp
;
348 if (buf_invalidateblks(devvp
, 0, 0, 0))
349 panic("ffs_reload: dirty1");
351 * Step 2: re-read superblock from disk.
353 size
= vfs_devblocksize(mountp
);
355 if (error
= (int)buf_bread(devvp
, (daddr64_t
)((unsigned)(SBOFF
/size
)), SBSIZE
, NOCRED
,&bp
)) {
359 newfs
= (struct fs
*)buf_dataptr(bp
);
362 error
= byte_swap_sbin(newfs
);
368 #endif /* REV_ENDIAN_FS */
369 if (newfs
->fs_magic
!= FS_MAGIC
|| newfs
->fs_bsize
> MAXBSIZE
||
370 newfs
->fs_bsize
< sizeof(struct fs
)) {
373 byte_swap_sbout(newfs
);
374 #endif /* REV_ENDIAN_FS */
377 return (EIO
); /* XXX needs translation */
379 fs
= VFSTOUFS(mountp
)->um_fs
;
381 * Copy pointer fields back into superblock before copying in XXX
382 * new superblock. These should really be in the ufsmount. XXX
383 * Note that important parameters (eg fs_ncg) are unchanged.
385 newfs
->fs_csp
= fs
->fs_csp
;
386 newfs
->fs_maxcluster
= fs
->fs_maxcluster
;
387 newfs
->fs_contigdirs
= fs
->fs_contigdirs
;
388 bcopy(newfs
, fs
, (u_int
)fs
->fs_sbsize
);
389 if (fs
->fs_sbsize
< SBSIZE
)
393 byte_swap_sbout(newfs
);
394 #endif /* REV_ENDIAN_FS */
396 mountp
->mnt_maxsymlinklen
= fs
->fs_maxsymlinklen
;
398 maxfilesize
= 0x100000000ULL
; /* 4GB */
399 if (fs
->fs_maxfilesize
> maxfilesize
) /* XXX */
400 fs
->fs_maxfilesize
= maxfilesize
; /* XXX */
402 * Step 3: re-read summary information from disk.
404 blks
= howmany(fs
->fs_cssize
, fs
->fs_fsize
);
406 for (i
= 0; i
< blks
; i
+= fs
->fs_frag
) {
408 if (i
+ fs
->fs_frag
> blks
)
409 size
= (blks
- i
) * fs
->fs_fsize
;
410 if (error
= (int)buf_bread(devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, fs
->fs_csaddr
+ i
)), size
,
418 byte_swap_ints((int *)buf_dataptr(bp
), size
/ sizeof(int));
420 #endif /* REV_ENDIAN_FS */
421 bcopy((char *)buf_dataptr(bp
), space
, (u_int
)size
);
425 byte_swap_ints((int *)buf_dataptr(bp
), size
/ sizeof(int));
427 #endif /* REV_ENDIAN_FS */
428 space
= (char *) space
+ size
;
432 * We no longer know anything about clusters per cylinder group.
434 if (fs
->fs_contigsumsize
> 0) {
435 lp
= fs
->fs_maxcluster
;
436 for (i
= 0; i
< fs
->fs_ncg
; i
++)
437 *lp
++ = fs
->fs_contigsumsize
;
440 args
.rev_endian
= rev_endian
;
441 #endif /* REV_ENDIAN_FS */
448 * ffs_reload_callback will be called for each vnode
449 * hung off of this mount point that can't be recycled...
450 * vnode_iterate will recycle those that it can (the VNODE_RELOAD option)
451 * the vnode will be in an 'unbusy' state (VNODE_WAIT) and
452 * properly referenced and unreferenced around the callback
454 vnode_iterate(mountp
, VNODE_RELOAD
| VNODE_WAIT
, ffs_reload_callback
, (void *)&args
);
460 * Common code for mount and mountroot
463 ffs_mountfs(devvp
, mp
, context
)
466 vfs_context_t context
;
468 struct ufsmount
*ump
;
474 int32_t clustersumoff
;
476 int error
, i
, blks
, ronly
;
480 u_int64_t maxfilesize
; /* XXX */
481 u_int dbsize
= DEV_BSIZE
;
484 #endif /* REV_ENDIAN_FS */
486 cred
= vfs_context_ucred(context
);
488 ronly
= vfs_isrdonly(mp
);
492 /* Advisory locking should be handled at the VFS layer */
493 vfs_setlocklocal(mp
);
495 /* Obtain the actual device block size */
496 if (VNOP_IOCTL(devvp
, DKIOCGETBLOCKSIZE
, (caddr_t
)&size
, 0, context
)) {
501 if (error
= (int)buf_bread(devvp
, (daddr64_t
)((unsigned)(SBOFF
/size
)),
504 fs
= (struct fs
*)buf_dataptr(bp
);
506 if (fs
->fs_magic
!= FS_MAGIC
|| fs
->fs_bsize
> MAXBSIZE
||
507 fs
->fs_bsize
< sizeof(struct fs
)) {
508 int magic
= fs
->fs_magic
;
510 byte_swap_ints(&magic
, 1);
511 if (magic
!= FS_MAGIC
) {
515 if (error
= byte_swap_sbin(fs
))
518 if (fs
->fs_magic
!= FS_MAGIC
|| fs
->fs_bsize
> MAXBSIZE
||
519 fs
->fs_bsize
< sizeof(struct fs
)) {
521 error
= EINVAL
; /* XXX needs translation */
526 #endif /* REV_ENDIAN_FS */
527 if (fs
->fs_magic
!= FS_MAGIC
|| fs
->fs_bsize
> MAXBSIZE
||
528 fs
->fs_bsize
< sizeof(struct fs
)) {
532 #endif /* REV_ENDIAN_FS */
533 error
= EINVAL
; /* XXX needs translation */
537 if (fs
->fs_sbsize
< 0 || fs
->fs_sbsize
> SBSIZE
) {
543 * Buffer cache does not handle multiple pages in a buf when
546 * Buffer cache does not handle multiple pages in a buf when
547 * invalidating incore buffer in pageout. There are no locks
548 * in the pageout path. So there is a danger of loosing data when
549 * block allocation happens at the same time a pageout of buddy
550 * page occurs. incore() returns buf with both
551 * pages, this leads vnode-pageout to incorrectly flush of entire.
552 * buf. Till the low level ffs code is modified to deal with these
553 * do not mount any FS more than 4K size.
556 * Can't mount filesystems with a fragment size less than DIRBLKSIZ
559 * Don't mount dirty filesystems, except for the root filesystem
561 if ((fs
->fs_bsize
> PAGE_SIZE
) || (fs
->fs_fsize
< DIRBLKSIZ
) ||
562 ((!(mp
->mnt_flag
& MNT_ROOTFS
)) && (!fs
->fs_clean
))) {
566 #endif /* REV_ENDIAN_FS */
571 /* Let's figure out the devblock size the file system is with */
572 /* the device block size = fragment size / number of sectors per frag */
574 dbsize
= fs
->fs_fsize
/ NSPF(fs
);
576 kprintf("device blocksize computaion failed\n");
578 if (VNOP_IOCTL(devvp
, DKIOCSETBLOCKSIZE
, (caddr_t
)&dbsize
,
579 FWRITE
, context
) != 0) {
580 kprintf("failed to set device blocksize\n");
582 /* force the specfs to reread blocksize from size() */
583 set_fsblocksize(devvp
);
586 /* XXX updating 4.2 FFS superblocks trashes rotational layout tables */
587 if (fs
->fs_postblformat
== FS_42POSTBLFMT
&& !ronly
) {
591 #endif /* REV_ENDIAN_FS */
592 error
= EROFS
; /* needs translation */
596 /* If we are not mounting read only, then check for overlap
597 * condition in cylinder group's free block map.
598 * If overlap exists, then force this into a read only mount
599 * to avoid further corruption. PR#2216969
602 if (error
= (int)buf_bread (devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, cgtod(fs
, 0))),
603 (int)fs
->fs_cgsize
, NOCRED
, &cgbp
)) {
607 cgp
= (struct cg
*)buf_dataptr(cgbp
);
610 byte_swap_cgin(cgp
,fs
);
611 #endif /* REV_ENDIAN_FS */
612 if (!cg_chkmagic(cgp
)){
615 byte_swap_cgout(cgp
,fs
);
616 #endif /* REV_ENDIAN_FS */
620 if (cgp
->cg_clustersumoff
!= 0) {
621 /* Check for overlap */
622 clustersumoff
= cgp
->cg_freeoff
+
623 howmany(fs
->fs_cpg
* fs
->fs_spc
/ NSPF(fs
), NBBY
);
624 clustersumoff
= roundup(clustersumoff
, sizeof(long));
625 if (cgp
->cg_clustersumoff
< clustersumoff
) {
627 mp
->mnt_flag
|= MNT_RDONLY
;
633 byte_swap_cgout(cgp
,fs
);
634 #endif /* REV_ENDIAN_FS */
638 ump
= _MALLOC(sizeof *ump
, M_UFSMNT
, M_WAITOK
);
639 bzero((caddr_t
)ump
, sizeof *ump
);
640 ump
->um_fs
= _MALLOC((u_long
)fs
->fs_sbsize
, M_UFSMNT
,
642 bcopy((char *)buf_dataptr(bp
), ump
->um_fs
, (u_int
)fs
->fs_sbsize
);
643 if (fs
->fs_sbsize
< SBSIZE
)
648 #endif /* REV_ENDIAN_FS */
652 fs
->fs_ronly
= ronly
;
653 if (fs
->fs_cssize
< 1 || fs
->fs_fsize
< 1 || fs
->fs_ncg
< 1) {
657 if (fs
->fs_frag
< 1 || fs
->fs_frag
> MAXFRAG
) {
662 size
= fs
->fs_cssize
;
663 blks
= howmany(size
, fs
->fs_fsize
);
664 if (fs
->fs_contigsumsize
> 0) {
665 if (fs
->fs_ncg
> INT_MAX
/ sizeof(int32_t) || size
> INT_MAX
- fs
->fs_ncg
* sizeof(int32_t)) {
669 size
+= fs
->fs_ncg
* sizeof(int32_t);
671 if (fs
->fs_ncg
> INT_MAX
/ sizeof(u_int8_t
) || size
> INT_MAX
- fs
->fs_ncg
* sizeof(u_int8_t
)) {
675 size
+= fs
->fs_ncg
* sizeof(u_int8_t
);
676 space
= _MALLOC((u_long
)size
, M_UFSMNT
, M_WAITOK
);
678 for (i
= 0; i
< blks
; i
+= fs
->fs_frag
) {
680 if (i
+ fs
->fs_frag
> blks
)
681 size
= (blks
- i
) * fs
->fs_fsize
;
682 if (error
= (int)buf_bread(devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, fs
->fs_csaddr
+ i
)),
684 _FREE(fs
->fs_csp
, M_UFSMNT
);
687 bcopy((char *)buf_dataptr(bp
), space
, (u_int
)size
);
690 byte_swap_ints((int *) space
, size
/ sizeof(int));
691 #endif /* REV_ENDIAN_FS */
692 space
= (char *)space
+ size
;
696 if (fs
->fs_contigsumsize
> 0) {
697 fs
->fs_maxcluster
= lp
= space
;
698 for (i
= 0; i
< fs
->fs_ncg
; i
++)
699 *lp
++ = fs
->fs_contigsumsize
;
702 size
= fs
->fs_ncg
* sizeof(u_int8_t
);
703 fs
->fs_contigdirs
= (u_int8_t
*)space
;
704 space
= (u_int8_t
*)space
+ size
;
705 bzero(fs
->fs_contigdirs
, size
);
706 /* XXX Compatibility for old filesystems */
707 if (fs
->fs_avgfilesize
<= 0)
708 fs
->fs_avgfilesize
= AVFILESIZ
;
709 if (fs
->fs_avgfpdir
<= 0)
710 fs
->fs_avgfpdir
= AFPDIR
;
711 /* XXX End of compatibility */
712 mp
->mnt_data
= (qaddr_t
)ump
;
713 mp
->mnt_vfsstat
.f_fsid
.val
[0] = (long)dev
;
714 mp
->mnt_vfsstat
.f_fsid
.val
[1] = vfs_typenum(mp
);
715 /* XXX warning hardcoded max symlen and not "mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen;" */
716 mp
->mnt_maxsymlinklen
= 60;
719 mp
->mnt_flag
|= MNT_REVEND
;
720 #endif /* REV_ENDIAN_FS */
723 ump
->um_devvp
= devvp
;
724 ump
->um_nindir
= fs
->fs_nindir
;
725 ump
->um_bptrtodb
= fs
->fs_fsbtodb
;
726 ump
->um_seqinc
= fs
->fs_frag
;
727 for (i
= 0; i
< MAXQUOTAS
; i
++)
728 dqfileinit(&ump
->um_qfiles
[i
]);
730 ump
->um_savedmaxfilesize
= fs
->fs_maxfilesize
; /* XXX */
731 maxfilesize
= 0x100000000ULL
; /* 4GB */
733 maxfilesize
= (u_int64_t
)0x40000000 * fs
->fs_bsize
- 1; /* XXX */
735 if (fs
->fs_maxfilesize
> maxfilesize
) /* XXX */
736 fs
->fs_maxfilesize
= maxfilesize
; /* XXX */
739 (void) ffs_sbupdate(ump
, MNT_WAIT
);
746 _FREE(ump
->um_fs
, M_UFSMNT
);
747 _FREE(ump
, M_UFSMNT
);
753 * Sanity checks for old file systems.
755 * XXX - goes away some day.
762 fs
->fs_npsect
= max(fs
->fs_npsect
, fs
->fs_nsect
); /* XXX */
763 fs
->fs_interleave
= max(fs
->fs_interleave
, 1); /* XXX */
764 if (fs
->fs_postblformat
== FS_42POSTBLFMT
) /* XXX */
765 fs
->fs_nrpos
= 8; /* XXX */
766 if (fs
->fs_inodefmt
< FS_44INODEFMT
) { /* XXX */
767 u_int64_t sizepb
= fs
->fs_bsize
; /* XXX */
769 fs
->fs_maxfilesize
= fs
->fs_bsize
* NDADDR
- 1; /* XXX */
770 for (i
= 0; i
< NIADDR
; i
++) { /* XXX */
771 sizepb
*= NINDIR(fs
); /* XXX */
772 fs
->fs_maxfilesize
+= sizepb
; /* XXX */
774 fs
->fs_qbmask
= ~fs
->fs_bmask
; /* XXX */
775 fs
->fs_qfmask
= ~fs
->fs_fmask
; /* XXX */
781 * unmount system call
784 ffs_unmount(mp
, mntflags
, context
)
787 vfs_context_t context
;
789 struct proc
*p
= vfs_context_proc(context
);
790 register struct ufsmount
*ump
;
791 register struct fs
*fs
;
797 if (mntflags
& MNT_FORCE
) {
801 if ( (error
= ffs_flushfiles(mp
, flags
, p
)) && !force
)
806 if (fs
->fs_ronly
== 0) {
808 if (error
= ffs_sbupdate(ump
, MNT_WAIT
)) {
811 /* we can atleast cleanup ; as the media could be WP */
812 /* & during mount, we do not check for write failures */
813 /* FIXME LATER : the Correct fix would be to have */
814 /* mount detect the WP media and downgrade to readonly mount */
815 /* For now, here it is */
820 _FREE(fs
->fs_csp
, M_UFSMNT
);
822 _FREE(ump
, M_UFSMNT
);
828 * Flush out all the files in a filesystem.
830 ffs_flushfiles(mp
, flags
, p
)
831 register struct mount
*mp
;
835 register struct ufsmount
*ump
;
842 * NOTE: The open quota files have an indirect reference
843 * on the root directory vnode. We must account for this
844 * extra reference when doing the intial vflush.
846 if (mp
->mnt_flag
& MNT_QUOTA
) {
847 struct vnode
*rootvp
= NULLVP
;
848 int quotafilecnt
= 0;
850 /* Find out how many quota files we have open. */
851 for (i
= 0; i
< MAXQUOTAS
; i
++) {
852 if (ump
->um_qfiles
[i
].qf_vp
!= NULLVP
)
857 * Check if the root vnode is in our inode hash
858 * (so we can skip over it).
860 rootvp
= ufs_ihashget(ump
->um_dev
, ROOTINO
);
862 error
= vflush(mp
, rootvp
, SKIPSYSTEM
|flags
);
866 * See if there are additional references on the
867 * root vp besides the ones obtained from the open
868 * quota files and the hfs_chashget call above.
871 (rootvp
->v_usecount
> (1 + quotafilecnt
))) {
872 error
= EBUSY
; /* root dir is still open */
876 if (error
&& (flags
& FORCECLOSE
) == 0)
879 for (i
= 0; i
< MAXQUOTAS
; i
++) {
880 if (ump
->um_qfiles
[i
].qf_vp
== NULLVP
)
885 * Here we fall through to vflush again to ensure
886 * that we have gotten rid of all the system vnodes.
890 error
= vflush(mp
, NULLVP
, SKIPSWAP
|flags
);
891 error
= vflush(mp
, NULLVP
, flags
);
896 * Get file system statistics.
899 ffs_statfs(mp
, sbp
, context
)
901 register struct vfsstatfs
*sbp
;
902 vfs_context_t context
;
904 register struct ufsmount
*ump
;
905 register struct fs
*fs
;
909 if (fs
->fs_magic
!= FS_MAGIC
)
911 sbp
->f_bsize
= fs
->fs_fsize
;
912 sbp
->f_iosize
= fs
->fs_bsize
;
913 sbp
->f_blocks
= (uint64_t)((unsigned long)fs
->fs_dsize
);
914 sbp
->f_bfree
= (uint64_t) ((unsigned long)(fs
->fs_cstotal
.cs_nbfree
* fs
->fs_frag
+
915 fs
->fs_cstotal
.cs_nffree
));
916 sbp
->f_bavail
= (uint64_t) ((unsigned long)freespace(fs
, fs
->fs_minfree
));
917 sbp
->f_files
= (uint64_t) ((unsigned long)(fs
->fs_ncg
* fs
->fs_ipg
- ROOTINO
));
918 sbp
->f_ffree
= (uint64_t) ((unsigned long)fs
->fs_cstotal
.cs_nifree
);
923 ffs_vfs_getattr(mp
, fsap
, context
)
925 struct vfs_attr
*fsap
;
926 vfs_context_t context
;
928 struct ufsmount
*ump
;
933 struct ufslabel
*ulp
;
935 int bs
, error
, length
;
939 cred
= vfs_context_ucred(context
);
941 VFSATTR_RETURN(fsap
, f_bsize
, fs
->fs_fsize
);
942 VFSATTR_RETURN(fsap
, f_iosize
, fs
->fs_bsize
);
943 VFSATTR_RETURN(fsap
, f_blocks
, (uint64_t)((unsigned long)fs
->fs_dsize
));
944 VFSATTR_RETURN(fsap
, f_bfree
, (uint64_t)((unsigned long)
945 (fs
->fs_cstotal
.cs_nbfree
* fs
->fs_frag
+
946 fs
->fs_cstotal
.cs_nffree
)));
947 VFSATTR_RETURN(fsap
, f_bavail
, (uint64_t)((unsigned long)freespace(fs
,
949 VFSATTR_RETURN(fsap
, f_files
, (uint64_t)((unsigned long)
950 (fs
->fs_ncg
* fs
->fs_ipg
- ROOTINO
)));
951 VFSATTR_RETURN(fsap
, f_ffree
, (uint64_t)((unsigned long)
952 fs
->fs_cstotal
.cs_nifree
));
954 if (VFSATTR_IS_ACTIVE(fsap
, f_fsid
)) {
955 fsap
->f_fsid
.val
[0] = mp
->mnt_vfsstat
.f_fsid
.val
[0];
956 fsap
->f_fsid
.val
[1] = mp
->mnt_vfsstat
.f_fsid
.val
[1];
957 VFSATTR_SET_SUPPORTED(fsap
, f_fsid
);
960 if (VFSATTR_IS_ACTIVE(fsap
, f_vol_name
)) {
961 devvp
= ump
->um_devvp
;
962 bs
= vfs_devblocksize(mp
);
964 if (error
= (int)buf_meta_bread(devvp
,
965 (daddr64_t
)(UFS_LABEL_OFFSET
/ bs
),
966 MAX(bs
, UFS_LABEL_SIZE
), cred
, &bp
)) {
973 * Since the disklabel is read directly by older user space
974 * code, make sure this buffer won't remain in the cache when
977 buf_setflags(bp
, B_NOCACHE
);
979 offset
= buf_dataptr(bp
) + (UFS_LABEL_OFFSET
% bs
);
980 ulp
= (struct ufslabel
*)offset
;
982 if (ufs_label_check(ulp
)) {
983 length
= ulp
->ul_namelen
;
985 if (mp
->mnt_flag
& MNT_REVEND
)
986 length
= OSSwapInt16(length
);
988 if (length
> 0 && length
<= UFS_MAX_LABEL_NAME
) {
989 bcopy(ulp
->ul_name
, fsap
->f_vol_name
, length
);
990 fsap
->f_vol_name
[UFS_MAX_LABEL_NAME
- 1] = '\0';
991 fsap
->f_vol_name
[length
] = '\0';
996 VFSATTR_SET_SUPPORTED(fsap
, f_vol_name
);
999 if (VFSATTR_IS_ACTIVE(fsap
, f_capabilities
)) {
1000 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_FORMAT
] =
1001 VOL_CAP_FMT_SYMBOLICLINKS
|
1002 VOL_CAP_FMT_HARDLINKS
|
1003 VOL_CAP_FMT_SPARSE_FILES
|
1004 VOL_CAP_FMT_CASE_SENSITIVE
|
1005 VOL_CAP_FMT_CASE_PRESERVING
|
1006 VOL_CAP_FMT_FAST_STATFS
;
1007 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_INTERFACES
]
1008 = VOL_CAP_INT_NFSEXPORT
|
1009 VOL_CAP_INT_VOL_RENAME
|
1010 VOL_CAP_INT_ADVLOCK
|
1012 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED1
]
1014 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED2
]
1017 /* Capabilities we know about: */
1018 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_FORMAT
] =
1019 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
1020 VOL_CAP_FMT_SYMBOLICLINKS
|
1021 VOL_CAP_FMT_HARDLINKS
|
1022 VOL_CAP_FMT_JOURNAL
|
1023 VOL_CAP_FMT_JOURNAL_ACTIVE
|
1024 VOL_CAP_FMT_NO_ROOT_TIMES
|
1025 VOL_CAP_FMT_SPARSE_FILES
|
1026 VOL_CAP_FMT_ZERO_RUNS
|
1027 VOL_CAP_FMT_CASE_SENSITIVE
|
1028 VOL_CAP_FMT_CASE_PRESERVING
|
1029 VOL_CAP_FMT_FAST_STATFS
|
1030 VOL_CAP_FMT_2TB_FILESIZE
;
1031 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_INTERFACES
] =
1032 VOL_CAP_INT_SEARCHFS
|
1033 VOL_CAP_INT_ATTRLIST
|
1034 VOL_CAP_INT_NFSEXPORT
|
1035 VOL_CAP_INT_READDIRATTR
|
1036 VOL_CAP_INT_EXCHANGEDATA
|
1037 VOL_CAP_INT_COPYFILE
|
1038 VOL_CAP_INT_ALLOCATE
|
1039 VOL_CAP_INT_VOL_RENAME
|
1040 VOL_CAP_INT_ADVLOCK
|
1042 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
1043 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
1045 VFSATTR_SET_SUPPORTED(fsap
, f_capabilities
);
1048 if (VFSATTR_IS_ACTIVE(fsap
, f_attributes
)) {
1049 fsap
->f_attributes
.validattr
.commonattr
= 0;
1050 fsap
->f_attributes
.validattr
.volattr
=
1051 ATTR_VOL_NAME
| ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
1052 fsap
->f_attributes
.validattr
.dirattr
= 0;
1053 fsap
->f_attributes
.validattr
.fileattr
= 0;
1054 fsap
->f_attributes
.validattr
.forkattr
= 0;
1056 fsap
->f_attributes
.nativeattr
.commonattr
= 0;
1057 fsap
->f_attributes
.nativeattr
.volattr
=
1058 ATTR_VOL_NAME
| ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
1059 fsap
->f_attributes
.nativeattr
.dirattr
= 0;
1060 fsap
->f_attributes
.nativeattr
.fileattr
= 0;
1061 fsap
->f_attributes
.nativeattr
.forkattr
= 0;
1063 VFSATTR_SET_SUPPORTED(fsap
, f_attributes
);
1071 ffs_vfs_setattr(mp
, fsap
, context
)
1073 struct vfs_attr
*fsap
;
1074 vfs_context_t context
;
1076 struct ufsmount
*ump
;
1077 struct vnode
*devvp
;
1079 struct ufslabel
*ulp
;
1086 cred
= vfs_context_ucred(context
);
1088 if (VFSATTR_IS_ACTIVE(fsap
, f_vol_name
)) {
1089 devvp
= ump
->um_devvp
;
1090 bs
= vfs_devblocksize(mp
);
1091 if (error
= buf_meta_bread(devvp
,
1092 (daddr64_t
)(UFS_LABEL_OFFSET
/ bs
),
1093 MAX(bs
, UFS_LABEL_SIZE
), cred
, &bp
)) {
1100 * Since the disklabel is read directly by older user space
1101 * code, make sure this buffer won't remain in the cache when
1104 buf_setflags(bp
, B_NOCACHE
);
1106 /* Validate the label structure; init if not valid */
1107 offset
= buf_dataptr(bp
) + (UFS_LABEL_OFFSET
% bs
);
1108 ulp
= (struct ufslabel
*)offset
;
1109 if (!ufs_label_check(ulp
))
1110 ufs_label_init(ulp
);
1112 /* Copy new name over existing name */
1113 ulp
->ul_namelen
= strlen(fsap
->f_vol_name
);
1114 bcopy(fsap
->f_vol_name
, ulp
->ul_name
, ulp
->ul_namelen
);
1115 ulp
->ul_name
[UFS_MAX_LABEL_NAME
- 1] = '\0';
1116 ulp
->ul_name
[ulp
->ul_namelen
] = '\0';
1119 if (mp
->mnt_flag
& MNT_REVEND
)
1120 ulp
->ul_namelen
= OSSwapInt16(ulp
->ul_namelen
);
1123 /* Update the checksum */
1124 ulp
->ul_checksum
= 0;
1125 ulp
->ul_checksum
= ul_cksum(ulp
, sizeof(*ulp
));
1127 /* Write the label back to disk */
1131 VFSATTR_SET_SUPPORTED(fsap
, f_vol_name
);
1136 struct ffs_sync_cargs
{
1137 vfs_context_t context
;
1144 ffs_sync_callback(struct vnode
*vp
, void *cargs
)
1147 struct ffs_sync_cargs
*args
;
1150 args
= (struct ffs_sync_cargs
*)cargs
;
1154 if ((ip
->i_flag
& (IN_ACCESS
| IN_CHANGE
| IN_MODIFIED
| IN_UPDATE
)) || vnode_hasdirtyblks(vp
)) {
1155 error
= VNOP_FSYNC(vp
, args
->waitfor
, args
->context
);
1158 args
->error
= error
;
1161 return (VNODE_RETURNED
);
1165 * Go through the disk queues to initiate sandbagged IO;
1166 * go through the inodes to write those that have been modified;
1167 * initiate the writing of the super block if it has been modified.
1169 * Note: we are always called with the filesystem marked `MPBUSY'.
1172 ffs_sync(mp
, waitfor
, context
)
1175 vfs_context_t context
;
1177 struct vnode
*nvp
, *vp
;
1178 struct ufsmount
*ump
= VFSTOUFS(mp
);
1181 int error
, allerror
= 0;
1182 struct ffs_sync_cargs args
;
1185 if (fs
->fs_fmod
!= 0 && fs
->fs_ronly
!= 0) { /* XXX */
1186 printf("fs = %s\n", fs
->fs_fsmnt
);
1187 panic("update: rofs mod");
1190 * Write back each (modified) inode.
1192 args
.context
= context
;
1193 args
.waitfor
= waitfor
;
1196 * ffs_sync_callback will be called for each vnode
1197 * hung off of this mount point... the vnode will be
1198 * properly referenced and unreferenced around the callback
1200 vnode_iterate(mp
, 0, ffs_sync_callback
, (void *)&args
);
1203 allerror
= args
.error
;
1206 * Force stale file system control information to be flushed.
1208 if (error
= VNOP_FSYNC(ump
->um_devvp
, waitfor
, context
))
1214 * Write back modified superblock.
1216 if (fs
->fs_fmod
!= 0) {
1219 fs
->fs_time
= tv
.tv_sec
;
1220 if (error
= ffs_sbupdate(ump
, waitfor
))
1227 * Look up a FFS dinode number to find its incore vnode, otherwise read it
1228 * in from disk. If it is in core, wait for the lock bit to clear, then
1229 * return the inode locked. Detection and handling of mount points must be
1230 * done by the calling routine.
1233 ffs_vget(mp
, ino
, vpp
, context
)
1237 vfs_context_t context
;
1239 return(ffs_vget_internal(mp
, (ino_t
)ino
, vpp
, NULL
, NULL
, 0, 0));
1244 ffs_vget_internal(mp
, ino
, vpp
, dvp
, cnp
, mode
, fhwanted
)
1249 struct componentname
*cnp
;
1253 struct proc
*p
= current_proc(); /* XXX */
1256 struct ufsmount
*ump
;
1259 struct vnode_fsparam vfsp
;
1263 int i
, type
, error
= 0;
1269 /* Check for unmount in progress */
1270 if (mp
->mnt_kern_flag
& MNTK_UNMOUNT
) {
1275 * Allocate a new inode... do it before we check the
1276 * cache, because the MALLOC_ZONE may block
1279 MALLOC_ZONE(ip
, struct inode
*, sizeof(struct inode
), type
, M_WAITOK
);
1282 * check in the inode hash
1284 if ((*vpp
= ufs_ihashget(dev
, ino
)) != NULL
) {
1286 * found it... get rid of the allocation
1287 * that we didn't need and return
1290 FREE_ZONE(ip
, sizeof(struct inode
), type
);
1294 bzero((caddr_t
)ip
, sizeof(struct inode
));
1298 // lockinit(&ip->i_lock, PINOD, "inode", 0, 0);
1299 // lockmgr(&ip->i_lock, LK_EXCLUSIVE, (struct slock *)0, p);
1301 ip
->i_fs
= fs
= ump
->um_fs
;
1305 for (i
= 0; i
< MAXQUOTAS
; i
++)
1306 ip
->i_dquot
[i
] = NODQUOT
;
1308 SET(ip
->i_flag
, IN_ALLOC
);
1310 * Put it onto its hash chain locked so that other requests for
1311 * this inode will block if they arrive while we are sleeping waiting
1312 * for old data structures to be purged or for the contents of the
1313 * disk portion of this inode to be read.
1317 /* Read in the disk contents for the inode, copy into the inode. */
1318 if (error
= (int)buf_bread(ump
->um_devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, ino_to_fsba(fs
, ino
))),
1319 (int)fs
->fs_bsize
, NOCRED
, &bp
)) {
1324 if (mp
->mnt_flag
& MNT_REVEND
) {
1325 byte_swap_inode_in(((struct dinode
*)buf_dataptr(bp
) + ino_to_fsbo(fs
, ino
)),ip
);
1327 ip
->i_din
= *((struct dinode
*)buf_dataptr(bp
) + ino_to_fsbo(fs
, ino
));
1330 ip
->i_din
= *((struct dinode
*)buf_dataptr(bp
) + ino_to_fsbo(fs
, ino
));
1331 #endif /* REV_ENDIAN_FS */
1335 vtype
= IFTOVT(ip
->i_mode
);
1337 vtype
= IFTOVT(mode
);
1339 if (vtype
== VNON
) {
1341 /* NFS is in play */
1351 vfsp
.vnfs_vtype
= vtype
;
1352 vfsp
.vnfs_str
= "ufs";
1353 vfsp
.vnfs_dvp
= dvp
;
1354 vfsp
.vnfs_fsnode
= ip
;
1355 vfsp
.vnfs_cnp
= cnp
;
1358 vfsp
.vnfs_filesize
= ip
->i_din
.di_size
;
1360 vfsp
.vnfs_filesize
= 0;
1362 if (vtype
== VFIFO
)
1363 vfsp
.vnfs_vops
= FFS_FIFOOPS
;
1364 else if (vtype
== VBLK
|| vtype
== VCHR
)
1365 vfsp
.vnfs_vops
= ffs_specop_p
;
1367 vfsp
.vnfs_vops
= ffs_vnodeop_p
;
1369 if (vtype
== VBLK
|| vtype
== VCHR
)
1370 vfsp
.vnfs_rdev
= ip
->i_rdev
;
1374 if (dvp
&& cnp
&& (cnp
->cn_flags
& MAKEENTRY
))
1375 vfsp
.vnfs_flags
= 0;
1377 vfsp
.vnfs_flags
= VNFS_NOCACHE
;
1380 * Tag root directory
1382 vfsp
.vnfs_markroot
= (ip
->i_number
== ROOTINO
);
1383 vfsp
.vnfs_marksystem
= 0;
1385 if ((error
= vnode_create(VNCREATE_FLAVOR
, VCREATESIZE
, &vfsp
, &vp
)))
1389 * Finish inode initialization now that aliasing has been resolved.
1391 ip
->i_devvp
= ump
->um_devvp
;
1394 vnode_ref(ip
->i_devvp
);
1396 vnode_settag(vp
, VT_UFS
);
1399 * Initialize modrev times
1402 SETHIGH(ip
->i_modrev
, tv
.tv_sec
);
1403 SETLOW(ip
->i_modrev
, tv
.tv_usec
* 4294);
1406 * Set up a generation number for this inode if it does not
1407 * already have one. This should only happen on old filesystems.
1409 if (ip
->i_gen
== 0) {
1410 if (++nextgennumber
< (u_long
)tv
.tv_sec
)
1411 nextgennumber
= tv
.tv_sec
;
1412 ip
->i_gen
= nextgennumber
;
1413 if ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
) == 0)
1414 ip
->i_flag
|= IN_MODIFIED
;
1417 * Ensure that uid and gid are correct. This is a temporary
1418 * fix until fsck has been changed to do the update.
1420 if (fs
->fs_inodefmt
< FS_44INODEFMT
) { /* XXX */
1421 ip
->i_uid
= ip
->i_din
.di_ouid
; /* XXX */
1422 ip
->i_gid
= ip
->i_din
.di_ogid
; /* XXX */
1426 CLR(ip
->i_flag
, IN_ALLOC
);
1428 if (ISSET(ip
->i_flag
, IN_WALLOC
))
1436 if (ISSET(ip
->i_flag
, IN_WALLOC
))
1438 FREE_ZONE(ip
, sizeof(struct inode
), type
);
1444 * File handle to vnode
1446 * Have to be really careful about stale file handles:
1447 * - check that the inode number is valid
1448 * - call vget to get the locked inode
1449 * - check for an unallocated inode (i_mode == 0)
1452 ffs_fhtovp(mp
, fhlen
, fhp
, vpp
, context
)
1453 register struct mount
*mp
;
1457 vfs_context_t context
;
1459 register struct ufid
*ufhp
;
1460 register struct inode
*ip
;
1466 if (fhlen
< (int)sizeof(struct ufid
))
1468 ufhp
= (struct ufid
*)fhp
;
1469 fs
= VFSTOUFS(mp
)->um_fs
;
1470 ino
= ntohl(ufhp
->ufid_ino
);
1471 if (ino
< ROOTINO
|| ino
>= fs
->fs_ncg
* fs
->fs_ipg
)
1473 error
= ffs_vget_internal(mp
, ino
, &nvp
, NULL
, NULL
, 0, 1);
1479 if (ip
->i_mode
== 0 || ip
->i_gen
!= ntohl(ufhp
->ufid_gen
)) {
1489 * Vnode pointer to File handle
1493 ffs_vptofh(vp
, fhlenp
, fhp
, context
)
1497 vfs_context_t context
;
1499 register struct inode
*ip
;
1500 register struct ufid
*ufhp
;
1502 if (*fhlenp
< (int)sizeof(struct ufid
))
1505 ufhp
= (struct ufid
*)fhp
;
1506 ufhp
->ufid_ino
= htonl(ip
->i_number
);
1507 ufhp
->ufid_gen
= htonl(ip
->i_gen
);
1508 *fhlenp
= sizeof(struct ufid
);
1513 * Initialize the filesystem; just use ufs_init.
1517 struct vfsconf
*vfsp
;
1520 return (ufs_init(vfsp
));
1524 * fast filesystem related variables.
1526 ffs_sysctl(int *name
, u_int namelen
, user_addr_t oldp
, size_t *oldlenp
,
1527 user_addr_t newp
, size_t newlen
, vfs_context_t context
)
1529 extern int doclusterread
, doclusterwrite
, doreallocblks
, doasyncfree
;
1531 /* all sysctl names at this level are terminal */
1533 return (ENOTDIR
); /* overloaded */
1536 case FFS_CLUSTERREAD
:
1537 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
1539 case FFS_CLUSTERWRITE
:
1540 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
1542 case FFS_REALLOCBLKS
:
1543 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
1546 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
, &doasyncfree
));
1554 * Write a superblock and associated information back to disk.
1557 ffs_sbupdate(mp
, waitfor
)
1558 struct ufsmount
*mp
;
1561 register struct fs
*dfs
, *fs
= mp
->um_fs
;
1562 register struct buf
*bp
;
1565 int i
, size
, error
, allerror
= 0;
1568 int rev_endian
=(mp
->um_mountp
->mnt_flag
& MNT_REVEND
);
1569 #endif /* REV_ENDIAN_FS */
1572 * First write back the summary information.
1574 blks
= howmany(fs
->fs_cssize
, fs
->fs_fsize
);
1576 for (i
= 0; i
< blks
; i
+= fs
->fs_frag
) {
1577 size
= fs
->fs_bsize
;
1578 if (i
+ fs
->fs_frag
> blks
)
1579 size
= (blks
- i
) * fs
->fs_fsize
;
1580 bp
= buf_getblk(mp
->um_devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, fs
->fs_csaddr
+ i
)),
1581 size
, 0, 0, BLK_META
);
1582 bcopy(space
, (char *)buf_dataptr(bp
), (u_int
)size
);
1585 byte_swap_ints((int *)buf_dataptr(bp
), size
/ sizeof(int));
1587 #endif /* REV_ENDIAN_FS */
1588 space
= (char *)space
+ size
;
1589 if (waitfor
!= MNT_WAIT
)
1591 else if (error
= (int)buf_bwrite(bp
))
1595 * Now write back the superblock itself. If any errors occurred
1596 * up to this point, then fail so that the superblock avoids
1597 * being written out as clean.
1601 devBlockSize
= vfs_devblocksize(mp
->um_mountp
);
1603 bp
= buf_getblk(mp
->um_devvp
, (daddr64_t
)((unsigned)(SBOFF
/devBlockSize
)), (int)fs
->fs_sbsize
, 0, 0, BLK_META
);
1604 bcopy((caddr_t
)fs
, (char *)buf_dataptr(bp
), (u_int
)fs
->fs_sbsize
);
1605 /* Restore compatibility to old file systems. XXX */
1606 dfs
= (struct fs
*)buf_dataptr(bp
); /* XXX */
1607 if (fs
->fs_postblformat
== FS_42POSTBLFMT
) /* XXX */
1608 dfs
->fs_nrpos
= -1; /* XXX */
1611 * Swapping bytes here ; so that in case
1612 * of inode format < FS_44INODEFMT appropriate
1616 byte_swap_sbout((struct fs
*)buf_dataptr(bp
));
1618 #endif /* REV_ENDIAN_FS */
1619 if (fs
->fs_inodefmt
< FS_44INODEFMT
) { /* XXX */
1620 int32_t *lp
, tmp
; /* XXX */
1622 lp
= (int32_t *)&dfs
->fs_qbmask
; /* XXX */
1623 tmp
= lp
[4]; /* XXX */
1624 for (i
= 4; i
> 0; i
--) /* XXX */
1625 lp
[i
] = lp
[i
-1]; /* XXX */
1626 lp
[0] = tmp
; /* XXX */
1629 /* Note that dfs is already swapped so swap the filesize
1633 dfs
->fs_maxfilesize
= OSSwapInt64(mp
->um_savedmaxfilesize
); /* XXX */
1635 #endif /* REV_ENDIAN_FS */
1636 dfs
->fs_maxfilesize
= mp
->um_savedmaxfilesize
; /* XXX */
1639 #endif /* REV_ENDIAN_FS */
1640 if (waitfor
!= MNT_WAIT
)
1642 else if (error
= (int)buf_bwrite(bp
))