blob: e2f4bb2e049cebca5f2be22b67161d56b9218876 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001--- a/squashfs-tools/mksquashfs.c
2+++ b/squashfs-tools/mksquashfs.c
3@@ -117,6 +117,9 @@ unsigned int inode_bytes = 0, inode_size
4 char *data_cache = NULL;
5 unsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;
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@@ -1554,6 +1557,11 @@ void dir_scan(squashfs_inode *inode, cha
14 perror(buffer);
15 return;
16 }
17+
18+ /* override timestamp of lstat if fixed_time is given */
19+ if(fixed_time != -1)
20+ inode_info->buf.st_mtime = fixed_time;
21+
22 if(sorted)
23 sort_files_and_write(dir_info);
24 dir_scan2(inode, dir_info);
25@@ -1582,6 +1590,10 @@ struct dir_info *dir_scan1(char *pathnam
26 perror(buffer);
27 continue;
28 }
29+
30+ if(fixed_time != -1)
31+ buf.st_mtime = fixed_time;
32+
33 if(excluded(filename, &buf))
34 continue;
35
36@@ -1621,6 +1633,9 @@ int dir_scan2(squashfs_inode *inode, str
37 char *dir_name = dir_ent->name;
38 unsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;
39
40+ if(fixed_time != -1)
41+ buf->st_mtime = fixed_time;
42+
43 if(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {
44 switch(buf->st_mode & S_IFMT) {
45 case S_IFREG:
46@@ -1898,6 +1913,16 @@ int main(int argc, char *argv[])
47 exit(1);
48 }
49 }
50+ } else if(strcmp(argv[i], "-fixed-time") == 0) {
51+ if(++i == argc) {
52+ ERROR("%s: -fixed-time missing a timestamp\n", argv[0]);
53+ exit(1);
54+ }
55+ fixed_time = strtoll(argv[i], &b, 10);
56+ if(*b != '\0') {
57+ ERROR("%s: -fixed-time has an invalid number\n", argv[0]);
58+ exit(1);
59+ }
60 } else if(strcmp(argv[i], "-noI") == 0 ||
61 strcmp(argv[i], "-noInodeCompression") == 0)
62 noI = TRUE;
63@@ -1967,6 +1992,7 @@ printOptions:
64 ERROR("-all-root\t\tmake all files owned by root\n");
65 ERROR("-force-uid uid\t\tset all file uids to uid\n");
66 ERROR("-force-gid gid\t\tset all file gids to gid\n");
67+ ERROR("-fixed-time timestamp\tset all timestamps to timestamp\n");
68 ERROR("-le\t\t\tcreate a little endian filesystem\n");
69 ERROR("-be\t\t\tcreate a big endian filesystem\n");
70 ERROR("-nopad\t\t\tdo not pad filesystem to a multiple of 4K\n");
71@@ -2190,7 +2216,7 @@ printOptions:
72 sBlk.block_size = block_size;
73 sBlk.block_log = block_log;
74 sBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking);
75- sBlk.mkfs_time = time(NULL);
76+ sBlk.mkfs_time = fixed_time != -1 ? fixed_time : time(NULL);
77
78 restore_filesystem:
79 write_fragment();