Author: emaste
Date: Fri May 26 15:49:20 2017
New Revision: 318951
URL: https://svnweb.freebsd.org/changeset/base/318951

Log:
  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

Modified:
  head/usr.sbin/makefs/ffs.c
  head/usr.sbin/makefs/ffs/buf.c
  head/usr.sbin/makefs/ffs/mkfs.c
  head/usr.sbin/makefs/makefs.8
  head/usr.sbin/makefs/makefs.c
  head/usr.sbin/makefs/makefs.h

Modified: head/usr.sbin/makefs/ffs.c
==============================================================================
--- head/usr.sbin/makefs/ffs.c  Fri May 26 15:13:46 2017        (r318950)
+++ head/usr.sbin/makefs/ffs.c  Fri May 26 15:49:20 2017        (r318951)
@@ -476,13 +476,15 @@ ffs_create_image(const char *image, fsin
        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, fsin
                            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) {

Modified: head/usr.sbin/makefs/ffs/buf.c
==============================================================================
--- head/usr.sbin/makefs/ffs/buf.c      Fri May 26 15:13:46 2017        
(r318950)
+++ head/usr.sbin/makefs/ffs/buf.c      Fri May 26 15:49:20 2017        
(r318951)
@@ -68,7 +68,7 @@ bread(struct vnode *vp, daddr_t blkno, i
                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,

Modified: head/usr.sbin/makefs/ffs/mkfs.c
==============================================================================
--- head/usr.sbin/makefs/ffs/mkfs.c     Fri May 26 15:13:46 2017        
(r318950)
+++ head/usr.sbin/makefs/ffs/mkfs.c     Fri May 26 15:49:20 2017        
(r318951)
@@ -774,8 +774,7 @@ ffs_rdfs(daddr_t bno, int size, void *bf
        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
        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__,

Modified: head/usr.sbin/makefs/makefs.8
==============================================================================
--- head/usr.sbin/makefs/makefs.8       Fri May 26 15:13:46 2017        
(r318950)
+++ head/usr.sbin/makefs/makefs.8       Fri May 26 15:49:20 2017        
(r318951)
@@ -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 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

Modified: head/usr.sbin/makefs/makefs.c
==============================================================================
--- head/usr.sbin/makefs/makefs.c       Fri May 26 15:13:46 2017        
(r318950)
+++ head/usr.sbin/makefs/makefs.c       Fri May 26 15:49:20 2017        
(r318951)
@@ -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 *fsopti
        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);
 

Modified: head/usr.sbin/makefs/makefs.h
==============================================================================
--- head/usr.sbin/makefs/makefs.h       Fri May 26 15:13:46 2017        
(r318950)
+++ head/usr.sbin/makefs/makefs.h       Fri May 26 15:49:20 2017        
(r318951)
@@ -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 % */
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to