Message ID | CAMRmmpL01PqR1nZPGhyDv1ECdWaBDrhVbx-9FH83x-3ez+M_pQ@mail.gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Oct 24, 2012 at 10:04:47AM +0800, Rock Lee wrote: > @@ -572,7 +576,7 @@ int btrfs_prepare_device(int fd, char *file, int > zero_end, u64 *block_count_ret, > discard_blocks(fd, 0, block_count); > } > > - ret = zero_dev_start(fd); > + ret = zero_dev_start(fd, block_count); > if (ret) { > fprintf(stderr, "failed to zero device start %d\n", ret); > exit(1); Please add a separate check for a minimal image size instead, right after 553 block_count = device_size(fd, &st); 554 if (block_count == 0) { 555 fprintf(stderr, "unable to find %s size\n", file); 556 exit(1); 557 } 558 if (max_block_count) 559 block_count = min(block_count, max_block_count); if (block_count < 2 MB ) { fprintf(stderr, "Image too small (less than 2MB)"); exit } thanks, david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Got it. 2012/10/25 David Sterba <dave@jikos.cz>: > On Wed, Oct 24, 2012 at 10:04:47AM +0800, Rock Lee wrote: >> @@ -572,7 +576,7 @@ int btrfs_prepare_device(int fd, char *file, int >> zero_end, u64 *block_count_ret, >> discard_blocks(fd, 0, block_count); >> } >> >> - ret = zero_dev_start(fd); >> + ret = zero_dev_start(fd, block_count); >> if (ret) { >> fprintf(stderr, "failed to zero device start %d\n", ret); >> exit(1); > > Please add a separate check for a minimal image size instead, right after > > 553 block_count = device_size(fd, &st); > 554 if (block_count == 0) { > 555 fprintf(stderr, "unable to find %s size\n", file); > 556 exit(1); > 557 } > 558 if (max_block_count) > 559 block_count = min(block_count, max_block_count); > > if (block_count < 2 MB ) { > fprintf(stderr, "Image too small (less than 2MB)"); > exit > } > > thanks, > david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/utils.c b/utils.c index 205e667..3c88d2e 100644 --- a/utils.c +++ b/utils.c @@ -441,7 +441,7 @@ static int zero_blocks(int fd, off_t start, size_t len) return ret; } -static int zero_dev_start(int fd) +static int zero_dev_start(int fd, u64 dev_size) { off_t start = 0; size_t len = 2 * 1024 * 1024; @@ -451,6 +451,10 @@ static int zero_dev_start(int fd) start = 1024; len -= 1024; #endif + + if (dev_size < len) + return -EIO; + return zero_blocks(fd, start, len); } @@ -572,7 +576,7 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret, discard_blocks(fd, 0, block_count); } - ret = zero_dev_start(fd); + ret = zero_dev_start(fd, block_count); if (ret) { fprintf(stderr, "failed to zero device start %d\n", ret);