Convert newfs to use libufs. I've tested this on md filesystems, as has
keramida, and all seems well.
This commit is contained in:
parent
66e390feb6
commit
9d492cddac
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109926
@ -2,6 +2,8 @@
|
|||||||
# $FreeBSD$
|
# $FreeBSD$
|
||||||
|
|
||||||
PROG= newfs
|
PROG= newfs
|
||||||
|
DPADD= ${LIBUFS}
|
||||||
|
LDADD= -lufs
|
||||||
SRCS= newfs.c mkfs.c
|
SRCS= newfs.c mkfs.c
|
||||||
WARNS?= 2
|
WARNS?= 2
|
||||||
MAN= newfs.8
|
MAN= newfs.8
|
||||||
|
@ -80,18 +80,10 @@ static const char rcsid[] =
|
|||||||
#define UMASK 0755
|
#define UMASK 0755
|
||||||
#define POWEROF2(num) (((num) & ((num) - 1)) == 0)
|
#define POWEROF2(num) (((num) & ((num) - 1)) == 0)
|
||||||
|
|
||||||
static union {
|
struct uufsd disk;
|
||||||
struct fs fs;
|
|
||||||
char pad[SBLOCKSIZE];
|
|
||||||
} fsun;
|
|
||||||
#define sblock fsun.fs
|
|
||||||
static struct csum *fscs;
|
static struct csum *fscs;
|
||||||
|
#define sblock disk.d_fs
|
||||||
static union {
|
#define acg disk.d_cg
|
||||||
struct cg cg;
|
|
||||||
char pad[MAXBSIZE];
|
|
||||||
} cgun;
|
|
||||||
#define acg cgun.cg
|
|
||||||
|
|
||||||
union dinode {
|
union dinode {
|
||||||
struct ufs1_dinode dp1;
|
struct ufs1_dinode dp1;
|
||||||
@ -113,10 +105,8 @@ static void initcg(int, time_t);
|
|||||||
static int isblock(struct fs *, unsigned char *, int);
|
static int isblock(struct fs *, unsigned char *, int);
|
||||||
static void iput(union dinode *, ino_t);
|
static void iput(union dinode *, ino_t);
|
||||||
static int makedir(struct direct *, int);
|
static int makedir(struct direct *, int);
|
||||||
static void rdfs(ufs2_daddr_t, int, char *);
|
|
||||||
static void setblock(struct fs *, unsigned char *, int);
|
static void setblock(struct fs *, unsigned char *, int);
|
||||||
static void wtfs(ufs2_daddr_t, int, char *);
|
static void wtfs(ufs2_daddr_t, int, char *);
|
||||||
static void wtfsflush(void);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mkfs(struct partition *pp, char *fsys)
|
mkfs(struct partition *pp, char *fsys)
|
||||||
@ -128,6 +118,12 @@ mkfs(struct partition *pp, char *fsys)
|
|||||||
int width;
|
int width;
|
||||||
char tmpbuf[100]; /* XXX this will break in about 2,500 years */
|
char tmpbuf[100]; /* XXX this will break in about 2,500 years */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Our blocks == sector size, and the version of UFS we are using is
|
||||||
|
* specified by Oflag.
|
||||||
|
*/
|
||||||
|
disk.d_bsize = sectorsize;
|
||||||
|
disk.d_ufs = Oflag;
|
||||||
if (Rflag)
|
if (Rflag)
|
||||||
utime = 1000000000;
|
utime = 1000000000;
|
||||||
else
|
else
|
||||||
@ -487,13 +483,13 @@ mkfs(struct partition *pp, char *fsys)
|
|||||||
sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree;
|
sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree;
|
||||||
sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree;
|
sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree;
|
||||||
}
|
}
|
||||||
wtfs(sblock.fs_sblockloc / sectorsize, SBLOCKSIZE, (char *)&sblock);
|
if (!Nflag)
|
||||||
|
sbwrite(&disk, 1);
|
||||||
for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize)
|
for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize)
|
||||||
wtfs(fsbtodb(&sblock, sblock.fs_csaddr + numfrags(&sblock, i)),
|
wtfs(fsbtodb(&sblock, sblock.fs_csaddr + numfrags(&sblock, i)),
|
||||||
sblock.fs_cssize - i < sblock.fs_bsize ?
|
sblock.fs_cssize - i < sblock.fs_bsize ?
|
||||||
sblock.fs_cssize - i : sblock.fs_bsize,
|
sblock.fs_cssize - i : sblock.fs_bsize,
|
||||||
((char *)fscs) + i);
|
((char *)fscs) + i);
|
||||||
wtfsflush();
|
|
||||||
/*
|
/*
|
||||||
* Update information about this partion in pack
|
* Update information about this partion in pack
|
||||||
* label, to that it may be updated on disk.
|
* label, to that it may be updated on disk.
|
||||||
@ -769,8 +765,8 @@ alloc(int size, int mode)
|
|||||||
{
|
{
|
||||||
int i, d, blkno, frag;
|
int i, d, blkno, frag;
|
||||||
|
|
||||||
rdfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
|
bread(&disk, fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
|
||||||
(char *)&acg);
|
sblock.fs_cgsize);
|
||||||
if (acg.cg_magic != CG_MAGIC) {
|
if (acg.cg_magic != CG_MAGIC) {
|
||||||
printf("cg 0: bad magic number\n");
|
printf("cg 0: bad magic number\n");
|
||||||
return (0);
|
return (0);
|
||||||
@ -806,6 +802,7 @@ alloc(int size, int mode)
|
|||||||
for (i = frag; i < sblock.fs_frag; i++)
|
for (i = frag; i < sblock.fs_frag; i++)
|
||||||
setbit(cg_blksfree(&acg), d + i);
|
setbit(cg_blksfree(&acg), d + i);
|
||||||
}
|
}
|
||||||
|
/* XXX cgwrite(&disk, 0)??? */
|
||||||
wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
|
wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
|
||||||
(char *)&acg);
|
(char *)&acg);
|
||||||
return ((ufs2_daddr_t)d);
|
return ((ufs2_daddr_t)d);
|
||||||
@ -821,8 +818,8 @@ iput(union dinode *ip, ino_t ino)
|
|||||||
int c;
|
int c;
|
||||||
|
|
||||||
c = ino_to_cg(&sblock, ino);
|
c = ino_to_cg(&sblock, ino);
|
||||||
rdfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
|
bread(&disk, fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
|
||||||
(char *)&acg);
|
sblock.fs_cgsize);
|
||||||
if (acg.cg_magic != CG_MAGIC) {
|
if (acg.cg_magic != CG_MAGIC) {
|
||||||
printf("cg 0: bad magic number\n");
|
printf("cg 0: bad magic number\n");
|
||||||
exit(31);
|
exit(31);
|
||||||
@ -838,101 +835,25 @@ iput(union dinode *ip, ino_t ino)
|
|||||||
exit(32);
|
exit(32);
|
||||||
}
|
}
|
||||||
d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino));
|
d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino));
|
||||||
rdfs(d, sblock.fs_bsize, (char *)iobuf);
|
bread(&disk, d, (char *)iobuf, sblock.fs_bsize);
|
||||||
if (sblock.fs_magic == FS_UFS1_MAGIC)
|
if (sblock.fs_magic == FS_UFS1_MAGIC)
|
||||||
((struct ufs1_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] =
|
((struct ufs1_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] =
|
||||||
ip->dp1;
|
ip->dp1;
|
||||||
else
|
else
|
||||||
((struct ufs2_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] =
|
((struct ufs2_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] =
|
||||||
ip->dp2;
|
ip->dp2;
|
||||||
wtfs(d, sblock.fs_bsize, (char *)iobuf);
|
wtfs(d, sblock.fs_size, (char *)iobuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* read a block from the file system
|
* possibly write to disk
|
||||||
*/
|
|
||||||
void
|
|
||||||
rdfs(ufs2_daddr_t bno, int size, char *bf)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
wtfsflush();
|
|
||||||
if (lseek(fso, (off_t)bno * sectorsize, 0) < 0) {
|
|
||||||
printf("seek error: %ld\n", (long)bno);
|
|
||||||
err(33, "rdfs");
|
|
||||||
}
|
|
||||||
n = read(fso, bf, size);
|
|
||||||
if (n != size) {
|
|
||||||
printf("read error: %ld\n", (long)bno);
|
|
||||||
err(34, "rdfs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define WCSIZE (128 * 1024)
|
|
||||||
ufs2_daddr_t wc_sect; /* units of sectorsize */
|
|
||||||
int wc_end; /* bytes */
|
|
||||||
static char wc[WCSIZE]; /* bytes */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Flush dirty write behind buffer.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
wtfsflush()
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
if (wc_end) {
|
|
||||||
if (lseek(fso, (off_t)wc_sect * sectorsize, SEEK_SET) < 0) {
|
|
||||||
printf("seek error: %ld\n", (long)wc_sect);
|
|
||||||
err(35, "wtfs - writecombine");
|
|
||||||
}
|
|
||||||
n = write(fso, wc, wc_end);
|
|
||||||
if (n != wc_end) {
|
|
||||||
printf("write error: %ld\n", (long)wc_sect);
|
|
||||||
err(36, "wtfs - writecombine");
|
|
||||||
}
|
|
||||||
wc_end = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* write a block to the file system
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
wtfs(ufs2_daddr_t bno, int size, char *bf)
|
wtfs(ufs2_daddr_t bno, int size, char *bf)
|
||||||
{
|
{
|
||||||
int done, n;
|
|
||||||
|
|
||||||
if (Nflag)
|
if (Nflag)
|
||||||
return;
|
return;
|
||||||
done = 0;
|
bwrite(&disk, bno, bf, size);
|
||||||
if (wc_end == 0 && size <= WCSIZE) {
|
|
||||||
wc_sect = bno;
|
|
||||||
bcopy(bf, wc, size);
|
|
||||||
wc_end = size;
|
|
||||||
if (wc_end < WCSIZE)
|
|
||||||
return;
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
if ((off_t)wc_sect * sectorsize + wc_end == (off_t)bno * sectorsize &&
|
|
||||||
wc_end + size <= WCSIZE) {
|
|
||||||
bcopy(bf, wc + wc_end, size);
|
|
||||||
wc_end += size;
|
|
||||||
if (wc_end < WCSIZE)
|
|
||||||
return;
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
wtfsflush();
|
|
||||||
if (done)
|
|
||||||
return;
|
|
||||||
if (lseek(fso, (off_t)bno * sectorsize, SEEK_SET) < 0) {
|
|
||||||
printf("seek error: %ld\n", (long)bno);
|
|
||||||
err(35, "wtfs");
|
|
||||||
}
|
|
||||||
n = write(fso, bf, size);
|
|
||||||
if (n != size) {
|
|
||||||
printf("write error: %ld\n", (long)bno);
|
|
||||||
err(36, "wtfs");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -135,7 +135,6 @@ int maxcontig = 0; /* max contiguous blocks to allocate */
|
|||||||
int maxbpg; /* maximum blocks per file in a cyl group */
|
int maxbpg; /* maximum blocks per file in a cyl group */
|
||||||
int avgfilesize = AVFILESIZ;/* expected average file size */
|
int avgfilesize = AVFILESIZ;/* expected average file size */
|
||||||
int avgfilesperdir = AFPDIR;/* expected number of files per directory */
|
int avgfilesperdir = AFPDIR;/* expected number of files per directory */
|
||||||
int fso; /* filedescriptor to device */
|
|
||||||
|
|
||||||
static char device[MAXPATHLEN];
|
static char device[MAXPATHLEN];
|
||||||
static char *disktype;
|
static char *disktype;
|
||||||
@ -261,17 +260,20 @@ main(int argc, char *argv[])
|
|||||||
special = device;
|
special = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
fso = open(special, Nflag ? O_RDONLY : O_RDWR);
|
if (ufs_disk_fillout_blank(&disk, special) == -1) {
|
||||||
if (fso < 0)
|
if (disk.d_error != NULL)
|
||||||
err(1, "%s", special);
|
errx(1, "%s: %s", special, disk.d_error);
|
||||||
if (fstat(fso, &st) < 0)
|
else
|
||||||
|
err(1, "%s", special);
|
||||||
|
}
|
||||||
|
if (fstat(disk.d_fd, &st) < 0)
|
||||||
err(1, "%s", special);
|
err(1, "%s", special);
|
||||||
if ((st.st_mode & S_IFMT) != S_IFCHR)
|
if ((st.st_mode & S_IFMT) != S_IFCHR)
|
||||||
errx(1, "%s: not a character-special device", special);
|
errx(1, "%s: not a character-special device", special);
|
||||||
|
|
||||||
if (sectorsize == 0)
|
if (sectorsize == 0)
|
||||||
ioctl(fso, DIOCGSECTORSIZE, §orsize);
|
ioctl(disk.d_fd, DIOCGSECTORSIZE, §orsize);
|
||||||
if (sectorsize && !ioctl(fso, DIOCGMEDIASIZE, &mediasize)) {
|
if (sectorsize && !ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize)) {
|
||||||
if (fssize == 0)
|
if (fssize == 0)
|
||||||
fssize = mediasize / sectorsize;
|
fssize = mediasize / sectorsize;
|
||||||
else if (fssize > mediasize / sectorsize)
|
else if (fssize > mediasize / sectorsize)
|
||||||
@ -350,7 +352,7 @@ main(int argc, char *argv[])
|
|||||||
if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition)))
|
if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition)))
|
||||||
rewritelabel(special, lp);
|
rewritelabel(special, lp);
|
||||||
}
|
}
|
||||||
close(fso);
|
ufs_disk_close(&disk);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +362,7 @@ getdisklabel(char *s)
|
|||||||
static struct disklabel lab;
|
static struct disklabel lab;
|
||||||
struct disklabel *lp;
|
struct disklabel *lp;
|
||||||
|
|
||||||
if (!ioctl(fso, DIOCGDINFO, (char *)&lab))
|
if (!ioctl(disk.d_fd, DIOCGDINFO, (char *)&lab))
|
||||||
return (&lab);
|
return (&lab);
|
||||||
unlabeled++;
|
unlabeled++;
|
||||||
if (disktype) {
|
if (disktype) {
|
||||||
@ -378,12 +380,12 @@ rewritelabel(char *s, struct disklabel *lp)
|
|||||||
return;
|
return;
|
||||||
lp->d_checksum = 0;
|
lp->d_checksum = 0;
|
||||||
lp->d_checksum = dkcksum(lp);
|
lp->d_checksum = dkcksum(lp);
|
||||||
if (ioctl(fso, DIOCWDINFO, (char *)lp) < 0)
|
if (ioctl(disk.d_fd, DIOCWDINFO, (char *)lp) < 0)
|
||||||
warn("ioctl (WDINFO): %s: can't rewrite disk label", s);
|
warn("ioctl (WDINFO): %s: can't rewrite disk label", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage()
|
usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: %s [ -fsoptions ] special-device%s\n",
|
"usage: %s [ -fsoptions ] special-device%s\n",
|
||||||
|
@ -45,6 +45,13 @@
|
|||||||
* $FreeBSD$
|
* $FreeBSD$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libufs interfaces.
|
||||||
|
*/
|
||||||
|
#include <libufs.h>
|
||||||
|
|
||||||
|
extern struct uufsd disk; /* the disk where we will operate */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* variables set up by front end.
|
* variables set up by front end.
|
||||||
@ -67,6 +74,5 @@ extern int maxcontig; /* max contiguous blocks to allocate */
|
|||||||
extern int maxbpg; /* maximum blocks per file in a cyl group */
|
extern int maxbpg; /* maximum blocks per file in a cyl group */
|
||||||
extern int avgfilesize; /* expected average file size */
|
extern int avgfilesize; /* expected average file size */
|
||||||
extern int avgfilesperdir; /* expected number of files per directory */
|
extern int avgfilesperdir; /* expected number of files per directory */
|
||||||
extern int fso; /* filedescriptor to device */
|
|
||||||
|
|
||||||
void mkfs (struct partition *, char *);
|
void mkfs (struct partition *, char *);
|
||||||
|
Loading…
Reference in New Issue
Block a user