/*
* mkfs.c - make a linux (minix) file-system.
*
- * (C) 1991 Linus Torvalds. This file may be redistributed as per
- * the Linux copyright.
+ * (C) 1991 Linus Torvalds.
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
*/
/*
* removed getopt based parser and added a hand rolled one.
*/
+//usage:#define mkfs_minix_trivial_usage
+//usage: "[-c | -l FILE] [-nXX] [-iXX] BLOCKDEV [KBYTES]"
+//usage:#define mkfs_minix_full_usage "\n\n"
+//usage: "Make a MINIX filesystem\n"
+//usage: "\n -c Check device for bad blocks"
+//usage: "\n -n [14|30] Maximum length of filenames"
+//usage: "\n -i INODES Number of inodes for the filesystem"
+//usage: "\n -l FILE Read bad blocks list from FILE"
+//usage: "\n -v Make version 2 filesystem"
+
#include "libbb.h"
#include <mntent.h>
static int minix_bit(const char* a, unsigned i)
{
- return a[i >> 3] & (1<<(i & 7));
+ return a[i >> 3] & (1<<(i & 7));
}
static void minix_setbit(char *a, unsigned i)
msg_eol = "seek to 0 failed";
xlseek(dev_fd, 0, SEEK_SET);
- msg_eol = "cannot clear boot sector";
+ msg_eol = "can't clear boot sector";
xwrite(dev_fd, G.boot_block_buffer, 512);
msg_eol = "seek to BLOCK_SIZE failed";
xlseek(dev_fd, BLOCK_SIZE, SEEK_SET);
- msg_eol = "cannot write superblock";
+ msg_eol = "can't write superblock";
xwrite(dev_fd, G.superblock_buffer, BLOCK_SIZE);
- msg_eol = "cannot write inode map";
+ msg_eol = "can't write inode map";
xwrite(dev_fd, G.inode_map, SB_IMAPS * BLOCK_SIZE);
- msg_eol = "cannot write zone map";
+ msg_eol = "can't write zone map";
xwrite(dev_fd, G.zone_map, SB_ZMAPS * BLOCK_SIZE);
- msg_eol = "cannot write inodes";
+ msg_eol = "can't write inodes";
xwrite(dev_fd, G.inode_buffer, INODE_BUFFER_SIZE);
msg_eol = "\n";
if (!G.currently_testing)
return;
printf("%d ...", G.currently_testing);
- fflush(stdout);
+ fflush_all();
}
static void check_blocks(void)
FILE *listfile;
unsigned long blockno;
- listfile = xfopen(filename, "r");
+ listfile = xfopen_for_read(filename);
while (!feof(listfile)) {
fscanf(listfile, "%ld\n", &blockno);
mark_zone(blockno);
int mkfs_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
{
- struct mntent *mp;
unsigned opt;
char *tmp;
struct stat statbuf;
G.total_blocks = 65535;
/* Check if it is mounted */
- mp = find_mount_point(G.device_name, NULL);
- if (mp && strcmp(G.device_name, mp->mnt_fsname) == 0)
- bb_error_msg_and_die("%s is mounted on %s; "
- "refusing to make a filesystem",
- G.device_name, mp->mnt_dir);
+ if (find_mount_point(G.device_name, 0))
+ bb_error_msg_and_die("can't format mounted filesystem");
xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
- if (fstat(dev_fd, &statbuf) < 0)
- bb_error_msg_and_die("cannot stat %s", G.device_name);
+ xfstat(dev_fd, &statbuf, G.device_name);
if (!S_ISBLK(statbuf.st_mode))
opt &= ~1; // clear -c (check)