Fix handling of unmountable filesystems.

This commit is contained in:
Jonas 'Sortie' Termansen 2016-03-24 23:51:06 +01:00
parent 34b5f061f9
commit 9ec09476ba
5 changed files with 51 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -49,6 +49,7 @@
#include "inode.h"
#include "ioleast.h"
// These must be kept up to date with libmount/ext2.c.
static const uint32_t EXT2_FEATURE_COMPAT_SUPPORTED = 0;
static const uint32_t EXT2_FEATURE_INCOMPAT_SUPPORTED = \
EXT2_FEATURE_INCOMPAT_FILETYPE;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2015, 2016 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -30,6 +30,13 @@
#include "util.h"
// These must be kept up to date with ext/extfs.cpp.
#define EXT2_FEATURE_COMPAT_SUPPORTED 0
#define EXT2_FEATURE_INCOMPAT_SUPPORTED \
(EXT2_FEATURE_INCOMPAT_FILETYPE)
#define EXT2_FEATURE_RO_COMPAT_SUPPORTED \
(EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
void ext2_superblock_decode(struct ext2_superblock* sb)
{
sb->s_inodes_count = le32toh(sb->s_inodes_count);
@ -141,6 +148,8 @@ static enum filesystem_error ext2_inspect(struct filesystem** fs_ptr,
fs->fstype_name = "ext2";
fs->fsck = "fsck.ext2";
fs->driver = "extfs";
if ( sb->s_feature_incompat & ~EXT2_FEATURE_INCOMPAT_SUPPORTED )
fs->driver = NULL;
fs->flags |= FILESYSTEM_FLAG_UUID;
memcpy(&fs->uuid, sb->s_uuid, 16);
struct timespec now;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2015, 2016 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -24,9 +24,23 @@
#include <mount/filesystem.h>
static const uint16_t EXT2_SUPER_MAGIC = 0xEF53;
static const uint16_t EXT2_VALID_FS = 1;
static const uint16_t EXT2_ERROR_FS = 2;
#define EXT2_SUPER_MAGIC 0xEF53
#define EXT2_VALID_FS 1
#define EXT2_ERROR_FS 2
#define EXT2_FEATURE_COMPAT_DIR_PREALLOC (1U << 0U)
#define EXT2_FEATURE_COMPAT_IMAGIC_INODES (1U << 1U)
#define EXT3_FEATURE_COMPAT_HAS_JOURNAL (1U << 2U)
#define EXT2_FEATURE_COMPAT_EXT_ATTR (1U << 3U)
#define EXT2_FEATURE_COMPAT_RESIZE_INO (1U << 4U)
#define EXT2_FEATURE_COMPAT_DIR_INDEX (1U << 5U)
#define EXT2_FEATURE_INCOMPAT_COMPRESSION (1U << 0U)
#define EXT2_FEATURE_INCOMPAT_FILETYPE (1U << 1U)
#define EXT2_FEATURE_INCOMPAT_RECOVER (1U << 2U)
#define EXT2_FEATURE_INCOMPAT_JOURNAL_DEV (1U << 3U)
#define EXT2_FEATURE_INCOMPAT_META_BG (1U << 4U)
#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER (1U << 0U)
#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE (1U << 1U)
#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR (1U << 2U)
struct ext2_superblock
{

View File

@ -378,20 +378,20 @@ void mountpoint_mount(struct mountpoint* mountpoint)
{
mountpoint->pid = -1;
if ( WIFSIGNALED(code) )
err(2, "%s: Mount failed: %s: %s", bdev_path, fs->driver,
strsignal(WTERMSIG(code)));
errx(2, "%s: Mount failed: %s: %s", bdev_path, fs->driver,
strsignal(WTERMSIG(code)));
else if ( !WIFEXITED(code) )
err(2, "%s: Mount failed: %s: %s", bdev_path, fs->driver,
"Unexpected unusual termination");
errx(2, "%s: Mount failed: %s: %s", bdev_path, fs->driver,
"Unexpected unusual termination");
else if ( WEXITSTATUS(code) == 127 )
err(2, "%s: Mount failed: %s: %s", bdev_path, fs->driver,
"Filesystem driver is absent");
errx(2, "%s: Mount failed: %s: %s", bdev_path, fs->driver,
"Filesystem driver is absent");
else if ( WEXITSTATUS(code) == 0 )
err(2, "%s: Mount failed: %s: Unexpected successful exit",
bdev_path, fs->driver);
errx(2, "%s: Mount failed: %s: Unexpected successful exit",
bdev_path, fs->driver);
else
err(2, "%s: Mount failed: %s: Exited with status %i", bdev_path,
fs->driver, WEXITSTATUS(code));
errx(2, "%s: Mount failed: %s: Exited with status %i", bdev_path,
fs->driver, WEXITSTATUS(code));
}
struct timespec delay = timespec_make(0, 50L * 1000L * 1000L);
nanosleep(&delay, NULL);

View File

@ -597,24 +597,32 @@ int main(void)
continue;
}
root_filesystem = NULL;
bool cant_mount = false;
for ( size_t i = 0; i < mountpoints_used; i++ )
{
struct mountpoint* mnt = &mountpoints[i];
const char* spec = mnt->entry.fs_spec;
if ( !(mnt->fs = search_for_filesystem_by_spec(spec)) )
{
warnx("fstab: Found no filesystem matching `%s'", spec);
warnx("fstab: %s: Found no mountable filesystem matching `%s'",
mnt->entry.fs_file, spec);
cant_mount = true;
continue;
}
if ( !mnt->fs->driver )
{
textf("Don't know how to mount a root filesystem of type %s. "
"Try again.\n", mnt->fs->fstype_name);
warnx("fstab: %s: %s: Don't know how to mount this %s filesystem",
mnt->entry.fs_file,
path_of_blockdevice(mnt->fs->bdev),
mnt->fs->fstype_name);
cant_mount = true;
continue;
}
if ( !strcmp(mnt->entry.fs_file, "/") )
root_filesystem = mnt->fs;
}
if ( cant_mount )
continue;
assert(root_filesystem);
if ( !strcasecmp(accept_grub, "yes") &&
missing_bios_boot_partition(root_filesystem) )