Retire dumplfs, mount_lfs and newlfs
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/18/93
|
||||
# $Id$
|
||||
|
||||
PROG= dumplfs
|
||||
CFLAGS+=-I${.CURDIR}/../../sys/ufs/lfs
|
||||
SRCS= dumplfs.c lfs_cksum.c misc.c
|
||||
.PATH: ${.CURDIR}/../../sys/ufs/lfs
|
||||
MAN8= dumplfs.8
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
@@ -1,60 +0,0 @@
|
||||
.\" Copyright (c) 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)dumplfs.8 8.1 (Berkeley) 6/18/93
|
||||
.\" $Id$
|
||||
.\"
|
||||
.Dd June 18, 1993
|
||||
.Dt DUMPLFS 8
|
||||
.Os BSD 4.4
|
||||
.Sh NAME
|
||||
.Nm dumplfs
|
||||
.Nd dump file system information
|
||||
.Sh SYNOPSIS
|
||||
.Nm dumplfs
|
||||
.Op Ar filesys No \&| Ar device
|
||||
.Sh DESCRIPTION
|
||||
.Nm Dumplfs
|
||||
prints out the file system layout information for the
|
||||
LFS file system or special device specified.
|
||||
The listing is very long and detailed.
|
||||
This command is useful mostly for finding out certain file system
|
||||
information such as the file system block size.
|
||||
.Sh SEE ALSO
|
||||
.Xr disktab 5 ,
|
||||
.Xr fs 5 ,
|
||||
.Xr disklabel 8 ,
|
||||
.Xr newlfs 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm dumplfs
|
||||
command appeared in
|
||||
.Bx 4.4 .
|
||||
@@ -1,617 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1991, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)dumplfs.c 8.5 (Berkeley) 5/24/95";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ucred.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <ufs/ufs/dinode.h>
|
||||
#include <ufs/lfs/lfs.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fstab.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "extern.h"
|
||||
|
||||
static void addseg __P((char *));
|
||||
static void dump_cleaner_info __P((struct lfs *, void *));
|
||||
static void dump_dinode __P((struct dinode *));
|
||||
static void dump_ifile __P((int, struct lfs *, int));
|
||||
static int dump_ipage_ifile __P((int, IFILE *, int));
|
||||
static int dump_ipage_segusage __P((struct lfs *, int, IFILE *, int));
|
||||
static void dump_segment __P((int, int, daddr_t, struct lfs *, int));
|
||||
static int dump_sum __P((int, struct lfs *, SEGSUM *, int, daddr_t));
|
||||
static void dump_super __P((struct lfs *));
|
||||
static void usage __P((void));
|
||||
|
||||
typedef struct seglist SEGLIST;
|
||||
struct seglist {
|
||||
SEGLIST *next;
|
||||
int num;
|
||||
};
|
||||
SEGLIST *seglist;
|
||||
|
||||
int daddr_shift;
|
||||
char *special;
|
||||
|
||||
/* Segment Usage formats */
|
||||
#define print_suheader \
|
||||
(void)printf("segnum\tflags\tnbytes\tninos\tnsums\tlastmod\n")
|
||||
|
||||
#define print_suentry(i, sp) \
|
||||
(void)printf("%d\t%c%c%c\t%d\t%d\t%d\t%s", i, \
|
||||
(((sp)->su_flags & SEGUSE_ACTIVE) ? 'A' : ' '), \
|
||||
(((sp)->su_flags & SEGUSE_DIRTY) ? 'D' : 'C'), \
|
||||
(((sp)->su_flags & SEGUSE_SUPERBLOCK) ? 'S' : ' '), \
|
||||
(sp)->su_nbytes, (sp)->su_ninos, (sp)->su_nsums, \
|
||||
ctime((time_t *)&(sp)->su_lastmod))
|
||||
|
||||
/* Ifile formats */
|
||||
#define print_iheader \
|
||||
(void)printf("inum\tstatus\tversion\tdaddr\t\tfreeptr\n")
|
||||
#define print_ientry(i, ip) \
|
||||
if (ip->if_daddr == LFS_UNUSED_DADDR) \
|
||||
(void)printf("%d\tFREE\t%d\t \t\t%d\n", \
|
||||
i, ip->if_version, ip->if_nextfree); \
|
||||
else \
|
||||
(void)printf("%d\tINUSE\t%d\t%8X \n", \
|
||||
i, ip->if_version, ip->if_daddr)
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
struct lfs lfs_sb1, lfs_sb2, *lfs_master;
|
||||
daddr_t seg_addr;
|
||||
int ch, do_allsb, do_ientries, fd, segnum;
|
||||
|
||||
do_allsb = 0;
|
||||
do_ientries = 0;
|
||||
while ((ch = getopt(argc, argv, "ais:")) != -1)
|
||||
switch(ch) {
|
||||
case 'a': /* Dump all superblocks */
|
||||
do_allsb = 1;
|
||||
break;
|
||||
case 'i': /* Dump ifile entries */
|
||||
do_ientries = 1;
|
||||
break;
|
||||
case 's': /* Dump out these segments */
|
||||
addseg(optarg);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
special = argv[0];
|
||||
if ((fd = open(special, O_RDONLY, 0)) < 0)
|
||||
err(1, "%s", special);
|
||||
|
||||
/* Read the first superblock */
|
||||
get(fd, LFS_LABELPAD, &lfs_sb1, sizeof(struct lfs));
|
||||
daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb;
|
||||
|
||||
/*
|
||||
* Read the second superblock and figure out which check point is
|
||||
* most up to date.
|
||||
*/
|
||||
get(fd,
|
||||
lfs_sb1.lfs_sboffs[1] << daddr_shift, &lfs_sb2, sizeof(struct lfs));
|
||||
|
||||
lfs_master = &lfs_sb1;
|
||||
if (lfs_sb1.lfs_tstamp < lfs_sb2.lfs_tstamp)
|
||||
lfs_master = &lfs_sb2;
|
||||
|
||||
(void)printf("Master Superblock:\n");
|
||||
dump_super(lfs_master);
|
||||
|
||||
dump_ifile(fd, lfs_master, do_ientries);
|
||||
|
||||
if (seglist != NULL)
|
||||
for (; seglist != NULL; seglist = seglist->next) {
|
||||
seg_addr = lfs_master->lfs_sboffs[0] + seglist->num *
|
||||
(lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb);
|
||||
dump_segment(fd,
|
||||
seglist->num, seg_addr, lfs_master, do_allsb);
|
||||
}
|
||||
else
|
||||
for (segnum = 0, seg_addr = lfs_master->lfs_sboffs[0];
|
||||
segnum < lfs_master->lfs_nseg; segnum++, seg_addr +=
|
||||
lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb)
|
||||
dump_segment(fd,
|
||||
segnum, seg_addr, lfs_master, do_allsb);
|
||||
|
||||
(void)close(fd);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* We are reading all the blocks of an inode and dumping out the ifile table.
|
||||
* This code could be tighter, but this is a first pass at getting the stuff
|
||||
* printed out rather than making this code incredibly efficient.
|
||||
*/
|
||||
static void
|
||||
dump_ifile(fd, lfsp, do_ientries)
|
||||
int fd;
|
||||
struct lfs *lfsp;
|
||||
int do_ientries;
|
||||
{
|
||||
IFILE *ipage;
|
||||
struct dinode *dip, *dpage;
|
||||
daddr_t addr, *addrp, *dindir, *iaddrp, *indir;
|
||||
int block_limit, i, inum, j, nblocks, nsupb, psize;
|
||||
|
||||
psize = lfsp->lfs_bsize;
|
||||
addr = lfsp->lfs_idaddr;
|
||||
|
||||
if (!(dpage = malloc(psize)))
|
||||
err(1, NULL);
|
||||
get(fd, addr << daddr_shift, dpage, psize);
|
||||
|
||||
for (dip = dpage + INOPB(lfsp) - 1; dip >= dpage; --dip)
|
||||
if (dip->di_inumber == LFS_IFILE_INUM)
|
||||
break;
|
||||
|
||||
if (dip < dpage)
|
||||
errx(1, "unable to locate ifile inode");
|
||||
|
||||
(void)printf("\nIFILE inode\n");
|
||||
dump_dinode(dip);
|
||||
|
||||
(void)printf("\nIFILE contents\n");
|
||||
nblocks = dip->di_size >> lfsp->lfs_bshift;
|
||||
block_limit = MIN(nblocks, NDADDR);
|
||||
|
||||
/* Get the direct block */
|
||||
if ((ipage = malloc(psize)) == NULL)
|
||||
err(1, NULL);
|
||||
for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit;
|
||||
i++, addrp++) {
|
||||
get(fd, *addrp << daddr_shift, ipage, psize);
|
||||
if (i < lfsp->lfs_cleansz) {
|
||||
dump_cleaner_info(lfsp, ipage);
|
||||
print_suheader;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i < (lfsp->lfs_segtabsz + lfsp->lfs_cleansz)) {
|
||||
inum = dump_ipage_segusage(lfsp, inum, ipage,
|
||||
lfsp->lfs_sepb);
|
||||
if (!inum)
|
||||
if(!do_ientries)
|
||||
goto e0;
|
||||
else
|
||||
print_iheader;
|
||||
} else
|
||||
inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
|
||||
|
||||
}
|
||||
|
||||
if (nblocks <= NDADDR)
|
||||
goto e0;
|
||||
|
||||
/* Dump out blocks off of single indirect block */
|
||||
if (!(indir = malloc(psize)))
|
||||
err(1, NULL);
|
||||
get(fd, dip->di_ib[0] << daddr_shift, indir, psize);
|
||||
block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
|
||||
for (addrp = indir; i < block_limit; i++, addrp++) {
|
||||
if (*addrp == LFS_UNUSED_DADDR)
|
||||
break;
|
||||
get(fd, *addrp << daddr_shift,ipage, psize);
|
||||
if (i < lfsp->lfs_cleansz) {
|
||||
dump_cleaner_info(lfsp, ipage);
|
||||
continue;
|
||||
} else
|
||||
i -= lfsp->lfs_cleansz;
|
||||
|
||||
if (i < lfsp->lfs_segtabsz) {
|
||||
inum = dump_ipage_segusage(lfsp, inum, ipage,
|
||||
lfsp->lfs_sepb);
|
||||
if (!inum)
|
||||
if(!do_ientries)
|
||||
goto e1;
|
||||
else
|
||||
print_iheader;
|
||||
} else
|
||||
inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
|
||||
}
|
||||
|
||||
if (nblocks <= lfsp->lfs_nindir * lfsp->lfs_ifpb)
|
||||
goto e1;
|
||||
|
||||
/* Get the double indirect block */
|
||||
if (!(dindir = malloc(psize)))
|
||||
err(1, NULL);
|
||||
get(fd, dip->di_ib[1] << daddr_shift, dindir, psize);
|
||||
for (iaddrp = dindir, j = 0; j < lfsp->lfs_nindir; j++, iaddrp++) {
|
||||
if (*iaddrp == LFS_UNUSED_DADDR)
|
||||
break;
|
||||
get(fd, *iaddrp << daddr_shift, indir, psize);
|
||||
block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
|
||||
for (addrp = indir; i < block_limit; i++, addrp++) {
|
||||
if (*addrp == LFS_UNUSED_DADDR)
|
||||
break;
|
||||
get(fd, *addrp << daddr_shift, ipage, psize);
|
||||
if (i < lfsp->lfs_cleansz) {
|
||||
dump_cleaner_info(lfsp, ipage);
|
||||
continue;
|
||||
} else
|
||||
i -= lfsp->lfs_cleansz;
|
||||
|
||||
if (i < lfsp->lfs_segtabsz) {
|
||||
inum = dump_ipage_segusage(lfsp,
|
||||
inum, ipage, lfsp->lfs_sepb);
|
||||
if (!inum)
|
||||
if(!do_ientries)
|
||||
goto e2;
|
||||
else
|
||||
print_iheader;
|
||||
} else
|
||||
inum = dump_ipage_ifile(inum,
|
||||
ipage, lfsp->lfs_ifpb);
|
||||
}
|
||||
}
|
||||
e2: free(dindir);
|
||||
e1: free(indir);
|
||||
e0: free(dpage);
|
||||
free(ipage);
|
||||
}
|
||||
|
||||
static int
|
||||
dump_ipage_ifile(i, pp, tot)
|
||||
int i;
|
||||
IFILE *pp;
|
||||
int tot;
|
||||
{
|
||||
IFILE *ip;
|
||||
int cnt, max;
|
||||
|
||||
max = i + tot;
|
||||
|
||||
for (ip = pp, cnt = i; cnt < max; cnt++, ip++)
|
||||
print_ientry(cnt, ip);
|
||||
return (max);
|
||||
}
|
||||
|
||||
static int
|
||||
dump_ipage_segusage(lfsp, i, pp, tot)
|
||||
struct lfs *lfsp;
|
||||
int i;
|
||||
IFILE *pp;
|
||||
int tot;
|
||||
{
|
||||
SEGUSE *sp;
|
||||
int cnt, max;
|
||||
|
||||
max = i + tot;
|
||||
for (sp = (SEGUSE *)pp, cnt = i;
|
||||
cnt < lfsp->lfs_nseg && cnt < max; cnt++, sp++)
|
||||
print_suentry(cnt, sp);
|
||||
if (max >= lfsp->lfs_nseg)
|
||||
return (0);
|
||||
else
|
||||
return (max);
|
||||
}
|
||||
|
||||
static void
|
||||
dump_dinode(dip)
|
||||
struct dinode *dip;
|
||||
{
|
||||
int i;
|
||||
|
||||
(void)printf("%s%d\t%s%d\t%s%d\t%s%d\t%s%d\n",
|
||||
"mode ", dip->di_mode,
|
||||
"nlink ", dip->di_nlink,
|
||||
"uid ", dip->di_uid,
|
||||
"gid ", dip->di_gid,
|
||||
"size ", dip->di_size);
|
||||
(void)printf("%s%s%s%s%s%s",
|
||||
"atime ", ctime(&dip->di_atime),
|
||||
"mtime ", ctime(&dip->di_mtime),
|
||||
"ctime ", ctime(&dip->di_ctime));
|
||||
(void)printf("inum %d\n", dip->di_inumber);
|
||||
(void)printf("Direct Addresses\n");
|
||||
for (i = 0; i < NDADDR; i++) {
|
||||
(void)printf("\t0x%X", dip->di_db[i]);
|
||||
if ((i % 6) == 5)
|
||||
(void)printf("\n");
|
||||
}
|
||||
for (i = 0; i < NIADDR; i++)
|
||||
(void)printf("\t0x%X", dip->di_ib[i]);
|
||||
(void)printf("\n");
|
||||
}
|
||||
|
||||
static int
|
||||
dump_sum(fd, lfsp, sp, segnum, addr)
|
||||
struct lfs *lfsp;
|
||||
SEGSUM *sp;
|
||||
int fd, segnum;
|
||||
daddr_t addr;
|
||||
{
|
||||
FINFO *fp;
|
||||
daddr_t *dp;
|
||||
int i, j;
|
||||
int ck;
|
||||
int numbytes;
|
||||
struct dinode *inop;
|
||||
|
||||
if (sp->ss_magic != SS_MAGIC ||
|
||||
sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,
|
||||
LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) {
|
||||
(void)printf("dumplfs: %s %d address 0x%lx\n",
|
||||
"corrupt summary block; segment", segnum, addr);
|
||||
return(0);
|
||||
}
|
||||
|
||||
(void)printf("Segment Summary Info at 0x%lx\tmagic no: 0x%x\n",
|
||||
addr, sp->ss_magic);
|
||||
(void)printf(" %s0x%X\t%s%d\t%s%d\n %s0x%X\t%s0x%X",
|
||||
"next ", sp->ss_next,
|
||||
"nfinfo ", sp->ss_nfinfo,
|
||||
"ninos ", sp->ss_ninos,
|
||||
"sumsum ", sp->ss_sumsum,
|
||||
"datasum ", sp->ss_datasum );
|
||||
(void)printf("\tcreate %s", ctime((time_t *)&sp->ss_create));
|
||||
|
||||
/* Dump out inode disk addresses */
|
||||
dp = (daddr_t *)sp;
|
||||
dp += LFS_SUMMARY_SIZE / sizeof(daddr_t);
|
||||
inop = malloc(1 << lfsp->lfs_bshift);
|
||||
printf(" Inode addresses:");
|
||||
numbytes = 0;
|
||||
for (dp--, i = 0; i < sp->ss_ninos; dp--) {
|
||||
numbytes += lfsp->lfs_bsize; /* add bytes for inode block */
|
||||
printf("\t0x%X {", *dp);
|
||||
get(fd, *dp << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb), inop,
|
||||
(1 << lfsp->lfs_bshift));
|
||||
for (j = 0; i < sp->ss_ninos && j < INOPB(lfsp); j++, i++) {
|
||||
if (j > 0)
|
||||
(void)printf(", ");
|
||||
(void)printf("%d", inop[j].di_inumber);
|
||||
}
|
||||
(void)printf("}");
|
||||
if (((i/INOPB(lfsp)) % 4) == 3)
|
||||
(void)printf("\n");
|
||||
}
|
||||
free(inop);
|
||||
|
||||
printf("\n");
|
||||
for (fp = (FINFO *)(sp + 1), i = 0; i < sp->ss_nfinfo; i++) {
|
||||
(void)printf(" FINFO for inode: %d version %d nblocks %d lastlength %d\n",
|
||||
fp->fi_ino, fp->fi_version, fp->fi_nblocks, fp->fi_lastlength);
|
||||
dp = &(fp->fi_blocks[0]);
|
||||
for (j = 0; j < fp->fi_nblocks; j++, dp++) {
|
||||
(void)printf("\t%d", *dp);
|
||||
if ((j % 8) == 7)
|
||||
(void)printf("\n");
|
||||
if (j == fp->fi_nblocks - 1)
|
||||
numbytes += fp->fi_lastlength;
|
||||
else
|
||||
numbytes += lfsp->lfs_bsize;
|
||||
}
|
||||
if ((j % 8) != 0)
|
||||
(void)printf("\n");
|
||||
fp = (FINFO *)dp;
|
||||
}
|
||||
return (numbytes);
|
||||
}
|
||||
|
||||
static void
|
||||
dump_segment(fd, segnum, addr, lfsp, dump_sb)
|
||||
int fd, segnum;
|
||||
daddr_t addr;
|
||||
struct lfs *lfsp;
|
||||
int dump_sb;
|
||||
{
|
||||
struct lfs lfs_sb, *sbp;
|
||||
SEGSUM *sump;
|
||||
char sumblock[LFS_SUMMARY_SIZE];
|
||||
int did_one, nbytes, sb;
|
||||
off_t sum_offset, super_off;
|
||||
|
||||
(void)printf("\nSEGMENT %d (Disk Address 0x%X)\n",
|
||||
addr >> (lfsp->lfs_segshift - daddr_shift), addr);
|
||||
sum_offset = (addr << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
|
||||
|
||||
sb = 0;
|
||||
did_one = 0;
|
||||
do {
|
||||
get(fd, sum_offset, sumblock, LFS_SUMMARY_SIZE);
|
||||
sump = (SEGSUM *)sumblock;
|
||||
if (sump->ss_sumsum != cksum (&sump->ss_datasum,
|
||||
LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) {
|
||||
sbp = (struct lfs *)sump;
|
||||
if (sb = (sbp->lfs_magic == LFS_MAGIC)) {
|
||||
super_off = sum_offset;
|
||||
sum_offset += LFS_SBPAD;
|
||||
} else if (did_one)
|
||||
break;
|
||||
else {
|
||||
printf("Segment at 0x%X corrupt\n", addr);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
nbytes = dump_sum(fd, lfsp, sump, segnum, sum_offset >>
|
||||
(lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
|
||||
if (nbytes)
|
||||
sum_offset += LFS_SUMMARY_SIZE + nbytes;
|
||||
else
|
||||
sum_offset = 0;
|
||||
did_one = 1;
|
||||
}
|
||||
} while (sum_offset);
|
||||
|
||||
if (dump_sb && sb) {
|
||||
get(fd, super_off, &lfs_sb, sizeof(struct lfs));
|
||||
dump_super(&lfs_sb);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
dump_super(lfsp)
|
||||
struct lfs *lfsp;
|
||||
{
|
||||
int i;
|
||||
|
||||
(void)printf("%s0x%X\t%s0x%X\t%s%d\t%s%d\n",
|
||||
"magic ", lfsp->lfs_magic,
|
||||
"version ", lfsp->lfs_version,
|
||||
"size ", lfsp->lfs_size,
|
||||
"ssize ", lfsp->lfs_ssize);
|
||||
(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
|
||||
"dsize ", lfsp->lfs_dsize,
|
||||
"bsize ", lfsp->lfs_bsize,
|
||||
"fsize ", lfsp->lfs_fsize,
|
||||
"frag ", lfsp->lfs_frag);
|
||||
|
||||
(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
|
||||
"minfree ", lfsp->lfs_minfree,
|
||||
"inopb ", lfsp->lfs_inopb,
|
||||
"ifpb ", lfsp->lfs_ifpb,
|
||||
"nindir ", lfsp->lfs_nindir);
|
||||
|
||||
(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
|
||||
"nseg ", lfsp->lfs_nseg,
|
||||
"nspf ", lfsp->lfs_nspf,
|
||||
"cleansz ", lfsp->lfs_cleansz,
|
||||
"segtabsz ", lfsp->lfs_segtabsz);
|
||||
|
||||
(void)printf("%s0x%X\t%s%d\t%s0x%qX\t%s%d\n",
|
||||
"segmask ", lfsp->lfs_segmask,
|
||||
"segshift ", lfsp->lfs_segshift,
|
||||
"bmask ", lfsp->lfs_bmask,
|
||||
"bshift ", lfsp->lfs_bshift);
|
||||
|
||||
(void)printf("%s0x%qX\t\t%s%d\t%s0x%qX\t%s%d\n",
|
||||
"ffmask ", lfsp->lfs_ffmask,
|
||||
"ffshift ", lfsp->lfs_ffshift,
|
||||
"fbmask ", lfsp->lfs_fbmask,
|
||||
"fbshift ", lfsp->lfs_fbshift);
|
||||
|
||||
(void)printf("%s%d\t%s%d\t%s0x%X\t%s0x%qx\n",
|
||||
"sushift ", lfsp->lfs_sushift,
|
||||
"fsbtodb ", lfsp->lfs_fsbtodb,
|
||||
"cksum ", lfsp->lfs_cksum,
|
||||
"maxfilesize ", lfsp->lfs_maxfilesize);
|
||||
|
||||
(void)printf("Superblock disk addresses:\t");
|
||||
for (i = 0; i < LFS_MAXNUMSB; i++) {
|
||||
(void)printf(" 0x%X", lfsp->lfs_sboffs[i]);
|
||||
if ( i == (LFS_MAXNUMSB >> 1))
|
||||
(void)printf("\n\t\t\t\t");
|
||||
}
|
||||
(void)printf("\n");
|
||||
|
||||
(void)printf("Checkpoint Info\n");
|
||||
(void)printf("%s%d\t%s0x%X\t%s%d\n",
|
||||
"free ", lfsp->lfs_free,
|
||||
"idaddr ", lfsp->lfs_idaddr,
|
||||
"ifile ", lfsp->lfs_ifile);
|
||||
(void)printf("%s%d\t%s%d\t%s%d\n",
|
||||
"bfree ", lfsp->lfs_bfree,
|
||||
"avail ", lfsp->lfs_avail,
|
||||
"uinodes ", lfsp->lfs_uinodes);
|
||||
(void)printf("%s%d\t%s0x%X\t%s0x%X\n%s0x%X\t%s0x%X\t",
|
||||
"nfiles ", lfsp->lfs_nfiles,
|
||||
"lastseg ", lfsp->lfs_lastseg,
|
||||
"nextseg ", lfsp->lfs_nextseg,
|
||||
"curseg ", lfsp->lfs_curseg,
|
||||
"offset ", lfsp->lfs_offset);
|
||||
(void)printf("tstamp %s", ctime((time_t *)&lfsp->lfs_tstamp));
|
||||
(void)printf("\nIn-Memory Information\n");
|
||||
(void)printf("%s%d\t%s0x%X\t%s%d%s%d\t%s%d\n",
|
||||
"seglock ", lfsp->lfs_seglock,
|
||||
"iocount ", lfsp->lfs_iocount,
|
||||
"writer ", lfsp->lfs_writer,
|
||||
"dirops ", lfsp->lfs_dirops,
|
||||
"doifile ", lfsp->lfs_doifile);
|
||||
(void)printf("%s%d\t%s%d\t%s0x%X\t%s%d\n",
|
||||
"nactive ", lfsp->lfs_nactive,
|
||||
"fmod ", lfsp->lfs_fmod,
|
||||
"clean ", lfsp->lfs_clean,
|
||||
"ronly ", lfsp->lfs_ronly);
|
||||
}
|
||||
|
||||
static void
|
||||
addseg(arg)
|
||||
char *arg;
|
||||
{
|
||||
SEGLIST *p;
|
||||
|
||||
if ((p = malloc(sizeof(SEGLIST))) == NULL)
|
||||
err(1, NULL);
|
||||
p->next = seglist;
|
||||
p->num = atoi(arg);
|
||||
seglist = p;
|
||||
}
|
||||
|
||||
static void
|
||||
dump_cleaner_info(lfsp, ipage)
|
||||
struct lfs *lfsp;
|
||||
void *ipage;
|
||||
{
|
||||
CLEANERINFO *cip;
|
||||
|
||||
cip = (CLEANERINFO *)ipage;
|
||||
(void)printf("segments clean\t%d\tsegments dirty\t%d\n\n",
|
||||
cip->clean, cip->dirty);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: dumplfs [-ai] [-s segnum] file\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.2 (Berkeley) 4/28/95
|
||||
*/
|
||||
|
||||
void get __P((int, off_t, void *, size_t));
|
||||
|
||||
extern char *special;
|
||||
@@ -1,63 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)misc.c 8.2 (Berkeley) 4/28/95";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
get(fd, off, p, len)
|
||||
int fd;
|
||||
off_t off;
|
||||
void *p;
|
||||
size_t len;
|
||||
{
|
||||
int rbytes;
|
||||
|
||||
if (lseek(fd, off, SEEK_SET) < 0)
|
||||
err(1, "%s", special);
|
||||
if ((rbytes = read(fd, p, len)) < 0)
|
||||
err(1, "%s", special);
|
||||
if (rbytes != len)
|
||||
errx(1, "%s: short read (%d, not %d)", special, rbytes, len);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
# @(#)Makefile 8.2 (Berkeley) 3/27/94
|
||||
|
||||
PROG= mount_lfs
|
||||
SRCS= mount_lfs.c getmntopts.c
|
||||
MAN8= mount_lfs.8
|
||||
|
||||
MOUNT= ${.CURDIR}/../mount
|
||||
CFLAGS+= -I${MOUNT}
|
||||
.PATH: ${MOUNT}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
@@ -1,129 +0,0 @@
|
||||
.\" Copyright (c) 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)mount_lfs.8 8.5 (Berkeley) 3/30/94
|
||||
.\"
|
||||
.Dd March 30, 1994
|
||||
.Dt MOUNT_LFS 8
|
||||
.Os BSD 4.4
|
||||
.Sh NAME
|
||||
.Nm mount_lfs
|
||||
.Nd mount a log-structured file system
|
||||
.Sh SYNOPSIS
|
||||
.Nm mount_lfs
|
||||
.Op Fl dns
|
||||
.Op Fl o Ar options
|
||||
.Ar special
|
||||
.Ar node
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm mount_lfs
|
||||
command attaches a log-structured file system
|
||||
.Ar special
|
||||
device on to the file system tree at the point
|
||||
.Ar node .
|
||||
In addition, the
|
||||
.Xr lfs_cleanerd 8
|
||||
utility is invoked to clean the file system periodically.
|
||||
.Pp
|
||||
This command is normally executed by
|
||||
.Xr mount 8
|
||||
at boot time.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl d
|
||||
Run
|
||||
.Xr lfs_cleanerd 8
|
||||
in debug mode.
|
||||
.It Fl o
|
||||
Options are specified with a
|
||||
.Fl o
|
||||
flag followed by a comma separated string of options.
|
||||
See the
|
||||
.Xr mount 8
|
||||
man page for possible options and their meanings.
|
||||
.It Fl n
|
||||
Don't start
|
||||
.Xr lfs_cleanerd 8
|
||||
on the file system.
|
||||
.It Fl s
|
||||
Cause
|
||||
.Xr lfs_cleanerd 8
|
||||
to read data in small chunks when cleaning the file system.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr mount 2 ,
|
||||
.Xr unmount 2 ,
|
||||
.Xr fstab 5 ,
|
||||
.Xr lfs_cleanerd 8 ,
|
||||
.Xr mount 8
|
||||
.sp
|
||||
.Rs
|
||||
.%A Ousterhout and Douglis
|
||||
.%D 1989
|
||||
.%T "Beating the I/O Bottleneck: A Case for Log-structured File Systems"
|
||||
.%J "Operating Systems Review"
|
||||
.%V Vol. 23
|
||||
.%N No. 1
|
||||
.%P pp. 11-27
|
||||
.%O "also available as Technical Report UCB/CSD 88/467"
|
||||
.Re
|
||||
.Rs
|
||||
.%A Rosenblum and Ousterhout
|
||||
.%D 1991
|
||||
.%T "The Design and Implementation of a Log-Structured File System"
|
||||
.%J "ACM SIGOPS Operating Systems Review"
|
||||
.%V Vol. 25
|
||||
.%N No. 5
|
||||
.Re
|
||||
.Rs
|
||||
.%A Seltzer
|
||||
.%D 1992
|
||||
.%T "File System Performance and Transaction Support"
|
||||
.%B "PhD Thesis, University of California, Berkeley"
|
||||
.%O "also available as Technical Report UCB/ERL M92"
|
||||
.Re
|
||||
.Rs
|
||||
.%A Seltzer, Bostic, McKusick and Staelin
|
||||
.%D 1993
|
||||
.%T "An Implementation of a Log-Structured File System for UNIX"
|
||||
.%J "Proc. of the Winter 1993 USENIX Conf."
|
||||
.%P pp. 315-331
|
||||
.Re
|
||||
.Sh BUGS
|
||||
LFS does not currently work in any variant of FreeBSD and should therefore
|
||||
not be used.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm mount_lfs
|
||||
function first appeared in
|
||||
.Bx 4.4 .
|
||||
@@ -1,167 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*
|
||||
static char sccsid[] = "@(#)mount_lfs.c 8.4 (Berkeley) 4/26/95";
|
||||
*/
|
||||
static const char rcsid[] =
|
||||
"$Id: mount_lfs.c,v 1.8 1997/03/11 12:30:33 peter Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <ufs/ufs/ufsmount.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "mntopts.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
static struct mntopt mopts[] = {
|
||||
MOPT_STDOPTS,
|
||||
MOPT_UPDATE,
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static void usage __P((void)) __dead2;
|
||||
static void invoke_cleaner __P((char *, int, int));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
struct ufs_args args;
|
||||
int ch, mntflags, noclean;
|
||||
char *fs_name, *options;
|
||||
struct vfsconf vfc;
|
||||
int error;
|
||||
int short_rds, cleaner_debug;
|
||||
|
||||
|
||||
options = NULL;
|
||||
mntflags = noclean = short_rds = cleaner_debug = 0;
|
||||
while ((ch = getopt(argc, argv, "dno:s")) != -1)
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
cleaner_debug = 1;
|
||||
break;
|
||||
case 'n':
|
||||
noclean = 1;
|
||||
break;
|
||||
case 'o':
|
||||
getmntopts(optarg, mopts, &mntflags, 0);
|
||||
break;
|
||||
case 's':
|
||||
short_rds = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
args.fspec = argv[0]; /* the name of the device file */
|
||||
fs_name = argv[1]; /* the mount point */
|
||||
|
||||
#define DEFAULT_ROOTUID -2
|
||||
args.export.ex_root = DEFAULT_ROOTUID;
|
||||
if (mntflags & MNT_RDONLY)
|
||||
args.export.ex_flags = MNT_EXRDONLY;
|
||||
else
|
||||
args.export.ex_flags = 0;
|
||||
|
||||
error = getvfsbyname("lfs", &vfc);
|
||||
if (error && vfsisloadable("lfs")) {
|
||||
if(vfsload("lfs"))
|
||||
err(EX_OSERR, "vfsload(lfs)");
|
||||
endvfsent(); /* clear cache */
|
||||
error = getvfsbyname("lfs", &vfc);
|
||||
}
|
||||
if (error)
|
||||
errx(EX_OSERR, "lfs filesystem is not available");
|
||||
|
||||
if (mount(vfc.vfc_name, fs_name, mntflags, &args))
|
||||
err(1, NULL);
|
||||
|
||||
if (!noclean)
|
||||
invoke_cleaner(fs_name, short_rds, cleaner_debug);
|
||||
/* NOTREACHED */
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
invoke_cleaner(name, short_rds, cleaner_debug)
|
||||
char *name;
|
||||
int short_rds;
|
||||
int cleaner_debug;
|
||||
{
|
||||
char *args[6], **ap = args;
|
||||
|
||||
/* Build the argument list. */
|
||||
*ap++ = _PATH_LFS_CLEANERD;
|
||||
if (short_rds)
|
||||
*ap++ = "-s";
|
||||
if (cleaner_debug)
|
||||
*ap++ = "-d";
|
||||
*ap++ = name;
|
||||
*ap = NULL;
|
||||
|
||||
execv(args[0], args);
|
||||
err(EX_OSERR, "exec %s", _PATH_LFS_CLEANERD);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: mount_lfs [-dns] [-o options] special node\n");
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)pathnames.h 8.1 (Berkeley) 6/8/93
|
||||
*/
|
||||
|
||||
#define _PATH_LFS_CLEANERD "/usr/libexec/lfs_cleanerd"
|
||||
@@ -1,9 +0,0 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/18/93
|
||||
|
||||
PROG= newlfs
|
||||
CFLAGS+=-I${.CURDIR}/../../sys/ufs/lfs
|
||||
SRCS= dkcksum.c lfs.c lfs_cksum.c misc.c newfs.c
|
||||
MAN8= newlfs.8
|
||||
.PATH: ${.CURDIR}/../../sys/ufs/lfs ${.CURDIR}/../disklabel
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
@@ -1,140 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)config.h 8.3 (Berkeley) 5/24/95
|
||||
*/
|
||||
|
||||
/*
|
||||
* The first boot and super blocks are given in absolute disk addresses.
|
||||
* The byte-offset forms are preferred, as they don't imply a sector size.
|
||||
*/
|
||||
#define BBSIZE 8192
|
||||
#define SBSIZE 8192
|
||||
|
||||
/*
|
||||
* The following two constants set the default block and fragment sizes.
|
||||
* Both constants must be a power of 2 and meet the following constraints:
|
||||
* MINBSIZE <= DESBLKSIZE <= MAXBSIZE
|
||||
* sectorsize <= DESFRAGSIZE <= DESBLKSIZE
|
||||
* DESBLKSIZE / DESFRAGSIZE <= 8
|
||||
*/
|
||||
#define DFL_FRAGSIZE 1024
|
||||
#define DFL_BLKSIZE 8192
|
||||
|
||||
/*
|
||||
* Cylinder groups may have up to many cylinders. The actual
|
||||
* number used depends upon how much information can be stored
|
||||
* on a single cylinder. The default is to use 16 cylinders
|
||||
* per group.
|
||||
*/
|
||||
#define DESCPG 16 /* desired fs_cpg */
|
||||
|
||||
/*
|
||||
* MINFREE gives the minimum acceptable percentage of file system
|
||||
* blocks which may be free. If the freelist drops below this level
|
||||
* only the superuser may continue to allocate blocks. This may
|
||||
* be set to 0 if no reserve of free blocks is deemed necessary,
|
||||
* however throughput drops by fifty percent if the file system
|
||||
* is run at between 90% and 100% full; thus the default value of
|
||||
* fs_minfree is 10%. With 10% free space, fragmentation is not a
|
||||
* problem, so we choose to optimize for time.
|
||||
*/
|
||||
#define MINFREE 10
|
||||
#define DEFAULTOPT FS_OPTTIME
|
||||
|
||||
/*
|
||||
* Preference for optimization.
|
||||
*/
|
||||
#define FS_OPTTIME 0 /* minimize allocation time */
|
||||
#define FS_OPTSPACE 1 /* minimize disk fragmentation */
|
||||
|
||||
|
||||
/*
|
||||
* ROTDELAY gives the minimum number of milliseconds to initiate
|
||||
* another disk transfer on the same cylinder. It is used in
|
||||
* determining the rotationally optimal layout for disk blocks
|
||||
* within a file; the default of fs_rotdelay is 4ms.
|
||||
*/
|
||||
#define ROTDELAY 0
|
||||
|
||||
/*
|
||||
* MAXCONTIG sets the default for the maximum number of blocks
|
||||
* that may be allocated sequentially. Since UNIX drivers are
|
||||
* not capable of scheduling multi-block transfers, this defaults
|
||||
* to 1 (ie no contiguous blocks are allocated).
|
||||
*/
|
||||
#define MAXCONTIG 1
|
||||
|
||||
/*
|
||||
* MAXBLKPG determines the maximum number of data blocks which are
|
||||
* placed in a single cylinder group. The default is one indirect
|
||||
* block worth of data blocks.
|
||||
*/
|
||||
#define MAXBLKPG(bsize) ((bsize) / sizeof(daddr_t))
|
||||
|
||||
/*
|
||||
* Each file system has a number of inodes statically allocated.
|
||||
* We allocate one inode slot per NFPI fragments, expecting this
|
||||
* to be far more than we will ever need.
|
||||
*/
|
||||
#define NFPI 4
|
||||
|
||||
/*
|
||||
* For each cylinder we keep track of the availability of blocks at different
|
||||
* rotational positions, so that we can lay out the data to be picked
|
||||
* up with minimum rotational latency. NRPOS is the default number of
|
||||
* rotational positions that we distinguish. With NRPOS of 8 the resolution
|
||||
* of our summary information is 2ms for a typical 3600 rpm drive.
|
||||
*/
|
||||
#define NRPOS 1 /* number distinct rotational positions */
|
||||
|
||||
/*
|
||||
* The following constants set the default block and segment size for a log
|
||||
* structured file system. Both must be powers of two and the segment size
|
||||
* must be a multiple of the block size. We also set minimum block and segment
|
||||
* sizes.
|
||||
*/
|
||||
#define LFS_MINSEGSIZE (64*1024)
|
||||
#define DFL_LFSSEG (1024 * 1024)
|
||||
#define DFL_LFSSEG_SHIFT 20
|
||||
#define DFL_LFSSEG_MASK 0xFFFFF
|
||||
|
||||
#define LFS_MINBLOCKSIZE 1024
|
||||
#define DFL_LFSBLOCK 4096
|
||||
#define DFL_LFSBLOCK_SHIFT 12
|
||||
#define DFL_LFSBLOCK_MASK 0xFFF
|
||||
|
||||
#define DFL_LFSFRAG 4096
|
||||
#define DFL_LFS_FFMASK DFL_LFSBLOCK_MASK
|
||||
#define DFL_LFS_FFSHIFT DFL_LFSBLOCK_SHIFT
|
||||
#define DFL_LFS_FBMASK 0
|
||||
#define DFL_LFS_FBSHIFT 0
|
||||
@@ -1,45 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.2 (Berkeley) 5/24/95
|
||||
*/
|
||||
|
||||
u_long cksum __P((void *, size_t));
|
||||
u_short dkcksum __P((struct disklabel *));
|
||||
void fatal __P((const char *fmt, ...));
|
||||
u_int log2 __P((u_int));
|
||||
int make_lfs __P((int, struct disklabel *, struct partition *, int,
|
||||
int, int, int));
|
||||
int mkfs __P((struct partition *, char *, int, int));
|
||||
|
||||
extern char *progname;
|
||||
extern char *special;
|
||||
@@ -1,684 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <ufs/ufs/dir.h>
|
||||
#include <ufs/ufs/quota.h>
|
||||
#include <ufs/ufs/dinode.h>
|
||||
#include <ufs/lfs/lfs.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* This table is indexed by the log base 2 of the block size.
|
||||
* It returns the maximum file size allowed in a file system
|
||||
* with the specified block size. For block sizes smaller than
|
||||
* 8K, the size is limited by tha maximum number of blocks that
|
||||
* can be reached by triply indirect blocks:
|
||||
* NDADDR + INOPB(bsize) + INOPB(bsize)^2 + INOPB(bsize)^3
|
||||
* For block size of 8K or larger, the file size is limited by the
|
||||
* number of blocks that can be represented in the file system. Since
|
||||
* we use negative block numbers to represent indirect blocks, we can
|
||||
* have a maximum of 2^31 blocks.
|
||||
*/
|
||||
|
||||
u_quad_t maxtable[] = {
|
||||
/* 1 */ -1,
|
||||
/* 2 */ -1,
|
||||
/* 4 */ -1,
|
||||
/* 8 */ -1,
|
||||
/* 16 */ -1,
|
||||
/* 32 */ -1,
|
||||
/* 64 */ -1,
|
||||
/* 128 */ -1,
|
||||
/* 256 */ -1,
|
||||
/* 512 */ NDADDR + 128 + 128 * 128 + 128 * 128 * 128,
|
||||
/* 1024 */ NDADDR + 256 + 256 * 256 + 256 * 256 * 256,
|
||||
/* 2048 */ NDADDR + 512 + 512 * 512 + 512 * 512 * 512,
|
||||
/* 4096 */ NDADDR + 1024 + 1024 * 1024 + 1024 * 1024 * 1024,
|
||||
/* 8192 */ 1 << 31,
|
||||
/* 16 K */ 1 << 31,
|
||||
/* 32 K */ 1 << 31,
|
||||
};
|
||||
|
||||
static struct lfs lfs_default = {
|
||||
/* lfs_magic */ LFS_MAGIC,
|
||||
/* lfs_version */ LFS_VERSION,
|
||||
/* lfs_size */ 0,
|
||||
/* lfs_ssize */ DFL_LFSSEG/DFL_LFSBLOCK,
|
||||
/* lfs_dsize */ 0,
|
||||
/* lfs_bsize */ DFL_LFSBLOCK,
|
||||
/* lfs_fsize */ DFL_LFSFRAG,
|
||||
/* lfs_frag */ 1,
|
||||
/* lfs_free */ LFS_FIRST_INUM,
|
||||
/* lfs_bfree */ 0,
|
||||
/* lfs_nfiles */ 0,
|
||||
/* lfs_avail */ 0,
|
||||
/* lfs_uinodes */ 0,
|
||||
/* lfs_idaddr */ 0,
|
||||
/* lfs_ifile */ LFS_IFILE_INUM,
|
||||
/* lfs_lastseg */ 0,
|
||||
/* lfs_nextseg */ 0,
|
||||
/* lfs_curseg */ 0,
|
||||
/* lfs_offset */ 0,
|
||||
/* lfs_lastpseg */ 0,
|
||||
/* lfs_tstamp */ 0,
|
||||
/* lfs_maxsymlinklen */ MAXSYMLINKLEN,
|
||||
/* lfs_minfree */ MINFREE,
|
||||
/* lfs_maxfilesize */ 0,
|
||||
/* lfs_dbpseg */ DFL_LFSSEG/DEV_BSIZE,
|
||||
/* lfs_inopb */ DFL_LFSBLOCK/sizeof(struct dinode),
|
||||
/* lfs_ifpb */ DFL_LFSBLOCK/sizeof(IFILE),
|
||||
/* lfs_sepb */ DFL_LFSBLOCK/sizeof(SEGUSE),
|
||||
/* lfs_nindir */ DFL_LFSBLOCK/sizeof(daddr_t),
|
||||
/* lfs_nseg */ 0,
|
||||
/* lfs_nspf */ 0,
|
||||
/* lfs_cleansz */ 0,
|
||||
/* lfs_segtabsz */ 0,
|
||||
/* lfs_segmask */ DFL_LFSSEG_MASK,
|
||||
/* lfs_segshift */ DFL_LFSSEG_SHIFT,
|
||||
/* lfs_bmask */ DFL_LFSBLOCK_MASK,
|
||||
/* lfs_bshift */ DFL_LFSBLOCK_SHIFT,
|
||||
/* lfs_ffmask */ DFL_LFS_FFMASK,
|
||||
/* lfs_ffshift */ DFL_LFS_FFSHIFT,
|
||||
/* lfs_fbmask */ DFL_LFS_FBMASK,
|
||||
/* lfs_fbshift */ DFL_LFS_FBSHIFT,
|
||||
/* lfs_fsbtodb */ 0,
|
||||
/* lfs_sushift */ 0,
|
||||
/* lfs_sboffs */ { 0 },
|
||||
/* lfs_sp */ NULL,
|
||||
/* lfs_ivnode */ NULL,
|
||||
/* lfs_seglock */ 0,
|
||||
/* lfs_lockpid */ 0,
|
||||
/* lfs_iocount */ 0,
|
||||
/* lfs_writer */ 0,
|
||||
/* lfs_dirops */ 0,
|
||||
/* lfs_doifile */ 0,
|
||||
/* lfs_nactive */ 0,
|
||||
/* lfs_fmod */ 0,
|
||||
/* lfs_clean */ 0,
|
||||
/* lfs_ronly */ 0,
|
||||
/* lfs_flags */ 0,
|
||||
/* lfs_fsmnt */ { 0 },
|
||||
/* lfs_pad */ { 0 },
|
||||
/* lfs_cksum */ 0,
|
||||
/* lfs_maxsymlinklen */ MAXSYMLINKLEN
|
||||
};
|
||||
|
||||
|
||||
struct direct lfs_root_dir[] = {
|
||||
{ ROOTINO, sizeof(struct direct), DT_DIR, 1, "."},
|
||||
{ ROOTINO, sizeof(struct direct), DT_DIR, 2, ".."},
|
||||
{ LFS_IFILE_INUM, sizeof(struct direct), DT_REG, 5, "ifile"},
|
||||
{ LOSTFOUNDINO, sizeof(struct direct), DT_DIR, 10, "lost+found"},
|
||||
};
|
||||
|
||||
struct direct lfs_lf_dir[] = {
|
||||
{ LOSTFOUNDINO, sizeof(struct direct), DT_DIR, 1, "." },
|
||||
{ ROOTINO, sizeof(struct direct), DT_DIR, 2, ".." },
|
||||
};
|
||||
|
||||
static daddr_t make_dinode
|
||||
__P((ino_t, struct dinode *, int, daddr_t, struct lfs *));
|
||||
static void make_dir __P(( void *, struct direct *, int));
|
||||
static void put __P((int, off_t, void *, size_t));
|
||||
|
||||
int
|
||||
make_lfs(fd, lp, partp, minfree, block_size, frag_size, seg_size)
|
||||
int fd;
|
||||
struct disklabel *lp;
|
||||
struct partition *partp;
|
||||
int minfree;
|
||||
int block_size;
|
||||
int frag_size;
|
||||
int seg_size;
|
||||
{
|
||||
struct dinode *dip; /* Pointer to a disk inode */
|
||||
struct dinode *dpagep; /* Pointer to page of disk inodes */
|
||||
CLEANERINFO *cleaninfo; /* Segment cleaner information table */
|
||||
FINFO file_info; /* File info structure in summary blocks */
|
||||
IFILE *ifile; /* Pointer to array of ifile structures */
|
||||
IFILE *ip; /* Pointer to array of ifile structures */
|
||||
struct lfs *lfsp; /* Superblock */
|
||||
SEGUSE *segp; /* Segment usage table */
|
||||
SEGUSE *segtable; /* Segment usage table */
|
||||
SEGSUM summary; /* Segment summary structure */
|
||||
SEGSUM *sp; /* Segment summary pointer */
|
||||
daddr_t last_sb_addr; /* Address of superblocks */
|
||||
daddr_t last_addr; /* Previous segment address */
|
||||
daddr_t sb_addr; /* Address of superblocks */
|
||||
daddr_t seg_addr; /* Address of current segment */
|
||||
void *ipagep; /* Pointer to the page we use to write stuff */
|
||||
void *sump; /* Used to copy stuff into segment buffer */
|
||||
u_long *block_array; /* Array of logical block nos to put in sum */
|
||||
u_long blocks_used; /* Number of blocks in first segment */
|
||||
u_long *dp; /* Used to computed checksum on data */
|
||||
u_long *datasump; /* Used to computed checksum on data */
|
||||
int block_array_size; /* How many entries in block array */
|
||||
int bsize; /* Block size */
|
||||
int fsize; /* Fragment size */
|
||||
int db_per_fb; /* Disk blocks per file block */
|
||||
int i, j;
|
||||
int off; /* Offset at which to write */
|
||||
int sb_interval; /* number of segs between super blocks */
|
||||
int seg_seek; /* Seek offset for a segment */
|
||||
int ssize; /* Segment size */
|
||||
int sum_size; /* Size of the summary block */
|
||||
|
||||
lfsp = &lfs_default;
|
||||
|
||||
if (!(bsize = block_size))
|
||||
bsize = DFL_LFSBLOCK;
|
||||
if (!(fsize = frag_size))
|
||||
fsize = DFL_LFSFRAG;
|
||||
if (!(ssize = seg_size))
|
||||
ssize = DFL_LFSSEG;
|
||||
|
||||
/* Modify parts of superblock overridden by command line arguments */
|
||||
if (bsize != DFL_LFSBLOCK || fsize != DFL_LFSFRAG) {
|
||||
lfsp->lfs_bshift = log2(bsize);
|
||||
if (1 << lfsp->lfs_bshift != bsize)
|
||||
fatal("%d: block size not a power of 2", bsize);
|
||||
lfsp->lfs_bsize = bsize;
|
||||
lfsp->lfs_fsize = fsize;
|
||||
lfsp->lfs_bmask = bsize - 1;
|
||||
lfsp->lfs_inopb = bsize / sizeof(struct dinode);
|
||||
lfsp->lfs_ffmask = fsize - 1;
|
||||
lfsp->lfs_ffshift = log2(fsize);
|
||||
if (1 << lfsp->lfs_ffshift != fsize)
|
||||
fatal("%d: frag size not a power of 2", fsize);
|
||||
lfsp->lfs_frag = numfrags(lfsp, bsize);
|
||||
lfsp->lfs_fbmask = lfsp->lfs_frag - 1;
|
||||
lfsp->lfs_fbshift = log2(lfsp->lfs_frag);
|
||||
/* MIS -- should I round to power of 2 */
|
||||
lfsp->lfs_ifpb = bsize / sizeof(IFILE);
|
||||
lfsp->lfs_sepb = bsize / sizeof(SEGUSE);
|
||||
lfsp->lfs_nindir = bsize / sizeof(daddr_t);
|
||||
}
|
||||
|
||||
if (ssize != DFL_LFSSEG) {
|
||||
lfsp->lfs_segshift = log2(ssize);
|
||||
if (1 << lfsp->lfs_segshift != ssize)
|
||||
fatal("%d: segment size not power of 2", ssize);
|
||||
lfsp->lfs_ssize = ssize;
|
||||
lfsp->lfs_segmask = ssize - 1;
|
||||
lfsp->lfs_dbpseg = ssize / DEV_BSIZE;
|
||||
}
|
||||
lfsp->lfs_ssize = ssize >> lfsp->lfs_bshift;
|
||||
|
||||
if (minfree)
|
||||
lfsp->lfs_minfree = minfree;
|
||||
|
||||
/*
|
||||
* Fill in parts of superblock that can be computed from file system
|
||||
* size, disk geometry and current time.
|
||||
*/
|
||||
db_per_fb = bsize/lp->d_secsize;
|
||||
lfsp->lfs_fsbtodb = log2(db_per_fb);
|
||||
lfsp->lfs_sushift = log2(lfsp->lfs_sepb);
|
||||
lfsp->lfs_size = partp->p_size >> lfsp->lfs_fsbtodb;
|
||||
lfsp->lfs_dsize = lfsp->lfs_size - (LFS_LABELPAD >> lfsp->lfs_bshift);
|
||||
lfsp->lfs_nseg = lfsp->lfs_dsize / lfsp->lfs_ssize;
|
||||
lfsp->lfs_maxfilesize = maxtable[lfsp->lfs_bshift] << lfsp->lfs_bshift;
|
||||
|
||||
/*
|
||||
* The number of free blocks is set from the number of segments times
|
||||
* the segment size - 2 (that we never write because we need to make
|
||||
* sure the cleaner can run). Then we'll subtract off the room for the
|
||||
* superblocks ifile entries and segment usage table.
|
||||
*/
|
||||
lfsp->lfs_dsize = fsbtodb(lfsp, (lfsp->lfs_nseg - 2) * lfsp->lfs_ssize);
|
||||
lfsp->lfs_bfree = lfsp->lfs_dsize;
|
||||
lfsp->lfs_segtabsz = SEGTABSIZE_SU(lfsp);
|
||||
lfsp->lfs_cleansz = CLEANSIZE_SU(lfsp);
|
||||
if ((lfsp->lfs_tstamp = time(NULL)) == -1)
|
||||
fatal("time: %s", strerror(errno));
|
||||
if ((sb_interval = lfsp->lfs_nseg / LFS_MAXNUMSB) < LFS_MIN_SBINTERVAL)
|
||||
sb_interval = LFS_MIN_SBINTERVAL;
|
||||
|
||||
/*
|
||||
* Now, lay out the file system. We need to figure out where
|
||||
* the superblocks go, initialize the checkpoint information
|
||||
* for the first two superblocks, initialize the segment usage
|
||||
* information, put the segusage information in the ifile, create
|
||||
* the first block of IFILE structures, and link all the IFILE
|
||||
* structures into a free list.
|
||||
*/
|
||||
|
||||
/* Figure out where the superblocks are going to live */
|
||||
lfsp->lfs_sboffs[0] = LFS_LABELPAD/lp->d_secsize;
|
||||
for (i = 1; i < LFS_MAXNUMSB; i++) {
|
||||
sb_addr = ((i * sb_interval) <<
|
||||
(lfsp->lfs_segshift - lfsp->lfs_bshift + lfsp->lfs_fsbtodb))
|
||||
+ lfsp->lfs_sboffs[0];
|
||||
if (sb_addr > partp->p_size)
|
||||
break;
|
||||
lfsp->lfs_sboffs[i] = sb_addr;
|
||||
}
|
||||
last_sb_addr = lfsp->lfs_sboffs[i - 1];
|
||||
lfsp->lfs_lastseg = lfsp->lfs_sboffs[0];
|
||||
lfsp->lfs_nextseg =
|
||||
lfsp->lfs_sboffs[1] ? lfsp->lfs_sboffs[1] : lfsp->lfs_sboffs[0];
|
||||
lfsp->lfs_curseg = lfsp->lfs_lastseg;
|
||||
|
||||
/*
|
||||
* Initialize the segment usage table. The first segment will
|
||||
* contain the superblock, the cleanerinfo (cleansz), the segusage
|
||||
* table * (segtabsz), 1 block's worth of IFILE entries, the root
|
||||
* directory, the lost+found directory and one block's worth of
|
||||
* inodes (containing the ifile, root, and l+f inodes).
|
||||
*/
|
||||
if (!(cleaninfo = malloc(lfsp->lfs_cleansz << lfsp->lfs_bshift)))
|
||||
fatal("%s", strerror(errno));
|
||||
cleaninfo->clean = lfsp->lfs_nseg - 1;
|
||||
cleaninfo->dirty = 1;
|
||||
|
||||
if (!(segtable = malloc(lfsp->lfs_segtabsz << lfsp->lfs_bshift)))
|
||||
fatal("%s", strerror(errno));
|
||||
segp = segtable;
|
||||
blocks_used = lfsp->lfs_segtabsz + lfsp->lfs_cleansz + 4;
|
||||
segp->su_nbytes = ((blocks_used - 1) << lfsp->lfs_bshift) +
|
||||
3 * sizeof(struct dinode) + LFS_SUMMARY_SIZE;
|
||||
segp->su_lastmod = lfsp->lfs_tstamp;
|
||||
segp->su_nsums = 1; /* 1 summary blocks */
|
||||
segp->su_ninos = 1; /* 1 inode block */
|
||||
segp->su_flags = SEGUSE_SUPERBLOCK | SEGUSE_DIRTY;
|
||||
lfsp->lfs_bfree -= LFS_SUMMARY_SIZE / lp->d_secsize;
|
||||
lfsp->lfs_bfree -=
|
||||
fsbtodb(lfsp, lfsp->lfs_cleansz + lfsp->lfs_segtabsz + 4);
|
||||
|
||||
/*
|
||||
* Now figure out the address of the ifile inode. The inode block
|
||||
* appears immediately after the segment summary.
|
||||
*/
|
||||
lfsp->lfs_idaddr = (LFS_LABELPAD + LFS_SBPAD + LFS_SUMMARY_SIZE) /
|
||||
lp->d_secsize;
|
||||
|
||||
for (segp = segtable + 1, i = 1; i < lfsp->lfs_nseg; i++, segp++) {
|
||||
if ((i % sb_interval) == 0) {
|
||||
segp->su_flags = SEGUSE_SUPERBLOCK;
|
||||
lfsp->lfs_bfree -= (LFS_SBPAD / lp->d_secsize);
|
||||
} else
|
||||
segp->su_flags = 0;
|
||||
segp->su_lastmod = 0;
|
||||
segp->su_nbytes = 0;
|
||||
segp->su_ninos = 0;
|
||||
segp->su_nsums = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize dynamic accounting. The blocks available for
|
||||
* writing are the bfree blocks minus 1 segment summary for
|
||||
* each segment since you can't write any new data without
|
||||
* creating a segment summary - 2 segments that the cleaner
|
||||
* needs.
|
||||
*/
|
||||
lfsp->lfs_avail = lfsp->lfs_bfree - lfsp->lfs_nseg -
|
||||
fsbtodb(lfsp, 2 * lfsp->lfs_ssize);
|
||||
lfsp->lfs_uinodes = 0;
|
||||
/*
|
||||
* Ready to start writing segments. The first segment is different
|
||||
* because it contains the segment usage table and the ifile inode
|
||||
* as well as a superblock. For the rest of the segments, set the
|
||||
* time stamp to be 0 so that the first segment is the most recent.
|
||||
* For each segment that is supposed to contain a copy of the super
|
||||
* block, initialize its first few blocks and its segment summary
|
||||
* to indicate this.
|
||||
*/
|
||||
lfsp->lfs_nfiles = LFS_FIRST_INUM - 1;
|
||||
lfsp->lfs_cksum =
|
||||
cksum(lfsp, sizeof(struct lfs) - sizeof(lfsp->lfs_cksum));
|
||||
|
||||
/* Now create a block of disk inodes */
|
||||
if (!(dpagep = malloc(lfsp->lfs_bsize)))
|
||||
fatal("%s", strerror(errno));
|
||||
dip = (struct dinode *)dpagep;
|
||||
memset(dip, 0, lfsp->lfs_bsize);
|
||||
|
||||
/* Create a block of IFILE structures. */
|
||||
if (!(ipagep = malloc(lfsp->lfs_bsize)))
|
||||
fatal("%s", strerror(errno));
|
||||
ifile = (IFILE *)ipagep;
|
||||
|
||||
/*
|
||||
* Initialize IFILE. It is the next block following the
|
||||
* block of inodes (whose address has been calculated in
|
||||
* lfsp->lfs_idaddr;
|
||||
*/
|
||||
sb_addr = lfsp->lfs_idaddr + lfsp->lfs_bsize / lp->d_secsize;
|
||||
sb_addr = make_dinode(LFS_IFILE_INUM, dip,
|
||||
lfsp->lfs_cleansz + lfsp->lfs_segtabsz+1, sb_addr, lfsp);
|
||||
dip->di_mode = IFREG|IREAD|IWRITE;
|
||||
ip = &ifile[LFS_IFILE_INUM];
|
||||
ip->if_version = 1;
|
||||
ip->if_daddr = lfsp->lfs_idaddr;
|
||||
|
||||
/* Initialize the ROOT Directory */
|
||||
sb_addr = make_dinode(ROOTINO, ++dip, 1, sb_addr, lfsp);
|
||||
dip->di_mode = IFDIR|IREAD|IWRITE|IEXEC;
|
||||
dip->di_size = DIRBLKSIZ;
|
||||
dip->di_nlink = 3;
|
||||
ip = &ifile[ROOTINO];
|
||||
ip->if_version = 1;
|
||||
ip->if_daddr = lfsp->lfs_idaddr;
|
||||
|
||||
/* Initialize the lost+found Directory */
|
||||
sb_addr = make_dinode(LOSTFOUNDINO, ++dip, 1, sb_addr, lfsp);
|
||||
dip->di_mode = IFDIR|IREAD|IWRITE|IEXEC;
|
||||
dip->di_size = DIRBLKSIZ;
|
||||
dip->di_nlink = 2;
|
||||
ip = &ifile[LOSTFOUNDINO];
|
||||
ip->if_version = 1;
|
||||
ip->if_daddr = lfsp->lfs_idaddr;
|
||||
|
||||
/* Make all the other dinodes invalid */
|
||||
for (i = INOPB(lfsp)-3, dip++; i; i--, dip++)
|
||||
dip->di_inumber = LFS_UNUSED_INUM;
|
||||
|
||||
|
||||
/* Link remaining IFILE entries in free list */
|
||||
for (ip = &ifile[LFS_FIRST_INUM], i = LFS_FIRST_INUM;
|
||||
i < lfsp->lfs_ifpb; ++ip) {
|
||||
ip->if_version = 1;
|
||||
ip->if_daddr = LFS_UNUSED_DADDR;
|
||||
ip->if_nextfree = ++i;
|
||||
}
|
||||
ifile[lfsp->lfs_ifpb - 1].if_nextfree = LFS_UNUSED_INUM;
|
||||
|
||||
/* Now, write the segment */
|
||||
|
||||
/* Compute a checksum across all the data you're writing */
|
||||
dp = datasump = malloc (blocks_used * sizeof(u_long));
|
||||
*dp++ = ((u_long *)dpagep)[0]; /* inode block */
|
||||
for (i = 0; i < lfsp->lfs_cleansz; i++)
|
||||
*dp++ = ((u_long *)cleaninfo)[(i << lfsp->lfs_bshift) /
|
||||
sizeof(u_long)]; /* Cleaner info */
|
||||
for (i = 0; i < lfsp->lfs_segtabsz; i++)
|
||||
*dp++ = ((u_long *)segtable)[(i << lfsp->lfs_bshift) /
|
||||
sizeof(u_long)]; /* Segusage table */
|
||||
*dp++ = ((u_long *)ifile)[0]; /* Ifile */
|
||||
|
||||
/* Still need the root and l+f bytes; get them later */
|
||||
|
||||
/* Write out the inode block */
|
||||
off = LFS_LABELPAD + LFS_SBPAD + LFS_SUMMARY_SIZE;
|
||||
put(fd, off, dpagep, lfsp->lfs_bsize);
|
||||
free(dpagep);
|
||||
off += lfsp->lfs_bsize;
|
||||
|
||||
/* Write out the ifile */
|
||||
|
||||
put(fd, off, cleaninfo, lfsp->lfs_cleansz << lfsp->lfs_bshift);
|
||||
off += (lfsp->lfs_cleansz << lfsp->lfs_bshift);
|
||||
(void)free(cleaninfo);
|
||||
|
||||
put(fd, off, segtable, lfsp->lfs_segtabsz << lfsp->lfs_bshift);
|
||||
off += (lfsp->lfs_segtabsz << lfsp->lfs_bshift);
|
||||
(void)free(segtable);
|
||||
|
||||
put(fd, off, ifile, lfsp->lfs_bsize);
|
||||
off += lfsp->lfs_bsize;
|
||||
|
||||
/*
|
||||
* use ipagep for space for writing out other stuff. It used to
|
||||
* contain the ifile, but we're done with it.
|
||||
*/
|
||||
|
||||
/* Write out the root and lost and found directories */
|
||||
memset(ipagep, 0, lfsp->lfs_bsize);
|
||||
make_dir(ipagep, lfs_root_dir,
|
||||
sizeof(lfs_root_dir) / sizeof(struct direct));
|
||||
*dp++ = ((u_long *)ipagep)[0];
|
||||
put(fd, off, ipagep, lfsp->lfs_bsize);
|
||||
off += lfsp->lfs_bsize;
|
||||
|
||||
memset(ipagep, 0, lfsp->lfs_bsize);
|
||||
make_dir(ipagep, lfs_lf_dir,
|
||||
sizeof(lfs_lf_dir) / sizeof(struct direct));
|
||||
*dp++ = ((u_long *)ipagep)[0];
|
||||
put(fd, off, ipagep, lfsp->lfs_bsize);
|
||||
|
||||
/* Write Supberblock */
|
||||
lfsp->lfs_offset = (off + lfsp->lfs_bsize) / lp->d_secsize;
|
||||
put(fd, LFS_LABELPAD, lfsp, sizeof(struct lfs));
|
||||
|
||||
/*
|
||||
* Finally, calculate all the fields for the summary structure
|
||||
* and write it.
|
||||
*/
|
||||
|
||||
summary.ss_next = lfsp->lfs_nextseg;
|
||||
summary.ss_create = lfsp->lfs_tstamp;
|
||||
summary.ss_nfinfo = 3;
|
||||
summary.ss_ninos = 3;
|
||||
summary.ss_magic = SS_MAGIC;
|
||||
summary.ss_datasum = cksum(datasump, sizeof(u_long) * blocks_used);
|
||||
|
||||
/*
|
||||
* Make sure that we don't overflow a summary block. We have to
|
||||
* record: FINFO structures for ifile, root, and l+f. The number
|
||||
* of blocks recorded for the ifile is determined by the size of
|
||||
* the cleaner info and the segments usage table. There is room
|
||||
* for one block included in sizeof(FINFO) so we don't need to add
|
||||
* any extra space for the ROOT and L+F, and one block of the ifile
|
||||
* is already counted. Finally, we leave room for 1 inode block
|
||||
* address.
|
||||
*/
|
||||
sum_size = 3*sizeof(FINFO) + sizeof(SEGSUM) + sizeof(daddr_t) +
|
||||
(lfsp->lfs_cleansz + lfsp->lfs_segtabsz) * sizeof(u_long);
|
||||
#define SUMERR \
|
||||
"Multiple summary blocks in segment 1 not yet implemented\nsummary is %d bytes."
|
||||
if (sum_size > LFS_SUMMARY_SIZE)
|
||||
fatal(SUMERR, sum_size);
|
||||
|
||||
block_array_size = lfsp->lfs_cleansz + lfsp->lfs_segtabsz + 1;
|
||||
|
||||
if (!(block_array = malloc(block_array_size *sizeof(int))))
|
||||
fatal("%s: %s", special, strerror(errno));
|
||||
|
||||
/* fill in the array */
|
||||
for (i = 0; i < block_array_size; i++)
|
||||
block_array[i] = i;
|
||||
|
||||
/* copy into segment */
|
||||
sump = ipagep;
|
||||
memmove(sump, &summary, sizeof(SEGSUM));
|
||||
sump += sizeof(SEGSUM);
|
||||
|
||||
/* Now, add the ifile */
|
||||
file_info.fi_nblocks = block_array_size;
|
||||
file_info.fi_version = 1;
|
||||
file_info.fi_lastlength = lfsp->lfs_bsize;
|
||||
file_info.fi_ino = LFS_IFILE_INUM;
|
||||
|
||||
memmove(sump, &file_info, sizeof(FINFO) - sizeof(u_long));
|
||||
sump += sizeof(FINFO) - sizeof(u_long);
|
||||
memmove(sump, block_array, sizeof(u_long) * file_info.fi_nblocks);
|
||||
sump += sizeof(u_long) * file_info.fi_nblocks;
|
||||
|
||||
/* Now, add the root directory */
|
||||
file_info.fi_nblocks = 1;
|
||||
file_info.fi_version = 1;
|
||||
file_info.fi_lastlength = lfsp->lfs_bsize;
|
||||
file_info.fi_ino = ROOTINO;
|
||||
file_info.fi_blocks[0] = 0;
|
||||
memmove(sump, &file_info, sizeof(FINFO));
|
||||
sump += sizeof(FINFO);
|
||||
|
||||
/* Now, add the lost and found */
|
||||
file_info.fi_ino = LOSTFOUNDINO;
|
||||
memmove(sump, &file_info, sizeof(FINFO));
|
||||
|
||||
((daddr_t *)ipagep)[LFS_SUMMARY_SIZE / sizeof(daddr_t) - 1] =
|
||||
lfsp->lfs_idaddr;
|
||||
((SEGSUM *)ipagep)->ss_sumsum = cksum(ipagep+sizeof(summary.ss_sumsum),
|
||||
LFS_SUMMARY_SIZE - sizeof(summary.ss_sumsum));
|
||||
put(fd, LFS_LABELPAD + LFS_SBPAD, ipagep, LFS_SUMMARY_SIZE);
|
||||
|
||||
sp = (SEGSUM *)ipagep;
|
||||
sp->ss_create = 0;
|
||||
sp->ss_nfinfo = 0;
|
||||
sp->ss_ninos = 0;
|
||||
sp->ss_datasum = 0;
|
||||
sp->ss_magic = SS_MAGIC;
|
||||
|
||||
/* Now write the summary block for the next partial so it's invalid */
|
||||
lfsp->lfs_tstamp = 0;
|
||||
off += lfsp->lfs_bsize;
|
||||
sp->ss_sumsum =
|
||||
cksum(&sp->ss_datasum, LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum));
|
||||
put(fd, off, sp, LFS_SUMMARY_SIZE);
|
||||
|
||||
/* Now, write rest of segments containing superblocks */
|
||||
lfsp->lfs_cksum =
|
||||
cksum(lfsp, sizeof(struct lfs) - sizeof(lfsp->lfs_cksum));
|
||||
for (seg_addr = last_addr = lfsp->lfs_sboffs[0], j = 1, i = 1;
|
||||
i < lfsp->lfs_nseg; i++) {
|
||||
|
||||
seg_addr += lfsp->lfs_ssize << lfsp->lfs_fsbtodb;
|
||||
sp->ss_next = last_addr;
|
||||
last_addr = seg_addr;
|
||||
seg_seek = seg_addr * lp->d_secsize;
|
||||
|
||||
if (seg_addr == lfsp->lfs_sboffs[j]) {
|
||||
if (j < (LFS_MAXNUMSB - 2))
|
||||
j++;
|
||||
put(fd, seg_seek, lfsp, sizeof(struct lfs));
|
||||
seg_seek += LFS_SBPAD;
|
||||
}
|
||||
|
||||
/* Summary */
|
||||
sp->ss_sumsum = cksum(&sp->ss_datasum,
|
||||
LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum));
|
||||
put(fd, seg_seek, sp, LFS_SUMMARY_SIZE);
|
||||
}
|
||||
free(ipagep);
|
||||
close(fd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
put(fd, off, p, len)
|
||||
int fd;
|
||||
off_t off;
|
||||
void *p;
|
||||
size_t len;
|
||||
{
|
||||
int wbytes;
|
||||
|
||||
if (lseek(fd, off, SEEK_SET) < 0)
|
||||
fatal("%s: %s", special, strerror(errno));
|
||||
if ((wbytes = write(fd, p, len)) < 0)
|
||||
fatal("%s: %s", special, strerror(errno));
|
||||
if (wbytes != len)
|
||||
fatal("%s: short write (%d, not %d)", special, wbytes, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the root directory for this file system and the lost+found
|
||||
* directory.
|
||||
*/
|
||||
|
||||
void
|
||||
lfsinit()
|
||||
{}
|
||||
|
||||
static daddr_t
|
||||
make_dinode(ino, dip, nblocks, saddr, lfsp)
|
||||
ino_t ino; /* inode we're creating */
|
||||
struct dinode *dip; /* disk inode */
|
||||
int nblocks; /* number of blocks in file */
|
||||
daddr_t saddr; /* starting block address */
|
||||
struct lfs *lfsp; /* superblock */
|
||||
{
|
||||
int db_per_fb, i;
|
||||
|
||||
dip->di_nlink = 1;
|
||||
dip->di_blocks = nblocks << lfsp->lfs_fsbtodb;
|
||||
|
||||
dip->di_size = (nblocks << lfsp->lfs_bshift);
|
||||
dip->di_atime = dip->di_mtime = dip->di_ctime = lfsp->lfs_tstamp;
|
||||
dip->di_atimensec = dip->di_mtimensec = dip->di_ctimensec = 0;
|
||||
dip->di_inumber = ino;
|
||||
|
||||
#define SEGERR \
|
||||
"File requires more than the number of direct blocks; increase block or segment size."
|
||||
if (NDADDR < nblocks)
|
||||
fatal("%s", SEGERR);
|
||||
|
||||
/* Assign the block addresses for the ifile */
|
||||
db_per_fb = 1 << lfsp->lfs_fsbtodb;
|
||||
for (i = 0; i < nblocks; i++, saddr += db_per_fb)
|
||||
dip->di_db[i] = saddr;
|
||||
|
||||
return (saddr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Construct a set of directory entries in "bufp". We assume that all the
|
||||
* entries in protodir fir in the first DIRBLKSIZ.
|
||||
*/
|
||||
static void
|
||||
make_dir(bufp, protodir, entries)
|
||||
void *bufp;
|
||||
register struct direct *protodir;
|
||||
int entries;
|
||||
{
|
||||
char *cp;
|
||||
int i, spcleft;
|
||||
|
||||
spcleft = DIRBLKSIZ;
|
||||
for (cp = bufp, i = 0; i < entries - 1; i++) {
|
||||
protodir[i].d_reclen = DIRSIZ(NEWDIRFMT, &protodir[i]);
|
||||
memmove(cp, &protodir[i], protodir[i].d_reclen);
|
||||
cp += protodir[i].d_reclen;
|
||||
if ((spcleft -= protodir[i].d_reclen) < 0)
|
||||
fatal("%s: %s", special, "directory too big");
|
||||
}
|
||||
protodir[i].d_reclen = spcleft;
|
||||
memmove(cp, &protodir[i], DIRSIZ(NEWDIRFMT, &protodir[i]));
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/5/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "extern.h"
|
||||
|
||||
u_int
|
||||
log2(num)
|
||||
u_int num;
|
||||
{
|
||||
register u_int i, limit;
|
||||
|
||||
limit = 1;
|
||||
for (i = 0; limit < num; limit = limit << 1, i++);
|
||||
return (i);
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
#if __STDC__
|
||||
fatal(const char *fmt, ...)
|
||||
#else
|
||||
fatal(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
(void)fprintf(stderr, "%s: ", progname);
|
||||
(void)vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
(void)fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
@@ -1,483 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1989, 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1989, 1992, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)newfs.c 8.5 (Berkeley) 5/24/95";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* newfs: friendly front end to mkfs
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/ucred.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <ufs/ufs/dir.h>
|
||||
#include <ufs/ufs/dinode.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <paths.h>
|
||||
#include "config.h"
|
||||
#include "extern.h"
|
||||
|
||||
#define COMPAT /* allow non-labeled disks */
|
||||
|
||||
int mfs; /* run as the memory based filesystem */
|
||||
int Nflag; /* run without writing file system */
|
||||
int fssize; /* file system size */
|
||||
int ntracks; /* # tracks/cylinder */
|
||||
int nsectors; /* # sectors/track */
|
||||
int nphyssectors; /* # sectors/track including spares */
|
||||
int secpercyl; /* sectors per cylinder */
|
||||
int trackspares = -1; /* spare sectors per track */
|
||||
int cylspares = -1; /* spare sectors per cylinder */
|
||||
int sectorsize; /* bytes/sector */
|
||||
#ifdef tahoe
|
||||
int realsectorsize; /* bytes/sector in hardware */
|
||||
#endif
|
||||
int rpm; /* revolutions/minute of drive */
|
||||
int interleave; /* hardware sector interleave */
|
||||
int trackskew = -1; /* sector 0 skew, per track */
|
||||
int headswitch; /* head switch time, usec */
|
||||
int trackseek; /* track-to-track seek, usec */
|
||||
int fsize = 0; /* fragment size */
|
||||
int bsize = 0; /* block size */
|
||||
int cpg = DESCPG; /* cylinders/cylinder group */
|
||||
int cpgflg; /* cylinders/cylinder group flag was given */
|
||||
int minfree = MINFREE; /* free space threshold */
|
||||
int opt = DEFAULTOPT; /* optimization preference (space or time) */
|
||||
int density; /* number of bytes per inode */
|
||||
int maxcontig = MAXCONTIG; /* max contiguous blocks to allocate */
|
||||
int rotdelay = ROTDELAY; /* rotational delay between blocks */
|
||||
int maxbpg; /* maximum blocks per file in a cyl group */
|
||||
int nrpos = NRPOS; /* # of distinguished rotational positions */
|
||||
int bbsize = BBSIZE; /* boot block size */
|
||||
int sbsize = SBSIZE; /* superblock size */
|
||||
int mntflags; /* flags to be passed to mount */
|
||||
u_long memleft; /* virtual memory available */
|
||||
caddr_t membase; /* start address of memory based filesystem */
|
||||
#ifdef COMPAT
|
||||
char *disktype;
|
||||
int unlabeled;
|
||||
#endif
|
||||
|
||||
char device[MAXPATHLEN];
|
||||
char *progname, *special;
|
||||
|
||||
static struct disklabel *getdisklabel __P((char *, int));
|
||||
static struct disklabel *debug_readlabel __P((int));
|
||||
static void rewritelabel __P((char *, int, struct disklabel *));
|
||||
static void usage __P((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int ch;
|
||||
register struct partition *pp;
|
||||
register struct disklabel *lp;
|
||||
struct partition oldpartition;
|
||||
struct stat st;
|
||||
int debug, lfs, fsi, fso, segsize;
|
||||
char *cp, *opstring;
|
||||
|
||||
if (progname = strrchr(*argv, '/'))
|
||||
++progname;
|
||||
else
|
||||
progname = *argv;
|
||||
|
||||
if (strstr(progname, "mfs")) {
|
||||
mfs = 1;
|
||||
Nflag++;
|
||||
}
|
||||
|
||||
/* -F is mfs only and MUST come first! */
|
||||
opstring = "F:B:DLNS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:";
|
||||
if (!mfs)
|
||||
opstring += 2;
|
||||
|
||||
debug = lfs = segsize = 0;
|
||||
while ((ch = getopt(argc, argv, opstring)) != -1)
|
||||
switch(ch) {
|
||||
case 'B': /* LFS segment size */
|
||||
if ((segsize = atoi(optarg)) < LFS_MINSEGSIZE)
|
||||
fatal("%s: bad segment size", optarg);
|
||||
break;
|
||||
case 'D':
|
||||
debug = 1;
|
||||
break;
|
||||
case 'F':
|
||||
if ((mntflags = atoi(optarg)) == 0)
|
||||
fatal("%s: bad mount flags", optarg);
|
||||
break;
|
||||
case 'L': /* Create lfs */
|
||||
lfs = 1;
|
||||
break;
|
||||
case 'N':
|
||||
Nflag++;
|
||||
break;
|
||||
case 'S':
|
||||
if ((sectorsize = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad sector size", optarg);
|
||||
break;
|
||||
#ifdef COMPAT
|
||||
case 'T':
|
||||
disktype = optarg;
|
||||
break;
|
||||
#endif
|
||||
case 'a':
|
||||
if ((maxcontig = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad max contiguous blocks\n",
|
||||
optarg);
|
||||
break;
|
||||
case 'b': /* used for LFS */
|
||||
if ((bsize = atoi(optarg)) < LFS_MINBLOCKSIZE)
|
||||
fatal("%s: bad block size", optarg);
|
||||
break;
|
||||
case 'c':
|
||||
if ((cpg = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad cylinders/group", optarg);
|
||||
cpgflg++;
|
||||
break;
|
||||
case 'd':
|
||||
if ((rotdelay = atoi(optarg)) < 0)
|
||||
fatal("%s: bad rotational delay\n", optarg);
|
||||
break;
|
||||
case 'e':
|
||||
if ((maxbpg = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad blocks per file in a cyl group\n",
|
||||
optarg);
|
||||
break;
|
||||
case 'f':
|
||||
if ((fsize = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad frag size", optarg);
|
||||
break;
|
||||
case 'i':
|
||||
if ((density = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad bytes per inode\n", optarg);
|
||||
break;
|
||||
case 'k':
|
||||
if ((trackskew = atoi(optarg)) < 0)
|
||||
fatal("%s: bad track skew", optarg);
|
||||
break;
|
||||
case 'l':
|
||||
if ((interleave = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad interleave", optarg);
|
||||
break;
|
||||
case 'm': /* used for LFS */
|
||||
if ((minfree = atoi(optarg)) < 0 || minfree > 99)
|
||||
fatal("%s: bad free space %%\n", optarg);
|
||||
break;
|
||||
case 'n':
|
||||
if ((nrpos = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad rotational layout count\n",
|
||||
optarg);
|
||||
break;
|
||||
case 'o':
|
||||
if (strcmp(optarg, "space") == 0)
|
||||
opt = FS_OPTSPACE;
|
||||
else if (strcmp(optarg, "time") == 0)
|
||||
opt = FS_OPTTIME;
|
||||
else
|
||||
fatal("%s: bad optimization preference %s",
|
||||
optarg, "(options are `space' or `time')");
|
||||
break;
|
||||
case 'p':
|
||||
if ((trackspares = atoi(optarg)) < 0)
|
||||
fatal("%s: bad spare sectors per track",
|
||||
optarg);
|
||||
break;
|
||||
case 'r':
|
||||
if ((rpm = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad revs/minute\n", optarg);
|
||||
break;
|
||||
case 's': /* used for LFS */
|
||||
if ((fssize = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad file system size", optarg);
|
||||
break;
|
||||
case 't':
|
||||
if ((ntracks = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad total tracks", optarg);
|
||||
break;
|
||||
case 'u':
|
||||
if ((nsectors = atoi(optarg)) <= 0)
|
||||
fatal("%s: bad sectors/track", optarg);
|
||||
break;
|
||||
case 'x':
|
||||
if ((cylspares = atoi(optarg)) < 0)
|
||||
fatal("%s: bad spare sectors per cylinder",
|
||||
optarg);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc != 2 && (mfs || argc != 1))
|
||||
usage();
|
||||
|
||||
/*
|
||||
* If the -N flag isn't specified, open the output file. If no path
|
||||
* prefix, try /dev/r%s and then /dev/%s.
|
||||
*/
|
||||
special = argv[0];
|
||||
if (strchr(special, '/') == NULL) {
|
||||
(void)sprintf(device, "%sr%s", _PATH_DEV, special);
|
||||
if (stat(device, &st) == -1)
|
||||
(void)sprintf(device, "%s%s", _PATH_DEV, special);
|
||||
special = device;
|
||||
}
|
||||
if (!Nflag) {
|
||||
fso = open(special,
|
||||
(debug ? O_CREAT : 0) | O_WRONLY, DEFFILEMODE);
|
||||
if (fso < 0)
|
||||
fatal("%s: %s", special, strerror(errno));
|
||||
} else
|
||||
fso = -1;
|
||||
|
||||
/* Open the input file. */
|
||||
fsi = open(special, O_RDONLY);
|
||||
if (fsi < 0)
|
||||
fatal("%s: %s", special, strerror(errno));
|
||||
if (fstat(fsi, &st) < 0)
|
||||
fatal("%s: %s", special, strerror(errno));
|
||||
|
||||
if (!debug && !mfs && !S_ISCHR(st.st_mode))
|
||||
(void)printf("%s: %s: not a character-special device\n",
|
||||
progname, special);
|
||||
cp = strchr(argv[0], '\0') - 1;
|
||||
if (!debug && (cp == 0 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp)))
|
||||
fatal("%s: can't figure out file system partition", argv[0]);
|
||||
|
||||
#ifdef COMPAT
|
||||
if (!mfs && disktype == NULL)
|
||||
disktype = argv[1];
|
||||
#endif
|
||||
if (debug)
|
||||
lp = debug_readlabel(fsi);
|
||||
else
|
||||
lp = getdisklabel(special, fsi);
|
||||
|
||||
if (isdigit(*cp))
|
||||
pp = &lp->d_partitions[0];
|
||||
else
|
||||
pp = &lp->d_partitions[*cp - 'a'];
|
||||
if (pp->p_size == 0)
|
||||
fatal("%s: `%c' partition is unavailable", argv[0], *cp);
|
||||
if (fsize == 0) {
|
||||
fsize = pp->p_fsize;
|
||||
if (fsize <= 0)
|
||||
fsize = MAX(DFL_FRAGSIZE, lp->d_secsize);
|
||||
}
|
||||
|
||||
if (bsize == 0) {
|
||||
bsize = pp->p_frag * fsize;
|
||||
if (bsize <= 0)
|
||||
bsize = MIN(DFL_LFSBLOCK, 8 * fsize);
|
||||
}
|
||||
|
||||
if (segsize == 0) {
|
||||
segsize = pp->p_cpg * bsize;
|
||||
if (segsize <= 0)
|
||||
segsize = DFL_LFSSEG;
|
||||
}
|
||||
|
||||
/* If we're making a LFS, we break out here */
|
||||
exit(make_lfs(fso, lp, pp, minfree, bsize, fsize, segsize));
|
||||
}
|
||||
|
||||
#ifdef COMPAT
|
||||
char lmsg[] = "%s: can't read disk label; disk type must be specified";
|
||||
#else
|
||||
char lmsg[] = "%s: can't read disk label";
|
||||
#endif
|
||||
|
||||
static struct disklabel *
|
||||
getdisklabel(s, fd)
|
||||
char *s;
|
||||
int fd;
|
||||
{
|
||||
static struct disklabel lab;
|
||||
|
||||
if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) {
|
||||
#ifdef COMPAT
|
||||
if (disktype) {
|
||||
struct disklabel *lp, *getdiskbyname();
|
||||
|
||||
unlabeled++;
|
||||
lp = getdiskbyname(disktype);
|
||||
if (lp == NULL)
|
||||
fatal("%s: unknown disk type", disktype);
|
||||
return (lp);
|
||||
}
|
||||
#endif
|
||||
(void)fprintf(stderr,
|
||||
"%s: ioctl (GDINFO): %s\n", progname, strerror(errno));
|
||||
fatal(lmsg, s);
|
||||
}
|
||||
return (&lab);
|
||||
}
|
||||
|
||||
|
||||
static struct disklabel *
|
||||
debug_readlabel(fd)
|
||||
int fd;
|
||||
{
|
||||
static struct disklabel lab;
|
||||
int n;
|
||||
|
||||
if ((n = read(fd, &lab, sizeof(struct disklabel))) < 0)
|
||||
fatal("unable to read disk label: %s", strerror(errno));
|
||||
else if (n < sizeof(struct disklabel))
|
||||
fatal("short read of disklabel: %d of %d bytes", n,
|
||||
sizeof(struct disklabel));
|
||||
return(&lab);
|
||||
}
|
||||
|
||||
static void
|
||||
rewritelabel(s, fd, lp)
|
||||
char *s;
|
||||
int fd;
|
||||
register struct disklabel *lp;
|
||||
{
|
||||
#ifdef COMPAT
|
||||
if (unlabeled)
|
||||
return;
|
||||
#endif
|
||||
lp->d_checksum = 0;
|
||||
lp->d_checksum = dkcksum(lp);
|
||||
if (ioctl(fd, DIOCWDINFO, (char *)lp) < 0) {
|
||||
(void)fprintf(stderr,
|
||||
"%s: ioctl (WDINFO): %s\n", progname, strerror(errno));
|
||||
fatal("%s: can't rewrite disk label", s);
|
||||
}
|
||||
#if vax
|
||||
if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) {
|
||||
register i;
|
||||
int cfd;
|
||||
daddr_t alt;
|
||||
char specname[64];
|
||||
char blk[1024];
|
||||
char *cp;
|
||||
|
||||
/*
|
||||
* Make name for 'c' partition.
|
||||
*/
|
||||
strcpy(specname, s);
|
||||
cp = specname + strlen(specname) - 1;
|
||||
if (!isdigit(*cp))
|
||||
*cp = 'c';
|
||||
cfd = open(specname, O_WRONLY);
|
||||
if (cfd < 0)
|
||||
fatal("%s: %s", specname, strerror(errno));
|
||||
memset(blk, 0, sizeof(blk));
|
||||
*(struct disklabel *)(blk + LABELOFFSET) = *lp;
|
||||
alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
|
||||
for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {
|
||||
if (lseek(cfd, (off_t)(alt + i) * lp->d_secsize,
|
||||
L_SET) == -1)
|
||||
fatal("lseek to badsector area: %s",
|
||||
strerror(errno));
|
||||
if (write(cfd, blk, lp->d_secsize) < lp->d_secsize)
|
||||
fprintf(stderr,
|
||||
"%s: alternate label %d write: %s\n",
|
||||
progname, i/2, strerror(errno));
|
||||
}
|
||||
close(cfd);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
if (mfs) {
|
||||
fprintf(stderr,
|
||||
"usage: mfs [ -fsoptions ] special-device mount-point\n");
|
||||
} else
|
||||
fprintf(stderr,
|
||||
"usage: newlfs [ -fsoptions ] special-device%s\n",
|
||||
#ifdef COMPAT
|
||||
" [device-type]");
|
||||
#else
|
||||
"");
|
||||
#endif
|
||||
fprintf(stderr, "where fsoptions are:\n");
|
||||
fprintf(stderr, "\t-B LFS segment size\n");
|
||||
fprintf(stderr, "\t-D debug\n");
|
||||
fprintf(stderr, "\t-F mount flags\n");
|
||||
fprintf(stderr, "\t-L create LFS file system\n");
|
||||
fprintf(stderr,
|
||||
"\t-N do not create file system, just print out parameters\n");
|
||||
fprintf(stderr, "\t-S sector size\n");
|
||||
#ifdef COMPAT
|
||||
fprintf(stderr, "\t-T disktype\n");
|
||||
#endif
|
||||
fprintf(stderr, "\t-a maximum contiguous blocks\n");
|
||||
fprintf(stderr, "\t-b block size\n");
|
||||
fprintf(stderr, "\t-c cylinders/group\n");
|
||||
fprintf(stderr, "\t-d rotational delay between contiguous blocks\n");
|
||||
fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
|
||||
fprintf(stderr, "\t-f frag size\n");
|
||||
fprintf(stderr, "\t-i number of bytes per inode\n");
|
||||
fprintf(stderr, "\t-k sector 0 skew, per track\n");
|
||||
fprintf(stderr, "\t-l hardware sector interleave\n");
|
||||
fprintf(stderr, "\t-m minimum free space %%\n");
|
||||
fprintf(stderr, "\t-n number of distinguished rotational positions\n");
|
||||
fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
|
||||
fprintf(stderr, "\t-p spare sectors per track\n");
|
||||
fprintf(stderr, "\t-r revolutions/minute\n");
|
||||
fprintf(stderr, "\t-s file system size (sectors)\n");
|
||||
fprintf(stderr, "\t-t tracks/cylinder\n");
|
||||
fprintf(stderr, "\t-u sectors/track\n");
|
||||
fprintf(stderr, "\t-x spare sectors per cylinder\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
.\" Copyright (c) 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)newlfs.8 8.1 (Berkeley) 6/19/93
|
||||
.\" $Id$
|
||||
.\"
|
||||
.Dd June 19, 1993
|
||||
.Dt NEWLFS 8
|
||||
.Os BSD 4.4
|
||||
.Sh NAME
|
||||
.Nm newlfs
|
||||
.Nd construct a new LFS file system
|
||||
.Sh SYNOPSIS
|
||||
.Nm newlfs
|
||||
.Fl L
|
||||
.Op Ar newlfs-options
|
||||
.Ar special
|
||||
.Sh DESCRIPTION
|
||||
.Nm Newlfs
|
||||
builds a log-structured file system on the specified special
|
||||
device basing its defaults on the information in the disk label.
|
||||
(Before running
|
||||
.Nm newlfs
|
||||
the disk must be labeled using
|
||||
.Xr disklabel 8 .)
|
||||
.Pp
|
||||
The following options define the general layout policies.
|
||||
.Bl -tag -width Fl
|
||||
.It Fl B
|
||||
The logical segment size of the file system in bytes.
|
||||
.It Fl b Ar block-size
|
||||
The block size of the file system in bytes.
|
||||
.It Fl L
|
||||
Create a log-structured file system (LFS).
|
||||
This flag is currently required.
|
||||
.It Fl m Ar free space \&%
|
||||
The percentage of space reserved from normal users; the minimum
|
||||
free space threshold. The default value used is 10%.
|
||||
See
|
||||
.Xr tunefs 8
|
||||
for more details on how to set this option.
|
||||
.It Fl s Ar size
|
||||
The size of the file system in sectors.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr disktab 5 ,
|
||||
.Xr fs 5 ,
|
||||
.Xr disklabel 8 ,
|
||||
.Xr diskpart 8 ,
|
||||
.Xr dumplfs 8 ,
|
||||
.Xr tunefs 8
|
||||
.Rs
|
||||
.%A M. McKusick
|
||||
.%A W. Joy
|
||||
.%A S. Leffler
|
||||
.%A R. Fabry
|
||||
.%T A Fast File System for UNIX ,
|
||||
.%J ACM Transactions on Computer Systems 2
|
||||
.%V 3
|
||||
.%P pp 181-197
|
||||
.%D August 1984
|
||||
.%O (reprinted in the BSD System Manager's Manual)
|
||||
.Re
|
||||
.Sh BUGS
|
||||
LFS does not currently work in any variant of FreeBSD and should therefore
|
||||
not be used.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 4.4 .
|
||||
Reference in New Issue
Block a user