summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-06-03 17:40:17 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-06-03 17:40:17 +0200
commita07a965967f3ba44a74528f607d514502b928b17 (patch)
tree2be5eceff020769be07866aa9076eb9a3f4a73be
parent5a8761b4991b5ef93322666fd1d3fbea05330511 (diff)
Cleanup: Add defines for minimum and maximum block size
This commit adds propper defines in the super block header and removes some of the hard coded constants. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/sqfs/super.h5
-rw-r--r--lib/sqfs/read_super.c5
-rw-r--r--lib/sqfs/super.c5
3 files changed, 12 insertions, 3 deletions
diff --git a/include/sqfs/super.h b/include/sqfs/super.h
index cdf8029..97ccef2 100644
--- a/include/sqfs/super.h
+++ b/include/sqfs/super.h
@@ -33,7 +33,10 @@
#define SQFS_VERSION_MAJOR 4
#define SQFS_VERSION_MINOR 0
#define SQFS_DEVBLK_SIZE 4096
-#define SQFS_DEFAULT_BLOCK_SIZE 131072
+
+#define SQFS_MIN_BLOCK_SIZE (4 * 1024)
+#define SQFS_MAX_BLOCK_SIZE (1024 * 1024)
+#define SQFS_DEFAULT_BLOCK_SIZE (128 * 1024)
/**
* @struct sqfs_super_t
diff --git a/lib/sqfs/read_super.c b/lib/sqfs/read_super.c
index 8b3f019..919e720 100644
--- a/lib/sqfs/read_super.c
+++ b/lib/sqfs/read_super.c
@@ -54,7 +54,10 @@ int sqfs_super_read(sqfs_super_t *super, sqfs_file_t *file)
if ((temp.block_size - 1) & temp.block_size)
return SQFS_ERROR_SUPER_BLOCK_SIZE;
- if (temp.block_size < 4096 || temp.block_size > (1 << 20))
+ if (temp.block_size < SQFS_MIN_BLOCK_SIZE)
+ return SQFS_ERROR_SUPER_BLOCK_SIZE;
+
+ if (temp.block_size > SQFS_MAX_BLOCK_SIZE)
return SQFS_ERROR_SUPER_BLOCK_SIZE;
if (temp.block_log < 12 || temp.block_log > 20)
diff --git a/lib/sqfs/super.c b/lib/sqfs/super.c
index 0257453..470c06a 100644
--- a/lib/sqfs/super.c
+++ b/lib/sqfs/super.c
@@ -20,7 +20,10 @@ int sqfs_super_init(sqfs_super_t *super, size_t block_size, sqfs_u32 mtime,
if (block_size & (block_size - 1))
return SQFS_ERROR_SUPER_BLOCK_SIZE;
- if (block_size < 4096 || block_size > (1 << 20))
+ if (block_size < SQFS_MIN_BLOCK_SIZE)
+ return SQFS_ERROR_SUPER_BLOCK_SIZE;
+
+ if (block_size > SQFS_MAX_BLOCK_SIZE)
return SQFS_ERROR_SUPER_BLOCK_SIZE;
memset(super, 0, sizeof(*super));