1 # From https://github.com/plougher/squashfs-tools/pull/264
2 diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
3 --- a/squashfs-tools/mksquashfs.c
4 +++ b/squashfs-tools/mksquashfs.c
5 @@ -182,6 +182,12 @@ int exit_on_error = FALSE;
6 /* Is filesystem stored at an offset from the start of the block device/file? */
7 long long start_offset = 0;
9 +/* Do we have an extra_info metadata block? */
10 +int extra_info = FALSE;
11 +/* parameters for the extra_info block */
12 +char *volume_label = NULL;
15 /* File count statistics used to print summary and fill in superblock */
16 unsigned int file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0,
17 fifo_count = 0, sock_count = 0, id_count = 0;
18 @@ -342,7 +348,7 @@ char *option_table[] = { "comp", "b", "mkfs-time", "fstime", "all-time",
19 "vaf", "taf", "faf", "read-queue", "write-queue", "fragment-queue",
20 "root-time", "root-uid", "root-gid", "xattrs-exclude", "xattrs-include",
21 "xattrs-add", "default-mode", "default-uid", "default-gid",
23 + "mem-percent", "label", "uuid", NULL
26 char *sqfstar_option_table[] = { "comp", "b", "mkfs-time", "fstime", "all-time",
27 @@ -6252,6 +6258,8 @@ static void print_options(FILE *stream, char *name, int total_mem)
28 fprintf(stream, "-keep-as-directory\tif one source directory is specified, ");
29 fprintf(stream, "create a root\n");
30 fprintf(stream, "\t\t\tdirectory containing that directory, rather than the\n");
31 + fprintf(stream, "-label <volume-label>\tSet the volume label\n");
32 + fprintf(stream, "-uuid <UUID>\tSet the volume UUID\n");
33 fprintf(stream, "\t\t\tcontents of the directory\n");
34 fprintf(stream, "\nFilesystem filter options:\n");
35 fprintf(stream, "-p <pseudo-definition>\tadd pseudo file ");
36 @@ -7555,6 +7563,7 @@ int sqfstar(int argc, char *argv[])
37 SQUASHFS_MAJOR, SQUASHFS_MINOR,
38 destination_file, block_size);
40 + bytes = sizeof(struct squashfs_super_block);
42 * store any compressor specific options after the superblock,
43 * and set the COMP_OPT flag to show that the filesystem has
44 @@ -7568,11 +7577,9 @@ int sqfstar(int argc, char *argv[])
45 sizeof(c_byte), &c_byte);
46 write_destination(fd, sizeof(struct squashfs_super_block) +
47 sizeof(c_byte), size, comp_data);
48 - bytes = sizeof(struct squashfs_super_block) + sizeof(c_byte)
50 + bytes += sizeof(c_byte) + size;
53 - bytes = sizeof(struct squashfs_super_block);
57 paths = add_subdir(paths, path);
58 @@ -7593,7 +7600,7 @@ int sqfstar(int argc, char *argv[])
59 sBlk.block_log = block_log;
60 sBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, noX, noId, no_fragments,
61 always_use_fragments, duplicate_checking, exportable,
62 - no_xattrs, comp_opts);
63 + no_xattrs, comp_opts, extra_info);
64 sBlk.mkfs_time = mkfs_time_opt ? mkfs_time : time(NULL);
67 @@ -7643,6 +7650,70 @@ int sqfstar(int argc, char *argv[])
71 +void *info_dump(int *psize) {
72 + int bytes = 0, pos = 0;
74 + const int UUID_LEN = 16; /* avoid depending on uuid-dev for now */
77 + /* The extra_info section contains one or more entries of the form:
80 + VAL byte_1 ... byte_len
82 + Terminated by the tag: SQUASHFS_EXTRA_INFO_TAG_END
85 + label_len = strlen(volume_label);
86 + if (label_len > 255) label_len = 255;
87 + bytes += 1 + 1 + label_len;
90 + bytes += 1 + 1 + UUID_LEN;
93 + bytes += 1; /* TAG_END */
95 + buf = malloc(bytes);
98 + buf[pos++] = SQUASHFS_EXTRA_INFO_TAG_LABEL;
99 + buf[pos++] = label_len;
100 + memcpy(&buf[pos], volume_label, label_len);
104 + char *puuid = uuid;
105 + buf[pos++] = SQUASHFS_EXTRA_INFO_TAG_UUID;
106 + buf[pos++] = UUID_LEN;
107 + /* poor man's uuid_parse() */
108 + for (int i = 0; i < UUID_LEN; i++) {
110 + char *endptr = NULL;
111 + if (*puuid == '-') {
114 + if (puuid[0] && puuid[1]) {
115 + memcpy(&hex[0], puuid, 2);
116 + buf[pos++] = strtoul(hex, &endptr, 16);
118 + if (endptr != hex + 2) {
119 + ERROR("invalid UUID: %s\n", uuid);
125 + buf[pos++] = SQUASHFS_EXTRA_INFO_TAG_END;
126 + if (pos != bytes) {
127 + ERROR("extra_info legth mismatch\n");
135 int main(int argc, char *argv[])
137 struct stat buf, source_buf;
138 @@ -8436,6 +8507,20 @@ int main(int argc, char *argv[])
140 } else if(strcmp(argv[i], "-4k-align") == 0) {
142 + } else if (strcmp(argv[i], "-label") == 0) {
144 + ERROR("%s: -label: missing label\n",
148 + volume_label = argv[i];
149 + } else if (strcmp(argv[i], "-uuid") == 0) {
151 + ERROR("%s: -uuid: missing uuid\n",
157 ERROR("%s: invalid option\n\n", argv[0]);
158 print_options(stderr, argv[0], total_mem);
159 @@ -8661,6 +8746,7 @@ int main(int argc, char *argv[])
160 exportable = SQUASHFS_EXPORTABLE(sBlk.flags);
161 no_xattrs = SQUASHFS_NO_XATTRS(sBlk.flags);
162 comp_opts = SQUASHFS_COMP_OPTS(sBlk.flags);
163 + extra_info = SQUASHFS_EXTRA_INFO(sBlk.flags);
166 initialise_threads(readq, fragq, bwriteq, fwriteq, !appending,
167 @@ -8682,33 +8768,44 @@ int main(int argc, char *argv[])
168 memset(dupl_frag, 0, block_size * sizeof(struct file_info *));
173 void *comp_data = compressor_dump_options(comp, block_size,
178 + void *info_data = info_dump(&info_size);
181 printf("Creating %d.%d filesystem on %s, block size %d.\n",
182 SQUASHFS_MAJOR, SQUASHFS_MINOR,
183 destination_file, block_size);
185 + bytes = sizeof(struct squashfs_super_block);
187 * store any compressor specific options after the superblock,
188 * and set the COMP_OPT flag to show that the filesystem has
189 * compressor specfic options
192 - unsigned short c_byte = size | SQUASHFS_COMPRESSED_BIT;
193 + unsigned short c_byte = comp_size | SQUASHFS_COMPRESSED_BIT;
195 SQUASHFS_INSWAP_SHORTS(&c_byte, 1);
196 - write_destination(fd, sizeof(struct squashfs_super_block),
197 - sizeof(c_byte), &c_byte);
198 - write_destination(fd, sizeof(struct squashfs_super_block) +
199 - sizeof(c_byte), size, comp_data);
200 - bytes = sizeof(struct squashfs_super_block) + sizeof(c_byte)
202 + write_destination(fd, bytes, sizeof(c_byte), &c_byte);
203 + bytes += sizeof(c_byte);
204 + write_destination(fd, bytes, comp_size, comp_data);
205 + bytes += comp_size;
208 - bytes = sizeof(struct squashfs_super_block);
211 + unsigned short i_byte = info_size | SQUASHFS_COMPRESSED_BIT;
213 + SQUASHFS_INSWAP_SHORTS(&i_byte, 1);
214 + write_destination(fd, bytes, sizeof(i_byte), &i_byte);
215 + bytes += sizeof(i_byte);
216 + write_destination(fd, bytes, info_size, info_data);
217 + bytes += info_size;
221 unsigned int last_directory_block, inode_dir_file_size,
222 root_inode_size, inode_dir_start_block,
223 @@ -8868,7 +8965,7 @@ int main(int argc, char *argv[])
224 sBlk.block_log = block_log;
225 sBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, noX, noId, no_fragments,
226 always_use_fragments, duplicate_checking, exportable,
227 - no_xattrs, comp_opts);
228 + no_xattrs, comp_opts, extra_info);
229 sBlk.mkfs_time = mkfs_time_opt ? mkfs_time : time(NULL);
232 diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h
233 --- a/squashfs-tools/squashfs_fs.h
234 +++ b/squashfs-tools/squashfs_fs.h
236 #define SQUASHFS_NO_XATTR 9
237 #define SQUASHFS_COMP_OPT 10
238 #define SQUASHFS_NOID 11
239 +#define SQUASHFS_INFO 12
241 #define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
243 @@ -108,12 +109,16 @@
244 #define SQUASHFS_UNCOMPRESSED_IDS(flags) SQUASHFS_BIT(flags, \
247 +#define SQUASHFS_EXTRA_INFO(flags) SQUASHFS_BIT(flags, \
250 #define SQUASHFS_MKFLAGS(noi, nod, nof, nox, noid, no_frag, always_frag, \
251 - duplicate_checking, exportable, no_xattr, comp_opt) (noi | \
252 + duplicate_checking, exportable, no_xattr, comp_opt, \
253 + extra_info) (noi | \
254 (nod << 1) | (nof << 3) | (no_frag << 4) | \
255 (always_frag << 5) | (duplicate_checking << 6) | \
256 (exportable << 7) | (nox << 8) | (no_xattr << 9) | \
257 - (comp_opt << 10) | (noid << 11))
258 + (comp_opt << 10) | (noid << 11) | (extra_info << 12))
260 /* Max number of types and file types */
261 #define SQUASHFS_DIR_TYPE 1
262 @@ -289,6 +294,10 @@ typedef long long squashfs_inode;
263 #define LZ4_COMPRESSION 5
264 #define ZSTD_COMPRESSION 6
266 +#define SQUASHFS_EXTRA_INFO_TAG_END 0
267 +#define SQUASHFS_EXTRA_INFO_TAG_LABEL 1
268 +#define SQUASHFS_EXTRA_INFO_TAG_UUID 2
270 struct squashfs_super_block {
271 unsigned int s_magic;