summaryrefslogtreecommitdiffstats
path: root/usr.sbin/makefs
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2013-04-12 20:48:55 +0000
committersjg <sjg@FreeBSD.org>2013-04-12 20:48:55 +0000
commit97d8b9495668afa398ab17c8c5f7e223b5fd2e89 (patch)
tree54038c9ac32a45f8741dcc23fb9a8ffc0e15ff89 /usr.sbin/makefs
parent5ee3bfdb338e7c80af29a67f4425c4be24c7b866 (diff)
parent086d73aef6d0ab7d21daa2076fdc8d25961f9b05 (diff)
downloadFreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.zip
FreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.tar.gz
sync from head
Diffstat (limited to 'usr.sbin/makefs')
-rw-r--r--usr.sbin/makefs/makefs.86
-rw-r--r--usr.sbin/makefs/makefs.c7
-rw-r--r--usr.sbin/makefs/makefs.h3
-rw-r--r--usr.sbin/makefs/mtree.c58
-rw-r--r--usr.sbin/makefs/walk.c3
5 files changed, 54 insertions, 23 deletions
diff --git a/usr.sbin/makefs/makefs.8 b/usr.sbin/makefs/makefs.8
index b1a5751..4d81e45 100644
--- a/usr.sbin/makefs/makefs.8
+++ b/usr.sbin/makefs/makefs.8
@@ -43,7 +43,7 @@
.Nd create a file system image from a directory tree or a mtree manifest
.Sh SYNOPSIS
.Nm
-.Op Fl px
+.Op Fl Dpx
.Op Fl B Ar byte-order
.Op Fl b Ar free-blocks
.Op Fl d Ar debug-mask
@@ -106,6 +106,8 @@ An optional
suffix may be provided to indicate that
.Ar free-blocks
indicates a percentage of the calculated image size.
+.It Fl D
+Treat duplicate paths in an mtree manifest as warnings not error.
.It Fl d Ar debug-mask
Enable various levels of debugging, depending upon which bits are
set in
@@ -323,7 +325,7 @@ Load a generic boot image into the first 32K of the cd9660 image.
.It Sy hard-disk-boot
Boot image is a hard disk image.
.It Sy keep-bad-images
-Don't throw away images whose write was aborted due to an error.
+Do not throw away images whose write was aborted due to an error.
For debugging purposes.
.It Sy label
Label name of the image.
diff --git a/usr.sbin/makefs/makefs.c b/usr.sbin/makefs/makefs.c
index b2da82b..03ff1ac 100644
--- a/usr.sbin/makefs/makefs.c
+++ b/usr.sbin/makefs/makefs.c
@@ -73,6 +73,7 @@ static fstype_t fstypes[] = {
};
u_int debug;
+int dupsok;
struct timespec start_time;
static fstype_t *get_fstype(const char *);
@@ -112,7 +113,7 @@ main(int argc, char *argv[])
start_time.tv_sec = start.tv_sec;
start_time.tv_nsec = start.tv_usec * 1000;
- while ((ch = getopt(argc, argv, "B:b:d:f:F:M:m:N:o:ps:S:t:x")) != -1) {
+ while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:o:ps:S:t:x")) != -1) {
switch (ch) {
case 'B':
@@ -148,6 +149,10 @@ main(int argc, char *argv[])
}
break;
+ case 'D':
+ dupsok = 1;
+ break;
+
case 'd':
debug = strtoll(optarg, NULL, 0);
break;
diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h
index 483ccff..c6707d9 100644
--- a/usr.sbin/makefs/makefs.h
+++ b/usr.sbin/makefs/makefs.h
@@ -169,6 +169,7 @@ void cd9660_makefs(const char *, const char *, fsnode *, fsinfo_t *);
extern u_int debug;
+extern int dupsok;
extern struct timespec start_time;
/*
@@ -279,6 +280,8 @@ extern struct timespec start_time;
struct fs;
void ffs_fragacct_swap(struct fs *, int, int32_t [], int, int);
+fsinode *link_check(fsinode *);
+
/*
* Declarations for compat routines.
*/
diff --git a/usr.sbin/makefs/mtree.c b/usr.sbin/makefs/mtree.c
index 836e766..c90c974 100644
--- a/usr.sbin/makefs/mtree.c
+++ b/usr.sbin/makefs/mtree.c
@@ -508,8 +508,8 @@ read_mtree_keywords(FILE *fp, fsnode *node)
{
char keyword[PATH_MAX];
char *name, *p, *value;
- struct group *grent;
- struct passwd *pwent;
+ gid_t gid;
+ uid_t uid;
struct stat *st, sb;
intmax_t num;
u_long flset, flclr;
@@ -585,11 +585,10 @@ read_mtree_keywords(FILE *fp, fsnode *node)
error = ENOATTR;
break;
}
- grent = getgrnam(value);
- if (grent != NULL)
- st->st_gid = grent->gr_gid;
+ if (gid_from_group(value, &gid) == 0)
+ st->st_gid = gid;
else
- error = errno;
+ error = EINVAL;
} else
error = ENOSYS;
break;
@@ -698,11 +697,10 @@ read_mtree_keywords(FILE *fp, fsnode *node)
error = ENOATTR;
break;
}
- pwent = getpwnam(value);
- if (pwent != NULL)
- st->st_uid = pwent->pw_uid;
+ if (uid_from_user(value, &uid) == 0)
+ st->st_uid = uid;
else
- error = errno;
+ error = EINVAL;
} else
error = ENOSYS;
break;
@@ -781,6 +779,24 @@ read_mtree_keywords(FILE *fp, fsnode *node)
return (0);
}
+ /*
+ * Check for hardlinks. If the contents key is used, then the check
+ * will only trigger if the contents file is a link even if it is used
+ * by more than one file
+ */
+ if (sb.st_nlink > 1) {
+ fsinode *curino;
+
+ st->st_ino = sb.st_ino;
+ st->st_dev = sb.st_dev;
+ curino = link_check(node->inode);
+ if (curino != NULL) {
+ free(node->inode);
+ node->inode = curino;
+ node->inode->nlink++;
+ }
+ }
+
free(node->contents);
node->contents = name;
st->st_size = sb.st_size;
@@ -881,8 +897,14 @@ read_mtree_spec1(FILE *fp, bool def, const char *name)
if (strcmp(name, node->name) == 0) {
if (def == true) {
- mtree_error("duplicate definition of %s",
- name);
+ if (!dupsok)
+ mtree_error(
+ "duplicate definition of %s",
+ name);
+ else
+ mtree_warning(
+ "duplicate definition of %s",
+ name);
return (0);
}
@@ -970,15 +992,15 @@ read_mtree_spec(FILE *fp)
do {
*cp++ = '\0';
- /* Disallow '.' and '..' as components. */
- if (IS_DOT(pathspec) || IS_DOTDOT(pathspec)) {
- mtree_error("absolute path cannot contain . "
- "or .. components");
+ /* Disallow '..' as a component. */
+ if (IS_DOTDOT(pathspec)) {
+ mtree_error("absolute path cannot contain "
+ ".. component");
goto out;
}
- /* Ignore multiple adjacent slashes. */
- if (pathspec[0] != '\0')
+ /* Ignore multiple adjacent slashes and '.'. */
+ if (pathspec[0] != '\0' && !IS_DOT(pathspec))
error = read_mtree_spec1(fp, false, pathspec);
memmove(pathspec, cp, strlen(cp) + 1);
cp = strchr(pathspec, '/');
diff --git a/usr.sbin/makefs/walk.c b/usr.sbin/makefs/walk.c
index 0664c84..7af92bb 100644
--- a/usr.sbin/makefs/walk.c
+++ b/usr.sbin/makefs/walk.c
@@ -59,7 +59,6 @@ static void apply_specdir(const char *, NODE *, fsnode *, int);
static void apply_specentry(const char *, NODE *, fsnode *);
static fsnode *create_fsnode(const char *, const char *, const char *,
struct stat *);
-static fsinode *link_check(fsinode *);
/*
@@ -644,7 +643,7 @@ inode_type(mode_t mode)
/* This was borrowed from du.c and tweaked to keep an fsnode
* pointer instead. -- dbj@netbsd.org
*/
-static fsinode *
+fsinode *
link_check(fsinode *entry)
{
static struct entry {
OpenPOWER on IntegriCloud