mkfs.vfat: make it possible to create tiny 5KB images
function old new delta mkfs_vfat_main 1539 1586 +47 mkswap_main 253 256 +3 mkfs_minix_main 2575 2578 +3 mkfs_ext2_main 2297 2299 +2 .rodata 104946 104913 -33 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 55/-33) Total: 22 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
1 parent
d03387ebf3
commit
4f986c0f9d
8 files changed
+35
-13
No files matched your search
+1
-1
@@ -698,7 +698,7 @@ off_t fdlength(int fd) FAST_FUNC;
|
||||
uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
|
||||
const char *override,
|
||||
unsigned override_units,
|
||||
int extend);
|
||||
unsigned minsize_extend);
|
||||
|
||||
void xpipe(int *filedes) FAST_FUNC;
|
||||
/* In this form code with pipes is much more readable */
|
||||
|
||||
+6
-5
@@ -11,10 +11,12 @@
|
||||
uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
|
||||
const char *override,
|
||||
unsigned override_units,
|
||||
int extend)
|
||||
unsigned minsize_extend)
|
||||
{
|
||||
uoff_t result;
|
||||
#define ULL(x) ((unsigned long long)(x))
|
||||
uoff_t result;
|
||||
#define extend ((minsize_extend) & 1)
|
||||
#define minsize ((minsize_extend) & ~1u)
|
||||
|
||||
if (override) {
|
||||
result = XATOOFF(override);
|
||||
@@ -47,10 +49,9 @@ uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
|
||||
// $ dd if=/dev/zero of=foo count=1 bs=1024
|
||||
// $ mkswap foo
|
||||
// Setting up swapspace version 1, size = 18446744073709548544 bytes
|
||||
//
|
||||
// Picked 16k arbitrarily:
|
||||
if (result < 16*1024) {
|
||||
if (result < minsize) {
|
||||
insane:
|
||||
/* common message */
|
||||
bb_error_msg_and_die("image is too small: %lld bytes", ULL(result));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
# testing "test name" "options" "expected result" "file input" "stdin"
|
||||
|
||||
optional BLKID
|
||||
# This creates 32MB FAT32 image, and tests that blkid does recognize it.
|
||||
# This is technically incorrect: at this size, image should be FAT16
|
||||
# according to Microsoft rules (it says that FAT12/16/32-ness of the volume
|
||||
@@ -18,4 +19,10 @@ testing "mkfs.vfat 32MB image" \
|
||||
' \
|
||||
"" ""
|
||||
|
||||
testing "mkfs.vfat 5KB image" \
|
||||
"mkfs.vfat input 5; blkid input | sed 's/\"....-....\"/\"xxxx-xxxx\"/' " \
|
||||
'input: UUID="xxxx-xxxx" TYPE="vfat"
|
||||
' \
|
||||
"" ""
|
||||
|
||||
exit $FAILCOUNT
|
||||
@@ -268,7 +268,9 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_simple_error_msg_and_die("can't format mounted filesystem");
|
||||
|
||||
// get size in kbytes
|
||||
kilobytes = get_volume_size_in_bytes(fd, argv[1], 1024, /*extend:*/ !(option_mask32 & OPT_n)) / 1024;
|
||||
kilobytes = get_volume_size_in_bytes(fd, argv[1], 1024,
|
||||
/*minsize:*/ 16*1024 | /*extend:*/ !(option_mask32 & OPT_n)
|
||||
) / 1024;
|
||||
|
||||
bytes_per_inode = 16384;
|
||||
if (kilobytes < 512*1024)
|
||||
|
||||
@@ -657,7 +657,9 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
|
||||
|
||||
G.total_blocks = get_volume_size_in_bytes(dev_fd, argv[1], 1024, /*extend:*/ 1) / 1024;
|
||||
G.total_blocks = get_volume_size_in_bytes(dev_fd, argv[1], 1024,
|
||||
/*minsize:*/ 16*1024 | /*extend:*/ 1
|
||||
) / 1024;
|
||||
|
||||
if (G.total_blocks < 10)
|
||||
bb_simple_error_msg_and_die("must have at least 10 blocks");
|
||||
|
||||
@@ -180,7 +180,9 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_simple_error_msg_and_die("can't format mounted filesystem");
|
||||
|
||||
// open the device, get size in blocks
|
||||
blocks = get_volume_size_in_bytes(fd, argv[1], blocksize, /*extend:*/ 1) / blocksize;
|
||||
blocks = get_volume_size_in_bytes(fd, argv[1], blocksize,
|
||||
/*minsize:*/ 16*1024 | /*extend:*/ 1
|
||||
) / blocksize;
|
||||
|
||||
// block number sanity check
|
||||
// we have a limit: skipped area, super block, journal and root block
|
||||
|
||||
+10
-3
@@ -340,7 +340,9 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_error_msg("for this device sector size is %u", min_bytes_per_sect);
|
||||
}
|
||||
}
|
||||
volume_size_bytes = get_volume_size_in_bytes(dev, argv[1], 1024, /*extend:*/ 1);
|
||||
volume_size_bytes = get_volume_size_in_bytes(dev, argv[1], 1024,
|
||||
/*minsize:*/ 6 * bytes_per_sect | /*extend:*/ 1
|
||||
);
|
||||
volume_size_sect = volume_size_bytes / bytes_per_sect;
|
||||
|
||||
//
|
||||
@@ -436,10 +438,15 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
|
||||
// Calculate number of clusters, sectors/cluster, sectors/FAT
|
||||
// (an initial guess for sect_per_clust should already be set)
|
||||
//
|
||||
// "mkdosfs -v -F 32 image5k 5" is the minimum:
|
||||
// "mkdosfs -v -F 32 image5k 5" is the minimum for now:
|
||||
// 2 sectors for FATs and 2 data sectors
|
||||
// and Linux can successfully mount it.
|
||||
//TODO: would 3 kbyte image mount? 1 boot, 1 fsinfo, 1*2 FAT, 1*2 data area
|
||||
//needs support for -b0 -R2
|
||||
if ((off_t)(volume_size_sect - reserved_sect) < 4)
|
||||
bb_simple_error_msg_and_die("the image is too small for FAT32");
|
||||
/* common message */
|
||||
bb_error_msg_and_die("image is too small: %lld bytes",
|
||||
(unsigned long long)volume_size_sect * bytes_per_sect);
|
||||
|
||||
// From now on we know it fits 32 bits
|
||||
#define volume_size_sect ((uint32_t)volume_size_sect)
|
||||
|
||||
+2
-1
@@ -124,8 +124,9 @@ int mkswap_main(int argc UNUSED_PARAM, char **argv)
|
||||
fd = xopen(argv[0], O_RDWR);
|
||||
|
||||
/* Figure out how big the device is */
|
||||
len = get_volume_size_in_bytes(fd, argv[1], 1024, /*extend:*/ 1);
|
||||
pagesize = bb_getpagesize();
|
||||
len = get_volume_size_in_bytes(fd, argv[1], 1024,
|
||||
/*minsize:*/ 2*pagesize | /*extend:*/ 1);
|
||||
len -= pagesize;
|
||||
|
||||
/* Announce our intentions */
|
||||
|
||||
Reference in new issue
Block a user