diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-06-28 12:41:26 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-06-28 15:07:34 +0200 |
commit | 4e017928c7b5b590d2c7e04e42cb497eb3a4f8cf (patch) | |
tree | 28f649af1074ab74576a9a715991c610b210f1c0 /lib/sqfs/write_inode.c | |
parent | d89d7e3d7f5b21fe53ea0cbf65134bdc3df30950 (diff) |
Add support for packing sparse files
This commit adds support for packing sparse files into squashfs images
as follows:
- In the data writer: simply detect zero blocks and write a zero to the
block size field and don't emit any data. Record the number of bytes
saved this way. For fragments, set the fragment offset to invalid.
- In the inode writer: write out the number of bytes saved for sparse
files. If there should be a fragment but there is none, append a block
count of 0.
- In the data reader: if the block size is 0, read nothing from disk and
emit an empty block. Do the same if the fragment is missing.
- In the inode reader: restore the number of bytes saved for sparse files.
The sparse files can be packed and unpacked, but the unpacking will not
create sparse files for now.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/write_inode.c')
-rw-r--r-- | lib/sqfs/write_inode.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c index fd14913..82663e7 100644 --- a/lib/sqfs/write_inode.c +++ b/lib/sqfs/write_inode.c @@ -86,7 +86,7 @@ int meta_writer_write_inode(fstree_t *fs, id_table_t *idtbl, meta_writer_t *im, fi = node->data.file; if (fi->startblock > 0xFFFFFFFFUL || fi->size > 0xFFFFFFFFUL || - hard_link_count(node) > 1) { + hard_link_count(node) > 1 || fi->sparse > 0) { type = SQFS_INODE_EXT_FILE; } } @@ -185,7 +185,7 @@ int meta_writer_write_inode(fstree_t *fs, id_table_t *idtbl, meta_writer_t *im, sqfs_inode_file_ext_t ext = { .blocks_start = htole64(fi->startblock), .file_size = htole64(fi->size), - .sparse = htole64(0), + .sparse = htole64(fi->sparse), .nlink = htole32(hard_link_count(node)), .fragment_idx = htole32(0xFFFFFFFF), .fragment_offset = htole32(0xFFFFFFFF), @@ -298,5 +298,13 @@ out_file_blocks: if (meta_writer_append(im, &bs, sizeof(bs))) return -1; } + + if ((fi->size % fs->block_size) != 0 && + (fi->fragment == 0xFFFFFFFF || fi->fragment_offset == 0xFFFFFFFF)) { + bs = htole32(0); + + if (meta_writer_append(im, &bs, sizeof(bs))) + return -1; + } return 0; } |