summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Tsai <Ed.Tsai@mediatek.com>2021-01-19 17:36:57 +0800
committerElliott Hughes <enh@google.com>2021-01-20 14:09:49 -0800
commit7dd1b1bd08f55066e1b2f83dc03fe8b937cb6e09 (patch)
tree95ea34e58fdf7f7391974c2697fef829f2456c80
parent52a1f477401229a9cace451885c5ce35553b400a (diff)
downloadnewfs_msdos-7dd1b1bd08f55066e1b2f83dc03fe8b937cb6e09.tar.gz
Fixes the partition size for FAT.
BLKGETSIZE is in units of 512 bytes rather than bytes or the sector size returned by BLKSSZGET. Use BLKGETSIZE64 instead, to get the block size in bytes. Also rename block_size to make it clearer that it's actually the size of the whole block device. Change-Id: I9eb6cd4394722f8624c6ac6368b6da31583f026e Test: Create an new filesystem by newfs_msdos
-rw-r--r--mkfs_msdos.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/mkfs_msdos.c b/mkfs_msdos.c
index 0ef30f2..878ff8f 100644
--- a/mkfs_msdos.c
+++ b/mkfs_msdos.c
@@ -847,16 +847,17 @@ static int getdiskinfo(int fd, const char *fname, const char *dtype,
if (ckgeom(fname, bpb->bpbBytesPerSec, "bytes/sector") == -1) return -1;
- u_long block_size;
- if (ioctl(fd, BLKGETSIZE, &block_size)) {
- err(1, "ioctl(BLKGETSIZE) failed");
+ u_long device_size;
+ if (ioctl(fd, BLKGETSIZE64, &device_size)) {
+ err(1, "ioctl(BLKGETSIZE64) failed");
}
- if (block_size > UINT32_MAX) {
- errx(1, "block size too large: %lu", block_size);
+ u_long sectors = device_size/bpb->bpbBytesPerSec;
+ if (sectors > UINT32_MAX) {
+ errx(1, "too many sectors: %lu (%lu byte device, %u bytes/sector)",
+ sectors, device_size, bpb->bpbBytesPerSec);
}
-
- bpb->bpbHugeSectors = (u_int)block_size;
+ bpb->bpbHugeSectors = sectors;
bpb->bpbSecPerTrack = 63;
if (ckgeom(fname, bpb->bpbSecPerTrack, "sectors/track") == -1) return -1;