22
22
23
23
static unsigned int offset ;
24
24
static unsigned int ino = 721 ;
25
+ static time_t default_mtime ;
25
26
26
27
struct file_handler {
27
28
const char * type ;
@@ -102,7 +103,6 @@ static int cpio_mkslink(const char *name, const char *target,
102
103
unsigned int mode , uid_t uid , gid_t gid )
103
104
{
104
105
char s [256 ];
105
- time_t mtime = time (NULL );
106
106
107
107
if (name [0 ] == '/' )
108
108
name ++ ;
@@ -114,7 +114,7 @@ static int cpio_mkslink(const char *name, const char *target,
114
114
(long ) uid , /* uid */
115
115
(long ) gid , /* gid */
116
116
1 , /* nlink */
117
- (long ) mtime , /* mtime */
117
+ (long ) default_mtime , /* mtime */
118
118
(unsigned )strlen (target )+ 1 , /* filesize */
119
119
3 , /* major */
120
120
1 , /* minor */
@@ -152,7 +152,6 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,
152
152
uid_t uid , gid_t gid )
153
153
{
154
154
char s [256 ];
155
- time_t mtime = time (NULL );
156
155
157
156
if (name [0 ] == '/' )
158
157
name ++ ;
@@ -164,7 +163,7 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,
164
163
(long ) uid , /* uid */
165
164
(long ) gid , /* gid */
166
165
2 , /* nlink */
167
- (long ) mtime , /* mtime */
166
+ (long ) default_mtime , /* mtime */
168
167
0 , /* filesize */
169
168
3 , /* major */
170
169
1 , /* minor */
@@ -242,7 +241,6 @@ static int cpio_mknod(const char *name, unsigned int mode,
242
241
unsigned int maj , unsigned int min )
243
242
{
244
243
char s [256 ];
245
- time_t mtime = time (NULL );
246
244
247
245
if (dev_type == 'b' )
248
246
mode |= S_IFBLK ;
@@ -259,7 +257,7 @@ static int cpio_mknod(const char *name, unsigned int mode,
259
257
(long ) uid , /* uid */
260
258
(long ) gid , /* gid */
261
259
1 , /* nlink */
262
- (long ) mtime , /* mtime */
260
+ (long ) default_mtime , /* mtime */
263
261
0 , /* filesize */
264
262
3 , /* major */
265
263
1 , /* minor */
@@ -460,7 +458,7 @@ static int cpio_mkfile_line(const char *line)
460
458
static void usage (const char * prog )
461
459
{
462
460
fprintf (stderr , "Usage:\n"
463
- "\t%s <cpio_list>\n"
461
+ "\t%s [-t <timestamp>] <cpio_list>\n"
464
462
"\n"
465
463
"<cpio_list> is a file containing newline separated entries that\n"
466
464
"describe the files to be included in the initramfs archive:\n"
@@ -491,7 +489,11 @@ static void usage(const char *prog)
491
489
"nod /dev/console 0600 0 0 c 5 1\n"
492
490
"dir /root 0700 0 0\n"
493
491
"dir /sbin 0755 0 0\n"
494
- "file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0\n" ,
492
+ "file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0\n"
493
+ "\n"
494
+ "<timestamp> is time in seconds since Epoch that will be used\n"
495
+ "as mtime for symlinks, special files and directories. The default\n"
496
+ "is to use the current time for these entries.\n" ,
495
497
prog );
496
498
}
497
499
@@ -529,17 +531,42 @@ int main (int argc, char *argv[])
529
531
char * args , * type ;
530
532
int ec = 0 ;
531
533
int line_nr = 0 ;
534
+ const char * filename ;
535
+
536
+ default_mtime = time (NULL );
537
+ while (1 ) {
538
+ int opt = getopt (argc , argv , "t:h" );
539
+ char * invalid ;
532
540
533
- if (2 != argc ) {
541
+ if (opt == -1 )
542
+ break ;
543
+ switch (opt ) {
544
+ case 't' :
545
+ default_mtime = strtol (optarg , & invalid , 10 );
546
+ if (!* optarg || * invalid ) {
547
+ fprintf (stderr , "Invalid timestamp: %s\n" ,
548
+ optarg );
549
+ usage (argv [0 ]);
550
+ exit (1 );
551
+ }
552
+ break ;
553
+ case 'h' :
554
+ case '?' :
555
+ usage (argv [0 ]);
556
+ exit (opt == 'h' ? 0 : 1 );
557
+ }
558
+ }
559
+
560
+ if (argc - optind != 1 ) {
534
561
usage (argv [0 ]);
535
562
exit (1 );
536
563
}
537
-
538
- if (!strcmp (argv [ 1 ] , "-" ))
564
+ filename = argv [ optind ];
565
+ if (!strcmp (filename , "-" ))
539
566
cpio_list = stdin ;
540
- else if (! (cpio_list = fopen (argv [ 1 ] , "r" ))) {
567
+ else if (!(cpio_list = fopen (filename , "r" ))) {
541
568
fprintf (stderr , "ERROR: unable to open '%s': %s\n\n" ,
542
- argv [ 1 ] , strerror (errno ));
569
+ filename , strerror (errno ));
543
570
usage (argv [0 ]);
544
571
exit (1 );
545
572
}
0 commit comments