aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuli Mallett <jmallett@FreeBSD.org>2003-01-29 22:52:27 +0000
committerJuli Mallett <jmallett@FreeBSD.org>2003-01-29 22:52:27 +0000
commit5a29754e3f2b408d8df01c00b9e32675f0757778 (patch)
treee1435925939de1c4aef43d7be5845967744a2958
parent6718b083be8bac963395b6529d42c9f4d5fd8e21 (diff)
downloadsrc-5a29754e3f2b408d8df01c00b9e32675f0757778.tar.gz
src-5a29754e3f2b408d8df01c00b9e32675f0757778.zip
Back out conversion to libufs, for now. It seems to cause problems.
Reported by: phk
Notes
Notes: svn path=/head/; revision=110065
-rw-r--r--sbin/newfs/Makefile2
-rw-r--r--sbin/newfs/mkfs.c119
-rw-r--r--sbin/newfs/newfs.c24
-rw-r--r--sbin/newfs/newfs.h8
4 files changed, 111 insertions, 42 deletions
diff --git a/sbin/newfs/Makefile b/sbin/newfs/Makefile
index efbe7abfe492..f12e266917e0 100644
--- a/sbin/newfs/Makefile
+++ b/sbin/newfs/Makefile
@@ -2,8 +2,6 @@
# $FreeBSD$
PROG= newfs
-DPADD= ${LIBUFS}
-LDADD= -lufs
SRCS= newfs.c mkfs.c
WARNS?= 2
MAN= newfs.8
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index 968611b67342..4b78f9bc14cf 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -80,10 +80,18 @@ static const char rcsid[] =
#define UMASK 0755
#define POWEROF2(num) (((num) & ((num) - 1)) == 0)
-struct uufsd disk;
+static union {
+ struct fs fs;
+ char pad[SBLOCKSIZE];
+} fsun;
+#define sblock fsun.fs
static struct csum *fscs;
-#define sblock disk.d_fs
-#define acg disk.d_cg
+
+static union {
+ struct cg cg;
+ char pad[MAXBSIZE];
+} cgun;
+#define acg cgun.cg
union dinode {
struct ufs1_dinode dp1;
@@ -105,8 +113,10 @@ static void initcg(int, time_t);
static int isblock(struct fs *, unsigned char *, int);
static void iput(union dinode *, ino_t);
static int makedir(struct direct *, int);
+static void rdfs(ufs2_daddr_t, int, char *);
static void setblock(struct fs *, unsigned char *, int);
static void wtfs(ufs2_daddr_t, int, char *);
+static void wtfsflush(void);
void
mkfs(struct partition *pp, char *fsys)
@@ -118,12 +128,6 @@ mkfs(struct partition *pp, char *fsys)
int width;
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)
utime = 1000000000;
else
@@ -483,13 +487,13 @@ mkfs(struct partition *pp, char *fsys)
sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree;
sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree;
}
- if (!Nflag)
- sbwrite(&disk, 1);
+ wtfs(sblock.fs_sblockloc / sectorsize, SBLOCKSIZE, (char *)&sblock);
for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize)
wtfs(fsbtodb(&sblock, sblock.fs_csaddr + numfrags(&sblock, i)),
sblock.fs_cssize - i < sblock.fs_bsize ?
sblock.fs_cssize - i : sblock.fs_bsize,
((char *)fscs) + i);
+ wtfsflush();
/*
* Update information about this partion in pack
* label, to that it may be updated on disk.
@@ -765,8 +769,8 @@ alloc(int size, int mode)
{
int i, d, blkno, frag;
- bread(&disk, fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
- sblock.fs_cgsize);
+ rdfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
+ (char *)&acg);
if (acg.cg_magic != CG_MAGIC) {
printf("cg 0: bad magic number\n");
return (0);
@@ -802,7 +806,6 @@ goth:
for (i = frag; i < sblock.fs_frag; i++)
setbit(cg_blksfree(&acg), d + i);
}
- /* XXX cgwrite(&disk, 0)??? */
wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
(char *)&acg);
return ((ufs2_daddr_t)d);
@@ -818,8 +821,8 @@ iput(union dinode *ip, ino_t ino)
int c;
c = ino_to_cg(&sblock, ino);
- bread(&disk, fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
- sblock.fs_cgsize);
+ rdfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
+ (char *)&acg);
if (acg.cg_magic != CG_MAGIC) {
printf("cg 0: bad magic number\n");
exit(31);
@@ -835,25 +838,101 @@ iput(union dinode *ip, ino_t ino)
exit(32);
}
d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino));
- bread(&disk, d, (char *)iobuf, sblock.fs_bsize);
+ rdfs(d, sblock.fs_bsize, (char *)iobuf);
if (sblock.fs_magic == FS_UFS1_MAGIC)
((struct ufs1_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] =
ip->dp1;
else
((struct ufs2_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] =
ip->dp2;
- wtfs(d, sblock.fs_size, (char *)iobuf);
+ wtfs(d, sblock.fs_bsize, (char *)iobuf);
+}
+
+/*
+ * read a block from the file system
+ */
+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;
+ }
}
/*
- * possibly write to disk
+ * write a block to the file system
*/
static void
wtfs(ufs2_daddr_t bno, int size, char *bf)
{
+ int done, n;
+
if (Nflag)
return;
- bwrite(&disk, bno, bf, size);
+ done = 0;
+ 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");
+ }
}
/*
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c
index 2d7b0c266a39..50034a2bda05 100644
--- a/sbin/newfs/newfs.c
+++ b/sbin/newfs/newfs.c
@@ -135,6 +135,7 @@ int maxcontig = 0; /* max contiguous blocks to allocate */
int maxbpg; /* maximum blocks per file in a cyl group */
int avgfilesize = AVFILESIZ;/* expected average file size */
int avgfilesperdir = AFPDIR;/* expected number of files per directory */
+int fso; /* filedescriptor to device */
static char device[MAXPATHLEN];
static char *disktype;
@@ -260,20 +261,17 @@ main(int argc, char *argv[])
special = device;
}
- if (ufs_disk_fillout_blank(&disk, special) == -1) {
- if (disk.d_error != NULL)
- errx(1, "%s: %s", special, disk.d_error);
- else
- err(1, "%s", special);
- }
- if (fstat(disk.d_fd, &st) < 0)
+ fso = open(special, Nflag ? O_RDONLY : O_RDWR);
+ if (fso < 0)
+ err(1, "%s", special);
+ if (fstat(fso, &st) < 0)
err(1, "%s", special);
if ((st.st_mode & S_IFMT) != S_IFCHR)
errx(1, "%s: not a character-special device", special);
if (sectorsize == 0)
- ioctl(disk.d_fd, DIOCGSECTORSIZE, &sectorsize);
- if (sectorsize && !ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize)) {
+ ioctl(fso, DIOCGSECTORSIZE, &sectorsize);
+ if (sectorsize && !ioctl(fso, DIOCGMEDIASIZE, &mediasize)) {
if (fssize == 0)
fssize = mediasize / sectorsize;
else if (fssize > mediasize / sectorsize)
@@ -352,7 +350,7 @@ main(int argc, char *argv[])
if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition)))
rewritelabel(special, lp);
}
- ufs_disk_close(&disk);
+ close(fso);
exit(0);
}
@@ -362,7 +360,7 @@ getdisklabel(char *s)
static struct disklabel lab;
struct disklabel *lp;
- if (!ioctl(disk.d_fd, DIOCGDINFO, (char *)&lab))
+ if (!ioctl(fso, DIOCGDINFO, (char *)&lab))
return (&lab);
unlabeled++;
if (disktype) {
@@ -380,12 +378,12 @@ rewritelabel(char *s, struct disklabel *lp)
return;
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
- if (ioctl(disk.d_fd, DIOCWDINFO, (char *)lp) < 0)
+ if (ioctl(fso, DIOCWDINFO, (char *)lp) < 0)
warn("ioctl (WDINFO): %s: can't rewrite disk label", s);
}
static void
-usage(void)
+usage()
{
fprintf(stderr,
"usage: %s [ -fsoptions ] special-device%s\n",
diff --git a/sbin/newfs/newfs.h b/sbin/newfs/newfs.h
index 02c271a019fb..fb32a629d456 100644
--- a/sbin/newfs/newfs.h
+++ b/sbin/newfs/newfs.h
@@ -45,13 +45,6 @@
* $FreeBSD$
*/
-/*
- * libufs interfaces.
- */
-#include <libufs.h>
-
-extern struct uufsd disk; /* the disk where we will operate */
-
/*
* variables set up by front end.
@@ -74,5 +67,6 @@ extern int maxcontig; /* max contiguous blocks to allocate */
extern int maxbpg; /* maximum blocks per file in a cyl group */
extern int avgfilesize; /* expected average file size */
extern int avgfilesperdir; /* expected number of files per directory */
+extern int fso; /* filedescriptor to device */
void mkfs (struct partition *, char *);