summaryrefslogtreecommitdiff
path: root/lib/sqfs/write_inode.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-28 12:24:54 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-28 12:24:54 +0200
commit8ac60e9b961f12acfe300258700522b02c06a50c (patch)
treeae7044aef1318735cad5cb508c0776fc64460416 /lib/sqfs/write_inode.c
parent62c596a761d9a511bbf908de36e51dc76b5e3340 (diff)
Fix inode fragment & sparse counter initialization
The sparse attribute should be initialized with 0. It is subtracted from the file size in the kernel to determine the file size on disk to report to stat(2). So it actually didn't matter anyway (just for correctness sake). Second, the fragment index and offset should be set to 0xFFFFFFFF in the rare case that no fragments exist. 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.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c
index ee4ebc6..fd14913 100644
--- a/lib/sqfs/write_inode.c
+++ b/lib/sqfs/write_inode.c
@@ -185,13 +185,18 @@ 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(0xFFFFFFFFFFFFFFFFUL),
+ .sparse = htole64(0),
.nlink = htole32(hard_link_count(node)),
- .fragment_idx = htole32(fi->fragment),
- .fragment_offset = htole32(fi->fragment_offset),
+ .fragment_idx = htole32(0xFFFFFFFF),
+ .fragment_offset = htole32(0xFFFFFFFF),
.xattr_idx = htole32(0xFFFFFFFF),
};
+ if ((fi->size % fs->block_size) != 0) {
+ ext.fragment_idx = htole32(fi->fragment);
+ ext.fragment_offset = htole32(fi->fragment_offset);
+ }
+
if (node->xattr != NULL)
ext.xattr_idx = htole32(node->xattr->index);
@@ -202,11 +207,16 @@ int meta_writer_write_inode(fstree_t *fs, id_table_t *idtbl, meta_writer_t *im,
case SQFS_INODE_FILE: {
sqfs_inode_file_t reg = {
.blocks_start = htole32(fi->startblock),
- .fragment_index = htole32(fi->fragment),
- .fragment_offset = htole32(fi->fragment_offset),
+ .fragment_index = htole32(0xFFFFFFFF),
+ .fragment_offset = htole32(0xFFFFFFFF),
.file_size = htole32(fi->size),
};
+ if ((fi->size % fs->block_size) != 0) {
+ reg.fragment_index = htole32(fi->fragment);
+ reg.fragment_offset = htole32(fi->fragment_offset);
+ }
+
if (meta_writer_append(im, &reg, sizeof(reg)))
return -1;
goto out_file_blocks;