Module Name: src Committed By: simonb Date: Sat Apr 3 14:10:56 UTC 2021
Modified Files: src/usr.sbin/makefs: makefs.8 makefs.c makefs.h walk.c Log Message: Add a -L option to follow all symbolic links. Useful if you have symlinks in a makefs directory tree but want to refer to the actual file. To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.67 src/usr.sbin/makefs/makefs.8 cvs rdiff -u -r1.53 -r1.54 src/usr.sbin/makefs/makefs.c cvs rdiff -u -r1.36 -r1.37 src/usr.sbin/makefs/makefs.h cvs rdiff -u -r1.29 -r1.30 src/usr.sbin/makefs/walk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/makefs/makefs.8 diff -u src/usr.sbin/makefs/makefs.8:1.66 src/usr.sbin/makefs/makefs.8:1.67 --- src/usr.sbin/makefs/makefs.8:1.66 Sun Nov 15 00:18:48 2020 +++ src/usr.sbin/makefs/makefs.8 Sat Apr 3 14:10:56 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: makefs.8,v 1.66 2020/11/15 00:18:48 jmcneill Exp $ +.\" $NetBSD: makefs.8,v 1.67 2021/04/03 14:10:56 simonb Exp $ .\" .\" Copyright (c) 2001-2003 Wasabi Systems, Inc. .\" All rights reserved. @@ -33,7 +33,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd November 14, 2020 +.Dd April 4, 2021 .Dt MAKEFS 8 .Os .Sh NAME @@ -41,7 +41,7 @@ .Nd create a file system image from a directory tree .Sh SYNOPSIS .Nm -.Op Fl rxZ +.Op Fl LrxZ .Op Fl B Ar endian .Op Fl b Ar free-blocks .Op Fl d Ar debug-mask @@ -158,6 +158,8 @@ An optional suffix may be provided to indicate that .Ar free-files indicates a percentage of the calculated image size. +.It Fl L +All symbolic links are followed. .It Fl M Ar minimum-size Set the minimum size of the file system image to .Ar minimum-size . Index: src/usr.sbin/makefs/makefs.c diff -u src/usr.sbin/makefs/makefs.c:1.53 src/usr.sbin/makefs/makefs.c:1.54 --- src/usr.sbin/makefs/makefs.c:1.53 Fri Nov 27 15:10:32 2015 +++ src/usr.sbin/makefs/makefs.c Sat Apr 3 14:10:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: makefs.c,v 1.53 2015/11/27 15:10:32 joerg Exp $ */ +/* $NetBSD: makefs.c,v 1.54 2021/04/03 14:10:56 simonb Exp $ */ /* * Copyright (c) 2001-2003 Wasabi Systems, Inc. @@ -41,7 +41,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: makefs.c,v 1.53 2015/11/27 15:10:32 joerg Exp $"); +__RCSID("$NetBSD: makefs.c,v 1.54 2021/04/03 14:10:56 simonb Exp $"); #endif /* !__lint */ #include <assert.h> @@ -129,7 +129,7 @@ main(int argc, char *argv[]) err(1, "Unable to get system time"); - while ((ch = getopt(argc, argv, "B:b:d:f:F:M:m:N:O:o:rs:S:t:T:xZ")) != -1) { + while ((ch = getopt(argc, argv, "B:b:d:f:F:LM:m:N:O:o:rs:S:t:T:xZ")) != -1) { switch (ch) { case 'B': @@ -187,6 +187,10 @@ main(int argc, char *argv[]) specfile = optarg; break; + case 'L': + fsoptions.follow = true; + break; + case 'M': fsoptions.minsize = strsuftoll("minimum size", optarg, 1LL, LLONG_MAX); @@ -286,7 +290,8 @@ main(int argc, char *argv[]) /* walk the tree */ TIMER_START(start); - root = walk_dir(argv[1], ".", NULL, NULL, fsoptions.replace); + root = walk_dir(argv[1], ".", NULL, NULL, fsoptions.replace, + fsoptions.follow); TIMER_RESULTS(start, "walk_dir"); /* append extra directory */ @@ -297,7 +302,8 @@ main(int argc, char *argv[]) if (!S_ISDIR(sb.st_mode)) errx(1, "%s: not a directory", argv[i]); TIMER_START(start); - root = walk_dir(argv[i], ".", NULL, root, fsoptions.replace); + root = walk_dir(argv[i], ".", NULL, root, fsoptions.replace, + fsoptions.follow); TIMER_RESULTS(start, "walk_dir2"); } Index: src/usr.sbin/makefs/makefs.h diff -u src/usr.sbin/makefs/makefs.h:1.36 src/usr.sbin/makefs/makefs.h:1.37 --- src/usr.sbin/makefs/makefs.h:1.36 Wed Nov 25 00:48:49 2015 +++ src/usr.sbin/makefs/makefs.h Sat Apr 3 14:10:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: makefs.h,v 1.36 2015/11/25 00:48:49 christos Exp $ */ +/* $NetBSD: makefs.h,v 1.37 2021/04/03 14:10:56 simonb Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -166,6 +166,7 @@ typedef struct makefs_fsinfo { int sectorsize; /* sector size */ int sparse; /* sparse image, don't fill it with zeros */ int replace; /* replace files when merging */ + int follow; /* follow symlinks */ void *fs_specific; /* File system specific additions. */ option_t *fs_options; /* File system specific options */ @@ -180,7 +181,8 @@ const char * inode_type(mode_t); int set_option(const option_t *, const char *, char *, size_t); int set_option_var(const option_t *, const char *, const char *, char *, size_t); -fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *, int); +fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *, int, + int); void free_fsnodes(fsnode *); option_t * copy_opts(const option_t *); Index: src/usr.sbin/makefs/walk.c diff -u src/usr.sbin/makefs/walk.c:1.29 src/usr.sbin/makefs/walk.c:1.30 --- src/usr.sbin/makefs/walk.c:1.29 Wed Nov 25 00:48:49 2015 +++ src/usr.sbin/makefs/walk.c Sat Apr 3 14:10:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: walk.c,v 1.29 2015/11/25 00:48:49 christos Exp $ */ +/* $NetBSD: walk.c,v 1.30 2021/04/03 14:10:56 simonb Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -41,7 +41,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: walk.c,v 1.29 2015/11/25 00:48:49 christos Exp $"); +__RCSID("$NetBSD: walk.c,v 1.30 2021/04/03 14:10:56 simonb Exp $"); #endif /* !__lint */ #include <sys/param.h> @@ -77,7 +77,7 @@ static fsinode *link_check(fsinode *); */ fsnode * walk_dir(const char *root, const char *dir, fsnode *parent, fsnode *join, - int replace) + int replace, int follow) { fsnode *first, *cur, *prev, *last; DIR *dirp; @@ -127,8 +127,13 @@ walk_dir(const char *root, const char *d if (snprintf(path + len, sizeof(path) - len, "/%s", name) >= (int)sizeof(path) - len) errx(1, "Pathname too long."); - if (lstat(path, &stbuf) == -1) - err(1, "Can't lstat `%s'", path); + if (follow) { + if (stat(path, &stbuf) == -1) + err(1, "Can't stat `%s'", path); + } else { + if (lstat(path, &stbuf) == -1) + err(1, "Can't lstat `%s'", path); + } #ifdef S_ISSOCK if (S_ISSOCK(stbuf.st_mode & S_IFMT)) { if (debug & DEBUG_WALK_DIR_NODE) @@ -155,7 +160,7 @@ walk_dir(const char *root, const char *d printf("merging %s with %p\n", path, cur->child); cur->child = walk_dir(root, rp, cur, - cur->child, replace); + cur->child, replace, follow); continue; } if (!replace) @@ -200,7 +205,7 @@ walk_dir(const char *root, const char *d cur->first = first; if (S_ISDIR(cur->type)) { cur->child = walk_dir(root, rp, cur, NULL, - replace); + replace, follow); continue; } }