2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
32 * Copyright (c) 1989, 1991, 1993, 1994
33 * The Regents of the University of California. All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * @(#)ffs_vfsops.c 8.31 (Berkeley) 5/20/95
66 #include <rev_endian_fs.h>
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/namei.h>
71 #include <sys/kauth.h>
72 #include <sys/kernel.h>
73 #include <sys/vnode_internal.h>
74 #include <sys/socket.h>
75 #include <sys/mount_internal.h>
76 #include <sys/mount.h>
81 #include <sys/ioctl.h>
82 #include <sys/errno.h>
83 #include <sys/malloc.h>
85 #include <sys/quota.h>
87 #include <miscfs/specfs/specdev.h>
89 #include <ufs/ufs/quota.h>
90 #include <ufs/ufs/ufsmount.h>
91 #include <ufs/ufs/inode.h>
92 #include <ufs/ufs/ufs_extern.h>
94 #include <ufs/ffs/fs.h>
95 #include <ufs/ffs/ffs_extern.h>
97 #include <ufs/ufs/ufs_byte_order.h>
98 #include <libkern/OSByteOrder.h>
99 #endif /* REV_ENDIAN_FS */
101 int ffs_sbupdate(struct ufsmount
*, int);
103 struct vfsops ufs_vfsops
= {
120 extern u_long nextgennumber
;
126 #define SETHIGH(q, h) { \
129 tmp.val[_QUAD_HIGHWORD] = (h); \
132 #define SETLOW(q, l) { \
135 tmp.val[_QUAD_LOWWORD] = (l); \
140 * Called by main() when ufs is going to be mounted as root.
143 ffs_mountroot(mount_t mp
, vnode_t rvp
, vfs_context_t context
)
145 struct proc
*p
= current_proc(); /* XXX */
148 /* Set asynchronous flag by default */
149 vfs_setflags(mp
, MNT_ASYNC
);
151 if (error
= ffs_mountfs(rvp
, mp
, context
))
154 (void)ffs_statfs(mp
, vfs_statfs(mp
), NULL
);
165 ffs_mount(struct mount
*mp
, vnode_t devvp
, __unused user_addr_t data
, vfs_context_t context
)
167 struct proc
*p
= vfs_context_proc(context
);
168 struct ufsmount
*ump
;
169 register struct fs
*fs
;
171 int error
= 0, flags
;
177 * If updating, check whether changing from read-write to
178 * read-only; if there is no device name, that's all we do.
180 if (mp
->mnt_flag
& MNT_UPDATE
) {
183 if (fs
->fs_ronly
== 0 && (mp
->mnt_flag
& MNT_RDONLY
)) {
185 * Flush any dirty data.
187 VFS_SYNC(mp
, MNT_WAIT
, context
);
189 * Check for and optionally get rid of files open
193 if (mp
->mnt_flag
& MNT_FORCE
)
195 if (error
= ffs_flushfiles(mp
, flags
, p
))
199 if (error
= ffs_sbupdate(ump
, MNT_WAIT
)) {
205 /* save fs_ronly to later use */
206 ronly
= fs
->fs_ronly
;
207 if ((mp
->mnt_flag
& MNT_RELOAD
) || ronly
)
210 (error
= ffs_reload(mp
, vfs_context_ucred(context
), p
)))
212 /* replace the ronly after load */
213 fs
->fs_ronly
= ronly
;
215 * Do not update the file system if the user was in singleuser
216 * and then tries to mount -uw without fscking
218 if (!fs
->fs_clean
&& ronly
) {
219 printf("WARNING: trying to mount a dirty file system\n");
220 if (issingleuser() && (mp
->mnt_flag
& MNT_ROOTFS
)) {
221 printf("WARNING: R/W mount of %s denied. Filesystem is not clean - run fsck\n",fs
->fs_fsmnt
);
223 * Reset the readonly bit as reload might have
231 if (ronly
&& (mp
->mnt_kern_flag
& MNTK_WANTRDWR
)) {
234 (void) ffs_sbupdate(ump
, MNT_WAIT
);
240 if ((mp
->mnt_flag
& MNT_UPDATE
) == 0)
241 error
= ffs_mountfs(devvp
, mp
, context
);
243 if (devvp
!= ump
->um_devvp
)
244 error
= EINVAL
; /* needs translation */
251 bzero(fs
->fs_fsmnt
, sizeof(fs
->fs_fsmnt
));
252 strncpy(fs
->fs_fsmnt
, (caddr_t
)mp
->mnt_vfsstat
.f_mntonname
, sizeof(fs
->fs_fsmnt
) - 1);
253 (void)ffs_statfs(mp
, &mp
->mnt_vfsstat
, p
);
258 struct ffs_reload_cargs
{
266 #endif /* REV_ENDIAN_FS */
271 ffs_reload_callback(struct vnode
*vp
, void *cargs
)
276 struct ffs_reload_cargs
*args
;
278 args
= (struct ffs_reload_cargs
*)cargs
;
281 * flush all the buffers associated with this node
283 if (buf_invalidateblks(vp
, 0, 0, 0))
284 panic("ffs_reload: dirty2");
287 * Step 6: re-read inode data
292 if (args
->error
= (int)buf_bread(args
->devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, ino_to_fsba(fs
, ip
->i_number
))),
293 (int)fs
->fs_bsize
, NOCRED
, &bp
)) {
296 return (VNODE_RETURNED_DONE
);
300 if (args
->rev_endian
) {
301 byte_swap_inode_in(((struct dinode
*)buf_dataptr(bp
) +
302 ino_to_fsbo(fs
, ip
->i_number
)), ip
);
304 #endif /* REV_ENDIAN_FS */
305 ip
->i_din
= *((struct dinode
*)buf_dataptr(bp
) +
306 ino_to_fsbo(fs
, ip
->i_number
));
309 #endif /* REV_ENDIAN_FS */
313 return (VNODE_RETURNED
);
318 * Reload all incore data for a filesystem (used after running fsck on
319 * the root filesystem and finding things to fix). The filesystem must
320 * be mounted read-only.
322 * Things to do to update the mount:
323 * 1) invalidate all cached meta-data.
324 * 2) re-read superblock from disk.
325 * 3) re-read summary information from disk.
326 * 4) invalidate all inactive vnodes.
327 * 5) invalidate all cached file data.
328 * 6) re-read inode data for all active vnodes.
330 ffs_reload(struct mount
*mountp
, kauth_cred_t cred
, struct proc
*p
)
332 register struct vnode
*devvp
;
335 struct fs
*fs
, *newfs
;
336 int i
, blks
, size
, error
;
337 u_int64_t maxfilesize
; /* XXX */
339 struct ffs_reload_cargs args
;
341 int rev_endian
= (mountp
->mnt_flag
& MNT_REVEND
);
342 #endif /* REV_ENDIAN_FS */
344 if ((mountp
->mnt_flag
& MNT_RDONLY
) == 0)
347 * Step 1: invalidate all cached meta-data.
349 devvp
= VFSTOUFS(mountp
)->um_devvp
;
350 if (buf_invalidateblks(devvp
, 0, 0, 0))
351 panic("ffs_reload: dirty1");
353 * Step 2: re-read superblock from disk.
355 size
= vfs_devblocksize(mountp
);
357 if (error
= (int)buf_bread(devvp
, (daddr64_t
)((unsigned)(SBOFF
/size
)), SBSIZE
, NOCRED
,&bp
)) {
361 newfs
= (struct fs
*)buf_dataptr(bp
);
364 byte_swap_sbin(newfs
);
366 #endif /* REV_ENDIAN_FS */
367 if (newfs
->fs_magic
!= FS_MAGIC
|| newfs
->fs_bsize
> MAXBSIZE
||
368 newfs
->fs_bsize
< sizeof(struct fs
)) {
371 byte_swap_sbout(newfs
);
372 #endif /* REV_ENDIAN_FS */
375 return (EIO
); /* XXX needs translation */
377 fs
= VFSTOUFS(mountp
)->um_fs
;
379 * Copy pointer fields back into superblock before copying in XXX
380 * new superblock. These should really be in the ufsmount. XXX
381 * Note that important parameters (eg fs_ncg) are unchanged.
383 newfs
->fs_csp
= fs
->fs_csp
;
384 newfs
->fs_maxcluster
= fs
->fs_maxcluster
;
385 newfs
->fs_contigdirs
= fs
->fs_contigdirs
;
386 bcopy(newfs
, fs
, (u_int
)fs
->fs_sbsize
);
387 if (fs
->fs_sbsize
< SBSIZE
)
391 byte_swap_sbout(newfs
);
392 #endif /* REV_ENDIAN_FS */
394 mountp
->mnt_maxsymlinklen
= fs
->fs_maxsymlinklen
;
396 maxfilesize
= 0x100000000ULL
; /* 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
= (int)buf_bread(devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, fs
->fs_csaddr
+ i
)), size
,
416 byte_swap_ints((int *)buf_dataptr(bp
), size
/ sizeof(int));
418 #endif /* REV_ENDIAN_FS */
419 bcopy((char *)buf_dataptr(bp
), space
, (u_int
)size
);
423 byte_swap_ints((int *)buf_dataptr(bp
), size
/ sizeof(int));
425 #endif /* REV_ENDIAN_FS */
426 space
= (char *) space
+ size
;
430 * We no longer know anything about clusters per cylinder group.
432 if (fs
->fs_contigsumsize
> 0) {
433 lp
= fs
->fs_maxcluster
;
434 for (i
= 0; i
< fs
->fs_ncg
; i
++)
435 *lp
++ = fs
->fs_contigsumsize
;
438 args
.rev_endian
= rev_endian
;
439 #endif /* REV_ENDIAN_FS */
446 * ffs_reload_callback will be called for each vnode
447 * hung off of this mount point that can't be recycled...
448 * vnode_iterate will recycle those that it can (the VNODE_RELOAD option)
449 * the vnode will be in an 'unbusy' state (VNODE_WAIT) and
450 * properly referenced and unreferenced around the callback
452 vnode_iterate(mountp
, VNODE_RELOAD
| VNODE_WAIT
, ffs_reload_callback
, (void *)&args
);
458 * Common code for mount and mountroot
461 ffs_mountfs(devvp
, mp
, context
)
464 vfs_context_t context
;
466 struct ufsmount
*ump
;
472 int32_t clustersumoff
;
474 int error
, i
, blks
, ronly
;
478 u_int64_t maxfilesize
; /* XXX */
479 u_int dbsize
= DEV_BSIZE
;
482 #endif /* REV_ENDIAN_FS */
484 cred
= vfs_context_ucred(context
);
486 ronly
= vfs_isrdonly(mp
);
490 /* Advisory locking should be handled at the VFS layer */
491 vfs_setlocklocal(mp
);
493 /* Obtain the actual device block size */
494 if (VNOP_IOCTL(devvp
, DKIOCGETBLOCKSIZE
, (caddr_t
)&size
, 0, context
)) {
499 if (error
= (int)buf_bread(devvp
, (daddr64_t
)((unsigned)(SBOFF
/size
)),
502 fs
= (struct fs
*)buf_dataptr(bp
);
504 if (fs
->fs_magic
!= FS_MAGIC
|| fs
->fs_bsize
> MAXBSIZE
||
505 fs
->fs_bsize
< sizeof(struct fs
)) {
506 int magic
= fs
->fs_magic
;
508 byte_swap_ints(&magic
, 1);
509 if (magic
!= FS_MAGIC
) {
514 if (fs
->fs_magic
!= FS_MAGIC
|| fs
->fs_bsize
> MAXBSIZE
||
515 fs
->fs_bsize
< sizeof(struct fs
)) {
517 error
= EINVAL
; /* XXX needs translation */
522 #endif /* REV_ENDIAN_FS */
523 if (fs
->fs_magic
!= FS_MAGIC
|| fs
->fs_bsize
> MAXBSIZE
||
524 fs
->fs_bsize
< sizeof(struct fs
)) {
528 #endif /* REV_ENDIAN_FS */
529 error
= EINVAL
; /* XXX needs translation */
535 * Buffer cache does not handle multiple pages in a buf when
536 * invalidating incore buffer in pageout. There are no locks
537 * in the pageout path. So there is a danger of loosing data when
538 * block allocation happens at the same time a pageout of buddy
539 * page occurs. incore() returns buf with both
540 * pages, this leads vnode-pageout to incorrectly flush of entire.
541 * buf. Till the low level ffs code is modified to deal with these
542 * do not mount any FS more than 4K size.
545 * Can't mount filesystems with a fragment size less than DIRBLKSIZ
548 * Don't mount dirty filesystems, except for the root filesystem
550 if ((fs
->fs_bsize
> PAGE_SIZE
) || (fs
->fs_fsize
< DIRBLKSIZ
) ||
551 ((!(mp
->mnt_flag
& MNT_ROOTFS
)) && (!fs
->fs_clean
))) {
555 #endif /* REV_ENDIAN_FS */
560 /* Let's figure out the devblock size the file system is with */
561 /* the device block size = fragment size / number of sectors per frag */
563 dbsize
= fs
->fs_fsize
/ NSPF(fs
);
565 kprintf("device blocksize computaion failed\n");
567 if (VNOP_IOCTL(devvp
, DKIOCSETBLOCKSIZE
, (caddr_t
)&dbsize
,
568 FWRITE
, context
) != 0) {
569 kprintf("failed to set device blocksize\n");
571 /* force the specfs to reread blocksize from size() */
572 set_fsblocksize(devvp
);
575 /* XXX updating 4.2 FFS superblocks trashes rotational layout tables */
576 if (fs
->fs_postblformat
== FS_42POSTBLFMT
&& !ronly
) {
580 #endif /* REV_ENDIAN_FS */
581 error
= EROFS
; /* needs translation */
585 /* If we are not mounting read only, then check for overlap
586 * condition in cylinder group's free block map.
587 * If overlap exists, then force this into a read only mount
588 * to avoid further corruption. PR#2216969
591 if (error
= (int)buf_bread (devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, cgtod(fs
, 0))),
592 (int)fs
->fs_cgsize
, NOCRED
, &cgbp
)) {
596 cgp
= (struct cg
*)buf_dataptr(cgbp
);
599 byte_swap_cgin(cgp
,fs
);
600 #endif /* REV_ENDIAN_FS */
601 if (!cg_chkmagic(cgp
)){
604 byte_swap_cgout(cgp
,fs
);
605 #endif /* REV_ENDIAN_FS */
609 if (cgp
->cg_clustersumoff
!= 0) {
610 /* Check for overlap */
611 clustersumoff
= cgp
->cg_freeoff
+
612 howmany(fs
->fs_cpg
* fs
->fs_spc
/ NSPF(fs
), NBBY
);
613 clustersumoff
= roundup(clustersumoff
, sizeof(long));
614 if (cgp
->cg_clustersumoff
< clustersumoff
) {
616 mp
->mnt_flag
|= MNT_RDONLY
;
622 byte_swap_cgout(cgp
,fs
);
623 #endif /* REV_ENDIAN_FS */
627 ump
= _MALLOC(sizeof *ump
, M_UFSMNT
, M_WAITOK
);
628 bzero((caddr_t
)ump
, sizeof *ump
);
629 ump
->um_fs
= _MALLOC((u_long
)fs
->fs_sbsize
, M_UFSMNT
,
631 bcopy((char *)buf_dataptr(bp
), ump
->um_fs
, (u_int
)fs
->fs_sbsize
);
632 if (fs
->fs_sbsize
< SBSIZE
)
637 #endif /* REV_ENDIAN_FS */
641 fs
->fs_ronly
= ronly
;
642 size
= fs
->fs_cssize
;
643 blks
= howmany(size
, fs
->fs_fsize
);
644 if (fs
->fs_contigsumsize
> 0)
645 size
+= fs
->fs_ncg
* sizeof(int32_t);
646 size
+= fs
->fs_ncg
* sizeof(u_int8_t
);
647 space
= _MALLOC((u_long
)size
, M_UFSMNT
, M_WAITOK
);
649 for (i
= 0; i
< blks
; i
+= fs
->fs_frag
) {
651 if (i
+ fs
->fs_frag
> blks
)
652 size
= (blks
- i
) * fs
->fs_fsize
;
653 if (error
= (int)buf_bread(devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, fs
->fs_csaddr
+ i
)),
655 _FREE(fs
->fs_csp
, M_UFSMNT
);
658 bcopy((char *)buf_dataptr(bp
), space
, (u_int
)size
);
661 byte_swap_ints((int *) space
, size
/ sizeof(int));
662 #endif /* REV_ENDIAN_FS */
663 space
= (char *)space
+ size
;
667 if (fs
->fs_contigsumsize
> 0) {
668 fs
->fs_maxcluster
= lp
= space
;
669 for (i
= 0; i
< fs
->fs_ncg
; i
++)
670 *lp
++ = fs
->fs_contigsumsize
;
673 size
= fs
->fs_ncg
* sizeof(u_int8_t
);
674 fs
->fs_contigdirs
= (u_int8_t
*)space
;
675 space
= (u_int8_t
*)space
+ size
;
676 bzero(fs
->fs_contigdirs
, size
);
677 /* XXX Compatibility for old filesystems */
678 if (fs
->fs_avgfilesize
<= 0)
679 fs
->fs_avgfilesize
= AVFILESIZ
;
680 if (fs
->fs_avgfpdir
<= 0)
681 fs
->fs_avgfpdir
= AFPDIR
;
682 /* XXX End of compatibility */
683 mp
->mnt_data
= (qaddr_t
)ump
;
684 mp
->mnt_vfsstat
.f_fsid
.val
[0] = (long)dev
;
685 mp
->mnt_vfsstat
.f_fsid
.val
[1] = vfs_typenum(mp
);
686 /* XXX warning hardcoded max symlen and not "mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen;" */
687 mp
->mnt_maxsymlinklen
= 60;
690 mp
->mnt_flag
|= MNT_REVEND
;
691 #endif /* REV_ENDIAN_FS */
694 ump
->um_devvp
= devvp
;
695 ump
->um_nindir
= fs
->fs_nindir
;
696 ump
->um_bptrtodb
= fs
->fs_fsbtodb
;
697 ump
->um_seqinc
= fs
->fs_frag
;
698 for (i
= 0; i
< MAXQUOTAS
; i
++)
699 dqfileinit(&ump
->um_qfiles
[i
]);
701 ump
->um_savedmaxfilesize
= fs
->fs_maxfilesize
; /* XXX */
702 maxfilesize
= 0x100000000ULL
; /* 4GB */
704 maxfilesize
= (u_int64_t
)0x40000000 * fs
->fs_bsize
- 1; /* XXX */
706 if (fs
->fs_maxfilesize
> maxfilesize
) /* XXX */
707 fs
->fs_maxfilesize
= maxfilesize
; /* XXX */
710 (void) ffs_sbupdate(ump
, MNT_WAIT
);
717 _FREE(ump
->um_fs
, M_UFSMNT
);
718 _FREE(ump
, M_UFSMNT
);
724 * Sanity checks for old file systems.
726 * XXX - goes away some day.
733 fs
->fs_npsect
= max(fs
->fs_npsect
, fs
->fs_nsect
); /* XXX */
734 fs
->fs_interleave
= max(fs
->fs_interleave
, 1); /* XXX */
735 if (fs
->fs_postblformat
== FS_42POSTBLFMT
) /* XXX */
736 fs
->fs_nrpos
= 8; /* XXX */
737 if (fs
->fs_inodefmt
< FS_44INODEFMT
) { /* XXX */
738 u_int64_t sizepb
= fs
->fs_bsize
; /* XXX */
740 fs
->fs_maxfilesize
= fs
->fs_bsize
* NDADDR
- 1; /* XXX */
741 for (i
= 0; i
< NIADDR
; i
++) { /* XXX */
742 sizepb
*= NINDIR(fs
); /* XXX */
743 fs
->fs_maxfilesize
+= sizepb
; /* XXX */
745 fs
->fs_qbmask
= ~fs
->fs_bmask
; /* XXX */
746 fs
->fs_qfmask
= ~fs
->fs_fmask
; /* XXX */
752 * unmount system call
755 ffs_unmount(mp
, mntflags
, context
)
758 vfs_context_t context
;
760 struct proc
*p
= vfs_context_proc(context
);
761 register struct ufsmount
*ump
;
762 register struct fs
*fs
;
768 if (mntflags
& MNT_FORCE
) {
772 if ( (error
= ffs_flushfiles(mp
, flags
, p
)) && !force
)
777 if (fs
->fs_ronly
== 0) {
779 if (error
= ffs_sbupdate(ump
, MNT_WAIT
)) {
782 /* we can atleast cleanup ; as the media could be WP */
783 /* & during mount, we do not check for write failures */
784 /* FIXME LATER : the Correct fix would be to have */
785 /* mount detect the WP media and downgrade to readonly mount */
786 /* For now, here it is */
791 _FREE(fs
->fs_csp
, M_UFSMNT
);
793 _FREE(ump
, M_UFSMNT
);
799 * Flush out all the files in a filesystem.
801 ffs_flushfiles(mp
, flags
, p
)
802 register struct mount
*mp
;
806 register struct ufsmount
*ump
;
813 * NOTE: The open quota files have an indirect reference
814 * on the root directory vnode. We must account for this
815 * extra reference when doing the intial vflush.
817 if (mp
->mnt_flag
& MNT_QUOTA
) {
818 struct vnode
*rootvp
= NULLVP
;
819 int quotafilecnt
= 0;
821 /* Find out how many quota files we have open. */
822 for (i
= 0; i
< MAXQUOTAS
; i
++) {
823 if (ump
->um_qfiles
[i
].qf_vp
!= NULLVP
)
828 * Check if the root vnode is in our inode hash
829 * (so we can skip over it).
831 rootvp
= ufs_ihashget(ump
->um_dev
, ROOTINO
);
833 error
= vflush(mp
, rootvp
, SKIPSYSTEM
|flags
);
837 * See if there are additional references on the
838 * root vp besides the ones obtained from the open
839 * quota files and the hfs_chashget call above.
842 (rootvp
->v_usecount
> (1 + quotafilecnt
))) {
843 error
= EBUSY
; /* root dir is still open */
847 if (error
&& (flags
& FORCECLOSE
) == 0)
850 for (i
= 0; i
< MAXQUOTAS
; i
++) {
851 if (ump
->um_qfiles
[i
].qf_vp
== NULLVP
)
856 * Here we fall through to vflush again to ensure
857 * that we have gotten rid of all the system vnodes.
861 error
= vflush(mp
, NULLVP
, SKIPSWAP
|flags
);
862 error
= vflush(mp
, NULLVP
, flags
);
867 * Get file system statistics.
870 ffs_statfs(mp
, sbp
, context
)
872 register struct vfsstatfs
*sbp
;
873 vfs_context_t context
;
875 register struct ufsmount
*ump
;
876 register struct fs
*fs
;
880 if (fs
->fs_magic
!= FS_MAGIC
)
882 sbp
->f_bsize
= fs
->fs_fsize
;
883 sbp
->f_iosize
= fs
->fs_bsize
;
884 sbp
->f_blocks
= (uint64_t)((unsigned long)fs
->fs_dsize
);
885 sbp
->f_bfree
= (uint64_t) ((unsigned long)(fs
->fs_cstotal
.cs_nbfree
* fs
->fs_frag
+
886 fs
->fs_cstotal
.cs_nffree
));
887 sbp
->f_bavail
= (uint64_t) ((unsigned long)freespace(fs
, fs
->fs_minfree
));
888 sbp
->f_files
= (uint64_t) ((unsigned long)(fs
->fs_ncg
* fs
->fs_ipg
- ROOTINO
));
889 sbp
->f_ffree
= (uint64_t) ((unsigned long)fs
->fs_cstotal
.cs_nifree
);
894 ffs_vfs_getattr(mp
, fsap
, context
)
896 struct vfs_attr
*fsap
;
897 vfs_context_t context
;
899 struct ufsmount
*ump
;
904 struct ufslabel
*ulp
;
906 int bs
, error
, length
;
910 cred
= vfs_context_ucred(context
);
912 VFSATTR_RETURN(fsap
, f_bsize
, fs
->fs_fsize
);
913 VFSATTR_RETURN(fsap
, f_iosize
, fs
->fs_bsize
);
914 VFSATTR_RETURN(fsap
, f_blocks
, (uint64_t)((unsigned long)fs
->fs_dsize
));
915 VFSATTR_RETURN(fsap
, f_bfree
, (uint64_t)((unsigned long)
916 (fs
->fs_cstotal
.cs_nbfree
* fs
->fs_frag
+
917 fs
->fs_cstotal
.cs_nffree
)));
918 VFSATTR_RETURN(fsap
, f_bavail
, (uint64_t)((unsigned long)freespace(fs
,
920 VFSATTR_RETURN(fsap
, f_files
, (uint64_t)((unsigned long)
921 (fs
->fs_ncg
* fs
->fs_ipg
- ROOTINO
)));
922 VFSATTR_RETURN(fsap
, f_ffree
, (uint64_t)((unsigned long)
923 fs
->fs_cstotal
.cs_nifree
));
925 if (VFSATTR_IS_ACTIVE(fsap
, f_fsid
)) {
926 fsap
->f_fsid
.val
[0] = mp
->mnt_vfsstat
.f_fsid
.val
[0];
927 fsap
->f_fsid
.val
[1] = mp
->mnt_vfsstat
.f_fsid
.val
[1];
928 VFSATTR_SET_SUPPORTED(fsap
, f_fsid
);
931 if (VFSATTR_IS_ACTIVE(fsap
, f_vol_name
)) {
932 devvp
= ump
->um_devvp
;
933 bs
= vfs_devblocksize(mp
);
935 if (error
= (int)buf_meta_bread(devvp
,
936 (daddr64_t
)(UFS_LABEL_OFFSET
/ bs
),
937 MAX(bs
, UFS_LABEL_SIZE
), cred
, &bp
)) {
944 * Since the disklabel is read directly by older user space
945 * code, make sure this buffer won't remain in the cache when
948 buf_setflags(bp
, B_NOCACHE
);
950 offset
= buf_dataptr(bp
) + (UFS_LABEL_OFFSET
% bs
);
951 ulp
= (struct ufslabel
*)offset
;
953 if (ufs_label_check(ulp
)) {
954 length
= ulp
->ul_namelen
;
956 if (mp
->mnt_flag
& MNT_REVEND
)
957 length
= OSSwapInt16(length
);
959 if (length
> 0 && length
<= UFS_MAX_LABEL_NAME
) {
960 bcopy(ulp
->ul_name
, fsap
->f_vol_name
, length
);
961 fsap
->f_vol_name
[UFS_MAX_LABEL_NAME
- 1] = '\0';
962 fsap
->f_vol_name
[length
] = '\0';
967 VFSATTR_SET_SUPPORTED(fsap
, f_vol_name
);
970 if (VFSATTR_IS_ACTIVE(fsap
, f_capabilities
)) {
971 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_FORMAT
] =
972 VOL_CAP_FMT_SYMBOLICLINKS
|
973 VOL_CAP_FMT_HARDLINKS
|
974 VOL_CAP_FMT_SPARSE_FILES
|
975 VOL_CAP_FMT_CASE_SENSITIVE
|
976 VOL_CAP_FMT_CASE_PRESERVING
|
977 VOL_CAP_FMT_FAST_STATFS
;
978 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_INTERFACES
]
979 = VOL_CAP_INT_NFSEXPORT
|
980 VOL_CAP_INT_VOL_RENAME
|
981 VOL_CAP_INT_ADVLOCK
|
983 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED1
]
985 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED2
]
988 /* Capabilities we know about: */
989 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_FORMAT
] =
990 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
991 VOL_CAP_FMT_SYMBOLICLINKS
|
992 VOL_CAP_FMT_HARDLINKS
|
993 VOL_CAP_FMT_JOURNAL
|
994 VOL_CAP_FMT_JOURNAL_ACTIVE
|
995 VOL_CAP_FMT_NO_ROOT_TIMES
|
996 VOL_CAP_FMT_SPARSE_FILES
|
997 VOL_CAP_FMT_ZERO_RUNS
|
998 VOL_CAP_FMT_CASE_SENSITIVE
|
999 VOL_CAP_FMT_CASE_PRESERVING
|
1000 VOL_CAP_FMT_FAST_STATFS
|
1001 VOL_CAP_FMT_2TB_FILESIZE
;
1002 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_INTERFACES
] =
1003 VOL_CAP_INT_SEARCHFS
|
1004 VOL_CAP_INT_ATTRLIST
|
1005 VOL_CAP_INT_NFSEXPORT
|
1006 VOL_CAP_INT_READDIRATTR
|
1007 VOL_CAP_INT_EXCHANGEDATA
|
1008 VOL_CAP_INT_COPYFILE
|
1009 VOL_CAP_INT_ALLOCATE
|
1010 VOL_CAP_INT_VOL_RENAME
|
1011 VOL_CAP_INT_ADVLOCK
|
1013 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
1014 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
1016 VFSATTR_SET_SUPPORTED(fsap
, f_capabilities
);
1019 if (VFSATTR_IS_ACTIVE(fsap
, f_attributes
)) {
1020 fsap
->f_attributes
.validattr
.commonattr
= 0;
1021 fsap
->f_attributes
.validattr
.volattr
=
1022 ATTR_VOL_NAME
| ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
1023 fsap
->f_attributes
.validattr
.dirattr
= 0;
1024 fsap
->f_attributes
.validattr
.fileattr
= 0;
1025 fsap
->f_attributes
.validattr
.forkattr
= 0;
1027 fsap
->f_attributes
.nativeattr
.commonattr
= 0;
1028 fsap
->f_attributes
.nativeattr
.volattr
=
1029 ATTR_VOL_NAME
| ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
1030 fsap
->f_attributes
.nativeattr
.dirattr
= 0;
1031 fsap
->f_attributes
.nativeattr
.fileattr
= 0;
1032 fsap
->f_attributes
.nativeattr
.forkattr
= 0;
1034 VFSATTR_SET_SUPPORTED(fsap
, f_attributes
);
1042 ffs_vfs_setattr(mp
, fsap
, context
)
1044 struct vfs_attr
*fsap
;
1045 vfs_context_t context
;
1047 struct ufsmount
*ump
;
1048 struct vnode
*devvp
;
1050 struct ufslabel
*ulp
;
1057 cred
= vfs_context_ucred(context
);
1059 if (VFSATTR_IS_ACTIVE(fsap
, f_vol_name
)) {
1060 devvp
= ump
->um_devvp
;
1061 bs
= vfs_devblocksize(mp
);
1062 if (error
= buf_meta_bread(devvp
,
1063 (daddr64_t
)(UFS_LABEL_OFFSET
/ bs
),
1064 MAX(bs
, UFS_LABEL_SIZE
), cred
, &bp
)) {
1071 * Since the disklabel is read directly by older user space
1072 * code, make sure this buffer won't remain in the cache when
1075 buf_setflags(bp
, B_NOCACHE
);
1077 /* Validate the label structure; init if not valid */
1078 offset
= buf_dataptr(bp
) + (UFS_LABEL_OFFSET
% bs
);
1079 ulp
= (struct ufslabel
*)offset
;
1080 if (!ufs_label_check(ulp
))
1081 ufs_label_init(ulp
);
1083 /* Copy new name over existing name */
1084 ulp
->ul_namelen
= strlen(fsap
->f_vol_name
);
1085 bcopy(fsap
->f_vol_name
, ulp
->ul_name
, ulp
->ul_namelen
);
1086 ulp
->ul_name
[UFS_MAX_LABEL_NAME
- 1] = '\0';
1087 ulp
->ul_name
[ulp
->ul_namelen
] = '\0';
1090 if (mp
->mnt_flag
& MNT_REVEND
)
1091 ulp
->ul_namelen
= OSSwapInt16(ulp
->ul_namelen
);
1094 /* Update the checksum */
1095 ulp
->ul_checksum
= 0;
1096 ulp
->ul_checksum
= ul_cksum(ulp
, sizeof(*ulp
));
1098 /* Write the label back to disk */
1102 VFSATTR_SET_SUPPORTED(fsap
, f_vol_name
);
1107 struct ffs_sync_cargs
{
1108 vfs_context_t context
;
1115 ffs_sync_callback(struct vnode
*vp
, void *cargs
)
1118 struct ffs_sync_cargs
*args
;
1121 args
= (struct ffs_sync_cargs
*)cargs
;
1125 if ((ip
->i_flag
& (IN_ACCESS
| IN_CHANGE
| IN_MODIFIED
| IN_UPDATE
)) || vnode_hasdirtyblks(vp
)) {
1126 error
= VNOP_FSYNC(vp
, args
->waitfor
, args
->context
);
1129 args
->error
= error
;
1132 return (VNODE_RETURNED
);
1136 * Go through the disk queues to initiate sandbagged IO;
1137 * go through the inodes to write those that have been modified;
1138 * initiate the writing of the super block if it has been modified.
1140 * Note: we are always called with the filesystem marked `MPBUSY'.
1143 ffs_sync(mp
, waitfor
, context
)
1146 vfs_context_t context
;
1148 struct vnode
*nvp
, *vp
;
1149 struct ufsmount
*ump
= VFSTOUFS(mp
);
1152 int error
, allerror
= 0;
1153 struct ffs_sync_cargs args
;
1156 if (fs
->fs_fmod
!= 0 && fs
->fs_ronly
!= 0) { /* XXX */
1157 printf("fs = %s\n", fs
->fs_fsmnt
);
1158 panic("update: rofs mod");
1161 * Write back each (modified) inode.
1163 args
.context
= context
;
1164 args
.waitfor
= waitfor
;
1167 * ffs_sync_callback will be called for each vnode
1168 * hung off of this mount point... the vnode will be
1169 * properly referenced and unreferenced around the callback
1171 vnode_iterate(mp
, 0, ffs_sync_callback
, (void *)&args
);
1174 allerror
= args
.error
;
1177 * Force stale file system control information to be flushed.
1179 if (error
= VNOP_FSYNC(ump
->um_devvp
, waitfor
, context
))
1185 * Write back modified superblock.
1187 if (fs
->fs_fmod
!= 0) {
1190 fs
->fs_time
= tv
.tv_sec
;
1191 if (error
= ffs_sbupdate(ump
, waitfor
))
1198 * Look up a FFS dinode number to find its incore vnode, otherwise read it
1199 * in from disk. If it is in core, wait for the lock bit to clear, then
1200 * return the inode locked. Detection and handling of mount points must be
1201 * done by the calling routine.
1204 ffs_vget(mp
, ino
, vpp
, context
)
1208 vfs_context_t context
;
1210 return(ffs_vget_internal(mp
, (ino_t
)ino
, vpp
, NULL
, NULL
, 0, 0));
1215 ffs_vget_internal(mp
, ino
, vpp
, dvp
, cnp
, mode
, fhwanted
)
1220 struct componentname
*cnp
;
1224 struct proc
*p
= current_proc(); /* XXX */
1227 struct ufsmount
*ump
;
1230 struct vnode_fsparam vfsp
;
1234 int i
, type
, error
= 0;
1240 /* Check for unmount in progress */
1241 if (mp
->mnt_kern_flag
& MNTK_UNMOUNT
) {
1246 * Allocate a new inode... do it before we check the
1247 * cache, because the MALLOC_ZONE may block
1250 MALLOC_ZONE(ip
, struct inode
*, sizeof(struct inode
), type
, M_WAITOK
);
1253 * check in the inode hash
1255 if ((*vpp
= ufs_ihashget(dev
, ino
)) != NULL
) {
1257 * found it... get rid of the allocation
1258 * that we didn't need and return
1261 FREE_ZONE(ip
, sizeof(struct inode
), type
);
1265 bzero((caddr_t
)ip
, sizeof(struct inode
));
1269 // lockinit(&ip->i_lock, PINOD, "inode", 0, 0);
1270 // lockmgr(&ip->i_lock, LK_EXCLUSIVE, (struct slock *)0, p);
1272 ip
->i_fs
= fs
= ump
->um_fs
;
1276 for (i
= 0; i
< MAXQUOTAS
; i
++)
1277 ip
->i_dquot
[i
] = NODQUOT
;
1279 SET(ip
->i_flag
, IN_ALLOC
);
1281 * Put it onto its hash chain locked so that other requests for
1282 * this inode will block if they arrive while we are sleeping waiting
1283 * for old data structures to be purged or for the contents of the
1284 * disk portion of this inode to be read.
1288 /* Read in the disk contents for the inode, copy into the inode. */
1289 if (error
= (int)buf_bread(ump
->um_devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, ino_to_fsba(fs
, ino
))),
1290 (int)fs
->fs_bsize
, NOCRED
, &bp
)) {
1295 if (mp
->mnt_flag
& MNT_REVEND
) {
1296 byte_swap_inode_in(((struct dinode
*)buf_dataptr(bp
) + ino_to_fsbo(fs
, ino
)),ip
);
1298 ip
->i_din
= *((struct dinode
*)buf_dataptr(bp
) + ino_to_fsbo(fs
, ino
));
1301 ip
->i_din
= *((struct dinode
*)buf_dataptr(bp
) + ino_to_fsbo(fs
, ino
));
1302 #endif /* REV_ENDIAN_FS */
1306 vtype
= IFTOVT(ip
->i_mode
);
1308 vtype
= IFTOVT(mode
);
1310 if (vtype
== VNON
) {
1312 /* NFS is in play */
1322 vfsp
.vnfs_vtype
= vtype
;
1323 vfsp
.vnfs_str
= "ufs";
1324 vfsp
.vnfs_dvp
= dvp
;
1325 vfsp
.vnfs_fsnode
= ip
;
1326 vfsp
.vnfs_cnp
= cnp
;
1329 vfsp
.vnfs_filesize
= ip
->i_din
.di_size
;
1331 vfsp
.vnfs_filesize
= 0;
1333 if (vtype
== VFIFO
)
1334 vfsp
.vnfs_vops
= FFS_FIFOOPS
;
1335 else if (vtype
== VBLK
|| vtype
== VCHR
)
1336 vfsp
.vnfs_vops
= ffs_specop_p
;
1338 vfsp
.vnfs_vops
= ffs_vnodeop_p
;
1340 if (vtype
== VBLK
|| vtype
== VCHR
)
1341 vfsp
.vnfs_rdev
= ip
->i_rdev
;
1345 if (dvp
&& cnp
&& (cnp
->cn_flags
& MAKEENTRY
))
1346 vfsp
.vnfs_flags
= 0;
1348 vfsp
.vnfs_flags
= VNFS_NOCACHE
;
1351 * Tag root directory
1353 vfsp
.vnfs_markroot
= (ip
->i_number
== ROOTINO
);
1354 vfsp
.vnfs_marksystem
= 0;
1356 if ((error
= vnode_create(VNCREATE_FLAVOR
, VCREATESIZE
, &vfsp
, &vp
)))
1360 * Finish inode initialization now that aliasing has been resolved.
1362 ip
->i_devvp
= ump
->um_devvp
;
1365 vnode_ref(ip
->i_devvp
);
1367 vnode_settag(vp
, VT_UFS
);
1370 * Initialize modrev times
1373 SETHIGH(ip
->i_modrev
, tv
.tv_sec
);
1374 SETLOW(ip
->i_modrev
, tv
.tv_usec
* 4294);
1377 * Set up a generation number for this inode if it does not
1378 * already have one. This should only happen on old filesystems.
1380 if (ip
->i_gen
== 0) {
1381 if (++nextgennumber
< (u_long
)tv
.tv_sec
)
1382 nextgennumber
= tv
.tv_sec
;
1383 ip
->i_gen
= nextgennumber
;
1384 if ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
) == 0)
1385 ip
->i_flag
|= IN_MODIFIED
;
1388 * Ensure that uid and gid are correct. This is a temporary
1389 * fix until fsck has been changed to do the update.
1391 if (fs
->fs_inodefmt
< FS_44INODEFMT
) { /* XXX */
1392 ip
->i_uid
= ip
->i_din
.di_ouid
; /* XXX */
1393 ip
->i_gid
= ip
->i_din
.di_ogid
; /* XXX */
1397 CLR(ip
->i_flag
, IN_ALLOC
);
1399 if (ISSET(ip
->i_flag
, IN_WALLOC
))
1407 if (ISSET(ip
->i_flag
, IN_WALLOC
))
1409 FREE_ZONE(ip
, sizeof(struct inode
), type
);
1415 * File handle to vnode
1417 * Have to be really careful about stale file handles:
1418 * - check that the inode number is valid
1419 * - call vget to get the locked inode
1420 * - check for an unallocated inode (i_mode == 0)
1423 ffs_fhtovp(mp
, fhlen
, fhp
, vpp
, context
)
1424 register struct mount
*mp
;
1428 vfs_context_t context
;
1430 register struct ufid
*ufhp
;
1431 register struct inode
*ip
;
1437 if (fhlen
< (int)sizeof(struct ufid
))
1439 ufhp
= (struct ufid
*)fhp
;
1440 fs
= VFSTOUFS(mp
)->um_fs
;
1441 ino
= ntohl(ufhp
->ufid_ino
);
1442 if (ino
< ROOTINO
|| ino
>= fs
->fs_ncg
* fs
->fs_ipg
)
1444 error
= ffs_vget_internal(mp
, ino
, &nvp
, NULL
, NULL
, 0, 1);
1450 if (ip
->i_mode
== 0 || ip
->i_gen
!= ntohl(ufhp
->ufid_gen
)) {
1460 * Vnode pointer to File handle
1464 ffs_vptofh(vp
, fhlenp
, fhp
, context
)
1468 vfs_context_t context
;
1470 register struct inode
*ip
;
1471 register struct ufid
*ufhp
;
1473 if (*fhlenp
< (int)sizeof(struct ufid
))
1476 ufhp
= (struct ufid
*)fhp
;
1477 ufhp
->ufid_ino
= htonl(ip
->i_number
);
1478 ufhp
->ufid_gen
= htonl(ip
->i_gen
);
1479 *fhlenp
= sizeof(struct ufid
);
1484 * Initialize the filesystem; just use ufs_init.
1488 struct vfsconf
*vfsp
;
1491 return (ufs_init(vfsp
));
1495 * fast filesystem related variables.
1497 ffs_sysctl(int *name
, u_int namelen
, user_addr_t oldp
, size_t *oldlenp
,
1498 user_addr_t newp
, size_t newlen
, vfs_context_t context
)
1500 extern int doclusterread
, doclusterwrite
, doreallocblks
, doasyncfree
;
1502 /* all sysctl names at this level are terminal */
1504 return (ENOTDIR
); /* overloaded */
1507 case FFS_CLUSTERREAD
:
1508 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
1510 case FFS_CLUSTERWRITE
:
1511 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
1513 case FFS_REALLOCBLKS
:
1514 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
,
1517 return (sysctl_int(oldp
, oldlenp
, newp
, newlen
, &doasyncfree
));
1525 * Write a superblock and associated information back to disk.
1528 ffs_sbupdate(mp
, waitfor
)
1529 struct ufsmount
*mp
;
1532 register struct fs
*dfs
, *fs
= mp
->um_fs
;
1533 register struct buf
*bp
;
1536 int i
, size
, error
, allerror
= 0;
1539 int rev_endian
=(mp
->um_mountp
->mnt_flag
& MNT_REVEND
);
1540 #endif /* REV_ENDIAN_FS */
1543 * First write back the summary information.
1545 blks
= howmany(fs
->fs_cssize
, fs
->fs_fsize
);
1547 for (i
= 0; i
< blks
; i
+= fs
->fs_frag
) {
1548 size
= fs
->fs_bsize
;
1549 if (i
+ fs
->fs_frag
> blks
)
1550 size
= (blks
- i
) * fs
->fs_fsize
;
1551 bp
= buf_getblk(mp
->um_devvp
, (daddr64_t
)((unsigned)fsbtodb(fs
, fs
->fs_csaddr
+ i
)),
1552 size
, 0, 0, BLK_META
);
1553 bcopy(space
, (char *)buf_dataptr(bp
), (u_int
)size
);
1556 byte_swap_ints((int *)buf_dataptr(bp
), size
/ sizeof(int));
1558 #endif /* REV_ENDIAN_FS */
1559 space
= (char *)space
+ size
;
1560 if (waitfor
!= MNT_WAIT
)
1562 else if (error
= (int)buf_bwrite(bp
))
1566 * Now write back the superblock itself. If any errors occurred
1567 * up to this point, then fail so that the superblock avoids
1568 * being written out as clean.
1572 devBlockSize
= vfs_devblocksize(mp
->um_mountp
);
1574 bp
= buf_getblk(mp
->um_devvp
, (daddr64_t
)((unsigned)(SBOFF
/devBlockSize
)), (int)fs
->fs_sbsize
, 0, 0, BLK_META
);
1575 bcopy((caddr_t
)fs
, (char *)buf_dataptr(bp
), (u_int
)fs
->fs_sbsize
);
1576 /* Restore compatibility to old file systems. XXX */
1577 dfs
= (struct fs
*)buf_dataptr(bp
); /* XXX */
1578 if (fs
->fs_postblformat
== FS_42POSTBLFMT
) /* XXX */
1579 dfs
->fs_nrpos
= -1; /* XXX */
1582 * Swapping bytes here ; so that in case
1583 * of inode format < FS_44INODEFMT appropriate
1587 byte_swap_sbout((struct fs
*)buf_dataptr(bp
));
1589 #endif /* REV_ENDIAN_FS */
1590 if (fs
->fs_inodefmt
< FS_44INODEFMT
) { /* XXX */
1591 int32_t *lp
, tmp
; /* XXX */
1593 lp
= (int32_t *)&dfs
->fs_qbmask
; /* XXX */
1594 tmp
= lp
[4]; /* XXX */
1595 for (i
= 4; i
> 0; i
--) /* XXX */
1596 lp
[i
] = lp
[i
-1]; /* XXX */
1597 lp
[0] = tmp
; /* XXX */
1600 /* Note that dfs is already swapped so swap the filesize
1604 dfs
->fs_maxfilesize
= OSSwapInt64(mp
->um_savedmaxfilesize
); /* XXX */
1606 #endif /* REV_ENDIAN_FS */
1607 dfs
->fs_maxfilesize
= mp
->um_savedmaxfilesize
; /* XXX */
1610 #endif /* REV_ENDIAN_FS */
1611 if (waitfor
!= MNT_WAIT
)
1613 else if (error
= (int)buf_bwrite(bp
))