From: Ken Sumrall Date: Sat, 15 Jan 2011 02:33:06 +0000 (-0800) Subject: Add the ability to specify a reserved space size when making filesystems. X-Git-Tag: android-x86-4.4-r1~228^2~6 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=435a8b61e925e3efb22fce08612efe210e83f791;hp=f3df372c18c3baf9c0c9c93bce7622818ae6a8a1;p=android-x86%2Fsystem-extras.git Add the ability to specify a reserved space size when making filesystems. If you specify a negative length when making a filesystem, then the filesystem size is the size of the partiton (or image file) minus the absolute value of the negative length specified. Change-Id: I53e3b6de2ea692f4678682c3f49ff36429d9ad31 --- diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.c index 1804e4bd..bdf2a749 100644 --- a/ext4_utils/ext4_utils.c +++ b/ext4_utils/ext4_utils.c @@ -103,7 +103,7 @@ int count_sparse_chunks() for_each_data_block(count_data_block, count_file_block, &count_chunks); - if (count_chunks.cur_ptr != info.len) + if (count_chunks.cur_ptr != (u64) info.len) count_chunks.chunks++; return count_chunks.chunks; @@ -442,17 +442,29 @@ u64 get_file_size(const char *filename) { struct stat buf; int ret; + u64 reserve_len = 0; + s64 computed_size; ret = stat(filename, &buf); if (ret) return 0; + if (info.len < 0) + reserve_len = -info.len; + if (S_ISREG(buf.st_mode)) - return buf.st_size; + computed_size = buf.st_size - reserve_len; else if (S_ISBLK(buf.st_mode)) - return get_block_device_size(filename); + computed_size = get_block_device_size(filename) - reserve_len; else - return 0; + computed_size = 0; + + if (computed_size < 0) { + warn("Computed filesystem size less than 0"); + computed_size = 0; + } + + return computed_size; } u64 parse_num(const char *arg) diff --git a/ext4_utils/ext4_utils.h b/ext4_utils/ext4_utils.h index 8f3a64d7..b770294e 100644 --- a/ext4_utils/ext4_utils.h +++ b/ext4_utils/ext4_utils.h @@ -76,6 +76,7 @@ extern int force; #define __u8 u8 typedef unsigned long long u64; +typedef signed long long s64; typedef unsigned int u32; typedef unsigned short int u16; typedef unsigned char u8; @@ -94,7 +95,9 @@ struct ext2_group_desc { }; struct fs_info { - u64 len; + s64 len; /* If set to 0, ask the block device for the size, + * if less than 0, reserve that much space at the + * end of the partition, else use the size given. */ u32 block_size; u32 blocks_per_group; u32 inodes_per_group; diff --git a/ext4_utils/make_ext4fs.c b/ext4_utils/make_ext4fs.c index 3fee1331..a366a37c 100644 --- a/ext4_utils/make_ext4fs.c +++ b/ext4_utils/make_ext4fs.c @@ -249,7 +249,7 @@ int make_ext4fs(const char *filename, const char *directory, u32 root_inode_num; u16 root_mode; - if (info.len == 0) + if (info.len <= 0) info.len = get_file_size(filename); if (info.len <= 0) { diff --git a/ext4_utils/output_file.c b/ext4_utils/output_file.c index 66550d56..c1997b65 100644 --- a/ext4_utils/output_file.c +++ b/ext4_utils/output_file.c @@ -333,7 +333,7 @@ void pad_output_file(struct output_file *out, u64 len) { int ret; - if (len > info.len) { + if (len > (u64) info.len) { error("attempted to pad file %llu bytes past end of filesystem", len - info.len); return; @@ -370,7 +370,7 @@ void write_data_block(struct output_file *out, u64 off, u8 *data, int len) { int ret; - if (off + len > info.len) { + if (off + len > (u64) info.len) { error("attempted to write block %llu past end of filesystem", off + len - info.len); return; @@ -397,7 +397,7 @@ void write_data_file(struct output_file *out, u64 off, const char *file, off64_t aligned_offset; int aligned_diff; - if (off + len >= info.len) { + if (off + len >= (u64) info.len) { error("attempted to write block %llu past end of filesystem", off + len - info.len); return;