Auto-detect ext2 partitions in mount
This commit is contained in:
parent
453be3b530
commit
a719ab7780
4 changed files with 49 additions and 25 deletions
|
@ -61,6 +61,17 @@ char *argv[];
|
|||
device = argv[1];
|
||||
if (!strcmp(device, "none")) device = NULL;
|
||||
|
||||
/* auto-detect type */
|
||||
v = fsversion(argv[1], "mount");
|
||||
if (type == NULL) {
|
||||
switch (v) {
|
||||
case FSVERSION_MFS1:
|
||||
case FSVERSION_MFS2:
|
||||
case FSVERSION_MFS3: type = "mfs"; break;
|
||||
case FSVERSION_EXT2: type = "ext2"; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mount(device, argv[2], mountflags, type, args) < 0) {
|
||||
err = strerror(errno);
|
||||
fprintf(stderr, "mount: Can't mount %s on %s: %s\n",
|
||||
|
@ -88,15 +99,12 @@ char *argv[];
|
|||
}
|
||||
/* For MFS, use a version number. Otherwise, use the FS type name. */
|
||||
if (type == NULL || !strcmp(type, MINIX_FS_TYPE)) {
|
||||
v = fsversion(argv[1], "mount");
|
||||
if (v == 1)
|
||||
vs = "1";
|
||||
else if (v == 2)
|
||||
vs = "2";
|
||||
else if (v == 3)
|
||||
vs = "3";
|
||||
else
|
||||
vs = "0";
|
||||
switch (v) {
|
||||
case FSVERSION_MFS1: vs = "1"; break;
|
||||
case FSVERSION_MFS2: vs = "2"; break;
|
||||
case FSVERSION_MFS3: vs = "3"; break;
|
||||
default: vs = "0"; break;
|
||||
}
|
||||
} else {
|
||||
/* Keep the version field sufficiently short. */
|
||||
if (strlen(type) < sizeof(version))
|
||||
|
|
|
@ -73,13 +73,12 @@ int status;
|
|||
}
|
||||
write(1, MESSAGE, sizeof MESSAGE - 1);
|
||||
v = fsversion(name, "printroot"); /* determine file system version */
|
||||
if (v == 1)
|
||||
write(1, "1 rw\n", 5);
|
||||
else if (v == 2)
|
||||
write(1, "2 rw\n", 5);
|
||||
else if (v == 3)
|
||||
write(1, "3 rw\n", 5);
|
||||
else
|
||||
write(1, "0 rw\n", 5);
|
||||
switch (v) {
|
||||
case FSVERSION_MFS1: write(1, "1 rw\n", 5); break;
|
||||
case FSVERSION_MFS2: write(1, "2 rw\n", 5); break;
|
||||
case FSVERSION_MFS3: write(1, "3 rw\n", 5); break;
|
||||
case FSVERSION_EXT2: write(1, "ext2 rw\n", 8); break;
|
||||
default: write(1, "0 rw\n", 5); break;
|
||||
}
|
||||
exit(status);
|
||||
}
|
||||
|
|
|
@ -21,4 +21,10 @@ _PROTOTYPE(int rewrite_mtab, (char *_prog_name));
|
|||
_PROTOTYPE(int get_mtab_entry, (char *_s1, char *_s2, char *_s3, char *_s4));
|
||||
_PROTOTYPE(int put_mtab_entry, (char *_s1, char *_s2, char *_s3, char *_s4));
|
||||
|
||||
/* return values for fsversion */
|
||||
#define FSVERSION_MFS1 0x00001
|
||||
#define FSVERSION_MFS2 0x00002
|
||||
#define FSVERSION_MFS3 0x00003
|
||||
#define FSVERSION_EXT2 0x10002
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,12 +16,20 @@
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mfs/const.h"
|
||||
#include "mfs/type.h"
|
||||
#include "mfs/super.h"
|
||||
|
||||
static struct super_block super, *sp;
|
||||
static char super[SUPER_BLOCK_BYTES];
|
||||
|
||||
#define MAGIC_OFFSET_MFS 0x18
|
||||
#define MAGIC_OFFSET_EXT 0x38
|
||||
#define MAGIC_VALUE_EXT2 0xef53
|
||||
|
||||
static int check_super(off_t offset, unsigned short magic)
|
||||
{
|
||||
return (memcmp(super + offset, &magic, sizeof(magic)) == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
int fsversion(dev, prog)
|
||||
char *dev, *prog;
|
||||
|
@ -36,7 +44,7 @@ char *dev, *prog;
|
|||
}
|
||||
|
||||
lseek(fd, (off_t) SUPER_BLOCK_BYTES, SEEK_SET); /* skip boot block */
|
||||
if (read(fd, (char *) &super, (unsigned) SUPER_SIZE) != SUPER_SIZE) {
|
||||
if (read(fd, (char *) &super, sizeof(super)) != sizeof(super)) {
|
||||
std_err(prog);
|
||||
std_err(" cannot read super block on ");
|
||||
perror(dev);
|
||||
|
@ -44,9 +52,12 @@ char *dev, *prog;
|
|||
return(-1);
|
||||
}
|
||||
close(fd);
|
||||
sp = &super;
|
||||
if (sp->s_magic == SUPER_MAGIC) return(1);
|
||||
if (sp->s_magic == SUPER_V2) return(2);
|
||||
if (sp->s_magic == SUPER_V3) return(3);
|
||||
|
||||
/* first check MFS, a valid MFS may look like EXT but not vice versa */
|
||||
if (check_super(MAGIC_OFFSET_MFS, SUPER_MAGIC)) return FSVERSION_MFS1;
|
||||
if (check_super(MAGIC_OFFSET_MFS, SUPER_V2)) return FSVERSION_MFS2;
|
||||
if (check_super(MAGIC_OFFSET_MFS, SUPER_V3)) return FSVERSION_MFS3;
|
||||
if (check_super(MAGIC_OFFSET_EXT, MAGIC_VALUE_EXT2)) return FSVERSION_EXT2;
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue