Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Nov 2012 00:10:30 +0000 (UTC)
From:      "Simon J. Gerraty" <sjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r242501 - head/usr.sbin/makefs
Message-ID:  <201211030010.qA30AUSE032225@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sjg
Date: Sat Nov  3 00:10:30 2012
New Revision: 242501
URL: http://svn.freebsd.org/changeset/base/242501

Log:
  If no contents keyword is specified, the default for files is
  the named file.
  
  Approved by:	marcel (mentor)

Modified:
  head/usr.sbin/makefs/mtree.c

Modified: head/usr.sbin/makefs/mtree.c
==============================================================================
--- head/usr.sbin/makefs/mtree.c	Fri Nov  2 23:25:52 2012	(r242500)
+++ head/usr.sbin/makefs/mtree.c	Sat Nov  3 00:10:30 2012	(r242501)
@@ -135,6 +135,47 @@ mtree_warning(const char *fmt, ...)
 	fputc('\n', stderr);
 }
 
+#ifndef MAKEFS_MAX_TREE_DEPTH
+# define MAKEFS_MAX_TREE_DEPTH (MAXPATHLEN/2)
+#endif
+
+/* construct path to node->name */
+static char *
+mtree_file_path(fsnode *node)
+{
+	fsnode *pnode;
+	struct sbuf *sb;
+	char *res, *rp[MAKEFS_MAX_TREE_DEPTH];
+	int depth;
+
+	depth = 0;
+	rp[depth] = node->name;
+	for (pnode = node->parent; pnode && depth < MAKEFS_MAX_TREE_DEPTH;
+	     pnode = pnode->parent) {
+		if (strcmp(pnode->name, ".") == 0)
+			break;
+		rp[++depth] = pnode->name;
+	}
+	
+	sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+	if (sb == NULL) {
+		errno = ENOMEM;
+		return (NULL);
+	}
+	while (depth > 0) {
+		sbuf_cat(sb, rp[depth--]);
+		sbuf_putc(sb, '/');
+	}
+	sbuf_cat(sb, rp[depth]);
+	sbuf_finish(sb);
+	res = strdup(sbuf_data(sb));
+	sbuf_delete(sb);
+	if (res == NULL)
+		errno = ENOMEM;
+	return res;
+
+}
+
 /* mtree_resolve() sets errno to indicate why NULL was returned. */
 static char *
 mtree_resolve(const char *spec, int *istemp)
@@ -706,6 +747,12 @@ read_mtree_keywords(FILE *fp, fsnode *no
 			return (0);
 		}
 		type = S_IFREG;
+	} else if (node->type != 0) {
+		type = node->type;
+		if (type == S_IFREG) {
+			/* the named path is the default contents */
+			node->contents = mtree_file_path(node);
+		}
 	} else
 		type = (node->symlink != NULL) ? S_IFLNK : S_IFDIR;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211030010.qA30AUSE032225>