[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree
zrouter-src-freebsd at zrouter.org
zrouter-src-freebsd at zrouter.org
Wed Feb 1 10:56:55 UTC 2012
details: http://zrouter.org/hg/FreeBSD/head//rev/1feeeb6fe234
changeset: 321:1feeeb6fe234
user: ray at terran.dlink.ua
date: Wed Feb 01 11:54:53 2012 +0200
description:
Update makefs
diffstat:
head/usr.sbin/makefs/cd9660.c | 47 ++--------
head/usr.sbin/makefs/cd9660.h | 6 +-
head/usr.sbin/makefs/cd9660/cd9660_write.c | 4 +-
head/usr.sbin/makefs/ffs.c | 6 +-
head/usr.sbin/makefs/makefs.8 | 14 ++-
head/usr.sbin/makefs/makefs.c | 23 +++-
head/usr.sbin/makefs/makefs.h | 8 +-
head/usr.sbin/makefs/walk.c | 130 +++++++++++++++++++++-------
8 files changed, 149 insertions(+), 89 deletions(-)
diffs (589 lines):
diff -r 7c66001cb7a6 -r 1feeeb6fe234 head/usr.sbin/makefs/cd9660.c
--- a/head/usr.sbin/makefs/cd9660.c Wed Feb 01 11:54:21 2012 +0200
+++ b/head/usr.sbin/makefs/cd9660.c Wed Feb 01 11:54:53 2012 +0200
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.sbin/makefs/cd9660.c 225121 2011-08-23 19:49:06Z mm $");
+__FBSDID("$FreeBSD: head/usr.sbin/makefs/cd9660.c 230795 2012-01-31 00:32:37Z jkim $");
#include <string.h>
#include <ctype.h>
@@ -472,8 +472,6 @@
return;
}
- diskStructure.rootFilesystemPath = dir;
-
if (diskStructure.verbose_level > 0)
printf("cd9660_makefs: image %s directory %s root %p\n",
image, dir, root);
@@ -623,10 +621,6 @@
cd9660_finalize_PVD(void)
{
time_t tim;
- unsigned char *temp;
-
- /* Copy the root directory record */
- temp = (unsigned char *) &diskStructure.primaryDescriptor;
/* root should be a fixed size of 34 bytes since it has no name */
memcpy(diskStructure.primaryDescriptor.root_directory_record,
@@ -1053,7 +1047,7 @@
cd9660_rename_filename(cd9660node *iter, int num, int delete_chars)
{
int i = 0;
- int numbts, dot, semi, digit, digits, temp, powers, multiplier, count;
+ int numbts, digit, digits, temp, powers, count;
char *naming;
int maxlength;
char *tmp;
@@ -1075,7 +1069,6 @@
powers = 1;
count = 0;
digits = 1;
- multiplier = 1;
while (((int)(i / powers) ) >= 10) {
digits++;
powers = powers * 10;
@@ -1090,15 +1083,9 @@
}
*/
- dot = -1;
- semi = -1;
while (count < maxlength) {
- if (*naming == '.')
- dot = count;
- else if (*naming == ';') {
- semi = count;
+ if (*naming == ';')
break;
- }
naming++;
count++;
}
@@ -1529,7 +1516,6 @@
cd9660node *last = dirNode;
int pathTableSize = 0; /* computed as we go */
int counter = 1; /* root gets a count of 0 */
- int parentRecNum = 0; /* root's parent is '0' */
TAILQ_HEAD(cd9660_pt_head, ptq_entry) pt_head;
TAILQ_INIT(&pt_head);
@@ -1559,10 +1545,6 @@
}
last = dirNode;
- parentRecNum = 1;
- if (dirNode->parent != 0)
- parentRecNum = dirNode->parent->ptnumber;
-
/* Push children onto queue */
TAILQ_FOREACH(cn, &dirNode->cn_children, cn_next_child) {
/*
@@ -1584,24 +1566,15 @@
}
void
-cd9660_compute_full_filename(cd9660node *node, char *buf, int level)
+cd9660_compute_full_filename(cd9660node *node, char *buf)
{
- cd9660node *parent;
+ int len;
- parent = (node->rr_real_parent == NULL ?
- node->parent : node->rr_real_parent);
- if (parent != NULL) {
- cd9660_compute_full_filename(parent, buf, level + 1);
- strcat(buf, node->node->name);
- } else {
- /* We are at the root */
- strcat(buf, diskStructure.rootFilesystemPath);
- if (buf[strlen(buf) - 1] == '/')
- buf[strlen(buf) - 1] = '\0';
- }
-
- if (level != 0)
- strcat(buf, "/");
+ len = CD9660MAXPATH + 1;
+ len = snprintf(buf, len, "%s/%s/%s", node->node->root,
+ node->node->path, node->node->name);
+ if (len > CD9660MAXPATH)
+ errx(1, "Pathname too long.");
}
/* NEW filename conversion method */
diff -r 7c66001cb7a6 -r 1feeeb6fe234 head/usr.sbin/makefs/cd9660.h
--- a/head/usr.sbin/makefs/cd9660.h Wed Feb 01 11:54:21 2012 +0200
+++ b/head/usr.sbin/makefs/cd9660.h Wed Feb 01 11:54:53 2012 +0200
@@ -31,7 +31,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
- * $FreeBSD: head/usr.sbin/makefs/cd9660.h 224762 2011-08-10 19:12:21Z marius $
+ * $FreeBSD: head/usr.sbin/makefs/cd9660.h 230795 2012-01-31 00:32:37Z jkim $
*/
#ifndef _MAKEFS_CD9660_H
@@ -244,8 +244,6 @@
cd9660node *rootNode;
- const char *rootFilesystemPath;
-
/* Important sector numbers here */
/* primaryDescriptor.type_l_path_table*/
int64_t primaryBigEndianTableSector;
@@ -345,7 +343,7 @@
int cd9660_write_image(const char *image);
int cd9660_copy_file(FILE *, off_t, const char *);
-void cd9660_compute_full_filename(cd9660node *, char *, int);
+void cd9660_compute_full_filename(cd9660node *, char *);
int cd9660_compute_record_size(cd9660node *);
/* Debugging functions */
diff -r 7c66001cb7a6 -r 1feeeb6fe234 head/usr.sbin/makefs/cd9660/cd9660_write.c
--- a/head/usr.sbin/makefs/cd9660/cd9660_write.c Wed Feb 01 11:54:21 2012 +0200
+++ b/head/usr.sbin/makefs/cd9660/cd9660_write.c Wed Feb 01 11:54:53 2012 +0200
@@ -36,7 +36,7 @@
#include "iso9660_rrip.h"
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.sbin/makefs/cd9660/cd9660_write.c 228990 2011-12-30 10:58:14Z uqs $");
+__FBSDID("$FreeBSD: head/usr.sbin/makefs/cd9660/cd9660_write.c 230795 2012-01-31 00:32:37Z jkim $");
static int cd9660_write_volume_descriptors(FILE *);
static int cd9660_write_path_table(FILE *, off_t, int);
@@ -296,7 +296,7 @@
inode->flags |= FI_WRITTEN;
if (writenode->node->contents == NULL)
cd9660_compute_full_filename(writenode,
- temp_file_name, 0);
+ temp_file_name);
ret = cd9660_copy_file(fd, writenode->fileDataSector,
(writenode->node->contents != NULL) ?
writenode->node->contents : temp_file_name);
diff -r 7c66001cb7a6 -r 1feeeb6fe234 head/usr.sbin/makefs/ffs.c
--- a/head/usr.sbin/makefs/ffs.c Wed Feb 01 11:54:21 2012 +0200
+++ b/head/usr.sbin/makefs/ffs.c Wed Feb 01 11:54:53 2012 +0200
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.sbin/makefs/ffs.c 228990 2011-12-30 10:58:14Z uqs $");
+__FBSDID("$FreeBSD: head/usr.sbin/makefs/ffs.c 230795 2012-01-31 00:32:37Z jkim $");
#include <sys/param.h>
@@ -780,8 +780,8 @@
cur->inode->flags |= FI_WRITTEN;
if (cur->contents == NULL) {
- if (snprintf(path, sizeof(path), "%s/%s", dir,
- cur->name) >= sizeof(path))
+ if (snprintf(path, sizeof(path), "%s/%s/%s", cur->root,
+ cur->path, cur->name) >= (int)sizeof(path))
errx(1, "Pathname too long.");
}
diff -r 7c66001cb7a6 -r 1feeeb6fe234 head/usr.sbin/makefs/makefs.8
--- a/head/usr.sbin/makefs/makefs.8 Wed Feb 01 11:54:21 2012 +0200
+++ b/head/usr.sbin/makefs/makefs.8 Wed Feb 01 11:54:53 2012 +0200
@@ -33,9 +33,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD: head/usr.sbin/makefs/makefs.8 226482 2011-10-17 21:31:03Z eadler $
+.\" $FreeBSD: head/usr.sbin/makefs/makefs.8 230795 2012-01-31 00:32:37Z jkim $
.\"
-.Dd January 10, 2009
+.Dd January 30, 2012
.Dt MAKEFS 8
.Os
.Sh NAME
@@ -58,6 +58,7 @@
.Op Fl t Ar fs-type
.Ar image-file
.Ar directory | manifest
+.Op Ar extra-directory ...
.Sh DESCRIPTION
The utility
.Nm
@@ -67,6 +68,15 @@
.Ar directory
or from the mtree manifest
.Ar manifest .
+If optional directory tree
+.Ar extra-directory
+is passed, then the directory tree of each argument will be merged
+into the
+.Ar directory
+or
+.Ar manifest
+first before creating
+.Ar image-file .
No special devices or privileges are required to perform this task.
.Pp
The options are as follows:
diff -r 7c66001cb7a6 -r 1feeeb6fe234 head/usr.sbin/makefs/makefs.c
--- a/head/usr.sbin/makefs/makefs.c Wed Feb 01 11:54:21 2012 +0200
+++ b/head/usr.sbin/makefs/makefs.c Wed Feb 01 11:54:53 2012 +0200
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.sbin/makefs/makefs.c 223306 2011-06-19 18:34:49Z marcel $");
+__FBSDID("$FreeBSD: head/usr.sbin/makefs/makefs.c 230795 2012-01-31 00:32:37Z jkim $");
#include <sys/types.h>
#include <sys/stat.h>
@@ -87,7 +87,7 @@
fstype_t *fstype;
fsinfo_t fsoptions;
fsnode *root;
- int ch, len;
+ int ch, i, len;
char *subtree;
char *specfile;
@@ -241,7 +241,7 @@
argc -= optind;
argv += optind;
- if (argc != 2)
+ if (argc < 2)
usage();
/* -x must be accompanied by -F */
@@ -260,7 +260,7 @@
case S_IFDIR: /* walk the tree */
subtree = argv[1];
TIMER_START(start);
- root = walk_dir(subtree, NULL);
+ root = walk_dir(subtree, ".", NULL, NULL);
TIMER_RESULTS(start, "walk_dir");
break;
case S_IFREG: /* read the manifest file */
@@ -274,6 +274,17 @@
/* NOTREACHED */
}
+ /* append extra directory */
+ for (i = 2; i < argc; i++) {
+ if (stat(argv[i], &sb) == -1)
+ err(1, "Can't stat `%s'", argv[i]);
+ if (!S_ISDIR(sb.st_mode))
+ errx(1, "%s: not a directory", argv[i]);
+ TIMER_START(start);
+ root = walk_dir(argv[i], ".", NULL, root);
+ TIMER_RESULTS(start, "walk_dir2");
+ }
+
if (specfile) { /* apply a specfile */
TIMER_START(start);
apply_specfile(specfile, subtree, root, fsoptions.onlyspec);
@@ -282,7 +293,7 @@
if (debug & DEBUG_DUMP_FSNODES) {
printf("\nparent: %s\n", subtree);
- dump_fsnodes(".", root);
+ dump_fsnodes(root);
putchar('\n');
}
@@ -336,7 +347,7 @@
"usage: %s [-t fs-type] [-o fs-options] [-d debug-mask] [-B endian]\n"
"\t[-S sector-size] [-M minimum-size] [-m maximum-size] [-s image-size]\n"
"\t[-b free-blocks] [-f free-files] [-F mtree-specfile] [-x]\n"
-"\t[-N userdb-dir] image-file directory | manifest\n",
+"\t[-N userdb-dir] image-file directory | manifest [extra-directory ...]\n",
prog);
exit(1);
}
diff -r 7c66001cb7a6 -r 1feeeb6fe234 head/usr.sbin/makefs/makefs.h
--- a/head/usr.sbin/makefs/makefs.h Wed Feb 01 11:54:21 2012 +0200
+++ b/head/usr.sbin/makefs/makefs.h Wed Feb 01 11:54:53 2012 +0200
@@ -34,7 +34,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: head/usr.sbin/makefs/makefs.h 223306 2011-06-19 18:34:49Z marcel $
+ * $FreeBSD: head/usr.sbin/makefs/makefs.h 230795 2012-01-31 00:32:37Z jkim $
*/
#ifndef _MAKEFS_H
@@ -94,6 +94,8 @@
fsinode *inode; /* actual inode data */
char *symlink; /* symlink target */
char *contents; /* file to provide contents */
+ const char *root; /* root path */
+ char *path; /* directory name */
char *name; /* file name */
int flags; /* misc flags */
} fsnode;
@@ -147,11 +149,11 @@
void apply_specfile(const char *, const char *, fsnode *, int);
-void dump_fsnodes(const char *, fsnode *);
+void dump_fsnodes(fsnode *);
const char * inode_type(mode_t);
fsnode * read_mtree(const char *, fsnode *);
int set_option(option_t *, const char *, const char *);
-fsnode * walk_dir(const char *, fsnode *);
+fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *);
void free_fsnodes(fsnode *);
void ffs_prep_opts(fsinfo_t *);
diff -r 7c66001cb7a6 -r 1feeeb6fe234 head/usr.sbin/makefs/walk.c
--- a/head/usr.sbin/makefs/walk.c Wed Feb 01 11:54:21 2012 +0200
+++ b/head/usr.sbin/makefs/walk.c Wed Feb 01 11:54:53 2012 +0200
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.sbin/makefs/walk.c 228990 2011-12-30 10:58:14Z uqs $");
+__FBSDID("$FreeBSD: head/usr.sbin/makefs/walk.c 230795 2012-01-31 00:32:37Z jkim $");
#include <sys/param.h>
@@ -57,40 +57,70 @@
static void apply_specdir(const char *, NODE *, fsnode *, int);
static void apply_specentry(const char *, NODE *, fsnode *);
-static fsnode *create_fsnode(const char *, struct stat *);
+static fsnode *create_fsnode(const char *, const char *, const char *,
+ struct stat *);
static fsinode *link_check(fsinode *);
/*
* walk_dir --
- * build a tree of fsnodes from `dir', with a parent fsnode of `parent'
- * (which may be NULL for the root of the tree).
+ * build a tree of fsnodes from `root' and `dir', with a parent
+ * fsnode of `parent' (which may be NULL for the root of the tree).
+ * append the tree to a fsnode of `join' if it is not NULL.
* each "level" is a directory, with the "." entry guaranteed to be
* at the start of the list, and without ".." entries.
*/
fsnode *
-walk_dir(const char *dir, fsnode *parent)
+walk_dir(const char *root, const char *dir, fsnode *parent, fsnode *join)
{
- fsnode *first, *cur, *prev;
+ fsnode *first, *cur, *prev, *last;
DIR *dirp;
struct dirent *dent;
char path[MAXPATHLEN + 1];
struct stat stbuf;
+ char *name, *rp;
+ int dot, len;
+ assert(root != NULL);
assert(dir != NULL);
+ len = snprintf(path, sizeof(path), "%s/%s", root, dir);
+ if (len >= (int)sizeof(path))
+ errx(1, "Pathname too long.");
if (debug & DEBUG_WALK_DIR)
- printf("walk_dir: %s %p\n", dir, parent);
- if ((dirp = opendir(dir)) == NULL)
- err(1, "Can't opendir `%s'", dir);
- first = prev = NULL;
+ printf("walk_dir: %s %p\n", path, parent);
+ if ((dirp = opendir(path)) == NULL)
+ err(1, "Can't opendir `%s'", path);
+ rp = path + strlen(root) + 1;
+ if (join != NULL) {
+ first = cur = join;
+ while (cur->next != NULL)
+ cur = cur->next;
+ prev = cur;
+ } else
+ first = prev = NULL;
+ last = prev;
while ((dent = readdir(dirp)) != NULL) {
- if (strcmp(dent->d_name, "..") == 0)
- continue;
+ name = dent->d_name;
+ dot = 0;
+ if (name[0] == '.')
+ switch (name[1]) {
+ case '\0': /* "." */
+ if (join != NULL)
+ continue;
+ dot = 1;
+ break;
+ case '.': /* ".." */
+ if (name[2] == '\0')
+ continue;
+ /* FALLTHROUGH */
+ default:
+ dot = 0;
+ }
if (debug & DEBUG_WALK_DIR_NODE)
- printf("scanning %s/%s\n", dir, dent->d_name);
- if (snprintf(path, sizeof(path), "%s/%s", dir, dent->d_name)
- >= sizeof(path))
+ printf("scanning %s/%s/%s\n", root, dir, name);
+ 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);
@@ -102,22 +132,51 @@
}
#endif
- cur = create_fsnode(dent->d_name, &stbuf);
+ if (join != NULL) {
+ cur = join->next;
+ for (;;) {
+ if (cur == NULL || strcmp(cur->name, name) == 0)
+ break;
+ if (cur == last) {
+ cur = NULL;
+ break;
+ }
+ cur = cur->next;
+ }
+ if (cur != NULL) {
+ if (S_ISDIR(cur->type) &&
+ S_ISDIR(stbuf.st_mode)) {
+ if (debug & DEBUG_WALK_DIR_NODE)
+ printf("merging %s with %p\n",
+ path, cur->child);
+ cur->child = walk_dir(root, rp, cur,
+ cur->child);
+ continue;
+ }
+ errx(1, "Can't merge %s `%s' with existing %s",
+ inode_type(stbuf.st_mode), path,
+ inode_type(cur->type));
+ }
+ }
+
+ cur = create_fsnode(root, dir, name, &stbuf);
cur->parent = parent;
- if (strcmp(dent->d_name, ".") == 0) {
+ if (dot) {
/* ensure "." is at the start of the list */
cur->next = first;
first = cur;
if (! prev)
prev = cur;
+ cur->first = first;
} else { /* not "." */
if (prev)
prev->next = cur;
prev = cur;
if (!first)
first = cur;
+ cur->first = first;
if (S_ISDIR(cur->type)) {
- cur->child = walk_dir(path, cur);
+ cur->child = walk_dir(root, rp, cur, NULL);
continue;
}
}
@@ -147,22 +206,27 @@
err(1, "Memory allocation error");
}
}
- for (cur = first; cur != NULL; cur = cur->next)
- cur->first = first;
+ assert(first != NULL);
+ if (join == NULL)
+ for (cur = first->next; cur != NULL; cur = cur->next)
+ cur->first = first;
if (closedir(dirp) == -1)
- err(1, "Can't closedir `%s'", dir);
+ err(1, "Can't closedir `%s/%s'", root, dir);
return (first);
}
static fsnode *
-create_fsnode(const char *name, struct stat *stbuf)
+create_fsnode(const char *root, const char *path, const char *name,
+ struct stat *stbuf)
{
fsnode *cur;
if ((cur = calloc(1, sizeof(fsnode))) == NULL ||
+ (cur->path = strdup(path)) == NULL ||
(cur->name = strdup(name)) == NULL ||
(cur->inode = calloc(1, sizeof(fsinode))) == NULL)
err(1, "Memory allocation error");
+ cur->root = root;
cur->type = stbuf->st_mode & S_IFMT;
cur->inode->nlink = 1;
cur->inode->st = *stbuf;
@@ -211,6 +275,7 @@
free(cur->inode);
if (cur->symlink)
free(cur->symlink);
+ free(cur->path);
free(cur->name);
free(cur);
}
@@ -388,14 +453,16 @@
stbuf.st_mtimensec = stbuf.st_atimensec =
stbuf.st_ctimensec = start_time.tv_nsec;
#endif
- curfsnode = create_fsnode(curnode->name, &stbuf);
+ curfsnode = create_fsnode(".", ".", curnode->name,
+ &stbuf);
curfsnode->parent = dirnode->parent;
curfsnode->first = dirnode;
curfsnode->next = dirnode->next;
dirnode->next = curfsnode;
if (curfsnode->type == S_IFDIR) {
/* for dirs, make "." entry as well */
- curfsnode->child = create_fsnode(".", &stbuf);
+ curfsnode->child = create_fsnode(".", ".", ".",
+ &stbuf);
curfsnode->child->parent = curfsnode;
curfsnode->child->first = curfsnode->child;
}
@@ -503,19 +570,18 @@
/*
* dump_fsnodes --
- * dump the fsnodes from `cur', based in the directory `dir'
+ * dump the fsnodes from `cur'
*/
void
-dump_fsnodes(const char *dir, fsnode *root)
+dump_fsnodes(fsnode *root)
{
fsnode *cur;
char path[MAXPATHLEN + 1];
- assert (dir != NULL);
- printf("dump_fsnodes: %s %p\n", dir, root);
+ printf("dump_fsnodes: %s %p\n", root->path, root);
for (cur = root; cur != NULL; cur = cur->next) {
- if (snprintf(path, sizeof(path), "%s/%s", dir, cur->name)
- >= sizeof(path))
+ if (snprintf(path, sizeof(path), "%s/%s", cur->path,
+ cur->name) >= (int)sizeof(path))
errx(1, "Pathname too long.");
if (debug & DEBUG_DUMP_FSNODES_VERBOSE)
@@ -534,10 +600,10 @@
if (cur->child) {
assert (cur->type == S_IFDIR);
- dump_fsnodes(path, cur->child);
+ dump_fsnodes(cur->child);
}
}
- printf("dump_fsnodes: finished %s\n", dir);
+ printf("dump_fsnodes: finished %s/%s\n", root->path, root->name);
}
More information about the Zrouter-src-freebsd
mailing list