version 1.24.8.3, 2014/05/22 11:43:05 |
version 1.25, 2012/01/28 02:35:46 |
Line 45 __RCSID("$NetBSD$"); |
|
Line 45 __RCSID("$NetBSD$"); |
|
#endif /* !__lint */ |
#endif /* !__lint */ |
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/stat.h> |
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <errno.h> |
#include <errno.h> |
Line 55 __RCSID("$NetBSD$"); |
|
Line 54 __RCSID("$NetBSD$"); |
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <util.h> |
#include <sys/stat.h> |
|
|
#include "makefs.h" |
#include "makefs.h" |
#include "mtree.h" |
#include "mtree.h" |
Line 76 static fsinode *link_check(fsinode *); |
|
Line 75 static fsinode *link_check(fsinode *); |
|
* at the start of the list, and without ".." entries. |
* at the start of the list, and without ".." entries. |
*/ |
*/ |
fsnode * |
fsnode * |
walk_dir(const char *root, const char *dir, fsnode *parent, fsnode *join, |
walk_dir(const char *root, const char *dir, fsnode *parent, fsnode *join) |
int replace) |
|
{ |
{ |
fsnode *first, *cur, *prev, *last; |
fsnode *first, *cur, *prev, *last; |
DIR *dirp; |
DIR *dirp; |
Line 155 walk_dir(const char *root, const char *d |
|
Line 153 walk_dir(const char *root, const char *d |
|
printf("merging %s with %p\n", |
printf("merging %s with %p\n", |
path, cur->child); |
path, cur->child); |
cur->child = walk_dir(root, rp, cur, |
cur->child = walk_dir(root, rp, cur, |
cur->child, replace); |
cur->child); |
continue; |
continue; |
} |
} |
if (!replace) |
errx(1, "Can't merge %s `%s' with existing %s", |
errx(1, "Can't merge %s `%s' with " |
inode_type(stbuf.st_mode), path, |
"existing %s", |
inode_type(cur->type)); |
inode_type(stbuf.st_mode), path, |
|
inode_type(cur->type)); |
|
else { |
|
if (debug & DEBUG_WALK_DIR_NODE) |
|
printf("replacing %s %s\n", |
|
inode_type(stbuf.st_mode), |
|
path); |
|
if (cur == join->next) |
|
join->next = cur->next; |
|
else { |
|
fsnode *p; |
|
for (p = join->next; |
|
p->next != cur; p = p->next) |
|
continue; |
|
p->next = cur->next; |
|
} |
|
free(cur); |
|
} |
|
} |
} |
} |
} |
|
|
Line 199 walk_dir(const char *root, const char *d |
|
Line 179 walk_dir(const char *root, const char *d |
|
first = cur; |
first = cur; |
cur->first = first; |
cur->first = first; |
if (S_ISDIR(cur->type)) { |
if (S_ISDIR(cur->type)) { |
cur->child = walk_dir(root, rp, cur, NULL, |
cur->child = walk_dir(root, rp, cur, NULL); |
replace); |
|
continue; |
continue; |
} |
} |
} |
} |
Line 226 walk_dir(const char *root, const char *d |
|
Line 205 walk_dir(const char *root, const char *d |
|
if (llen == -1) |
if (llen == -1) |
err(1, "Readlink `%s'", path); |
err(1, "Readlink `%s'", path); |
slink[llen] = '\0'; |
slink[llen] = '\0'; |
cur->symlink = estrdup(slink); |
if ((cur->symlink = strdup(slink)) == NULL) |
|
err(1, "Memory allocation error"); |
} |
} |
} |
} |
assert(first != NULL); |
assert(first != NULL); |
Line 244 create_fsnode(const char *root, const ch |
|
Line 224 create_fsnode(const char *root, const ch |
|
{ |
{ |
fsnode *cur; |
fsnode *cur; |
|
|
cur = ecalloc(1, sizeof(*cur)); |
if ((cur = calloc(1, sizeof(fsnode))) == NULL || |
cur->path = estrdup(path); |
(cur->path = strdup(path)) == NULL || |
cur->name = estrdup(name); |
(cur->name = strdup(name)) == NULL || |
cur->inode = ecalloc(1, sizeof(*cur->inode)); |
(cur->inode = calloc(1, sizeof(fsinode))) == NULL) |
|
err(1, "Memory allocation error"); |
cur->root = root; |
cur->root = root; |
cur->type = stbuf->st_mode & S_IFMT; |
cur->type = stbuf->st_mode & S_IFMT; |
cur->inode->nlink = 1; |
cur->inode->nlink = 1; |
Line 406 apply_specdir(const char *dir, NODE *spe |
|
Line 387 apply_specdir(const char *dir, NODE *spe |
|
if (strcmp(curnode->name, curfsnode->name) == 0) |
if (strcmp(curnode->name, curfsnode->name) == 0) |
break; |
break; |
} |
} |
if ((size_t)snprintf(path, sizeof(path), "%s/%s", |
if (snprintf(path, sizeof(path), "%s/%s", |
dir, curnode->name) >= sizeof(path)) |
dir, curnode->name) >= sizeof(path)) |
errx(1, "Pathname too long."); |
errx(1, "Pathname too long."); |
if (curfsnode == NULL) { /* need new entry */ |
if (curfsnode == NULL) { /* need new entry */ |
Line 465 apply_specdir(const char *dir, NODE *spe |
|
Line 446 apply_specdir(const char *dir, NODE *spe |
|
if (curfsnode->type == S_IFLNK) { |
if (curfsnode->type == S_IFLNK) { |
assert(curnode->slink != NULL); |
assert(curnode->slink != NULL); |
/* for symlinks, copy the target */ |
/* for symlinks, copy the target */ |
curfsnode->symlink = estrdup(curnode->slink); |
if ((curfsnode->symlink = |
|
strdup(curnode->slink)) == NULL) |
|
err(1, "Memory allocation error"); |
} |
} |
} |
} |
apply_specentry(dir, curnode, curfsnode); |
apply_specentry(dir, curnode, curfsnode); |
Line 521 apply_specentry(const char *dir, NODE *s |
|
Line 504 apply_specentry(const char *dir, NODE *s |
|
assert(specnode->slink != NULL); |
assert(specnode->slink != NULL); |
ASEPRINT("symlink", "%s", dirnode->symlink, specnode->slink); |
ASEPRINT("symlink", "%s", dirnode->symlink, specnode->slink); |
free(dirnode->symlink); |
free(dirnode->symlink); |
dirnode->symlink = estrdup(specnode->slink); |
if ((dirnode->symlink = strdup(specnode->slink)) == NULL) |
|
err(1, "Memory allocation error"); |
} |
} |
if (specnode->flags & F_TIME) { |
if (specnode->flags & F_TIME) { |
ASEPRINT("time", "%ld", |
ASEPRINT("time", "%ld", |
Line 656 link_check(fsinode *entry) |
|
Line 640 link_check(fsinode *entry) |
|
htused = 0; |
htused = 0; |
|
|
ohtable = htable; |
ohtable = htable; |
htable = ecalloc(htmask+1, sizeof(*htable)); |
htable = calloc(htmask+1, sizeof(*htable)); |
|
if (!htable) |
|
err(1, "Memory allocation error"); |
|
|
/* populate newly allocated hashtable */ |
/* populate newly allocated hashtable */ |
if (ohtable) { |
if (ohtable) { |
int i; |
int i; |