aboutsummaryrefslogtreecommitdiff
path: root/include/sqfs/dir_writer.h
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-07-21 09:41:47 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-07-21 09:56:31 +0200
commit248494992442fbde7eb6ca3979a778d82fa86016 (patch)
tree3ba8d5100aef7cf0d1f1aeae9f306fd5e6053503 /include/sqfs/dir_writer.h
parent5333fbe46bcbf70b4888bcc6655681f2cd0f161b (diff)
Fix libsquashfs directory writer size accounting
The squashfs readdir() implementation in the Linux kernel returns non-existing "." and ".." entries for offsets 0 and 1, and after that reads from disk. For convenience, it was decided to store an off-by-3 value on disk instead of doing complex primary school math to adjust for this. This didn't show up until now, because the kernel implementation trusts the value from the directory header more than the actual size in the inode and happily reads 3 more than the inode would allow it to. This only showed up with 7-zip which subtracts 3 from the size and expects the result to be exact and bails if the directory headers suggest otherwise. And yes, I did consider making a "Holy Hand Granade of Antioch" reference, but consciously decided not to. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/sqfs/dir_writer.h')
-rw-r--r--include/sqfs/dir_writer.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/include/sqfs/dir_writer.h b/include/sqfs/dir_writer.h
index 9615a41..7b35fe0 100644
--- a/include/sqfs/dir_writer.h
+++ b/include/sqfs/dir_writer.h
@@ -161,6 +161,11 @@ SQFS_API int sqfs_dir_writer_end(sqfs_dir_writer_t *writer);
* size of the directory listing that is required for the directory inodes.
* And also to determine which kind of directory inode to create.
*
+ * Note that this size is only what was written to disk. SquashFS directory
+ * inodes need you to add 3 to this value, to account for "." and ".." entries
+ * which are not actually stored on disk. The @ref sqfs_dir_writer_create_inode
+ * function takes this into account and adds the 3 internally.
+ *
* @param writer A pointer to a directory writer object.
*
* @return The size of the entire, uncompressed listing in bytes.
@@ -226,6 +231,8 @@ SQFS_API size_t sqfs_dir_writer_get_index_size(const sqfs_dir_writer_t *writer);
* convenience function called @ref sqfs_dir_writer_write_index to write the
* index meta data after writing the inode itself.
*
+ * @note The size is already adjusted for the required off-by-3 value.
+ *
* @param writer A pointer to a directory writer object.
* @param hlinks The number of hard links pointing to the directory.
* @param xattr If set to something other than 0xFFFFFFFF, an extended