From: Barry Naujok Date: Fri, 29 Feb 2008 15:18:04 +0000 (+0000) Subject: Make sure device size is aligned to the specified sector size X-Git-Tag: v2.10.0~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22aa6603c6bc5b4458aa5b2b9b294391fbe304ad;p=thirdparty%2Fxfsprogs-dev.git Make sure device size is aligned to the specified sector size Merge of master-melb:xfs-cmds:30600a by kenmcd. Make sure the device size is aligned to the specified sector size --- diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 3621b5ca7..1913b9535 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -703,6 +703,7 @@ main( int sectoralign; int sectorlog; unsigned int sectorsize; + __uint64_t sector_mask; int slflag; int ssflag; __uint64_t tmp_agsize; @@ -1637,12 +1638,17 @@ main( * Ok, Linux only has a 1024-byte resolution on device _size_, * and the sizes below are in basic 512-byte blocks, * so if we have (size % 2), on any partition, we can't get - * to the last 512 bytes. Just chop it down by a block. + * to the last 512 bytes. The same issue exists for larger + * sector sizes - we cannot write past the last sector. + * + * So, we reduce the size (in basic blocks) to a perfect + * multiple of the sector size, or 1024, whichever is larger. */ - xi.dsize -= (xi.dsize % 2); - xi.rtsize -= (xi.rtsize % 2); - xi.logBBsize -= (xi.logBBsize % 2); + sector_mask = (__uint64_t)-1 << (MAX(sectorlog, 10) - BBSHIFT); + xi.dsize &= sector_mask; + xi.rtsize &= sector_mask; + xi.logBBsize &= (__uint64_t)-1 << (MAX(lsectorlog, 10) - BBSHIFT); if (!force_overwrite) { if (check_overwrite(dfile) ||