From: Jean-Yves Migeon Date: Wed, 4 Sep 2013 16:58:47 +0000 (+0200) Subject: Implement "resdevice" and "inode" in the mtree(5) spec. X-Git-Tag: v3.1.900a~353^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c271b395a918da19311da04c4a1a6d0691a34c4;p=thirdparty%2Flibarchive.git Implement "resdevice" and "inode" in the mtree(5) spec. - resdevice is the keyword that corresponds to the "resident" device, e.g. the one where the entry resides; - inode is entry's inode number. --- diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index a1d34e2b7..a6cf332e1 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -368,7 +368,7 @@ bid_keyword(const char *p, ssize_t len) "gid", "gname", NULL }; static const char *keys_il[] = { - "ignore", "link", NULL + "ignore", "inode", "link", NULL }; static const char *keys_m[] = { "md5", "md5digest", "mode", NULL @@ -1435,6 +1435,11 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, archive_entry_copy_gname(entry, val); break; } + case 'i': + if (strcmp(key, "inode") == 0) { + archive_entry_set_ino(entry, mtree_atol10(&val)); + break; + } case 'l': if (strcmp(key, "link") == 0) { archive_entry_copy_symlink(entry, val); diff --git a/libarchive/archive_write_set_format_mtree.c b/libarchive/archive_write_set_format_mtree.c index fca398dcb..40db2ffc6 100644 --- a/libarchive/archive_write_set_format_mtree.c +++ b/libarchive/archive_write_set_format_mtree.c @@ -128,6 +128,9 @@ struct mtree_entry { unsigned long fflags_clear; dev_t rdevmajor; dev_t rdevminor; + dev_t devmajor; + dev_t devminor; + int64_t ino; }; struct mtree_writer { @@ -210,6 +213,9 @@ struct mtree_writer { #define F_SHA256 0x00800000 /* SHA-256 digest */ #define F_SHA384 0x01000000 /* SHA-384 digest */ #define F_SHA512 0x02000000 /* SHA-512 digest */ +#define F_INO 0x04000000 /* inode number */ +#define F_RESDEV 0x08000000 /* device ID on which the + * entry resides */ /* Options */ int dironly; /* If it is set, ignore all files except @@ -823,8 +829,11 @@ mtree_entry_new(struct archive_write *a, struct archive_entry *entry, archive_entry_fflags(entry, &me->fflags_set, &me->fflags_clear); me->mtime = archive_entry_mtime(entry); me->mtime_nsec = archive_entry_mtime_nsec(entry); - me->rdevmajor = archive_entry_rdevmajor(entry); + me->rdevmajor = archive_entry_rdevmajor(entry); me->rdevminor = archive_entry_rdevminor(entry); + me->devmajor = archive_entry_devmajor(entry); + me->devminor = archive_entry_devminor(entry); + me->ino = archive_entry_ino(entry); me->size = archive_entry_size(entry); if (me->filetype == AE_IFDIR) { me->dir_info = calloc(1, sizeof(*me->dir_info)); @@ -983,6 +992,15 @@ write_mtree_entry(struct archive_write *a, struct mtree_entry *me) if ((keys & F_UID) != 0) archive_string_sprintf(str, " uid=%jd", (intmax_t)me->uid); + if ((keys & F_INO) != 0) + archive_string_sprintf(str, " inode=%jd", (intmax_t)me->ino); + if ((keys & F_RESDEV) != 0) { + archive_string_sprintf(str, + " resdevice=native,%ju,%ju", + (uintmax_t)me->rdevmajor, + (uintmax_t)me->rdevminor); + } + switch (me->filetype) { case AE_IFLNK: if ((keys & F_TYPE) != 0) @@ -1117,7 +1135,7 @@ write_mtree_entry_tree(struct archive_write *a) } else { /* Whenever output_global_set is enabled * output global value(/set keywords) - * even if the directory entry is not allowd + * even if the directory entry is not allowed * to be written because the global values * can be used for the children. */ if (mtree->output_global_set) @@ -1296,6 +1314,8 @@ archive_write_mtree_options(struct archive_write *a, const char *key, if (strcmp(key, "indent") == 0) { mtree->indent = (value != NULL)? 1: 0; return (ARCHIVE_OK); + } else if (strcmp(key, "inode") == 0) { + keybit = F_INO; } break; case 'l': @@ -1314,7 +1334,9 @@ archive_write_mtree_options(struct archive_write *a, const char *key, keybit = F_NLINK; break; case 'r': - if (strcmp(key, "ripemd160digest") == 0 || + if (strcmp(key, "resdevice") == 0) { + keybit = F_RESDEV; + } else if (strcmp(key, "ripemd160digest") == 0 || strcmp(key, "rmd160") == 0 || strcmp(key, "rmd160digest") == 0) keybit = F_RMD160; @@ -2198,6 +2220,9 @@ mtree_entry_exchange_same_entry(struct archive_write *a, struct mtree_entry *np, np->mtime_nsec = file->mtime_nsec; np->rdevmajor = file->rdevmajor; np->rdevminor = file->rdevminor; + np->devmajor = file->devmajor; + np->devminor = file->devminor; + np->ino = file->ino; return (ARCHIVE_WARN); }