1 This patch is an old patch; see below for the original message body. The patch
2 has been updated twice: Once to apply to squashfs 4.4, commit
3 52eb4c279cd283ed9802dd1ceb686560b22ffb67, and later to apply to squashfs 4.5,
4 commit 0496d7c3de3e09da37ba492081c86159806ebb07.
6 From 7bda7c75748f36b0a50f93e46144d5a4de4974ad Mon Sep 17 00:00:00 2001
7 From: Amin Hassani <ahassani@google.com>
8 Date: Thu, 15 Dec 2016 10:43:15 -0800
9 Subject: [PATCH] mksquashfs 4K aligns the files inside the squashfs image
11 Files inside a squashfs image are not necessarily 4k (4096)
12 aligned. This patch starts each file in a 4k aligned address and pads
13 zero to the end of the file until it reaches the next 4k aligned
14 address. This will not change the size of the compressed
15 blocks (especially the last one) and hence it will not change how the
16 files are being loaded in kernel or unsquashfs. However on average this
17 increases the size of the squashfs image which can be calculated by the
20 increased_size = (number_of_unfragmented_files_in_image + number of fragments) * 2048
22 The 4k alignment can be enabled by flag '-4k-align'
24 squashfs-tools/mksquashfs.c | 17 +++++++++++++++++
25 1 file changed, 17 insertions(+)
27 diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
28 index aaa4b00..eb2fb23 100644
29 --- a/squashfs-tools/mksquashfs.c
30 +++ b/squashfs-tools/mksquashfs.c
31 @@ -99,6 +99,8 @@ int nopad = FALSE;
32 int exit_on_error = FALSE;
33 long long start_offset = 0;
35 +int do_4k_align = FALSE;
36 +#define ALIGN_UP(bytes, size) (bytes = (bytes + size - 1) & ~(size - 1))
38 long long global_uid = -1, global_gid = -1;
40 @@ -1553,6 +1555,9 @@ static void unlock_fragments()
43 while(!queue_empty(locked_fragment)) {
44 + // 4k align the start of remaining queued fragments.
46 + ALIGN_UP(bytes, 4096);
47 write_buffer = queue_get(locked_fragment);
48 frg = write_buffer->block;
49 size = SQUASHFS_COMPRESSED_SIZE_BLOCK(fragment_table[frg].size);
50 @@ -2460,6 +2465,9 @@ static void *frag_deflator(void *arg)
51 write_buffer->size = compressed_size;
52 pthread_mutex_lock(&fragment_mutex);
53 if(fragments_locked == FALSE) {
54 + // 4k align the start of each fragment.
56 + ALIGN_UP(bytes, 4096);
57 fragment_table[file_buffer->block].size = c_byte;
58 fragment_table[file_buffer->block].start_block = bytes;
59 write_buffer->block = bytes;
60 @@ -2850,6 +2858,10 @@ static struct file_info *write_file_blocks(int *status, struct dir_ent *dir_ent,
61 struct file_info *file;
64 + // 4k align the start of each file.
66 + ALIGN_UP(bytes, 4096);
68 if(pre_duplicate(read_size, dir_ent->inode, read_buffer, &bl_hash))
69 return write_file_blocks_dup(status, dir_ent, read_buffer, dup, bl_hash);
71 @@ -5975,6 +5987,7 @@ static void print_options(FILE *stream, char *name, int total_mem)
72 fprintf(stream, "actions from <f>\n");
73 fprintf(stream, "-false-action-file <f>\tas -false-action, but read ");
74 fprintf(stream, "actions from <f>\n");
75 + fprintf(stream, "-4k-align\t\tenables 4k alignment of all files\n");
76 fprintf(stream, "\nFilesystem filter options:\n");
77 fprintf(stream, "-p <pseudo-definition>\tAdd pseudo file definition\n");
78 fprintf(stream, "-pf <pseudo-file>\tAdd list of pseudo file definitions\n");
79 @@ -6198,6 +6211,7 @@ static void print_summary()
80 "compressed", no_fragments ? "no" : noF ? "uncompressed" :
81 "compressed", no_xattrs ? "no" : noX ? "uncompressed" :
82 "compressed", noI || noId ? "uncompressed" : "compressed");
83 + printf("\t4k %saligned\n", do_4k_align ? "" : "un");
84 printf("\tduplicates are %sremoved\n", duplicate_checking ? "" :
86 printf("Filesystem size %.2f Kbytes (%.2f Mbytes)\n", bytes / 1024.0,
87 @@ -7499,6 +7513,9 @@ print_compressor_options:
89 } else if(strcmp(argv[i], "-version") == 0) {
90 print_version("mksquashfs");
92 + } else if(strcmp(argv[i], "-4k-align") == 0) {
95 ERROR("%s: invalid option\n\n", argv[0]);
96 print_options(stderr, argv[0], total_mem);