Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/makefs Add a -L option to follow all symbolic links...
details: https://anonhg.NetBSD.org/src/rev/606bc97e28d2
branches: trunk
changeset: 960939:606bc97e28d2
user: simonb <simonb%NetBSD.org@localhost>
date: Sat Apr 03 14:10:56 2021 +0000
description:
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:
usr.sbin/makefs/makefs.8 | 8 +++++---
usr.sbin/makefs/makefs.c | 16 +++++++++++-----
usr.sbin/makefs/makefs.h | 6 ++++--
usr.sbin/makefs/walk.c | 19 ++++++++++++-------
4 files changed, 32 insertions(+), 17 deletions(-)
diffs (182 lines):
diff -r d1830357732b -r 606bc97e28d2 usr.sbin/makefs/makefs.8
--- a/usr.sbin/makefs/makefs.8 Sat Apr 03 13:37:18 2021 +0000
+++ b/usr.sbin/makefs/makefs.8 Sat Apr 03 14:10:56 2021 +0000
@@ -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 @@
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 -r d1830357732b -r 606bc97e28d2 usr.sbin/makefs/makefs.c
--- a/usr.sbin/makefs/makefs.c Sat Apr 03 13:37:18 2021 +0000
+++ b/usr.sbin/makefs/makefs.c Sat Apr 03 14:10:56 2021 +0000
@@ -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 @@
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 @@
specfile = optarg;
break;
+ case 'L':
+ fsoptions.follow = true;
+ break;
+
case 'M':
fsoptions.minsize =
strsuftoll("minimum size", optarg, 1LL, LLONG_MAX);
@@ -286,7 +290,8 @@
/* 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 @@
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 -r d1830357732b -r 606bc97e28d2 usr.sbin/makefs/makefs.h
--- a/usr.sbin/makefs/makefs.h Sat Apr 03 13:37:18 2021 +0000
+++ b/usr.sbin/makefs/makefs.h Sat Apr 03 14:10:56 2021 +0000
@@ -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 @@
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 @@
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 -r d1830357732b -r 606bc97e28d2 usr.sbin/makefs/walk.c
--- a/usr.sbin/makefs/walk.c Sat Apr 03 13:37:18 2021 +0000
+++ b/usr.sbin/makefs/walk.c Sat Apr 03 14:10:56 2021 +0000
@@ -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 @@
*/
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 @@
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 @@
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 @@
cur->first = first;
if (S_ISDIR(cur->type)) {
cur->child = walk_dir(root, rp, cur, NULL,
- replace);
+ replace, follow);
continue;
}
}
Home |
Main Index |
Thread Index |
Old Index