X-Gnus-Coding-System: -*- coding: utf-8; -*- 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(-) Index: util-linux-ng-2.13.1/disk-utils/mkfs.minix.c =================================================================== --- util-linux-ng-2.13.1.orig/disk-utils/mkfs.minix.c +++ util-linux-ng-2.13.1/disk-utils/mkfs.minix.c @@ -78,6 +78,7 @@ #ifndef BLKGETSIZE #define BLKGETSIZE _IO(0x12,96) /* return device size */ #endif +#define BLKSSZGET _IO(0x12,104)/* get block device sector size */ #ifndef __GNUC__ #error "needs gcc for the bitop-__asm__'s" @@ -238,6 +239,16 @@ get_size(const char *file) { return size; } +/* get hardware sector size */ +int +blkdev_get_sector_size(int fd, int *sector_size) +{ + if (ioctl(fd, BLKSSZGET, sector_size) >= 0) + return 0; + + return -1; +} + static void write_tables(void) { /* Mark the super block valid. */ @@ -707,9 +718,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)