summaryrefslogtreecommitdiff
path: root/usr.sbin/makefs
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2017-05-26 15:49:20 +0000
committerEd Maste <emaste@FreeBSD.org>2017-05-26 15:49:20 +0000
commitb79f050a884c1442e8ead094fa600c0e505e2b06 (patch)
treee918dcc42a4a1e1a46276e63f2ee35e3f1249f2f /usr.sbin/makefs
parent32ecf81aff79682a76602a1053975f62d3282767 (diff)
downloadsrc-test2-b79f050a884c1442e8ead094fa600c0e505e2b06.tar.gz
src-test2-b79f050a884c1442e8ead094fa600c0e505e2b06.zip
Notes
Diffstat (limited to 'usr.sbin/makefs')
-rw-r--r--usr.sbin/makefs/ffs.c11
-rw-r--r--usr.sbin/makefs/ffs/buf.c4
-rw-r--r--usr.sbin/makefs/ffs/mkfs.c8
-rw-r--r--usr.sbin/makefs/makefs.88
-rw-r--r--usr.sbin/makefs/makefs.c13
-rw-r--r--usr.sbin/makefs/makefs.h1
6 files changed, 32 insertions, 13 deletions
diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c
index ae09e604ed53..3c0be521f88e 100644
--- a/usr.sbin/makefs/ffs.c
+++ b/usr.sbin/makefs/ffs.c
@@ -476,13 +476,15 @@ ffs_create_image(const char *image, fsinfo_t *fsopts)
char *buf;
int i, bufsize;
off_t bufrem;
+ int oflags = O_RDWR | O_CREAT;
time_t tstamp;
- int oflags = O_RDWR | O_CREAT | O_TRUNC;
assert (image != NULL);
assert (fsopts != NULL);
/* create image */
+ if (fsopts->offset == 0)
+ oflags |= O_TRUNC;
if ((fsopts->fd = open(image, oflags, 0666)) == -1) {
warn("Can't open `%s' for writing", image);
return (-1);
@@ -517,6 +519,13 @@ ffs_create_image(const char *image, fsinfo_t *fsopts)
bufsize);
buf = ecalloc(1, bufsize);
}
+
+ if (fsopts->offset != 0)
+ if (lseek(fsopts->fd, fsopts->offset, SEEK_SET) == -1) {
+ warn("can't seek");
+ return -1;
+ }
+
while (bufrem > 0) {
i = write(fsopts->fd, buf, MIN(bufsize, bufrem));
if (i == -1) {
diff --git a/usr.sbin/makefs/ffs/buf.c b/usr.sbin/makefs/ffs/buf.c
index 5a0fa8acee79..2820bcafa0e0 100644
--- a/usr.sbin/makefs/ffs/buf.c
+++ b/usr.sbin/makefs/ffs/buf.c
@@ -68,7 +68,7 @@ bread(struct vnode *vp, daddr_t blkno, int size, struct ucred *u1 __unused,
printf("%s: blkno %lld size %d\n", __func__, (long long)blkno,
size);
*bpp = getblk(vp, blkno, size, 0, 0, 0);
- offset = (*bpp)->b_blkno * fsinfo->sectorsize;
+ offset = (*bpp)->b_blkno * fsinfo->sectorsize + fsinfo->offset;
if (debug & DEBUG_BUF_BREAD)
printf("%s: blkno %lld offset %lld bcount %ld\n", __func__,
(long long)(*bpp)->b_blkno, (long long) offset,
@@ -128,7 +128,7 @@ bwrite(struct buf *bp)
fsinfo_t *fs = bp->b_fs;
assert (bp != NULL);
- offset = bp->b_blkno * fs->sectorsize;
+ offset = bp->b_blkno * fs->sectorsize + fs->offset;
if (debug & DEBUG_BUF_BWRITE)
printf("bwrite: blkno %lld offset %lld bcount %ld\n",
(long long)bp->b_blkno, (long long) offset,
diff --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c
index bf70f3d09a04..3be9c6edcce4 100644
--- a/usr.sbin/makefs/ffs/mkfs.c
+++ b/usr.sbin/makefs/ffs/mkfs.c
@@ -774,8 +774,7 @@ ffs_rdfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts)
int n;
off_t offset;
- offset = bno;
- offset *= fsopts->sectorsize;
+ offset = bno * fsopts->sectorsize + fsopts->offset;
if (lseek(fsopts->fd, offset, SEEK_SET) < 0)
err(1, "%s: seek error for sector %lld", __func__,
(long long)bno);
@@ -799,11 +798,10 @@ ffs_wtfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts)
int n;
off_t offset;
- offset = bno;
- offset *= fsopts->sectorsize;
+ offset = bno * fsopts->sectorsize + fsopts->offset;
if (lseek(fsopts->fd, offset, SEEK_SET) < 0)
err(1, "%s: seek error for sector %lld", __func__,
- (long long)bno );
+ (long long)bno);
n = write(fsopts->fd, bf, size);
if (n == -1)
err(1, "%s: write error for sector %lld", __func__,
diff --git a/usr.sbin/makefs/makefs.8 b/usr.sbin/makefs/makefs.8
index 5ad56ab35d84..863ee5e670f7 100644
--- a/usr.sbin/makefs/makefs.8
+++ b/usr.sbin/makefs/makefs.8
@@ -35,7 +35,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 17, 2017
+.Dd May 26, 2017
.Dt MAKEFS 8
.Os
.Sh NAME
@@ -52,6 +52,7 @@
.Op Fl M Ar minimum-size
.Op Fl m Ar maximum-size
.Op Fl N Ar userdb-dir
+.Op Fl O Ar offset
.Op Fl o Ar fs-options
.Op Fl R Ar roundup-size
.Op Fl S Ar sector-size
@@ -193,6 +194,11 @@ rather than using the results from the system's
and
.Xr getgrnam 3
(and related) library calls.
+.It Fl O Ar offset
+Instead of creating the filesystem at the beginning of the file, start
+at offset.
+Valid only for
+.Sy ffs .
.It Fl o Ar fs-options
Set file system specific options.
.Ar fs-options
diff --git a/usr.sbin/makefs/makefs.c b/usr.sbin/makefs/makefs.c
index 5e8268e04411..26ab67b08920 100644
--- a/usr.sbin/makefs/makefs.c
+++ b/usr.sbin/makefs/makefs.c
@@ -124,7 +124,7 @@ main(int argc, char *argv[])
err(1, "Unable to get system time");
- while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:o:pR:s:S:t:T:xZ")) != -1) {
+ while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:O:o:pR:s:S:t:T:xZ")) != -1) {
switch (ch) {
case 'B':
@@ -202,7 +202,12 @@ main(int argc, char *argv[])
fsoptions.maxsize =
strsuftoll("maximum size", optarg, 1LL, LLONG_MAX);
break;
-
+
+ case 'O':
+ fsoptions.offset =
+ strsuftoll("offset", optarg, 0LL, LLONG_MAX);
+ break;
+
case 'o':
{
char *p;
@@ -479,8 +484,8 @@ usage(fstype_t *fstype, fsinfo_t *fsoptions)
fprintf(stderr,
"Usage: %s [-xZ] [-B endian] [-b free-blocks] [-d debug-mask]\n"
"\t[-F mtree-specfile] [-f free-files] [-M minimum-size] [-m maximum-size]\n"
-"\t[-N userdb-dir] [-o fs-options] [-R roundup-size] [-S sector-size]\n"
-"\t[-s image-size] [-T <timestamp/file>] [-t fs-type]\n"
+"\t[-N userdb-dir] [-O offset] [-o fs-options] [-R roundup-size]\n"
+"\t[-S sector-size] [-s image-size] [-T <timestamp/file>] [-t fs-type]\n"
"\timage-file directory | manifest [extra-directory ...]\n",
prog);
diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h
index 1d4f9897d1fd..ebfd736a54c7 100644
--- a/usr.sbin/makefs/makefs.h
+++ b/usr.sbin/makefs/makefs.h
@@ -151,6 +151,7 @@ typedef struct makefs_fsinfo {
off_t maxsize; /* maximum size image can be */
off_t freefiles; /* free file entries to leave */
off_t freeblocks; /* free blocks to leave */
+ off_t offset; /* offset from start of file */
off_t roundup; /* round image size up to this value */
int freefilepc; /* free file % */
int freeblockpc; /* free block % */