From owner-svn-src-head@FreeBSD.ORG Sat Nov 3 00:10:31 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6FFB3111; Sat, 3 Nov 2012 00:10:31 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 570438FC08; Sat, 3 Nov 2012 00:10:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id qA30AVxg032229; Sat, 3 Nov 2012 00:10:31 GMT (envelope-from sjg@svn.freebsd.org) Received: (from sjg@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id qA30AUSE032225; Sat, 3 Nov 2012 00:10:30 GMT (envelope-from sjg@svn.freebsd.org) Message-Id: <201211030010.qA30AUSE032225@svn.freebsd.org> From: "Simon J. Gerraty" Date: Sat, 3 Nov 2012 00:10:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r242501 - head/usr.sbin/makefs X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Nov 2012 00:10:31 -0000 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;