From 1f0ed3c00ee1011cd97a7eddb3f8d723100636dd Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Wed, 20 Feb 2013 19:32:31 +0000 Subject: [PATCH] Support hardlinks in manifest files by the same logic as the treewalk code. Reviewed by: marcel Sponsored by: DARPA, AFRL --- usr.sbin/makefs/makefs.h | 2 ++ usr.sbin/makefs/mtree.c | 18 ++++++++++++++++++ usr.sbin/makefs/walk.c | 3 +-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h index 614637620d26..c6707d93f1dd 100644 --- a/usr.sbin/makefs/makefs.h +++ b/usr.sbin/makefs/makefs.h @@ -280,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 2f2400ab26ec..c90c974d6c79 100644 --- a/usr.sbin/makefs/mtree.c +++ b/usr.sbin/makefs/mtree.c @@ -779,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; diff --git a/usr.sbin/makefs/walk.c b/usr.sbin/makefs/walk.c index 0664c8489bc9..7af92bb7e21f 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 {