diff --git a/zircon/system/core/devmgr/fshost/block-device.cpp b/zircon/system/core/devmgr/fshost/block-device.cpp index c5e64c85fc919e9fad24e55fe1cff78a955a31ba..3881a0ac2938b405b61d366bde57ffbfbd59a810 100644 --- a/zircon/system/core/devmgr/fshost/block-device.cpp +++ b/zircon/system/core/devmgr/fshost/block-device.cpp @@ -86,7 +86,7 @@ int UnsealZxcryptThread(void* arg) { zx_status_t rc; std::unique_ptr<zxcrypt::FdioVolume> zxcrypt_volume; if ((rc = zxcrypt::FdioVolume::Init(std::move(fd), &zxcrypt_volume)) != ZX_OK) { - printf("fshost: couldn't open zxcrypt fdio volume"); + printf("fshost: couldn't open zxcrypt fdio volume\n"); return ZX_OK; } @@ -94,14 +94,14 @@ int UnsealZxcryptThread(void* arg) { if ((rc = zxcrypt_volume->OpenManager(zx::sec(2), zxcrypt_volume_manager_chan.reset_and_get_address())) != ZX_OK) { - printf("fshost: couldn't open zxcrypt manager device"); + printf("fshost: couldn't open zxcrypt manager device\n"); return 0; } zxcrypt::FdioVolumeManager zxcrypt_volume_manager(std::move(zxcrypt_volume_manager_chan)); uint8_t slot = 0; if ((rc = zxcrypt_volume_manager.UnsealWithDeviceKey(slot)) != ZX_OK) { - printf("fshost: couldn't unseal zxcrypt manager device"); + printf("fshost: couldn't unseal zxcrypt manager device\n"); return 0; } @@ -112,7 +112,7 @@ int UnsealZxcryptThread(void* arg) { BlockDevice::BlockDevice(FilesystemMounter* mounter, fbl::unique_fd fd) : mounter_(mounter), fd_(std::move(fd)), - format_(detect_disk_format(fd_.get())) {} + format_(detect_disk_format_log_unknown(fd_.get())) {} disk_format_t BlockDevice::GetFormat() { return format_; diff --git a/zircon/system/core/devmgr/fshost/block-watcher.cpp b/zircon/system/core/devmgr/fshost/block-watcher.cpp index ac5b37547bda94168221fecb5f22e8831a0092c8..fab3a74d41fd72307645db4ff4013c1e3cd75ba6 100644 --- a/zircon/system/core/devmgr/fshost/block-watcher.cpp +++ b/zircon/system/core/devmgr/fshost/block-watcher.cpp @@ -60,7 +60,14 @@ zx_status_t BlockDeviceCallback(int dirfd, int event, const char* name, void* co auto mounter = static_cast<FilesystemMounter*>(cookie); BlockDevice device(mounter, std::move(device_fd)); - device.Add(); + zx_status_t rc = device.Add(); + if (rc != ZX_OK) { + // This callback has to return ZX_OK for resiliency reasons, or we'll + // stop getting subsequent callbacks, but we should log loudly that we + // tried to do something and that failed. + fprintf(stderr, "fshost: (%s/%s) failed: %s\n", kPathBlockDeviceRoot, + name, zx_status_get_string(rc)); + } return ZX_OK; } diff --git a/zircon/system/ulib/fs-management/BUILD.gn b/zircon/system/ulib/fs-management/BUILD.gn index c2b50087fcd13a15ee349fa79d625a620703459d..788d03cc92c68931a7053c12ce963ac447fe1ae6 100644 --- a/zircon/system/ulib/fs-management/BUILD.gn +++ b/zircon/system/ulib/fs-management/BUILD.gn @@ -29,6 +29,7 @@ library("fs-management") { "$zx/system/ulib/fvm", "$zx/system/ulib/fzl", "$zx/system/ulib/gpt", + "$zx/system/ulib/pretty", "$zx/system/ulib/zx", "$zx/system/ulib/zxcpp", "$zx/third_party/ulib/uboringssl", diff --git a/zircon/system/ulib/fs-management/include/fs-management/mount.h b/zircon/system/ulib/fs-management/include/fs-management/mount.h index 79fecda40fa282fc11990648a67035ba0552bd33..081483610a0307e1d531ab8ef28edc1b89f4a6f4 100644 --- a/zircon/system/ulib/fs-management/include/fs-management/mount.h +++ b/zircon/system/ulib/fs-management/include/fs-management/mount.h @@ -73,6 +73,7 @@ static const uint8_t zxcrypt_magic[16] = { }; disk_format_t detect_disk_format(int fd); +disk_format_t detect_disk_format_log_unknown(int fd); typedef struct mount_options { bool readonly; diff --git a/zircon/system/ulib/fs-management/mount.cpp b/zircon/system/ulib/fs-management/mount.cpp index 7666424df9810ce909548e925b588011da3da19a..2e24a44295f3496ccb69353c444507ed9ec5da69 100644 --- a/zircon/system/ulib/fs-management/mount.cpp +++ b/zircon/system/ulib/fs-management/mount.cpp @@ -25,6 +25,7 @@ #include <lib/fdio/vfs.h> #include <lib/fzl/fdio.h> #include <lib/zx/channel.h> +#include <pretty/hexdump.h> #include <zircon/compiler.h> #include <zircon/device/block.h> #include <zircon/device/vfs.h> @@ -271,7 +272,12 @@ const fsck_options_t default_fsck_options = { .apply_journal = false, }; -disk_format_t detect_disk_format(int fd) { +enum DiskFormatLogVerbosity { + Silent, + Verbose, +}; + +disk_format_t detect_disk_format_impl(int fd, DiskFormatLogVerbosity verbosity) { if (lseek(fd, 0, SEEK_SET) != 0) { fprintf(stderr, "detect_disk_format: Cannot seek to start of device.\n"); return DISK_FORMAT_UNKNOWN; @@ -327,9 +333,30 @@ disk_format_t detect_disk_format(int fd) { } return DISK_FORMAT_MBR; } + + if (verbosity == DiskFormatLogVerbosity::Verbose) { + // Log a hexdump of the bytes we looked at and didn't find any magic in. + fprintf(stderr, "detect_disk_format: did not recognize format. Looked at:\n"); + // fvm, zxcrypt, minfs, and blobfs have their magic bytes at the start + // of the block. + hexdump_very_ex(data, 16, 0, hexdump_stdio_printf, stderr); + // MBR is two bytes at offset 0x1fe, but print 16 just for consistency + hexdump_very_ex(data + 0x1f0, 16, 0x1f0, hexdump_stdio_printf, stderr); + // GPT magic is stored 512 bytes in, so it can coexist with MBR. + hexdump_very_ex(data + 0x200, 16, 0x200, hexdump_stdio_printf, stderr); + } + return DISK_FORMAT_UNKNOWN; } +disk_format_t detect_disk_format(int fd) { + return detect_disk_format_impl(fd, DiskFormatLogVerbosity::Silent); +} + +disk_format_t detect_disk_format_log_unknown(int fd) { + return detect_disk_format_impl(fd, DiskFormatLogVerbosity::Verbose); +} + zx_status_t fmount(int device_fd, int mount_fd, disk_format_t df, const mount_options_t* options, LaunchCallback cb) { Mounter mounter(mount_fd);