From: NeilBrown Date: Wed, 2 Mar 2011 23:17:47 +0000 (+1100) Subject: mkfs: adjust segment size based on device size, and complain if it didn't work. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=9b5b4c1bf1132acd2ffefd5dcf0b531d2f58019a;p=lafs-utils.git mkfs: adjust segment size based on device size, and complain if it didn't work. Signed-off-by: NeilBrown --- diff --git a/tools/mkfs.lafs.c b/tools/mkfs.lafs.c index f3a5157..f51cf0f 100644 --- a/tools/mkfs.lafs.c +++ b/tools/mkfs.lafs.c @@ -169,7 +169,8 @@ int is_pow2(long num) } -void validate_parameters(long *block_bytes, long *segment_bytes, long *stride_bytes, int *width) +void validate_parameters(long *block_bytes, long *segment_bytes, long *stride_bytes, + int *width, long long device_bytes) { if (*block_bytes == 0) @@ -207,6 +208,11 @@ void validate_parameters(long *block_bytes, long *segment_bytes, long *stride_by long blocks = 65536 / *width; blocks *= *width; seg = *block_bytes * blocks; + if (seg * 17 > device_bytes) { + blocks = device_bytes / 16 / *block_bytes / *width; + blocks *= *width; + seg = *block_bytes * blocks; + } if (*stride_bytes < seg) { seg /= *stride_bytes; seg *= *stride_bytes; @@ -219,6 +225,16 @@ void validate_parameters(long *block_bytes, long *segment_bytes, long *stride_by *segment_bytes = seg; } + if (*segment_bytes * 8 > device_bytes) { + fprintf(stderr, "lafs.mkfs: segment size too large for device.\n"); + exit(2); + } + + if (*segment_bytes < *block_bytes * 8) { + fprintf(stderr, "lafs.mkfs: segment must hold at least 8 blocks.\n"); + exit(2); + } + if (*segment_bytes % *block_bytes) { fprintf(stderr, "lafs.mkfs: segment size must be a multiple of block size\n"); exit(2); @@ -343,7 +359,8 @@ int main(int argc, char *argv[]) dev_fd = open_device(devname, &device_bytes); /* Validate parameters */ - validate_parameters(&block_bytes, &segment_bytes, &stride_bytes, &width); + validate_parameters(&block_bytes, &segment_bytes, &stride_bytes, &width, + device_bytes); /* Create filesystem handle */ lafs = lafs_alloc();