makefs: add -O (offset) option

NetBSD revs:
ffs.c		1.60
makefs.8	1.44
makefs.c	1.48
makefs.h	1.33
ffs/buf.c	1.20
ffs/mkfs.c	1.27

Obtained from:	NetBSD
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D10780
This commit is contained in:
Ed Maste 2017-05-26 15:49:20 +00:00
parent 32ecf81aff
commit b79f050a88
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=318951
6 changed files with 32 additions and 13 deletions

View File

@ -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) {

View File

@ -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,

View File

@ -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__,

View File

@ -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

View File

@ -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);

View File

@ -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 % */