tools/squashfs4: refresh patches
[openwrt.git] / tools / squashfs4 / patches / 200-add-fixed-timestamp-option.patch
1 --- a/squashfs-tools/mksquashfs.c
2 +++ b/squashfs-tools/mksquashfs.c
3 @@ -175,6 +175,9 @@ unsigned int cache_bytes = 0, cache_size
4  /* inode lookup table */
5  squashfs_inode *inode_lookup_table = NULL;
6  
7 +/* override all timestamps */
8 +time_t fixed_time = -1;
9 +
10  /* in memory directory data */
11  #define I_COUNT_SIZE           128
12  #define DIR_ENTRIES            32
13 @@ -2452,6 +2455,8 @@ again:
14  restat:
15         fstat(file, &buf2);
16         close(file);
17 +       if (fixed_time != -1)
18 +               buf2.st_mtime = fixed_time;
19         if(read_size != buf2.st_size) {
20                 memcpy(buf, &buf2, sizeof(struct stat));
21                 file_buffer->error = 2;
22 @@ -3612,7 +3617,7 @@ void dir_scan(squashfs_inode *inode, cha
23                 buf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;
24                 buf.st_uid = getuid();
25                 buf.st_gid = getgid();
26 -               buf.st_mtime = time(NULL);
27 +               buf.st_mtime = fixed_time != -1 ? fixed_time : time(NULL);
28                 buf.st_dev = 0;
29                 buf.st_ino = 0;
30                 dir_ent->inode = lookup_inode(&buf);
31 @@ -3623,6 +3628,8 @@ void dir_scan(squashfs_inode *inode, cha
32                                 pathname, strerror(errno));
33                         return;
34                 }
35 +               if(fixed_time != -1)
36 +                       buf.st_mtime = fixed_time;
37                 dir_ent->inode = lookup_inode(&buf);
38         }
39  
40 @@ -3677,6 +3684,8 @@ struct dir_info *dir_scan1(char *pathnam
41                                 filename, strerror(errno));
42                         continue;
43                 }
44 +               if(fixed_time != -1)
45 +                       buf.st_mtime = fixed_time;
46  
47                 if((buf.st_mode & S_IFMT) != S_IFREG &&
48                         (buf.st_mode & S_IFMT) != S_IFDIR &&
49 @@ -3795,7 +3804,7 @@ struct dir_info *dir_scan2(struct dir_in
50                 buf.st_gid = pseudo_ent->dev->gid;
51                 buf.st_rdev = makedev(pseudo_ent->dev->major,
52                         pseudo_ent->dev->minor);
53 -               buf.st_mtime = time(NULL);
54 +               buf.st_mtime = fixed_time != -1 ? fixed_time : time(NULL);
55                 buf.st_ino = pseudo_ino ++;
56  
57                 if(pseudo_ent->dev->type == 'f') {
58 @@ -4674,6 +4683,15 @@ int main(int argc, char *argv[])
59                         progress = FALSE;
60                 else if(strcmp(argv[i], "-no-exports") == 0)
61                         exportable = FALSE;
62 +               else if(strcmp(argv[i], "-fixed-time") == 0) {
63 +                       if((++i == argc) || (fixed_time =
64 +                                       strtoll(argv[i], &b, 10), *b != '\0')) {
65 +                               ERROR("%s: -fixed-time missing or invalid "
66 +                                       "timestamp\n", argv[0]);
67 +
68 +                               exit(1);
69 +                       }
70 +               }
71                 else if(strcmp(argv[i], "-processors") == 0) {
72                         if((++i == argc) || (processors =
73                                         strtol(argv[i], &b, 10), *b != '\0')) {
74 @@ -5314,7 +5332,7 @@ printOptions:
75         sBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, noX, no_fragments,
76                 always_use_fragments, duplicate_checking, exportable,
77                 no_xattrs, comp_opts);
78 -       sBlk.mkfs_time = time(NULL);
79 +       sBlk.mkfs_time = fixed_time != -1 ? fixed_time : time(NULL);
80  
81  restore_filesystem:
82         if(progress && estimated_uncompressed) {