aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2021-06-28 08:31:23 -0600
committerDenys Vlasenko <vda.linux@googlemail.com>2021-10-13 17:56:17 +0200
commit836b79211df3aeaba1b8b65c6db5ee6193172cc0 (patch)
treecc597df9f6c3a3c33a168c3332dcfab3537a6a48
parent8aa5585ff4974b8f7ed71d684af48432b2bc6929 (diff)
downloadbusybox-w32-836b79211df3aeaba1b8b65c6db5ee6193172cc0.tar.gz
busybox-w32-836b79211df3aeaba1b8b65c6db5ee6193172cc0.tar.bz2
busybox-w32-836b79211df3aeaba1b8b65c6db5ee6193172cc0.zip
cpio: add support for --renumber-inodes like GNU cpio
The --renumber-inodes option renumbers the inodes starting from 1, so that the sequence of inodes is always stable. This helps with reproducibility. function old new delta cpio_o 961 1045 +84 .rodata 78422 78440 +18 bbconfig_config_bz2 6168 6164 -4 packed_usage 25764 25756 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/2 up/down: 102/-12) Total: 90 bytes Signed-off-by: Ariadne Conill <ariadne@dereferenced.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/cpio.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/archival/cpio.c b/archival/cpio.c
index daf6cffc9..7149782d7 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -45,6 +45,13 @@
45//config: depends on FEATURE_CPIO_O && LONG_OPTS 45//config: depends on FEATURE_CPIO_O && LONG_OPTS
46//config: help 46//config: help
47//config: Optionally ignore device numbers when creating archives. 47//config: Optionally ignore device numbers when creating archives.
48//config:
49//config:config FEATURE_CPIO_RENUMBER_INODES
50//config: bool "Support --renumber-inodes like GNU cpio"
51//config: default y
52//config: depends on FEATURE_CPIO_O && LONG_OPTS
53//config: help
54//config: Optionally renumber inodes when creating archives.
48 55
49//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP)) 56//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
50 57
@@ -85,6 +92,9 @@
85//usage: IF_FEATURE_CPIO_IGNORE_DEVNO( 92//usage: IF_FEATURE_CPIO_IGNORE_DEVNO(
86//usage: "\n --ignore-devno" 93//usage: "\n --ignore-devno"
87//usage: ) 94//usage: )
95//usage: IF_FEATURE_CPIO_RENUMBER_INODES(
96//usage: "\n --renumber-inodes"
97//usage: )
88 98
89/* GNU cpio 2.9 --help (abridged): 99/* GNU cpio 2.9 --help (abridged):
90 100
@@ -173,18 +183,21 @@ enum {
173 IF_LONG_OPTS( OPTBIT_QUIET ,) 183 IF_LONG_OPTS( OPTBIT_QUIET ,)
174 IF_LONG_OPTS( OPTBIT_2STDOUT ,) 184 IF_LONG_OPTS( OPTBIT_2STDOUT ,)
175 IF_FEATURE_CPIO_IGNORE_DEVNO(OPTBIT_IGNORE_DEVNO,) 185 IF_FEATURE_CPIO_IGNORE_DEVNO(OPTBIT_IGNORE_DEVNO,)
186 IF_FEATURE_CPIO_RENUMBER_INODES(OPTBIT_RENUMBER_INODES,)
176 OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0, 187 OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
177 OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0, 188 OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
178 OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0, 189 OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
179 OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0, 190 OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
180 OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0, 191 OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
181 OPT_IGNORE_DEVNO = IF_FEATURE_CPIO_IGNORE_DEVNO((1 << OPTBIT_IGNORE_DEVNO)) + 0, 192 OPT_IGNORE_DEVNO = IF_FEATURE_CPIO_IGNORE_DEVNO((1 << OPTBIT_IGNORE_DEVNO)) + 0,
193 OPT_RENUMBER_INODES = IF_FEATURE_CPIO_RENUMBER_INODES((1 << OPTBIT_RENUMBER_INODES)) + 0,
182}; 194};
183 195
184#define OPTION_STR "it0uvdmLF:R:" 196#define OPTION_STR "it0uvdmLF:R:"
185 197
186struct globals { 198struct globals {
187 struct bb_uidgid_t owner_ugid; 199 struct bb_uidgid_t owner_ugid;
200 ino_t next_inode;
188} FIX_ALIASING; 201} FIX_ALIASING;
189#define G (*(struct globals*)bb_common_bufsiz1) 202#define G (*(struct globals*)bb_common_bufsiz1)
190void BUG_cpio_globals_too_big(void); 203void BUG_cpio_globals_too_big(void);
@@ -218,6 +231,9 @@ static NOINLINE int cpio_o(void)
218 struct inodes_s *next; 231 struct inodes_s *next;
219 struct name_s *names; 232 struct name_s *names;
220 struct stat st; 233 struct stat st;
234#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
235 ino_t mapped_inode;
236#endif
221 }; 237 };
222 238
223 struct inodes_s *links = NULL; 239 struct inodes_s *links = NULL;
@@ -272,6 +288,10 @@ static NOINLINE int cpio_o(void)
272 l = xzalloc(sizeof(*l)); 288 l = xzalloc(sizeof(*l));
273 l->st = st; 289 l->st = st;
274 l->next = links; 290 l->next = links;
291#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
292 if (option_mask32 & OPT_RENUMBER_INODES)
293 l->mapped_inode = ++G.next_inode;
294#endif
275 links = l; 295 links = l;
276 break; 296 break;
277 } 297 }
@@ -290,6 +310,11 @@ static NOINLINE int cpio_o(void)
290 free(line); 310 free(line);
291 continue; 311 continue;
292 } 312 }
313#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
314 else if (option_mask32 & OPT_RENUMBER_INODES) {
315 st.st_ino = ++G.next_inode;
316 }
317#endif
293 } else { /* line == NULL: EOF */ 318 } else { /* line == NULL: EOF */
294 next_link: 319 next_link:
295 if (links) { 320 if (links) {
@@ -297,6 +322,10 @@ static NOINLINE int cpio_o(void)
297 st = links->st; 322 st = links->st;
298 name = links->names->name; 323 name = links->names->name;
299 links->names = links->names->next; 324 links->names = links->names->next;
325#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
326 if (links->mapped_inode)
327 st.st_ino = links->mapped_inode;
328#endif
300 /* GNU cpio is reported to emit file data 329 /* GNU cpio is reported to emit file data
301 * only for the last instance. Mimic that. */ 330 * only for the last instance. Mimic that. */
302 if (links->names == NULL) 331 if (links->names == NULL)
@@ -399,6 +428,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
399#if ENABLE_FEATURE_CPIO_IGNORE_DEVNO 428#if ENABLE_FEATURE_CPIO_IGNORE_DEVNO
400 "ignore-devno\0" No_argument "\xfd" 429 "ignore-devno\0" No_argument "\xfd"
401#endif 430#endif
431#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
432 "renumber-inodes\0" No_argument "\xfc"
433#endif
402 ; 434 ;
403#endif 435#endif
404 436