diff options
author | Ken Sumrall <ksumrall@android.com> | 2011-01-14 18:33:06 -0800 |
---|---|---|
committer | Ken Sumrall <ksumrall@android.com> | 2011-01-14 18:33:06 -0800 |
commit | 435a8b61e925e3efb22fce08612efe210e83f791 (patch) | |
tree | 92d2a318cb995e7f0f62d01173c00f298919dadb /ext4_utils/ext4_utils.c | |
parent | f3df372c18c3baf9c0c9c93bce7622818ae6a8a1 (diff) | |
download | extras-435a8b61e925e3efb22fce08612efe210e83f791.tar.gz |
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
Diffstat (limited to 'ext4_utils/ext4_utils.c')
-rw-r--r-- | ext4_utils/ext4_utils.c | 20 |
1 files changed, 16 insertions, 4 deletions
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) |