]> git.neil.brown.name Git - lafs-utils.git/commitdiff
mkfs: adjust segment size based on device size, and complain if it didn't work.
authorNeilBrown <neilb@suse.de>
Wed, 2 Mar 2011 23:17:47 +0000 (10:17 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 2 Mar 2011 23:17:47 +0000 (10:17 +1100)
Signed-off-by: NeilBrown <neilb@suse.de>
tools/mkfs.lafs.c

index f3a5157e26d49239c4ac99ec4797ddb669f8546b..f51cf0f8e9db3748d1c5140c53904a40ac95f64c 100644 (file)
@@ -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();