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