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",
}
/* 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))
}
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);
}
_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
#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;
}
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);
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);
}