summaryrefslogtreecommitdiff
path: root/usr.sbin/makefs
diff options
context:
space:
mode:
authorsimonb <simonb@NetBSD.org>2021-04-03 14:10:56 +0000
committersimonb <simonb@NetBSD.org>2021-04-03 14:10:56 +0000
commit5bebfbb81022bc920b79ef670852e83ee415f84d (patch)
treede9a0e2ebb6d558b4c315a39b31313c2cc61af1e /usr.sbin/makefs
parent7307bbc58d562c02c09af9dbbcf61f632d1cb832 (diff)
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.
Diffstat (limited to 'usr.sbin/makefs')
-rw-r--r--usr.sbin/makefs/makefs.88
-rw-r--r--usr.sbin/makefs/makefs.c16
-rw-r--r--usr.sbin/makefs/makefs.h6
-rw-r--r--usr.sbin/makefs/walk.c19
4 files changed, 32 insertions, 17 deletions
diff --git a/usr.sbin/makefs/makefs.8 b/usr.sbin/makefs/makefs.8
index a9ffbff1a75..77dc46f7c0a 100644
--- a/usr.sbin/makefs/makefs.8
+++ b/usr.sbin/makefs/makefs.8
@@ -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 .
diff --git a/usr.sbin/makefs/makefs.c b/usr.sbin/makefs/makefs.c
index 508b68e2a99..1c303e0c2f6 100644
--- a/usr.sbin/makefs/makefs.c
+++ b/usr.sbin/makefs/makefs.c
@@ -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");
}
diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h
index 2929fcb502c..5e199836db1 100644
--- a/usr.sbin/makefs/makefs.h
+++ b/usr.sbin/makefs/makefs.h
@@ -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 *);
diff --git a/usr.sbin/makefs/walk.c b/usr.sbin/makefs/walk.c
index 77a75cf4a50..bf8ecbd4dfd 100644
--- a/usr.sbin/makefs/walk.c
+++ b/usr.sbin/makefs/walk.c
@@ -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 *dir, fsnode *parent, fsnode *join,
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 *dir, fsnode *parent, fsnode *join,
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 *dir, fsnode *parent, fsnode *join,
cur->first = first;
if (S_ISDIR(cur->type)) {
cur->child = walk_dir(root, rp, cur, NULL,
- replace);
+ replace, follow);
continue;
}
}