* [PATCH 00/12] pull: minix updates
@ 2015-06-24 8:15 Sami Kerola
2015-06-24 8:15 ` [PATCH 01/12] mkfs.minix: increase maximum minix v2 and v3 file system sizes Sami Kerola
` (12 more replies)
0 siblings, 13 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Hi all,
The patch 0001 is not re-submitted. It is the change Joshua Hudson sent
to mail list couple days ago. The rest are new changes, and they are
also available from my remote branch 'minix'.
The following changes since commit 4b7248c0296e94fc1d85c22bbad5f7b943689971:
libfdisk: add GPT GUIDs for ARMs (2015-06-22 11:56:43 +0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git minix
for you to fetch changes up to d60409ed753acb02fa1ea382e0c638d378653448:
docs: make fsck.minix(8) more pretty (2015-06-24 09:10:20 +0100)
Joshua Hudson (1):
mkfs.minix: increase maximum minix v2 and v3 file system sizes
Sami Kerola (11):
mkfs.minix: introduce long options to the command
mkfs.minix: use is_mounted() from libcommon
mkfs.minix: remove unuseful code
mkfs.minix: add fs_control structure, and remove most global variables
mkfs.minix: check user input carefully
mkfs.minix: check requested blocks will not exceed available on device
mkfs.minix: refactor root block content creation
fsck.minix: rename device file descriptor variable
fsck.minix: add minix v3 support
fsck.minix: introduce long options to the command
docs: make fsck.minix(8) more pretty
bash-completion/fsck.minix | 12 +-
bash-completion/mkfs.minix | 16 +-
disk-utils/fsck.minix.8 | 159 +++++++-----
disk-utils/fsck.minix.c | 223 ++++++++--------
disk-utils/mkfs.minix.8 | 37 +--
disk-utils/mkfs.minix.c | 623 +++++++++++++++++++++++----------------------
6 files changed, 567 insertions(+), 503 deletions(-)
--
2.4.4
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 01/12] mkfs.minix: increase maximum minix v2 and v3 file system sizes
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 02/12] mkfs.minix: introduce long options to the command Sami Kerola
` (11 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Joshua Hudson
From: Joshua Hudson <joshudson@gmail.com>
mkfs.minix misbehaves when attempting to create a large v2 or v3
filesystem. I finally traced it down to attempting to create too many
inodes so that the first zone is past 65535 blocks in. This obviously
doesn't work as the on-disk superblock says this is a 16 bit integer.
I wrote a patch that catches this, clamps to the absolute v2/v3 limit
(like it already does for v1), and sets the blocks per inode to a more
reasonable ratio when exceeding half a gigabyte. Having a half-gig
filesystem with most files being smaller than 3k isn't really reasonable.
I suppose if you don't want to adjust inode sizes automatically you could
take that part out, and it will just crab sooner.
Given the non-attention in the code, I suspect nobody ever had cause to
try such a big minix filesystem. Well I have my reasons involving some
deeply embedded work where ext2 would place too much strain on the
hardware.
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Joshua Hudson <joshudson@gmail.com>
---
disk-utils/mkfs.minix.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index c84aed2..564f2b4 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -49,6 +49,9 @@
* 06.29.11 - Overall cleanups for util-linux and v3 support
* Davidlohr Bueso <dave@gnu.org>
*
+ * 06.20.15 - Do not infinite loop or crash on large devices
+ * Joshua Hudson <joshudson@gmail.com>
+ *
* Usage: mkfs [-c | -l filename ] [-12v3] [-nXX] [-iXX] device [size-in-blocks]
*
* -c for readablility checking (SLOW!)
@@ -504,9 +507,16 @@ static void setup_tables(void) {
super_set_nzones();
zones = get_nzones();
- /* some magic nrs: 1 inode / 3 blocks */
- if ( req_nr_inodes == 0 )
- inodes = BLOCKS/3;
+ /* some magic nrs: 1 inode / 3 blocks for smaller filesystems,
+ * for one inode / 16 blocks for large ones. mkfs will eventually
+ * crab about too far when getting close to the maximum size. */
+ if (req_nr_inodes == 0)
+ if (2048 * 1024 < BLOCKS) /* 2GB */
+ inodes = BLOCKS / 16;
+ else if (512 * 1024 < BLOCKS) /* 0.5GB */
+ inodes = BLOCKS / 8;
+ else
+ inodes = BLOCKS / 3;
else
inodes = req_nr_inodes;
/* Round up inode count to fill block size */
@@ -524,8 +534,13 @@ static void setup_tables(void) {
if (inodes > MINIX_MAX_INODES)
inodes = MINIX_MAX_INODES;
}
-
super_set_map_blocks(inodes);
+ if (MINIX_MAX_INODES < first_zone_data())
+ errx(MKFS_EX_ERROR,
+ _("First data block at %jd, which is too far (max %d).\n"
+ "Try specifying fewer inodes by passing -i <inodes>"),
+ first_zone_data(),
+ MINIX_MAX_INODES);
imaps = get_nimaps();
zmaps = get_nzmaps();
@@ -793,6 +808,8 @@ int main(int argc, char ** argv) {
} else /* fs_version == 1 */
if (BLOCKS > MINIX_MAX_INODES)
BLOCKS = MINIX_MAX_INODES;
+ if (BLOCKS > MINIX_MAX_INODES * BITS_PER_BLOCK)
+ BLOCKS = MINIX_MAX_INODES * BITS_PER_BLOCK; /* Utter maximum: Clip. */
setup_tables();
if (check)
check_blocks();
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 02/12] mkfs.minix: introduce long options to the command
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
2015-06-24 8:15 ` [PATCH 01/12] mkfs.minix: increase maximum minix v2 and v3 file system sizes Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 03/12] mkfs.minix: use is_mounted() from libcommon Sami Kerola
` (10 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
bash-completion/mkfs.minix | 16 +++----
disk-utils/mkfs.minix.8 | 28 +++++++-----
disk-utils/mkfs.minix.c | 107 +++++++++++++++++++++++----------------------
3 files changed, 78 insertions(+), 73 deletions(-)
diff --git a/bash-completion/mkfs.minix b/bash-completion/mkfs.minix
index 3a3602e..e725fd6 100644
--- a/bash-completion/mkfs.minix
+++ b/bash-completion/mkfs.minix
@@ -5,25 +5,23 @@ _mkfs.minix_module()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
- '-i')
+ '-i'|'--inodes')
COMPREPLY=( $(compgen -W "inodes" -- $cur) )
return 0
;;
- '-l')
- COMPREPLY=( $(compgen -W "badblocks-file" -- $cur) )
+ '-l'|'--badblocks')
+ compopt -o filenames
+ COMPREPLY=( $(compgen -f -- $cur) )
return 0
;;
- '-n')
- COMPREPLY=( $(compgen -W "14 30" -- $cur) )
- return 0
- ;;
- '-V'|'--version')
+ '-n'|'--namelength')
+ COMPREPLY=( $(compgen -W "14 30 60" -- $cur) )
return 0
;;
esac
case $cur in
-*)
- OPTS="-c -i -l -n -1 -2 -3"
+ OPTS="--namelength --inodes --check --badblocks --help --version -1 -2 -3"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
diff --git a/disk-utils/mkfs.minix.8 b/disk-utils/mkfs.minix.8
index 2deeaf1..e46a768 100644
--- a/disk-utils/mkfs.minix.8
+++ b/disk-utils/mkfs.minix.8
@@ -1,17 +1,11 @@
.\" Copyright 1992, 1993, 1994 Rickard E. Faith (faith@cs.unc.edu)
.\" May be freely distributed.
-.TH MKFS.MINIX 8 "June 2011" "util-linux" "System Administration"
+.TH MKFS.MINIX 8 "June 2015" "util-linux" "System Administration"
.SH NAME
mkfs.minix \- make a Minix filesystem
.SH SYNOPSIS
.B mkfs.minix
-.RB [ \-c | \-l
-.IR filename ]
-.RB [ \-n
-.IR namelength ]
-.RB [ \-i
-.IR inodecount ]
-.RB [ \-v ]
+[options]
.I device
.RI [ size-in-blocks ]
.SH DESCRIPTION
@@ -31,6 +25,9 @@ is usually of the following form:
.RE
.fi
+The device may be a block device or a image file of one, but this is not
+enforced. Expect not much fun on a character device :-).
+.PP
The
.I size-in-blocks
parameter is the desired size of the file system, in blocks.
@@ -40,20 +37,20 @@ Only block counts strictly greater than 10 and strictly less than
65536 are allowed.
.SH OPTIONS
.TP
-.B \-c
+\fB\-c\fR, \fB\-\-check\fR
Check the device for bad blocks before creating the filesystem. If any
are found, the count is printed.
.TP
-.BI \-n " namelength"
+\fB\-n\fR, \fB\-\-namelength\fR \fIlength\fR
Specify the maximum length of filenames.
Currently, the only allowable values are 14 and 30.
The default is 30. Note that kernels older than 0.99p7
only accept namelength 14.
.TP
-.BI \-i " inodecount"
+\fB\-i\fR, \fB\-\-inodes\fR \fInumber\fR
Specify the number of inodes for the filesystem.
.TP
-.BI \-l " filename"
+\fB\-l\fR, \fB\-\-badblocks\fR \fIfilename\fR
Read the list of bad blocks from
.IR filename .
The file has one bad-block number per line. The count of bad blocks read
@@ -67,6 +64,13 @@ Make a Minix version 2 filesystem.
.TP
.B \-3
Make a Minix version 3 filesystem.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Display version information and exit. The long option cannot be combined
+with other options.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display help text and exit.
.SH "EXIT CODES"
The exit code returned by
.B mkfs.minix
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index 564f2b4..9e4212f 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -52,18 +52,6 @@
* 06.20.15 - Do not infinite loop or crash on large devices
* Joshua Hudson <joshudson@gmail.com>
*
- * Usage: mkfs [-c | -l filename ] [-12v3] [-nXX] [-iXX] device [size-in-blocks]
- *
- * -c for readablility checking (SLOW!)
- * -l for getting a list of bad blocks from a file.
- * -n for namelength (currently the kernel only uses 14 or 30)
- * -i for number of inodes
- * -1 for v1 filesystem
- * -2,-v for v2 filesystem
- * -3 for v3 filesystem
- *
- * The device may be a block device or a image of one, but this isn't
- * enforced (but it's not much fun on a character device :-).
*/
#include <stdio.h>
@@ -109,7 +97,6 @@ static char *inode_buffer = NULL;
#define Inode (((struct minix_inode *) inode_buffer) - 1)
#define Inode2 (((struct minix2_inode *) inode_buffer) - 1)
-static char *program_name = "mkfs";
static char *device_name;
static int DEV = -1;
static unsigned long long BLOCKS;
@@ -146,11 +133,23 @@ static char *zone_map;
#define mark_zone(x) (setbit(zone_map,(x)-get_first_zone()+1))
#define unmark_zone(x) (clrbit(zone_map,(x)-get_first_zone()+1))
-
-static void __attribute__((__noreturn__))
-usage(void) {
- errx(MKFS_EX_USAGE, _("Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]"),
- program_name);
+static void __attribute__((__noreturn__)) usage(FILE *out)
+{
+ fputs(USAGE_HEADER, out);
+ fprintf(out, _(" %s [options] /dev/name [blocks]\n"), program_invocation_short_name);
+ fputs(USAGE_OPTIONS, out);
+ fputs(_(" -1 use Minix version 1\n"), out);
+ fputs(_(" -2, -v use Minix version 2\n"), out);
+ fputs(_(" -3 use Minix version 3\n"), out);
+ fputs(_(" -n, --namelength <num> maximum length of filenames\n"), out);
+ fputs(_(" -i, --inodes <num> number of inodes for the filesystem\n"), out);
+ fputs(_(" -c, --check check the device for bad blocks\n"), out);
+ fputs(_(" -l, --badblocks <file> list of bad blocks from file\n"), out);
+ fputs(USAGE_SEPARATOR, out);
+ fputs(USAGE_HELP, out);
+ fputs(USAGE_VERSION, out);
+ fprintf(out, USAGE_MAN_TAIL("mkfs.minix(8)"));
+ exit(out == stderr ? MKFS_EX_USAGE : MKFS_EX_OK);
}
/*
@@ -538,7 +537,7 @@ static void setup_tables(void) {
if (MINIX_MAX_INODES < first_zone_data())
errx(MKFS_EX_ERROR,
_("First data block at %jd, which is too far (max %d).\n"
- "Try specifying fewer inodes by passing -i <inodes>"),
+ "Try specifying fewer inodes by passing --inodes <num>"),
first_zone_data(),
MINIX_MAX_INODES);
imaps = get_nimaps();
@@ -666,40 +665,41 @@ int main(int argc, char ** argv) {
char * tmp;
struct stat statbuf;
char * listfile = NULL;
- char * p;
-
- if (argc && *argv)
- program_name = *argv;
- if ((p = strrchr(program_name, '/')) != NULL)
- program_name = p+1;
+ static const struct option longopts[] = {
+ {"namelength", required_argument, NULL, 'n'},
+ {"inodes", required_argument, NULL, 'i'},
+ {"check", no_argument, NULL, 'c'},
+ {"badblocks", required_argument, NULL, 'l'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
atexit(close_stdout);
- if (argc == 2 &&
- (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
- printf(UTIL_LINUX_VERSION);
- exit(MKFS_EX_OK);
- }
-
if (INODE_SIZE * MINIX_INODES_PER_BLOCK != MINIX_BLOCK_SIZE)
errx(MKFS_EX_ERROR, _("%s: bad inode size"), device_name);
if (INODE2_SIZE * MINIX2_INODES_PER_BLOCK != MINIX_BLOCK_SIZE)
errx(MKFS_EX_ERROR, _("%s: bad inode size"), device_name);
- opterr = 0;
- while ((i = getopt(argc, argv, "ci:l:n:v123")) != -1)
+ while ((i = getopt_long(argc, argv, "1v23n:i:cl:Vh", longopts, NULL)) != -1)
switch (i) {
- case 'c':
- check=1; break;
- case 'i':
- req_nr_inodes = strtoul_or_err(optarg,
- _("failed to parse number of inodes"));
+ case '1':
+ fs_version = 1;
+ break;
+ case 'v': /* kept for backwards compatiblitly */
+ warnx(_("-v is ambiguous, use '-2' instead"));
+ case '2':
+ fs_version = 2;
+ break;
+ case '3':
+ fs_version = 3;
+ namelen = 60;
+ dirsize = 64;
break;
- case 'l':
- listfile = optarg; break;
case 'n':
i = strtoul_or_err(optarg,
_("failed to parse maximum length of filenames"));
@@ -708,24 +708,27 @@ int main(int argc, char ** argv) {
else if (i == 30)
magic = MINIX_SUPER_MAGIC2;
else
- usage();
+ usage(stderr);
namelen = i;
dirsize = i+2;
break;
- case '1':
- fs_version = 1;
+ case 'i':
+ req_nr_inodes = strtoul_or_err(optarg,
+ _("failed to parse number of inodes"));
break;
- case '2':
- case 'v': /* kept for backwards compatiblitly */
- fs_version = 2;
+ case 'c':
+ check=1;
break;
- case '3':
- fs_version = 3;
- namelen = 60;
- dirsize = 64;
+ case 'l':
+ listfile = optarg;
break;
+ case 'V':
+ printf(UTIL_LINUX_VERSION);
+ return MKFS_EX_OK;
+ case 'h':
+ usage(stdout);
default:
- usage();
+ usage(stderr);
}
argc -= optind;
argv += optind;
@@ -738,7 +741,7 @@ int main(int argc, char ** argv) {
BLOCKS = strtoul_or_err(argv[0], _("failed to parse number of blocks"));
if (!device_name) {
- usage();
+ usage(stderr);
}
check_mount(); /* is it already mounted? */
tmp = root_block;
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 03/12] mkfs.minix: use is_mounted() from libcommon
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
2015-06-24 8:15 ` [PATCH 01/12] mkfs.minix: increase maximum minix v2 and v3 file system sizes Sami Kerola
2015-06-24 8:15 ` [PATCH 02/12] mkfs.minix: introduce long options to the command Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 04/12] mkfs.minix: remove unuseful code Sami Kerola
` (9 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/mkfs.minix.c | 27 ++++-----------------------
1 file changed, 4 insertions(+), 23 deletions(-)
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index 9e4212f..a198e5a 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -77,6 +77,7 @@
#include "strutils.h"
#include "all-io.h"
#include "closestream.h"
+#include "ismounted.h"
#define MINIX_ROOT_INO 1
#define MINIX_BAD_INO 2
@@ -152,28 +153,6 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
exit(out == stderr ? MKFS_EX_USAGE : MKFS_EX_OK);
}
-/*
- * Check to make certain that our new filesystem won't be created on
- * an already mounted partition. Code adapted from mke2fs, Copyright
- * (C) 1994 Theodore Ts'o. Also licensed under GPL.
- */
-static void check_mount(void) {
- FILE * f;
- struct mntent * mnt;
-
- if ((f = setmntent (_PATH_MOUNTED, "r")) == NULL)
- return;
- while ((mnt = getmntent (f)) != NULL)
- if (strcmp (device_name, mnt->mnt_fsname) == 0)
- break;
- endmntent (f);
- if (!mnt)
- return;
-
- errx(MKFS_EX_ERROR, _("%s is mounted; will not make a filesystem here!"),
- device_name);
-}
-
static void super_set_state(void)
{
switch (fs_version) {
@@ -743,7 +722,9 @@ int main(int argc, char ** argv) {
if (!device_name) {
usage(stderr);
}
- check_mount(); /* is it already mounted? */
+ if (is_mounted(device_name))
+ errx(MKFS_EX_ERROR, _("%s is mounted; will not make a filesystem here!"),
+ device_name);
tmp = root_block;
if (fs_version == 3) {
*(uint32_t *)tmp = 1;
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 04/12] mkfs.minix: remove unuseful code
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (2 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 03/12] mkfs.minix: use is_mounted() from libcommon Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 05/12] mkfs.minix: add fs_control structure, and remove most global variables Sami Kerola
` (8 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Checks about inodes vs block sizes does not add much robustness. Both
values are derived at compilation time from struct minix_inode size, and
they form full definition circle.
Bad block check for none-block devices should not be supressed, user
requested it so let him have it.
Check for st_rdev == 0x0300 || st_rdev == 0x0340 was unreachable.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/mkfs.minix.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index a198e5a..d3b46b2 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -659,11 +659,6 @@ int main(int argc, char ** argv) {
textdomain(PACKAGE);
atexit(close_stdout);
- if (INODE_SIZE * MINIX_INODES_PER_BLOCK != MINIX_BLOCK_SIZE)
- errx(MKFS_EX_ERROR, _("%s: bad inode size"), device_name);
- if (INODE2_SIZE * MINIX2_INODES_PER_BLOCK != MINIX_BLOCK_SIZE)
- errx(MKFS_EX_ERROR, _("%s: bad inode size"), device_name);
-
while ((i = getopt_long(argc, argv, "1v23n:i:cl:Vh", longopts, NULL)) != -1)
switch (i) {
case '1':
@@ -776,9 +771,7 @@ int main(int argc, char ** argv) {
} else if (!S_ISBLK(statbuf.st_mode)) {
if (!BLOCKS)
BLOCKS = statbuf.st_size / MINIX_BLOCK_SIZE;
- check=0;
- } else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
- errx(MKFS_EX_ERROR, _("will not try to make filesystem on '%s'"), device_name);
+ }
if (BLOCKS < 10)
errx(MKFS_EX_ERROR, _("%s: number of blocks too small"), device_name);
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 05/12] mkfs.minix: add fs_control structure, and remove most global variables
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (3 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 04/12] mkfs.minix: remove unuseful code Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 06/12] mkfs.minix: check user input carefully Sami Kerola
` (7 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
This allows better code structure in future.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/mkfs.minix.c | 380 ++++++++++++++++++++++++------------------------
1 file changed, 190 insertions(+), 190 deletions(-)
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index d3b46b2..fcf7f37 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -98,30 +98,23 @@ static char *inode_buffer = NULL;
#define Inode (((struct minix_inode *) inode_buffer) - 1)
#define Inode2 (((struct minix2_inode *) inode_buffer) - 1)
-static char *device_name;
-static int DEV = -1;
-static unsigned long long BLOCKS;
-static int check;
-static int badblocks;
-
-/*
- * default (changed to 30, per Linus's
- * suggestion, Sun Nov 21 08:05:07 1993)
- * This should be changed in the future to 60,
- * since v3 needs to be the default nowadays (2011)
- */
-static size_t namelen = 30;
-static size_t dirsize = 32;
-static int magic = MINIX_SUPER_MAGIC2;
+struct fs_control {
+ char *device_name; /* device on a Minix file system is created */
+ int device_fd; /* open file descriptor of the device */
+ unsigned long long fs_blocks; /* device block count for the file system */
+ int fs_used_blocks; /* used blocks on a device */
+ int fs_bad_blocks; /* number of bad blocks found from device */
+ size_t fs_namelen; /* maximum length of filenames */
+ size_t fs_dirsize; /* maximum size of directory */
+ unsigned long fs_inodes; /* number of inodes */
+ int fs_magic; /* file system magic number */
+ unsigned int
+ check_blocks:1; /* check for bad blocks */
+};
static char root_block[MINIX_BLOCK_SIZE];
-
static char boot_block_buffer[512];
-
static unsigned short good_blocks_table[MAX_GOOD_BLOCKS];
-static int used_good_blocks;
-static unsigned long req_nr_inodes;
-
static char *inode_map;
static char *zone_map;
@@ -166,7 +159,7 @@ static void super_set_state(void)
}
}
-static void write_tables(void) {
+static void write_tables(const struct fs_control *ctl) {
unsigned long imaps = get_nimaps();
unsigned long zmaps = get_nzmaps();
size_t buffsz = get_inode_buffer_size();
@@ -174,59 +167,59 @@ static void write_tables(void) {
/* Mark the super block valid. */
super_set_state();
- if (lseek(DEV, 0, SEEK_SET))
+ if (lseek(ctl->device_fd, 0, SEEK_SET))
err(MKFS_EX_ERROR, _("%s: seek to boot block failed "
- " in write_tables"), device_name);
- if (write_all(DEV, boot_block_buffer, 512))
- err(MKFS_EX_ERROR, _("%s: unable to clear boot sector"), device_name);
- if (MINIX_BLOCK_SIZE != lseek(DEV, MINIX_BLOCK_SIZE, SEEK_SET))
- err(MKFS_EX_ERROR, _("%s: seek failed in write_tables"), device_name);
+ " in write_tables"), ctl->device_name);
+ if (write_all(ctl->device_fd, boot_block_buffer, 512))
+ err(MKFS_EX_ERROR, _("%s: unable to clear boot sector"), ctl->device_name);
+ if (MINIX_BLOCK_SIZE != lseek(ctl->device_fd, MINIX_BLOCK_SIZE, SEEK_SET))
+ err(MKFS_EX_ERROR, _("%s: seek failed in write_tables"), ctl->device_name);
- if (write_all(DEV, super_block_buffer, MINIX_BLOCK_SIZE))
- err(MKFS_EX_ERROR, _("%s: unable to write super-block"), device_name);
+ if (write_all(ctl->device_fd, super_block_buffer, MINIX_BLOCK_SIZE))
+ err(MKFS_EX_ERROR, _("%s: unable to write super-block"), ctl->device_name);
- if (write_all(DEV, inode_map, imaps * MINIX_BLOCK_SIZE))
- err(MKFS_EX_ERROR, _("%s: unable to write inode map"), device_name);
+ if (write_all(ctl->device_fd, inode_map, imaps * MINIX_BLOCK_SIZE))
+ err(MKFS_EX_ERROR, _("%s: unable to write inode map"), ctl->device_name);
- if (write_all(DEV, zone_map, zmaps * MINIX_BLOCK_SIZE))
- err(MKFS_EX_ERROR, _("%s: unable to write zone map"), device_name);
+ if (write_all(ctl->device_fd, zone_map, zmaps * MINIX_BLOCK_SIZE))
+ err(MKFS_EX_ERROR, _("%s: unable to write zone map"), ctl->device_name);
- if (write_all(DEV, inode_buffer, buffsz))
- err(MKFS_EX_ERROR, _("%s: unable to write inodes"), device_name);
+ if (write_all(ctl->device_fd, inode_buffer, buffsz))
+ err(MKFS_EX_ERROR, _("%s: unable to write inodes"), ctl->device_name);
}
-static void write_block(int blk, char * buffer) {
- if (blk*MINIX_BLOCK_SIZE != lseek(DEV, blk*MINIX_BLOCK_SIZE, SEEK_SET))
- errx(MKFS_EX_ERROR, _("%s: seek failed in write_block"), device_name);
+static void write_block(const struct fs_control *ctl, int blk, char * buffer) {
+ if (blk * MINIX_BLOCK_SIZE != lseek(ctl->device_fd, blk * MINIX_BLOCK_SIZE, SEEK_SET))
+ errx(MKFS_EX_ERROR, _("%s: seek failed in write_block"), ctl->device_name);
- if (write_all(DEV, buffer, MINIX_BLOCK_SIZE))
- errx(MKFS_EX_ERROR, _("%s: write failed in write_block"), device_name);
+ if (write_all(ctl->device_fd, buffer, MINIX_BLOCK_SIZE))
+ errx(MKFS_EX_ERROR, _("%s: write failed in write_block"), ctl->device_name);
}
-static int get_free_block(void) {
+static int get_free_block(struct fs_control *ctl) {
unsigned int blk;
unsigned int zones = get_nzones();
unsigned int first_zone = get_first_zone();
- if (used_good_blocks+1 >= MAX_GOOD_BLOCKS)
- errx(MKFS_EX_ERROR, _("%s: too many bad blocks"), device_name);
- if (used_good_blocks)
- blk = good_blocks_table[used_good_blocks-1]+1;
+ if (ctl->fs_used_blocks + 1 >= MAX_GOOD_BLOCKS)
+ errx(MKFS_EX_ERROR, _("%s: too many bad blocks"), ctl->device_name);
+ if (ctl->fs_used_blocks)
+ blk = good_blocks_table[ctl->fs_used_blocks - 1] + 1;
else
blk = first_zone;
while (blk < zones && zone_in_use(blk))
blk++;
if (blk >= zones)
- errx(MKFS_EX_ERROR, _("%s: not enough good blocks"), device_name);
- good_blocks_table[used_good_blocks] = blk;
- used_good_blocks++;
+ errx(MKFS_EX_ERROR, _("%s: not enough good blocks"), ctl->device_name);
+ good_blocks_table[ctl->fs_used_blocks] = blk;
+ ctl->fs_used_blocks++;
return blk;
}
-static void mark_good_blocks(void) {
+static void mark_good_blocks(const struct fs_control *ctl) {
int blk;
- for (blk=0 ; blk < used_good_blocks ; blk++)
+ for (blk=0 ; blk < ctl->fs_used_blocks ; blk++)
mark_zone(good_blocks_table[blk]);
}
@@ -242,7 +235,7 @@ static inline int next(unsigned long zone) {
return 0;
}
-static void make_bad_inode_v1(void)
+static void make_bad_inode_v1(struct fs_control *ctl)
{
struct minix_inode * inode = &Inode[MINIX_BAD_INO];
int i,j,zone;
@@ -252,31 +245,31 @@ static void make_bad_inode_v1(void)
#define NEXT_BAD (zone = next(zone))
- if (!badblocks)
+ if (!ctl->fs_bad_blocks)
return;
mark_inode(MINIX_BAD_INO);
inode->i_nlinks = 1;
inode->i_time = time(NULL);
inode->i_mode = S_IFREG + 0000;
- inode->i_size = badblocks*MINIX_BLOCK_SIZE;
+ inode->i_size = ctl->fs_bad_blocks * MINIX_BLOCK_SIZE;
zone = next(0);
for (i=0 ; i<7 ; i++) {
inode->i_zone[i] = zone;
if (!NEXT_BAD)
goto end_bad;
}
- inode->i_zone[7] = ind = get_free_block();
+ inode->i_zone[7] = ind = get_free_block(ctl);
memset(ind_block,0,MINIX_BLOCK_SIZE);
for (i=0 ; i<512 ; i++) {
ind_block[i] = zone;
if (!NEXT_BAD)
goto end_bad;
}
- inode->i_zone[8] = dind = get_free_block();
+ inode->i_zone[8] = dind = get_free_block(ctl);
memset(dind_block,0,MINIX_BLOCK_SIZE);
for (i=0 ; i<512 ; i++) {
- write_block(ind,(char *) ind_block);
- dind_block[i] = ind = get_free_block();
+ write_block(ctl, ind,(char *) ind_block);
+ dind_block[i] = ind = get_free_block(ctl);
memset(ind_block,0,MINIX_BLOCK_SIZE);
for (j=0 ; j<512 ; j++) {
ind_block[j] = zone;
@@ -284,15 +277,15 @@ static void make_bad_inode_v1(void)
goto end_bad;
}
}
- errx(MKFS_EX_ERROR, _("%s: too many bad blocks"), device_name);
+ errx(MKFS_EX_ERROR, _("%s: too many bad blocks"), ctl->device_name);
end_bad:
if (ind)
- write_block(ind, (char *) ind_block);
+ write_block(ctl, ind, (char *) ind_block);
if (dind)
- write_block(dind, (char *) dind_block);
+ write_block(ctl, dind, (char *) dind_block);
}
-static void make_bad_inode_v2_v3 (void)
+static void make_bad_inode_v2_v3 (struct fs_control *ctl)
{
struct minix2_inode *inode = &Inode2[MINIX_BAD_INO];
int i, j, zone;
@@ -300,31 +293,31 @@ static void make_bad_inode_v2_v3 (void)
unsigned long ind_block[MINIX_BLOCK_SIZE >> 2];
unsigned long dind_block[MINIX_BLOCK_SIZE >> 2];
- if (!badblocks)
+ if (!ctl->fs_bad_blocks)
return;
mark_inode (MINIX_BAD_INO);
inode->i_nlinks = 1;
inode->i_atime = inode->i_mtime = inode->i_ctime = time (NULL);
inode->i_mode = S_IFREG + 0000;
- inode->i_size = badblocks * MINIX_BLOCK_SIZE;
+ inode->i_size = ctl->fs_bad_blocks * MINIX_BLOCK_SIZE;
zone = next (0);
for (i = 0; i < 7; i++) {
inode->i_zone[i] = zone;
if (!NEXT_BAD)
goto end_bad;
}
- inode->i_zone[7] = ind = get_free_block ();
+ inode->i_zone[7] = ind = get_free_block (ctl);
memset (ind_block, 0, MINIX_BLOCK_SIZE);
for (i = 0; i < 256; i++) {
ind_block[i] = zone;
if (!NEXT_BAD)
goto end_bad;
}
- inode->i_zone[8] = dind = get_free_block ();
+ inode->i_zone[8] = dind = get_free_block (ctl);
memset (dind_block, 0, MINIX_BLOCK_SIZE);
for (i = 0; i < 256; i++) {
- write_block (ind, (char *) ind_block);
- dind_block[i] = ind = get_free_block ();
+ write_block (ctl, ind, (char *) ind_block);
+ dind_block[i] = ind = get_free_block (ctl);
memset (ind_block, 0, MINIX_BLOCK_SIZE);
for (j = 0; j < 256; j++) {
ind_block[j] = zone;
@@ -333,86 +326,86 @@ static void make_bad_inode_v2_v3 (void)
}
}
/* Could make triple indirect block here */
- errx(MKFS_EX_ERROR, _("%s: too many bad blocks"), device_name);
+ errx(MKFS_EX_ERROR, _("%s: too many bad blocks"), ctl->device_name);
end_bad:
if (ind)
- write_block (ind, (char *) ind_block);
+ write_block (ctl, ind, (char *) ind_block);
if (dind)
- write_block (dind, (char *) dind_block);
+ write_block (ctl, dind, (char *) dind_block);
}
-static void make_bad_inode(void)
+static void make_bad_inode(struct fs_control *ctl)
{
if (fs_version < 2) {
- make_bad_inode_v1();
+ make_bad_inode_v1(ctl);
return;
}
- make_bad_inode_v2_v3();
+ make_bad_inode_v2_v3(ctl);
}
-static void make_root_inode_v1(void) {
+static void make_root_inode_v1(struct fs_control *ctl) {
struct minix_inode * inode = &Inode[MINIX_ROOT_INO];
mark_inode(MINIX_ROOT_INO);
- inode->i_zone[0] = get_free_block();
+ inode->i_zone[0] = get_free_block(ctl);
inode->i_nlinks = 2;
inode->i_time = time(NULL);
- if (badblocks)
- inode->i_size = 3*dirsize;
+ if (ctl->fs_bad_blocks)
+ inode->i_size = 3 * ctl->fs_dirsize;
else {
- root_block[2*dirsize] = '\0';
- root_block[2*dirsize+1] = '\0';
- inode->i_size = 2*dirsize;
+ root_block[2 * ctl->fs_dirsize] = '\0';
+ root_block[2 * ctl->fs_dirsize + 1] = '\0';
+ inode->i_size = 2 * ctl->fs_dirsize;
}
inode->i_mode = S_IFDIR + 0755;
inode->i_uid = getuid();
if (inode->i_uid)
inode->i_gid = getgid();
- write_block(inode->i_zone[0],root_block);
+ write_block(ctl, inode->i_zone[0],root_block);
}
-static void make_root_inode_v2_v3 (void) {
+static void make_root_inode_v2_v3 (struct fs_control *ctl) {
struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO];
mark_inode (MINIX_ROOT_INO);
- inode->i_zone[0] = get_free_block ();
+ inode->i_zone[0] = get_free_block (ctl);
inode->i_nlinks = 2;
inode->i_atime = inode->i_mtime = inode->i_ctime = time (NULL);
- if (badblocks)
- inode->i_size = 3 * dirsize;
+ if (ctl->fs_bad_blocks)
+ inode->i_size = 3 * ctl->fs_dirsize;
else {
- root_block[2 * dirsize] = '\0';
- inode->i_size = 2 * dirsize;
+ root_block[2 * ctl->fs_dirsize] = '\0';
+ inode->i_size = 2 * ctl->fs_dirsize;
}
inode->i_mode = S_IFDIR + 0755;
inode->i_uid = getuid();
if (inode->i_uid)
inode->i_gid = getgid();
- write_block (inode->i_zone[0], root_block);
+ write_block (ctl, inode->i_zone[0], root_block);
}
-static void make_root_inode(void)
+static void make_root_inode(struct fs_control *ctl)
{
if (fs_version < 2) {
- make_root_inode_v1();
+ make_root_inode_v1(ctl);
return;
}
- make_root_inode_v2_v3();
+ make_root_inode_v2_v3(ctl);
}
-static void super_set_nzones(void)
+static void super_set_nzones(const struct fs_control *ctl)
{
switch (fs_version) {
case 3:
- Super3.s_zones = BLOCKS;
+ Super3.s_zones = ctl->fs_blocks;
break;
case 2:
- Super.s_zones = BLOCKS;
+ Super.s_zones = ctl->fs_blocks;
break;
default: /* v1 */
- Super.s_nzones = BLOCKS;
+ Super.s_nzones = ctl->fs_blocks;
break;
}
}
@@ -432,46 +425,46 @@ static void super_init_maxsize(void)
}
}
-static void super_set_map_blocks(unsigned long inodes)
+static void super_set_map_blocks(const struct fs_control *ctl, unsigned long inodes)
{
switch (fs_version) {
case 3:
Super3.s_imap_blocks = UPPER(inodes + 1, BITS_PER_BLOCK);
- Super3.s_zmap_blocks = UPPER(BLOCKS - (1+get_nimaps()+inode_blocks()),
- BITS_PER_BLOCK+1);
+ Super3.s_zmap_blocks = UPPER(ctl->fs_blocks - (1 + get_nimaps() + inode_blocks()),
+ BITS_PER_BLOCK + 1);
Super3.s_firstdatazone = first_zone_data();
break;
default:
Super.s_imap_blocks = UPPER(inodes + 1, BITS_PER_BLOCK);
- Super.s_zmap_blocks = UPPER(BLOCKS - (1+get_nimaps()+inode_blocks()),
- BITS_PER_BLOCK+1);
+ Super.s_zmap_blocks = UPPER(ctl->fs_blocks - (1 + get_nimaps() + inode_blocks()),
+ BITS_PER_BLOCK + 1);
Super.s_firstdatazone = first_zone_data();
break;
}
}
-static void super_set_magic(void)
+static void super_set_magic(const struct fs_control *ctl)
{
switch (fs_version) {
case 3:
- Super3.s_magic = magic;
+ Super3.s_magic = ctl->fs_magic;
break;
default:
- Super.s_magic = magic;
+ Super.s_magic = ctl->fs_magic;
break;
}
}
-static void setup_tables(void) {
+static void setup_tables(const struct fs_control *ctl) {
unsigned long inodes, zmaps, imaps, zones, i;
super_block_buffer = calloc(1, MINIX_BLOCK_SIZE);
if (!super_block_buffer)
err(MKFS_EX_ERROR, _("%s: unable to allocate buffer for superblock"),
- device_name);
+ ctl->device_name);
memset(boot_block_buffer,0,512);
- super_set_magic();
+ super_set_magic(ctl);
if (fs_version == 3) {
Super3.s_log_zone_size = 0;
@@ -482,21 +475,21 @@ static void setup_tables(void) {
}
super_init_maxsize();
- super_set_nzones();
+ super_set_nzones(ctl);
zones = get_nzones();
/* some magic nrs: 1 inode / 3 blocks for smaller filesystems,
* for one inode / 16 blocks for large ones. mkfs will eventually
* crab about too far when getting close to the maximum size. */
- if (req_nr_inodes == 0)
- if (2048 * 1024 < BLOCKS) /* 2GB */
- inodes = BLOCKS / 16;
- else if (512 * 1024 < BLOCKS) /* 0.5GB */
- inodes = BLOCKS / 8;
+ if (ctl->fs_inodes == 0)
+ if (2048 * 1024 < ctl->fs_blocks) /* 2GB */
+ inodes = ctl->fs_blocks / 16;
+ else if (512 * 1024 < ctl->fs_blocks) /* 0.5GB */
+ inodes = ctl->fs_blocks / 8;
else
- inodes = BLOCKS / 3;
+ inodes = ctl->fs_blocks / 3;
else
- inodes = req_nr_inodes;
+ inodes = ctl->fs_inodes;
/* Round up inode count to fill block size */
if (fs_version == 2 || fs_version == 3)
inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) &
@@ -512,7 +505,7 @@ static void setup_tables(void) {
if (inodes > MINIX_MAX_INODES)
inodes = MINIX_MAX_INODES;
}
- super_set_map_blocks(inodes);
+ super_set_map_blocks(ctl, inodes);
if (MINIX_MAX_INODES < first_zone_data())
errx(MKFS_EX_ERROR,
_("First data block at %jd, which is too far (max %d).\n"
@@ -526,7 +519,7 @@ static void setup_tables(void) {
zone_map = malloc(zmaps * MINIX_BLOCK_SIZE);
if (!inode_map || !zone_map)
err(MKFS_EX_ERROR, _("%s: unable to allocate buffers for maps"),
- device_name);
+ ctl->device_name);
memset(inode_map,0xff,imaps * MINIX_BLOCK_SIZE);
memset(zone_map,0xff,zmaps * MINIX_BLOCK_SIZE);
for (i = get_first_zone() ; i<zones ; i++)
@@ -536,7 +529,7 @@ static void setup_tables(void) {
inode_buffer = malloc(get_inode_buffer_size());
if (!inode_buffer)
err(MKFS_EX_ERROR, _("%s: unable to allocate buffer for inodes"),
- device_name);
+ ctl->device_name);
memset(inode_buffer,0, get_inode_buffer_size());
printf(P_("%lu inode\n", "%lu inodes\n", inodes), inodes);
printf(P_("%lu block\n", "%lu blocks\n", zones), zones);
@@ -549,17 +542,17 @@ static void setup_tables(void) {
* Perform a test of a block; return the number of
* blocks readable/writeable.
*/
-static size_t do_check(char * buffer, int try, unsigned int current_block) {
+static size_t do_check(const struct fs_control *ctl, char * buffer, int try, unsigned int current_block) {
ssize_t got;
/* Seek to the correct loc. */
- if (lseek(DEV, current_block * MINIX_BLOCK_SIZE, SEEK_SET) !=
+ if (lseek(ctl->device_fd, current_block * MINIX_BLOCK_SIZE, SEEK_SET) !=
current_block * MINIX_BLOCK_SIZE )
err(MKFS_EX_ERROR, _("%s: seek failed during testing of blocks"),
- device_name);
+ ctl->device_name);
/* Try the read */
- got = read(DEV, buffer, try * MINIX_BLOCK_SIZE);
+ got = read(ctl->device_fd, buffer, try * MINIX_BLOCK_SIZE);
if (got < 0) got = 0;
if (got & (MINIX_BLOCK_SIZE - 1 )) {
printf(_("Weird values in do_check: probably bugs\n"));
@@ -583,7 +576,7 @@ static void alarm_intr(int alnum __attribute__ ((__unused__))) {
fflush(stdout);
}
-static void check_blocks(void) {
+static void check_blocks(struct fs_control *ctl) {
size_t try, got;
static char buffer[MINIX_BLOCK_SIZE * TEST_BUFFER_BLOCKS];
unsigned long zones = get_nzones();
@@ -593,53 +586,60 @@ static void check_blocks(void) {
signal(SIGALRM,alarm_intr);
alarm(5);
while (currently_testing < zones) {
- if (lseek(DEV,currently_testing*MINIX_BLOCK_SIZE,SEEK_SET) !=
+ if (lseek(ctl->device_fd, currently_testing * MINIX_BLOCK_SIZE,SEEK_SET) !=
currently_testing*MINIX_BLOCK_SIZE)
errx(MKFS_EX_ERROR, _("%s: seek failed in check_blocks"),
- device_name);
+ ctl->device_name);
try = TEST_BUFFER_BLOCKS;
if (currently_testing + try > zones)
try = zones-currently_testing;
- got = do_check(buffer, try, currently_testing);
+ got = do_check(ctl, buffer, try, currently_testing);
currently_testing += got;
if (got == try)
continue;
if (currently_testing < first_zone)
errx(MKFS_EX_ERROR, _("%s: bad blocks before data-area: "
- "cannot make fs"), device_name);
+ "cannot make fs"), ctl->device_name);
mark_zone(currently_testing);
- badblocks++;
+ ctl->fs_bad_blocks++;
currently_testing++;
}
- if (badblocks > 0)
- printf(P_("%d bad block\n", "%d bad blocks\n", badblocks), badblocks);
+ if (ctl->fs_bad_blocks > 0)
+ printf(P_("%d bad block\n", "%d bad blocks\n", ctl->fs_bad_blocks), ctl->fs_bad_blocks);
}
-static void get_list_blocks(char *filename) {
+static void get_list_blocks(struct fs_control *ctl, char *filename) {
FILE *listfile;
unsigned long blockno;
listfile = fopen(filename,"r");
if (listfile == NULL)
err(MKFS_EX_ERROR, _("%s: can't open file of bad blocks"),
- device_name);
+ ctl->device_name);
while (!feof(listfile)) {
if (fscanf(listfile,"%lu\n", &blockno) != 1) {
- printf(_("badblock number input error on line %d\n"), badblocks + 1);
+ printf(_("badblock number input error on line %d\n"), ctl->fs_bad_blocks + 1);
errx(MKFS_EX_ERROR, _("%s: cannot read badblocks file"),
- device_name);
+ ctl->device_name);
}
mark_zone(blockno);
- badblocks++;
+ ctl->fs_bad_blocks++;
}
fclose(listfile);
- if (badblocks > 0)
- printf(P_("%d bad block\n", "%d bad blocks\n", badblocks), badblocks);
+ if (ctl->fs_bad_blocks > 0)
+ printf(P_("%d bad block\n", "%d bad blocks\n", ctl->fs_bad_blocks), ctl->fs_bad_blocks);
}
-int main(int argc, char ** argv) {
+int main(int argc, char ** argv)
+{
+ struct fs_control ctl = {
+ .fs_namelen = 30,
+ .fs_dirsize = 32,
+ .fs_magic = MINIX_SUPER_MAGIC2, /* version 1, long names */
+ 0
+ };
int i;
char * tmp;
struct stat statbuf;
@@ -671,27 +671,27 @@ int main(int argc, char ** argv) {
break;
case '3':
fs_version = 3;
- namelen = 60;
- dirsize = 64;
+ ctl.fs_namelen = 60;
+ ctl.fs_dirsize = 64;
break;
case 'n':
i = strtoul_or_err(optarg,
_("failed to parse maximum length of filenames"));
if (i == 14)
- magic = MINIX_SUPER_MAGIC;
+ ctl.fs_magic = MINIX_SUPER_MAGIC;
else if (i == 30)
- magic = MINIX_SUPER_MAGIC2;
+ ctl.fs_magic = MINIX_SUPER_MAGIC2;
else
usage(stderr);
- namelen = i;
- dirsize = i+2;
+ ctl.fs_namelen = i;
+ ctl.fs_dirsize = i + 2;
break;
case 'i':
- req_nr_inodes = strtoul_or_err(optarg,
+ ctl.fs_inodes = strtoul_or_err(optarg,
_("failed to parse number of inodes"));
break;
case 'c':
- check=1;
+ ctl.check_blocks = 1;
break;
case 'l':
listfile = optarg;
@@ -706,99 +706,99 @@ int main(int argc, char ** argv) {
}
argc -= optind;
argv += optind;
- if (argc > 0 && !device_name) {
- device_name = argv[0];
+ if (argc > 0) {
+ ctl.device_name = argv[0];
argc--;
argv++;
}
if (argc > 0)
- BLOCKS = strtoul_or_err(argv[0], _("failed to parse number of blocks"));
+ ctl.fs_blocks = strtoul_or_err(argv[0], _("failed to parse number of blocks"));
- if (!device_name) {
+ if (!ctl.device_name) {
usage(stderr);
}
- if (is_mounted(device_name))
+ if (is_mounted(ctl.device_name))
errx(MKFS_EX_ERROR, _("%s is mounted; will not make a filesystem here!"),
- device_name);
+ ctl.device_name);
tmp = root_block;
if (fs_version == 3) {
*(uint32_t *)tmp = 1;
strcpy(tmp+4,".");
- tmp += dirsize;
+ tmp += ctl.fs_dirsize;
*(uint32_t *)tmp = 1;
strcpy(tmp+4,"..");
- tmp += dirsize;
+ tmp += ctl.fs_dirsize;
*(uint32_t *)tmp = 2;
strcpy(tmp+4, ".badblocks");
} else {
*(uint16_t *)tmp = 1;
strcpy(tmp+2,".");
- tmp += dirsize;
+ tmp += ctl.fs_dirsize;
*(uint16_t *)tmp = 1;
strcpy(tmp+2,"..");
- tmp += dirsize;
+ tmp += ctl.fs_dirsize;
*(uint16_t *)tmp = 2;
strcpy(tmp+2, ".badblocks");
}
- if (stat(device_name, &statbuf) < 0)
- err(MKFS_EX_ERROR, _("stat of %s failed"), device_name);
+ if (stat(ctl.device_name, &statbuf) < 0)
+ err(MKFS_EX_ERROR, _("stat of %s failed"), ctl.device_name);
if (S_ISBLK(statbuf.st_mode))
- DEV = open(device_name,O_RDWR | O_EXCL);
+ ctl.device_fd = open(ctl.device_name, O_RDWR | O_EXCL);
else
- DEV = open(device_name,O_RDWR);
+ ctl.device_fd = open(ctl.device_name, O_RDWR);
- if (DEV<0)
- err(MKFS_EX_ERROR, _("cannot open %s"), device_name);
+ if (ctl.device_fd < 0)
+ err(MKFS_EX_ERROR, _("cannot open %s"), ctl.device_name);
if (S_ISBLK(statbuf.st_mode)) {
int sectorsize;
- if (blkdev_get_sector_size(DEV, §orsize) == -1)
+ if (blkdev_get_sector_size(ctl.device_fd, §orsize) == -1)
sectorsize = DEFAULT_SECTOR_SIZE; /* kernel < 2.3.3 */
- if (blkdev_is_misaligned(DEV))
- warnx(_("%s: device is misaligned"), device_name);
+ if (blkdev_is_misaligned(ctl.device_fd))
+ warnx(_("%s: device is misaligned"), ctl.device_name);
if (MINIX_BLOCK_SIZE < sectorsize)
errx(MKFS_EX_ERROR, _("block size smaller than physical "
- "sector size of %s"), device_name);
- if (!BLOCKS) {
- if (blkdev_get_size(DEV, &BLOCKS) == -1)
+ "sector size of %s"), ctl.device_name);
+ if (!ctl.fs_blocks) {
+ if (blkdev_get_size(ctl.device_fd, &ctl.fs_blocks) == -1)
errx(MKFS_EX_ERROR, _("cannot determine size of %s"),
- device_name);
- BLOCKS /= MINIX_BLOCK_SIZE;
+ ctl.device_name);
+ ctl.fs_blocks /= MINIX_BLOCK_SIZE;
}
} else if (!S_ISBLK(statbuf.st_mode)) {
- if (!BLOCKS)
- BLOCKS = statbuf.st_size / MINIX_BLOCK_SIZE;
+ if (!ctl.fs_blocks)
+ ctl.fs_blocks = statbuf.st_size / MINIX_BLOCK_SIZE;
}
- if (BLOCKS < 10)
- errx(MKFS_EX_ERROR, _("%s: number of blocks too small"), device_name);
+ if (ctl.fs_blocks < 10)
+ errx(MKFS_EX_ERROR, _("%s: number of blocks too small"), ctl.device_name);
if (fs_version == 3)
- magic = MINIX3_SUPER_MAGIC;
+ ctl.fs_magic = MINIX3_SUPER_MAGIC;
else if (fs_version == 2) {
- if (namelen == 14)
- magic = MINIX2_SUPER_MAGIC;
+ if (ctl.fs_namelen == 14)
+ ctl.fs_magic = MINIX2_SUPER_MAGIC;
else
- magic = MINIX2_SUPER_MAGIC2;
+ ctl.fs_magic = MINIX2_SUPER_MAGIC2;
} else /* fs_version == 1 */
- if (BLOCKS > MINIX_MAX_INODES)
- BLOCKS = MINIX_MAX_INODES;
- if (BLOCKS > MINIX_MAX_INODES * BITS_PER_BLOCK)
- BLOCKS = MINIX_MAX_INODES * BITS_PER_BLOCK; /* Utter maximum: Clip. */
- setup_tables();
- if (check)
- check_blocks();
+ if (ctl.fs_blocks > MINIX_MAX_INODES)
+ ctl.fs_blocks = MINIX_MAX_INODES;
+ if (ctl.fs_blocks > MINIX_MAX_INODES * BITS_PER_BLOCK)
+ ctl.fs_blocks = MINIX_MAX_INODES * BITS_PER_BLOCK; /* Utter maximum: Clip. */
+ setup_tables(&ctl);
+ if (ctl.check_blocks)
+ check_blocks(&ctl);
else if (listfile)
- get_list_blocks(listfile);
+ get_list_blocks(&ctl, listfile);
- make_root_inode();
- make_bad_inode();
+ make_root_inode(&ctl);
+ make_bad_inode(&ctl);
- mark_good_blocks();
- write_tables();
- if (close_fd(DEV) != 0)
+ mark_good_blocks(&ctl);
+ write_tables(&ctl);
+ if (close_fd(ctl.device_fd) != 0)
err(MKFS_EX_ERROR, _("write failed"));
return MKFS_EX_OK;
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 06/12] mkfs.minix: check user input carefully
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (4 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 05/12] mkfs.minix: add fs_control structure, and remove most global variables Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 07/12] mkfs.minix: check requested blocks will not exceed available on device Sami Kerola
` (6 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
File name lenght and version input needs to be checked against each
other, which will determine what version of file system is in question.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/mkfs.minix.8 | 9 +++---
disk-utils/mkfs.minix.c | 79 +++++++++++++++++++++++++++++++++----------------
2 files changed, 57 insertions(+), 31 deletions(-)
diff --git a/disk-utils/mkfs.minix.8 b/disk-utils/mkfs.minix.8
index e46a768..fcf0e7c 100644
--- a/disk-utils/mkfs.minix.8
+++ b/disk-utils/mkfs.minix.8
@@ -42,10 +42,9 @@ Check the device for bad blocks before creating the filesystem. If any
are found, the count is printed.
.TP
\fB\-n\fR, \fB\-\-namelength\fR \fIlength\fR
-Specify the maximum length of filenames.
-Currently, the only allowable values are 14 and 30.
-The default is 30. Note that kernels older than 0.99p7
-only accept namelength 14.
+Specify the maximum length of filenames. Currently, the only allowable
+values are 14 and 30 for file system versions 1 and 2. Version 3 allows
+only value 60. The default is 30.
.TP
\fB\-i\fR, \fB\-\-inodes\fR \fInumber\fR
Specify the number of inodes for the filesystem.
@@ -57,7 +56,7 @@ The file has one bad-block number per line. The count of bad blocks read
is printed.
.TP
.B \-1
-Make a Minix version 1 filesystem.
+Make a Minix version 1 filesystem. This is the default.
.TP
.BR \-2 , " \-v"
Make a Minix version 2 filesystem.
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index fcf7f37..59e1674 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -87,10 +87,12 @@
#define MINIX_MAX_INODES 65535
+#define DEFAULT_FS_VERSION 1
+
/*
* Global variables used in minix_programs.h inline fuctions
*/
-int fs_version = 1;
+int fs_version = DEFAULT_FS_VERSION;
char *super_block_buffer;
static char *inode_buffer = NULL;
@@ -104,7 +106,7 @@ struct fs_control {
unsigned long long fs_blocks; /* device block count for the file system */
int fs_used_blocks; /* used blocks on a device */
int fs_bad_blocks; /* number of bad blocks found from device */
- size_t fs_namelen; /* maximum length of filenames */
+ uint16_t fs_namelen; /* maximum length of filenames */
size_t fs_dirsize; /* maximum size of directory */
unsigned long fs_inodes; /* number of inodes */
int fs_magic; /* file system magic number */
@@ -632,12 +634,54 @@ static void get_list_blocks(struct fs_control *ctl, char *filename) {
printf(P_("%d bad block\n", "%d bad blocks\n", ctl->fs_bad_blocks), ctl->fs_bad_blocks);
}
+static int find_super_magic(const struct fs_control *ctl)
+{
+ switch (fs_version) {
+ case 1:
+ if (ctl->fs_namelen == 14)
+ return MINIX_SUPER_MAGIC;
+ else
+ return MINIX_SUPER_MAGIC2;
+ break;
+ case 2:
+ if (ctl->fs_namelen == 14)
+ return MINIX2_SUPER_MAGIC;
+ else
+ return MINIX2_SUPER_MAGIC2;
+ break;
+ case 3:
+ return MINIX3_SUPER_MAGIC;
+ default:
+ abort();
+ }
+}
+
+static void check_user_instructions(struct fs_control *ctl)
+{
+ switch (fs_version) {
+ case 1:
+ case 2:
+ if (ctl->fs_namelen == 14 || ctl->fs_namelen == 30)
+ ctl->fs_dirsize = ctl->fs_namelen + 2;
+ else
+ errx(MKFS_EX_ERROR, _("unsupported name length: %d"), ctl->fs_namelen);
+ break;
+ case 3:
+ if (ctl->fs_namelen == 60)
+ ctl->fs_dirsize = ctl->fs_namelen + 4;
+ else
+ errx(MKFS_EX_ERROR, _("unsupported name length: %d"), ctl->fs_namelen);
+ break;
+ default:
+ errx(MKFS_EX_ERROR, _("unsupported minix file system version: %d"), fs_version);
+ }
+ ctl->fs_magic = find_super_magic(ctl);
+}
+
int main(int argc, char ** argv)
{
struct fs_control ctl = {
- .fs_namelen = 30,
- .fs_dirsize = 32,
- .fs_magic = MINIX_SUPER_MAGIC2, /* version 1, long names */
+ .fs_namelen = 30, /* keep in sync with DEFAULT_FS_VERSION */
0
};
int i;
@@ -672,19 +716,10 @@ int main(int argc, char ** argv)
case '3':
fs_version = 3;
ctl.fs_namelen = 60;
- ctl.fs_dirsize = 64;
break;
case 'n':
- i = strtoul_or_err(optarg,
+ ctl.fs_namelen = strtou16_or_err(optarg,
_("failed to parse maximum length of filenames"));
- if (i == 14)
- ctl.fs_magic = MINIX_SUPER_MAGIC;
- else if (i == 30)
- ctl.fs_magic = MINIX_SUPER_MAGIC2;
- else
- usage(stderr);
- ctl.fs_namelen = i;
- ctl.fs_dirsize = i + 2;
break;
case 'i':
ctl.fs_inodes = strtoul_or_err(optarg,
@@ -717,6 +752,7 @@ int main(int argc, char ** argv)
if (!ctl.device_name) {
usage(stderr);
}
+ check_user_instructions(&ctl);
if (is_mounted(ctl.device_name))
errx(MKFS_EX_ERROR, _("%s is mounted; will not make a filesystem here!"),
ctl.device_name);
@@ -774,17 +810,8 @@ int main(int argc, char ** argv)
}
if (ctl.fs_blocks < 10)
errx(MKFS_EX_ERROR, _("%s: number of blocks too small"), ctl.device_name);
-
- if (fs_version == 3)
- ctl.fs_magic = MINIX3_SUPER_MAGIC;
- else if (fs_version == 2) {
- if (ctl.fs_namelen == 14)
- ctl.fs_magic = MINIX2_SUPER_MAGIC;
- else
- ctl.fs_magic = MINIX2_SUPER_MAGIC2;
- } else /* fs_version == 1 */
- if (ctl.fs_blocks > MINIX_MAX_INODES)
- ctl.fs_blocks = MINIX_MAX_INODES;
+ if (fs_version == 1 && ctl.fs_blocks > MINIX_MAX_INODES)
+ ctl.fs_blocks = MINIX_MAX_INODES;
if (ctl.fs_blocks > MINIX_MAX_INODES * BITS_PER_BLOCK)
ctl.fs_blocks = MINIX_MAX_INODES * BITS_PER_BLOCK; /* Utter maximum: Clip. */
setup_tables(&ctl);
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 07/12] mkfs.minix: check requested blocks will not exceed available on device
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (5 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 06/12] mkfs.minix: check user input carefully Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 08/12] mkfs.minix: refactor root block content creation Sami Kerola
` (5 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Earlier user could define more blocks than device, or backing file for
loopback file system, had available. That lead to a system crash with
following commands;
fallocate --length 64KiB test-file
mkfs.minix -3 -i 842160 test-file 104882174
mkdir test-file.d
mount test-file test-file.d
cp /etc/service test-file.d
Killed
sudo umount test-file.d
The minix driver should probably not hang the whole kernel, but the least
that mkfs.minix ought to do is not to let users to get that condition
quite as easily.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/mkfs.minix.c | 64 ++++++++++++++++++++++++++-----------------------
1 file changed, 34 insertions(+), 30 deletions(-)
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index 59e1674..c2ab664 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -656,6 +656,39 @@ static int find_super_magic(const struct fs_control *ctl)
}
}
+static void determine_device_blocks(struct fs_control *ctl, const struct stat *statbuf)
+{
+ unsigned long long dev_blocks;
+
+ if (S_ISBLK(statbuf->st_mode)) {
+ int sectorsize;
+
+ if (blkdev_get_sector_size(ctl->device_fd, §orsize) == -1)
+ sectorsize = DEFAULT_SECTOR_SIZE; /* kernel < 2.3.3 */
+ if (blkdev_is_misaligned(ctl->device_fd))
+ warnx(_("%s: device is misaligned"), ctl->device_name);
+ if (MINIX_BLOCK_SIZE < sectorsize)
+ errx(MKFS_EX_ERROR, _("block size smaller than physical "
+ "sector size of %s"), ctl->device_name);
+ if (blkdev_get_size(ctl->device_fd, &dev_blocks) == -1)
+ errx(MKFS_EX_ERROR, _("cannot determine size of %s"), ctl->device_name);
+ dev_blocks /= MINIX_BLOCK_SIZE;
+ } else if (!S_ISBLK(statbuf->st_mode))
+ dev_blocks = statbuf->st_size / MINIX_BLOCK_SIZE;
+ if (!ctl->fs_blocks)
+ ctl->fs_blocks = dev_blocks;
+ else if (dev_blocks < ctl->fs_blocks)
+ errx(MKFS_EX_ERROR,
+ _("%s: requested blocks (%llu) exceeds available (%llu) blocks\n"),
+ ctl->device_name, ctl->fs_blocks, dev_blocks);
+ if (ctl->fs_blocks < 10)
+ errx(MKFS_EX_ERROR, _("%s: number of blocks too small"), ctl->device_name);
+ if (fs_version == 1 && ctl->fs_blocks > MINIX_MAX_INODES)
+ ctl->fs_blocks = MINIX_MAX_INODES;
+ if (ctl->fs_blocks > MINIX_MAX_INODES * BITS_PER_BLOCK)
+ ctl->fs_blocks = MINIX_MAX_INODES * BITS_PER_BLOCK; /* Utter maximum: Clip. */
+}
+
static void check_user_instructions(struct fs_control *ctl)
{
switch (fs_version) {
@@ -782,38 +815,9 @@ int main(int argc, char ** argv)
ctl.device_fd = open(ctl.device_name, O_RDWR | O_EXCL);
else
ctl.device_fd = open(ctl.device_name, O_RDWR);
-
if (ctl.device_fd < 0)
err(MKFS_EX_ERROR, _("cannot open %s"), ctl.device_name);
-
- if (S_ISBLK(statbuf.st_mode)) {
- int sectorsize;
-
- if (blkdev_get_sector_size(ctl.device_fd, §orsize) == -1)
- sectorsize = DEFAULT_SECTOR_SIZE; /* kernel < 2.3.3 */
-
- if (blkdev_is_misaligned(ctl.device_fd))
- warnx(_("%s: device is misaligned"), ctl.device_name);
-
- if (MINIX_BLOCK_SIZE < sectorsize)
- errx(MKFS_EX_ERROR, _("block size smaller than physical "
- "sector size of %s"), ctl.device_name);
- if (!ctl.fs_blocks) {
- if (blkdev_get_size(ctl.device_fd, &ctl.fs_blocks) == -1)
- errx(MKFS_EX_ERROR, _("cannot determine size of %s"),
- ctl.device_name);
- ctl.fs_blocks /= MINIX_BLOCK_SIZE;
- }
- } else if (!S_ISBLK(statbuf.st_mode)) {
- if (!ctl.fs_blocks)
- ctl.fs_blocks = statbuf.st_size / MINIX_BLOCK_SIZE;
- }
- if (ctl.fs_blocks < 10)
- errx(MKFS_EX_ERROR, _("%s: number of blocks too small"), ctl.device_name);
- if (fs_version == 1 && ctl.fs_blocks > MINIX_MAX_INODES)
- ctl.fs_blocks = MINIX_MAX_INODES;
- if (ctl.fs_blocks > MINIX_MAX_INODES * BITS_PER_BLOCK)
- ctl.fs_blocks = MINIX_MAX_INODES * BITS_PER_BLOCK; /* Utter maximum: Clip. */
+ determine_device_blocks(&ctl, &statbuf);
setup_tables(&ctl);
if (ctl.check_blocks)
check_blocks(&ctl);
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 08/12] mkfs.minix: refactor root block content creation
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (6 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 07/12] mkfs.minix: check requested blocks will not exceed available on device Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 09/12] fsck.minix: rename device file descriptor variable Sami Kerola
` (4 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
This does not belong to main() function.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/mkfs.minix.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index c2ab664..16305b2 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -390,6 +390,27 @@ static void make_root_inode_v2_v3 (struct fs_control *ctl) {
static void make_root_inode(struct fs_control *ctl)
{
+ char *tmp = root_block;
+
+ if (fs_version == 3) {
+ *(uint32_t *) tmp = 1;
+ strcpy(tmp + 4, ".");
+ tmp += ctl->fs_dirsize;
+ *(uint32_t *) tmp = 1;
+ strcpy(tmp + 4, "..");
+ tmp += ctl->fs_dirsize;
+ *(uint32_t *) tmp = 2;
+ strcpy(tmp + 4, ".badblocks");
+ } else {
+ *(uint16_t *) tmp = 1;
+ strcpy(tmp + 2, ".");
+ tmp += ctl->fs_dirsize;
+ *(uint16_t *) tmp = 1;
+ strcpy(tmp + 2, "..");
+ tmp += ctl->fs_dirsize;
+ *(uint16_t *) tmp = 2;
+ strcpy(tmp + 2, ".badblocks");
+ }
if (fs_version < 2) {
make_root_inode_v1(ctl);
return;
@@ -718,7 +739,6 @@ int main(int argc, char ** argv)
0
};
int i;
- char * tmp;
struct stat statbuf;
char * listfile = NULL;
static const struct option longopts[] = {
@@ -789,26 +809,6 @@ int main(int argc, char ** argv)
if (is_mounted(ctl.device_name))
errx(MKFS_EX_ERROR, _("%s is mounted; will not make a filesystem here!"),
ctl.device_name);
- tmp = root_block;
- if (fs_version == 3) {
- *(uint32_t *)tmp = 1;
- strcpy(tmp+4,".");
- tmp += ctl.fs_dirsize;
- *(uint32_t *)tmp = 1;
- strcpy(tmp+4,"..");
- tmp += ctl.fs_dirsize;
- *(uint32_t *)tmp = 2;
- strcpy(tmp+4, ".badblocks");
- } else {
- *(uint16_t *)tmp = 1;
- strcpy(tmp+2,".");
- tmp += ctl.fs_dirsize;
- *(uint16_t *)tmp = 1;
- strcpy(tmp+2,"..");
- tmp += ctl.fs_dirsize;
- *(uint16_t *)tmp = 2;
- strcpy(tmp+2, ".badblocks");
- }
if (stat(ctl.device_name, &statbuf) < 0)
err(MKFS_EX_ERROR, _("stat of %s failed"), ctl.device_name);
if (S_ISBLK(statbuf.st_mode))
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 09/12] fsck.minix: rename device file descriptor variable
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (7 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 08/12] mkfs.minix: refactor root block content creation Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 10/12] fsck.minix: add minix v3 support Sami Kerola
` (3 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/fsck.minix.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c
index 52b001b..3c3faf0 100644
--- a/disk-utils/fsck.minix.c
+++ b/disk-utils/fsck.minix.c
@@ -127,7 +127,7 @@ static char *inode_buffer;
#define Inode2 (((struct minix2_inode *) inode_buffer) - 1)
static char *device_name;
-static int IN;
+static int device_fd;
static int repair, automatic, verbose, list, show, warn_mode, force;
static int directory, regular, blockdev, chardev, links, symlinks, total;
@@ -363,13 +363,13 @@ read_block(unsigned int nr, char *addr) {
memset(addr, 0, MINIX_BLOCK_SIZE);
return;
}
- if (MINIX_BLOCK_SIZE * nr != lseek(IN, MINIX_BLOCK_SIZE * nr, SEEK_SET)) {
+ if (MINIX_BLOCK_SIZE * nr != lseek(device_fd, MINIX_BLOCK_SIZE * nr, SEEK_SET)) {
get_current_name();
printf(_("Read error: unable to seek to block in file '%s'\n"),
current_name);
memset(addr, 0, MINIX_BLOCK_SIZE);
errors_uncorrected = 1;
- } else if (MINIX_BLOCK_SIZE != read(IN, addr, MINIX_BLOCK_SIZE)) {
+ } else if (MINIX_BLOCK_SIZE != read(device_fd, addr, MINIX_BLOCK_SIZE)) {
get_current_name();
printf(_("Read error: bad block in file '%s'\n"), current_name);
memset(addr, 0, MINIX_BLOCK_SIZE);
@@ -388,9 +388,9 @@ write_block(unsigned int nr, char *addr) {
errors_uncorrected = 1;
return;
}
- if (MINIX_BLOCK_SIZE * nr != lseek(IN, MINIX_BLOCK_SIZE * nr, SEEK_SET))
+ if (MINIX_BLOCK_SIZE * nr != lseek(device_fd, MINIX_BLOCK_SIZE * nr, SEEK_SET))
die(_("seek failed in write_block"));
- if (MINIX_BLOCK_SIZE != write(IN, addr, MINIX_BLOCK_SIZE)) {
+ if (MINIX_BLOCK_SIZE != write(device_fd, addr, MINIX_BLOCK_SIZE)) {
get_current_name();
printf(_("Write error: bad block in file '%s'\n"),
current_name);
@@ -503,9 +503,9 @@ write_super_block(void) {
else
Super.s_state &= ~MINIX_ERROR_FS;
- if (MINIX_BLOCK_SIZE != lseek(IN, MINIX_BLOCK_SIZE, SEEK_SET))
+ if (MINIX_BLOCK_SIZE != lseek(device_fd, MINIX_BLOCK_SIZE, SEEK_SET))
die(_("seek failed in write_super_block"));
- if (MINIX_BLOCK_SIZE != write(IN, super_block_buffer, MINIX_BLOCK_SIZE))
+ if (MINIX_BLOCK_SIZE != write(device_fd, super_block_buffer, MINIX_BLOCK_SIZE))
die(_("unable to write super-block"));
return;
}
@@ -518,13 +518,13 @@ write_tables(void) {
write_super_block();
- if (write_all(IN, inode_map, imaps * MINIX_BLOCK_SIZE))
+ if (write_all(device_fd, inode_map, imaps * MINIX_BLOCK_SIZE))
die(_("Unable to write inode map"));
- if (write_all(IN, zone_map, zmaps * MINIX_BLOCK_SIZE))
+ if (write_all(device_fd, zone_map, zmaps * MINIX_BLOCK_SIZE))
die(_("Unable to write zone map"));
- if (write_all(IN, inode_buffer, buffsz))
+ if (write_all(device_fd, inode_buffer, buffsz))
die(_("Unable to write inodes"));
}
@@ -552,14 +552,14 @@ get_dirsize(void) {
static void
read_superblock(void) {
- if (MINIX_BLOCK_SIZE != lseek(IN, MINIX_BLOCK_SIZE, SEEK_SET))
+ if (MINIX_BLOCK_SIZE != lseek(device_fd, MINIX_BLOCK_SIZE, SEEK_SET))
die(_("seek failed"));
super_block_buffer = calloc(1, MINIX_BLOCK_SIZE);
if (!super_block_buffer)
die(_("unable to alloc buffer for superblock"));
- if (MINIX_BLOCK_SIZE != read(IN, super_block_buffer, MINIX_BLOCK_SIZE))
+ if (MINIX_BLOCK_SIZE != read(device_fd, super_block_buffer, MINIX_BLOCK_SIZE))
die(_("unable to read super block"));
if (MAGIC == MINIX_SUPER_MAGIC) {
namelen = 14;
@@ -615,15 +615,15 @@ read_tables(void) {
if (!zone_count)
die(_("Unable to allocate buffer for zone count"));
- rc = read(IN, inode_map, imaps * MINIX_BLOCK_SIZE);
+ rc = read(device_fd, inode_map, imaps * MINIX_BLOCK_SIZE);
if (rc < 0 || imaps * MINIX_BLOCK_SIZE != (size_t) rc)
die(_("Unable to read inode map"));
- rc = read(IN, zone_map, zmaps * MINIX_BLOCK_SIZE);
+ rc = read(device_fd, zone_map, zmaps * MINIX_BLOCK_SIZE);
if (rc < 0 || zmaps * MINIX_BLOCK_SIZE != (size_t) rc)
die(_("Unable to read zone map"));
- rc = read(IN, inode_buffer, buffsz);
+ rc = read(device_fd, inode_buffer, buffsz);
if (rc < 0 || buffsz != (size_t) rc)
die(_("Unable to read inodes"));
if (norm_first_zone != first_zone) {
@@ -1112,9 +1112,9 @@ static int
bad_zone(int i) {
char buffer[1024];
- if (MINIX_BLOCK_SIZE * i != lseek(IN, MINIX_BLOCK_SIZE * i, SEEK_SET))
+ if (MINIX_BLOCK_SIZE * i != lseek(device_fd, MINIX_BLOCK_SIZE * i, SEEK_SET))
die(_("seek failed in bad_zone"));
- return (MINIX_BLOCK_SIZE != read(IN, buffer, MINIX_BLOCK_SIZE));
+ return (MINIX_BLOCK_SIZE != read(device_fd, buffer, MINIX_BLOCK_SIZE));
}
static void
@@ -1313,8 +1313,8 @@ main(int argc, char **argv) {
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO))
die(_("need terminal for interactive repairs"));
}
- IN = open(device_name, repair ? O_RDWR : O_RDONLY);
- if (IN < 0)
+ device_fd = open(device_name, repair ? O_RDWR : O_RDONLY);
+ if (device_fd < 0)
die(_("cannot open %s: %s"), device_name, strerror(errno));
for (count = 0; count < 3; count++)
sync();
@@ -1396,7 +1396,7 @@ main(int argc, char **argv) {
if (repair && !automatic)
tcsetattr(STDIN_FILENO, TCSANOW, &termios);
- if (close_fd(IN) != 0)
+ if (close_fd(device_fd) != 0)
err(FSCK_EX_ERROR, _("write failed"));
if (changed)
retcode += 3;
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 10/12] fsck.minix: add minix v3 support
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (8 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 09/12] fsck.minix: rename device file descriptor variable Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 11/12] fsck.minix: introduce long options to the command Sami Kerola
` (2 subsequent siblings)
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Relates-to: a2657ae3ffb56616ac9c921886bcca8ef242499f
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/fsck.minix.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c
index 3c3faf0..57e5be9 100644
--- a/disk-utils/fsck.minix.c
+++ b/disk-utils/fsck.minix.c
@@ -147,8 +147,6 @@ static char name_list[MAX_DEPTH][MINIX_NAME_MAX + 1];
* is a waste of 12kB or so. */
static char current_name[MAX_DEPTH * (MINIX_NAME_MAX + 1) + 1];
-#define MAGIC (Super.s_magic)
-
static unsigned char *inode_count = NULL;
static unsigned char *zone_count = NULL;
@@ -494,6 +492,9 @@ map_block2(struct minix2_inode *inode, unsigned int blknr) {
static void
write_super_block(void) {
+ /* v3 super block does not track state */
+ if (fs_version == 3)
+ return;
/* Set the state of the filesystem based on whether or not there are
* uncorrected errors. The filesystem valid flag is unconditionally
* set if we get this far. */
@@ -534,7 +535,7 @@ get_dirsize(void) {
char blk[MINIX_BLOCK_SIZE];
size_t size;
- if (fs_version == 2)
+ if (fs_version == 2 || fs_version == 3)
block = Inode2[ROOT_INO].i_zone[0];
else
block = Inode[ROOT_INO].i_zone[0];
@@ -561,22 +562,26 @@ read_superblock(void) {
if (MINIX_BLOCK_SIZE != read(device_fd, super_block_buffer, MINIX_BLOCK_SIZE))
die(_("unable to read super block"));
- if (MAGIC == MINIX_SUPER_MAGIC) {
+ if (Super.s_magic == MINIX_SUPER_MAGIC) {
namelen = 14;
dirsize = 16;
fs_version = 1;
- } else if (MAGIC == MINIX_SUPER_MAGIC2) {
+ } else if (Super.s_magic == MINIX_SUPER_MAGIC2) {
namelen = 30;
dirsize = 32;
fs_version = 1;
- } else if (MAGIC == MINIX2_SUPER_MAGIC) {
+ } else if (Super.s_magic == MINIX2_SUPER_MAGIC) {
namelen = 14;
dirsize = 16;
fs_version = 2;
- } else if (MAGIC == MINIX2_SUPER_MAGIC2) {
+ } else if (Super.s_magic == MINIX2_SUPER_MAGIC2) {
namelen = 30;
dirsize = 32;
fs_version = 2;
+ } else if (Super3.s_magic == MINIX3_SUPER_MAGIC) {
+ namelen = 60;
+ dirsize = 64;
+ fs_version = 3;
} else
die(_("bad magic number in super-block"));
if (get_zone_size() != 0 || MINIX_BLOCK_SIZE != 1024)
@@ -637,7 +642,8 @@ read_tables(void) {
printf(_("Firstdatazone=%jd (%jd)\n"), first_zone, norm_first_zone);
printf(_("Zonesize=%d\n"), MINIX_BLOCK_SIZE << get_zone_size());
printf(_("Maxsize=%zu\n"), get_max_size());
- printf(_("Filesystem state=%d\n"), Super.s_state);
+ if (fs_version < 3)
+ printf(_("Filesystem state=%d\n"), Super.s_state);
printf(_("namelen=%zd\n\n"), namelen);
}
}
@@ -1013,17 +1019,18 @@ check_file2(struct minix2_inode *dir, unsigned int offset) {
ino_t ino;
char *name;
int block;
+ const int version_offset = fs_version == 3 ? 4 : 2;
block = map_block2(dir, offset / MINIX_BLOCK_SIZE);
read_block(block, blk);
- name = blk + (offset % MINIX_BLOCK_SIZE) + 2;
- ino = *(unsigned short *)(name - 2);
+ name = blk + (offset % MINIX_BLOCK_SIZE) + version_offset;
+ ino = *(unsigned short *)(name - version_offset);
if (ino > get_ninodes()) {
get_current_name();
printf(_("The directory '%s' contains a bad inode number "
"for file '%.*s'."), current_name, (int)namelen, name);
if (ask(_(" Remove"), 1)) {
- *(unsigned short *)(name - 2) = 0;
+ *(unsigned short *)(name - version_offset) = 0;
write_block(block, blk);
}
ino = 0;
@@ -1323,7 +1330,7 @@ main(int argc, char **argv) {
/* Determine whether or not we should continue with the checking. This
* is based on the status of the filesystem valid and error flags and
* whether or not the -f switch was specified on the command line. */
- if (!(Super.s_state & MINIX_ERROR_FS) &&
+ if (fs_version < 3 && !(Super.s_state & MINIX_ERROR_FS) &&
(Super.s_state & MINIX_VALID_FS) && !force) {
if (repair)
printf(_("%s is clean, no check.\n"), device_name);
@@ -1350,7 +1357,7 @@ main(int argc, char **argv) {
termios_set = 1;
}
- if (fs_version == 2) {
+ if (fs_version == 2 || fs_version == 3) {
check_root2();
check2();
} else {
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 11/12] fsck.minix: introduce long options to the command
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (9 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 10/12] fsck.minix: add minix v3 support Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-06-24 8:15 ` [PATCH 12/12] docs: make fsck.minix(8) more pretty Sami Kerola
2015-07-30 9:55 ` [PATCH 00/12] pull: minix updates Karel Zak
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
bash-completion/fsck.minix | 12 ++--
disk-utils/fsck.minix.8 | 29 +++++----
disk-utils/fsck.minix.c | 150 ++++++++++++++++++++++-----------------------
3 files changed, 96 insertions(+), 95 deletions(-)
diff --git a/bash-completion/fsck.minix b/bash-completion/fsck.minix
index b2b2860..ac4571e 100644
--- a/bash-completion/fsck.minix
+++ b/bash-completion/fsck.minix
@@ -1,16 +1,16 @@
_fsck.minix_module()
{
- local cur prev OPTS
+ local cur OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
- prev="${COMP_WORDS[COMP_CWORD-1]}"
- case $prev in
- '-V'|'--version')
+ case $cur in
+ -*)
+ OPTS="--list --auto --repair --verbose --super --uncleared --force --help --version"
+ COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
- OPTS="-l -a -r -v -s -m -f --version"
- COMPREPLY=( $(compgen -W "${OPTS[*]} $(lsblk -pnro name)" -- $cur) )
+ COMPREPLY=( $(compgen -W "$(lsblk -pnro name)" -- $cur) )
return 0
}
complete -F _fsck.minix_module fsck.minix
diff --git a/disk-utils/fsck.minix.8 b/disk-utils/fsck.minix.8
index b672ab7..84d54bb 100644
--- a/disk-utils/fsck.minix.8
+++ b/disk-utils/fsck.minix.8
@@ -1,16 +1,15 @@
.\" Copyright 1992, 1993, 1994 Rickard E. Faith (faith@cs.unc.edu)
.\" May be freely distributed.
-.TH FSCK.MINIX 8 "July 1996" "util-linux" "System Administration"
+.TH FSCK.MINIX 8 "June 2015" "util-linux" "System Administration"
.SH NAME
fsck.minix \- check consistency of Minix filesystem
.SH SYNOPSIS
.B fsck.minix
-.RB [ \-larvsmf ]
+[options]
.I device
.SH DESCRIPTION
.B fsck.minix
-performs a consistency check for the Linux MINIX filesystem. The current
-version supports the 14 character and 30 character filename options.
+performs a consistency check for the Linux MINIX filesystem.
The program
assumes the filesystem is quiescent.
@@ -51,31 +50,37 @@ on a mounted filesystem (i.e., the root filesystem), make sure nothing is
writing to the disk, and that no files are "zombies" waiting for deletion.
.SH OPTIONS
.TP
-.B \-l
+\fB\-l\fR, \fB\-\-list\fR
List all filenames.
.TP
-.B \-r
+\fB\-r\fR, \fB\-\-repair\fR
Perform interactive repairs.
.TP
-.B \-a
+\fB\-a\fR, \fB\-\-auto\fR
Perform automatic repairs. (This option implies
-.B \-r
+.B \-\-repair
and serves to answer all of the questions asked with the default.) Note
that this can be extremely dangerous in the case of extensive filesystem
damage.
.TP
-.B \-v
+\fB\-v\fR, \fB\-\-verbose\fR
Be verbose.
.TP
-.B \-s
+\fB\-s\fR, \fB\-\-super\fR
Output super-block information.
.TP
-.B \-m
+\fB\-m\fR, \fB\-\-uncleared\fR
Activate MINIX-like "mode not cleared" warnings.
.TP
-.B \-f
+\fB\-f\fR, \fB\-\-force\fR
Force a filesystem check even if the filesystem was marked as valid (this
marking is done by the kernel when the filesystem is unmounted).
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Display version information and exit.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display help text and exit.
.SH "SEE ALSO"
.BR fsck (8),
.BR fsck.ext2 (8),
diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c
index 57e5be9..f73ac4a 100644
--- a/disk-utils/fsck.minix.c
+++ b/disk-utils/fsck.minix.c
@@ -76,17 +76,6 @@
* unless you can be sure nobody is writing to it (and remember that the
* kernel can write to it when it searches for files).
*
- * Usuage: fsck [-larvsm] device
- * -l for a listing of all the filenames
- * -a for automatic repairs (not implemented)
- * -r for repairs (interactive) (not implemented)
- * -v for verbose (tells how many files)
- * -s for super-block info
- * -m for minix-like "mode not cleared" warnings
- * -f force filesystem check even if filesystem marked as valid
- *
- * The device may be a block device or a image of one, but this isn't
- * enforced (but it's not much fun on a character device :-).
*/
#include <stdio.h>
@@ -101,6 +90,7 @@
#include <mntent.h>
#include <sys/stat.h>
#include <signal.h>
+#include <getopt.h>
#include "c.h"
#include "exitcodes.h"
@@ -181,33 +171,31 @@ fatalsig(int sig) {
raise(sig);
}
-static void
+static void __attribute__((__noreturn__))
leave(int status) {
reset();
exit(status);
}
static void
-usage(void) {
- fputs(USAGE_HEADER, stderr);
- fprintf(stderr,
- _(" %s [options] <device>\n"), program_invocation_short_name);
-
- fputs(USAGE_SEPARATOR, stderr);
- fputs(_("Check the consistency of a Minix filesystem.\n"), stderr);
-
- fputs(USAGE_OPTIONS, stderr);
- fputs(_(" -l list all filenames\n"), stderr);
- fputs(_(" -a automatic repair\n"), stderr);
- fputs(_(" -r interactive repair\n"), stderr);
- fputs(_(" -v be verbose\n"), stderr);
- fputs(_(" -s output super-block information\n"), stderr);
- fputs(_(" -m activate mode not cleared warnings\n"), stderr);
- fputs(_(" -f force check\n"), stderr);
- fputs(USAGE_SEPARATOR, stderr);
- fputs(USAGE_VERSION, stderr);
- fprintf(stderr, USAGE_MAN_TAIL("fsck.minix(8)"));
- leave(FSCK_EX_USAGE);
+usage(FILE *out) {
+ fputs(USAGE_HEADER, out);
+ fprintf(out, _(" %s [options] <device>\n"), program_invocation_short_name);
+ fputs(USAGE_SEPARATOR, out);
+ fputs(_("Check the consistency of a Minix filesystem.\n"), out);
+ fputs(USAGE_OPTIONS, out);
+ fputs(_(" -l, --list list all filenames\n"), out);
+ fputs(_(" -a, --auto automatic repair\n"), out);
+ fputs(_(" -r, --repair interactive repair\n"), out);
+ fputs(_(" -v, --verbose be verbose\n"), out);
+ fputs(_(" -s, --super output super-block information\n"), out);
+ fputs(_(" -m, --uncleared activate mode not cleared warnings\n"), out);
+ fputs(_(" -f, --force force check\n"), out);
+ fputs(USAGE_SEPARATOR, out);
+ fputs(USAGE_HELP, out);
+ fputs(USAGE_VERSION, out);
+ fprintf(out, USAGE_MAN_TAIL("fsck.minix(8)"));
+ leave(out == stderr ? FSCK_EX_USAGE : FSCK_EX_OK);
}
static void die(const char *fmt, ...)
@@ -1259,62 +1247,70 @@ main(int argc, char **argv) {
struct termios tmp;
int count;
int retcode = FSCK_EX_OK;
+ int i;
+ static const struct option longopts[] = {
+ {"list", no_argument, NULL, 'l'},
+ {"auto", no_argument, NULL, 'a'},
+ {"repair", no_argument, NULL, 'r'},
+ {"verbose", no_argument, NULL, 'v'},
+ {"super", no_argument, NULL, 's'},
+ {"uncleared", no_argument, NULL, 'm'},
+ {"force", no_argument, NULL, 'f'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
atexit(close_stdout);
- if (argc == 2 &&
- (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
- printf(UTIL_LINUX_VERSION);
- exit(FSCK_EX_OK);
- }
-
if (INODE_SIZE * MINIX_INODES_PER_BLOCK != MINIX_BLOCK_SIZE)
die(_("bad inode size"));
if (INODE2_SIZE * MINIX2_INODES_PER_BLOCK != MINIX_BLOCK_SIZE)
die(_("bad v2 inode size"));
- while (argc-- > 1) {
- argv++;
- if (argv[0][0] != '-') {
- if (device_name)
- usage();
- else
- device_name = argv[0];
- } else
- while (*++argv[0])
- switch (argv[0][0]) {
- case 'l':
- list = 1;
- break;
- case 'a':
- automatic = 1;
- repair = 1;
- break;
- case 'r':
- automatic = 0;
- repair = 1;
- break;
- case 'v':
- verbose = 1;
- break;
- case 's':
- show = 1;
- break;
- case 'm':
- warn_mode = 1;
- break;
- case 'f':
- force = 1;
- break;
- default:
- usage();
- }
- }
- if (!device_name)
- usage();
+ while ((i = getopt_long(argc, argv, "larvsmfVh", longopts, NULL)) != -1)
+ switch (i) {
+ case 'l':
+ list = 1;
+ break;
+ case 'a':
+ automatic = 1;
+ repair = 1;
+ break;
+ case 'r':
+ automatic = 0;
+ repair = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 's':
+ show = 1;
+ break;
+ case 'm':
+ warn_mode = 1;
+ break;
+ case 'f':
+ force = 1;
+ break;
+ case 'V':
+ printf(UTIL_LINUX_VERSION);
+ return FSCK_EX_OK;
+ case 'h':
+ usage(stdout);
+ default:
+ usage(stderr);
+ }
+ argc -= optind;
+ argv += optind;
+ if (0 < argc) {
+ device_name = argv[0];
+ } else
+ usage(stderr);
+
check_mount(); /* trying to check a mounted filesystem? */
if (repair && !automatic) {
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO))
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 12/12] docs: make fsck.minix(8) more pretty
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (10 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 11/12] fsck.minix: introduce long options to the command Sami Kerola
@ 2015-06-24 8:15 ` Sami Kerola
2015-07-30 9:55 ` [PATCH 00/12] pull: minix updates Karel Zak
12 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-06-24 8:15 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Use real table to device list, add missing new paragraph markers, remove
braces that cause reader to wonder if test is meant or not, squeeze error
code list, move references to bottom of the manual, and use mail or web
address macro when possible.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/fsck.minix.8 | 130 +++++++++++++++++++++++++++++-------------------
1 file changed, 80 insertions(+), 50 deletions(-)
diff --git a/disk-utils/fsck.minix.8 b/disk-utils/fsck.minix.8
index 84d54bb..3598781 100644
--- a/disk-utils/fsck.minix.8
+++ b/disk-utils/fsck.minix.8
@@ -10,32 +10,32 @@ fsck.minix \- check consistency of Minix filesystem
.SH DESCRIPTION
.B fsck.minix
performs a consistency check for the Linux MINIX filesystem.
-
-The program
-assumes the filesystem is quiescent.
+.PP
+The program assumes the filesystem is quiescent.
.B fsck.minix
should not be used on a mounted device unless you can be sure nobody is
-writing to it (and remember that the kernel can write to it when it
-searches for files).
-
+writing to it. Remember that the kernel can write to device when it
+searches for files.
+.PP
The \fIdevice\fR name will usually have the following form:
-.nf
.RS
-/dev/hda[1\(en63] (IDE disk 1)
-/dev/hdb[1\(en63] (IDE disk 2)
-/dev/sda[1\(en15] (SCSI disk 1)
-/dev/sdb[1\(en15] (SCSI disk 2)
+.TS
+tab(:);
+left l l.
+/dev/hda[1\(en63]:IDE disk 1
+/dev/hdb[1\(en63]:IDE disk 2
+/dev/sda[1\(en15]:SCSI disk 1
+/dev/sdb[1\(en15]:SCSI disk 2
+.TE
.RE
-.fi
-
-If the filesystem was changed (i.e., repaired), then
+.PP
+If the filesystem was changed, i.e., repaired, then
.B fsck.minix
will print "FILE SYSTEM HAS CHANGED" and will
.BR sync (2)
-three times before exiting. Since Linux does not currently have raw
-devices, there is
+three times before exiting. There is
.I no
-need to reboot at this time.
+need to reboot after check.
.SH WARNING
.B fsck.minix
should
@@ -46,8 +46,9 @@ on a mounted filesystem is very dangerous, due to the possibility that
deleted files are still in use, and can seriously damage a perfectly good
filesystem! If you absolutely have to run
.B fsck.minix
-on a mounted filesystem (i.e., the root filesystem), make sure nothing is
-writing to the disk, and that no files are "zombies" waiting for deletion.
+on a mounted filesystem, such as the root filesystem, make sure nothing
+is writing to the disk, and that no files are "zombies" waiting for
+deletion.
.SH OPTIONS
.TP
\fB\-l\fR, \fB\-\-list\fR
@@ -57,9 +58,9 @@ List all filenames.
Perform interactive repairs.
.TP
\fB\-a\fR, \fB\-\-auto\fR
-Perform automatic repairs. (This option implies
+Perform automatic repairs. This option implies
.B \-\-repair
-and serves to answer all of the questions asked with the default.) Note
+and serves to answer all of the questions asked with the default. Note
that this can be extremely dangerous in the case of extensive filesystem
damage.
.TP
@@ -73,25 +74,18 @@ Output super-block information.
Activate MINIX-like "mode not cleared" warnings.
.TP
\fB\-f\fR, \fB\-\-force\fR
-Force a filesystem check even if the filesystem was marked as valid (this
-marking is done by the kernel when the filesystem is unmounted).
+Force a filesystem check even if the filesystem was marked as valid.
+Marking is done by the kernel when the filesystem is unmounted.
.TP
\fB\-V\fR, \fB\-\-version\fR
Display version information and exit.
.TP
\fB\-h\fR, \fB\-\-help\fR
Display help text and exit.
-.SH "SEE ALSO"
-.BR fsck (8),
-.BR fsck.ext2 (8),
-.BR mkfs (8),
-.BR mkfs.minix (8),
-.BR mkfs.ext2 (8),
-.BR reboot (8)
.SH DIAGNOSTICS
There are numerous diagnostic messages. The ones mentioned here are the
most commonly seen in normal usage.
-
+.PP
If the device does not exist,
.B fsck.minix
will print "unable to read super block". If the device exists, but is not
@@ -102,37 +96,73 @@ will print "bad magic number in super-block".
The exit code returned by
.B fsck.minix
is the sum of the following:
-.IP 0
+.PP
+.RS
+.PD 0
+.TP
+.B 0
No errors
-.IP 3
+.TP
+.B 3
Filesystem errors corrected, system should be rebooted if filesystem was
mounted
-.IP 4
+.TP
+.B 4
Filesystem errors left uncorrected
-.IP 7
+.TP
+.B 7
Combination of exit codes 3 and 4
-.IP 8
+.TP
+.B 8
Operational error
-.IP 16
+.TP
+.B 16
Usage or syntax error
+.PD
+.RE
.PP
-In point of fact, only 0, 3, 4, 7, 8, and 16 can ever be returned.
-.SH AUTHOR
-Linus Torvalds (torvalds@cs.helsinki.fi)
+.SH AUTHORS
+.MT torvalds@\:cs.\:helsinki.\:fi
+Linus Torvalds
+.ME
.br
-Error code values by Rik Faith (faith@cs.unc.edu)
+Error code values by
+.MT faith@\:cs.\:unc.\:edu
+Rik Faith
+.ME
.br
-Added support for filesystem valid flag: Dr.\& Wettstein
-(greg%wind.uucp@plains.nodak.edu)
+Added support for filesystem valid flag:
+.MT greg%\:wind.\:uucp@\:plains.\:nodak.\:edu
+Dr.\& Wettstein
+.ME .
.br
-Check to prevent fsck of mounted filesystem added by Daniel Quinlan
-(quinlan@yggdrasil.com)
+Check to prevent fsck of mounted filesystem added by
+.MT quinlan@\:yggdrasil.\:com
+Daniel Quinlan
+.ME .
.br
-Minix v2 fs support by Andreas Schwab
-(schwab@issan.informatik.uni-dortmund.de), updated by Nicolai
-Langfeldt (janl@math.uio.no)
+Minix v2 fs support by
+.MT schwab@\:issan.\:informatik.\:uni-dortmund.\:de
+Andreas Schwab
+.ME ,
+updated by
+.MT janl@\:math.\:uio.\:no
+Nicolai Langfeldt
+.ME .
.br
-Portability patch by Russell King (rmk@ecs.soton.ac.uk).
+Portability patch by
+.MT rmk@\:ecs.\:soton.\:ac.\:uk
+Russell King
+.ME .
+.SH "SEE ALSO"
+.BR fsck (8),
+.BR fsck.ext2 (8),
+.BR mkfs (8),
+.BR mkfs.minix (8),
+.BR mkfs.ext2 (8),
+.BR reboot (8)
.SH AVAILABILITY
The fsck.minix command is part of the util-linux package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
+.UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
+Linux Kernel Archive
+.UE .
--
2.4.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 00/12] pull: minix updates
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
` (11 preceding siblings ...)
2015-06-24 8:15 ` [PATCH 12/12] docs: make fsck.minix(8) more pretty Sami Kerola
@ 2015-07-30 9:55 ` Karel Zak
2015-07-30 10:31 ` Sami Kerola
12 siblings, 1 reply; 15+ messages in thread
From: Karel Zak @ 2015-07-30 9:55 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Wed, Jun 24, 2015 at 09:15:07AM +0100, Sami Kerola wrote:
> The patch 0001 is not re-submitted. It is the change Joshua Hudson sent
> to mail list couple days ago. The rest are new changes, and they are
> also available from my remote branch 'minix'.
Merged from inbox (the stuff on github seems broken, see
https://github.com/kerolasa/lelux-utiliteetit/commit/8f15af61755fd0f2ee03f34f20ee8dccfd6f529a
where is also some bus-server.c ...).
It would be really really nice to have regression tests before
v2.27-rc2, I guess we need to test all versions (1,2,3) and all
possible namelens with mkfs.minix, fsck.minix and mount(8).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 00/12] pull: minix updates
2015-07-30 9:55 ` [PATCH 00/12] pull: minix updates Karel Zak
@ 2015-07-30 10:31 ` Sami Kerola
0 siblings, 0 replies; 15+ messages in thread
From: Sami Kerola @ 2015-07-30 10:31 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 30 July 2015 at 10:55, Karel Zak <kzak@redhat.com> wrote:
> On Wed, Jun 24, 2015 at 09:15:07AM +0100, Sami Kerola wrote:
>> The patch 0001 is not re-submitted. It is the change Joshua Hudson sent
>> to mail list couple days ago. The rest are new changes, and they are
>> also available from my remote branch 'minix'.
>
> Merged from inbox (the stuff on github seems broken, see
> https://github.com/kerolasa/lelux-utiliteetit/commit/8f15af61755fd0f2ee03f34f20ee8dccfd6f529a
> where is also some bus-server.c ...).
Oh garbage. Well, thank you for applying from mail list.
> It would be really really nice to have regression tests before
> v2.27-rc2, I guess we need to test all versions (1,2,3) and all
> possible namelens with mkfs.minix, fsck.minix and mount(8).
I started work to add tests last evening. I'm sure minix checks
are done within week, or two if paid work is causing me be too
tired at evenings.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2015-07-30 10:31 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
2015-06-24 8:15 ` [PATCH 01/12] mkfs.minix: increase maximum minix v2 and v3 file system sizes Sami Kerola
2015-06-24 8:15 ` [PATCH 02/12] mkfs.minix: introduce long options to the command Sami Kerola
2015-06-24 8:15 ` [PATCH 03/12] mkfs.minix: use is_mounted() from libcommon Sami Kerola
2015-06-24 8:15 ` [PATCH 04/12] mkfs.minix: remove unuseful code Sami Kerola
2015-06-24 8:15 ` [PATCH 05/12] mkfs.minix: add fs_control structure, and remove most global variables Sami Kerola
2015-06-24 8:15 ` [PATCH 06/12] mkfs.minix: check user input carefully Sami Kerola
2015-06-24 8:15 ` [PATCH 07/12] mkfs.minix: check requested blocks will not exceed available on device Sami Kerola
2015-06-24 8:15 ` [PATCH 08/12] mkfs.minix: refactor root block content creation Sami Kerola
2015-06-24 8:15 ` [PATCH 09/12] fsck.minix: rename device file descriptor variable Sami Kerola
2015-06-24 8:15 ` [PATCH 10/12] fsck.minix: add minix v3 support Sami Kerola
2015-06-24 8:15 ` [PATCH 11/12] fsck.minix: introduce long options to the command Sami Kerola
2015-06-24 8:15 ` [PATCH 12/12] docs: make fsck.minix(8) more pretty Sami Kerola
2015-07-30 9:55 ` [PATCH 00/12] pull: minix updates Karel Zak
2015-07-30 10:31 ` Sami Kerola
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox