summaryrefslogtreecommitdiff
path: root/lib/sqfs/write_dir.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-07 01:32:19 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-07 01:32:19 +0200
commita295f58338b1e0d5dfb2eed57026cafacf266d7d (patch)
tree69ec8bb3a0b5e4045c31e1b1afd4b24c6a567960 /lib/sqfs/write_dir.c
parentb2598623d8a4e3d3e83ee28da3ecdb0d4479a8f8 (diff)
Actually encode/decode directory inode difference as signed
The directory listing stores a signed difference of the inode number. Actually treating it as signed saves emitting extra headers if hard links or file deduplication are finally implemented. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/write_dir.c')
-rw-r--r--lib/sqfs/write_dir.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/sqfs/write_dir.c b/lib/sqfs/write_dir.c
index b334864..9f8923b 100644
--- a/lib/sqfs/write_dir.c
+++ b/lib/sqfs/write_dir.c
@@ -55,8 +55,10 @@ int meta_writer_write_dir(meta_writer_t *dm, dir_info_t *dir,
sqfs_dir_header_t hdr;
sqfs_dir_entry_t ent;
tree_node_t *c, *d;
+ uint16_t *diff_u16;
uint32_t offset;
uint64_t block;
+ int32_t diff;
c = dir->children;
dir->size = 0;
@@ -73,8 +75,9 @@ int meta_writer_write_dir(meta_writer_t *dm, dir_info_t *dir,
if ((d->inode_ref >> 16) != (c->inode_ref >> 16))
break;
- /* XXX: difference is actually signed */
- if ((d->inode_num - c->inode_num) > 0x7FFF)
+ diff = d->inode_num - c->inode_num;
+
+ if (diff > 32767 || diff < -32767)
break;
size += sizeof(ent) + strlen(c->name);
@@ -109,8 +112,12 @@ int meta_writer_write_dir(meta_writer_t *dm, dir_info_t *dir,
d = c;
for (i = 0; i < count; ++i) {
+ ent.inode_diff = c->inode_num - d->inode_num;
+
+ diff_u16 = (uint16_t *)&ent.inode_diff;
+ *diff_u16 = htole16(*diff_u16);
+
ent.offset = htole16(c->inode_ref & 0x0000FFFF);
- ent.inode_number = htole16(c->inode_num - d->inode_num);
ent.type = htole16(get_type(c->mode));
ent.size = htole16(strlen(c->name) - 1);
dir->size += sizeof(ent) + strlen(c->name);