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;
{
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)
#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;
};
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;
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) {
{
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;
{
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;
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;