}
-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)
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;
*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);
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();