summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ufs/main.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/ufs/main.c b/ufs/main.c
index 8c6114ed..e47586e7 100644
--- a/ufs/main.c
+++ b/ufs/main.c
@@ -112,6 +112,9 @@ main (int argc, char **argv)
char *devname;
mach_port_t bootstrap;
error_t err;
+ int sizes[DEV_GET_SIZE_COUNT];
+ u_int sizescnt = 2;
+
save_argv = argv;
@@ -133,9 +136,31 @@ main (int argc, char **argv)
(diskfs_readonly ? 0 : D_WRITE) | D_READ,
devname, &ufs_device);
assert (!err);
+
+ /* Check to make sure device sector size is reasonable. */
+ err = device_get_status (ufs_device, DEV_GET_SIZE, sizes, &sizescnt);
+ assert (sizescnt == DEV_GET_SIZE_COUNT);
+ if (sizes[DEV_GET_SIZE_RECORD_SIZE] != DEV_BSIZE)
+ {
+ fprintf (stderr, "Bad device record size %d (should be %d)\n",
+ sizes[DEV_GET_SIZE_RECORD_SIZE], DEV_BSIZE);
+ exit (1);
+ }
get_hypermetadata ();
+ /* Check to make sure device size is big enough. */
+ if (sizes[DEV_GET_SIZE_DEVICE_SIZE] != 0)
+ if (sizes[DEV_GET_SIZE_DEVICE_SIZE] < sblock->fs_size * sblock->fs_fsize)
+ {
+ fprintf (stderr,
+ "Disk size %d less than necessary "
+ "(superblock says we need %ld)\n",
+ sizes[DEV_GET_SIZE_DEVICE_SIZE],
+ sblock->fs_size * sblock->fs_fsize);
+ exit (1);
+ }
+
if (!diskfs_readonly)
{
sblock->fs_clean = 0;