From a28a3ad26de38d13eadd63836494e72cba85c260 Mon Sep 17 00:00:00 2001 From: Matthias Koenig Date: Tue, 13 Nov 2007 16:28:38 +0100 Subject: [PATCH] mkfs.minix: add sectorsize check Minix filesystem until version 2 has a fixed blocksize of 1024 bytes. If you try to create a filsystem on a device with a physical sectorsize larger than 1024 bytes, this resulting minix fs cannot be mounted, because the physical sectorsize must be smaller than the filesystem blocksize. This patch adds a check for this and will refuse to create a filesystem if the sectorsize is bigger than the blocksize. Signed-off-by: Matthias Koenig --- disk-utils/Makefile.am | 4 +++- disk-utils/mkfs.minix.c | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am index eadc89d6d..063a5516f 100644 --- a/disk-utils/Makefile.am +++ b/disk-utils/Makefile.am @@ -1,11 +1,13 @@ include $(top_srcdir)/config/include-Makefile.am +utils_common = ../lib/linux_version.c ../lib/blkdev.c + man_MANS = blockdev.8 isosize.8 mkfs.8 mkswap.8 \ fsck.minix.8 mkfs.minix.8 mkfs.bfs.8 sbin_PROGRAMS = mkfs mkswap blockdev fsck.minix mkfs.minix mkfs.bfs fsck_minix_SOURCES = fsck.minix.c bitops.h minix.h -mkfs_minix_SOURCES = mkfs.minix.c bitops.h minix.h +mkfs_minix_SOURCES = mkfs.minix.c bitops.h minix.h $(utils_common) mkfs_bfs_SOURCES = mkfs.bfs.c mkswap_SOURCES = mkswap.c swapheader.h ../lib/linux_version.c ../lib/blkdev.c blockdev_SOURCES = blockdev.c ../lib/linux_version.c ../lib/blkdev.c diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c index 7cd0958fb..6fc2893ea 100644 --- a/disk-utils/mkfs.minix.c +++ b/disk-utils/mkfs.minix.c @@ -72,6 +72,7 @@ #include #include +#include "blkdev.h" #include "minix.h" #include "nls.h" @@ -710,9 +711,16 @@ main(int argc, char ** argv) { DEV = open(device_name,O_RDWR); if (DEV<0) die(_("unable to open %s")); - if (!S_ISBLK(statbuf.st_mode)) + if (S_ISBLK(statbuf.st_mode)) { + int sectorsize; + + if (blkdev_get_sector_size(DEV, §orsize) == -1) + die(_("cannot determine sector size for %s")); + if (BLOCK_SIZE < sectorsize) + die(_("block size smaller than physical sector size of %s")); + } else if (!S_ISBLK(statbuf.st_mode)) { check=0; - else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) + } else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) die(_("will not try to make filesystem on '%s'")); setup_tables(); if (check)