Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 39247483 authored by Yumi Yukimura's avatar Yumi Yukimura Committed by Michael Bestas
Browse files

volume_manager: Add support for ISO9660/UDF CD-ROM

This commit is squash of the following commits, with improvements:

	Author: Yumi Yukimura <me.cafebabe@gmail.com>
	Date:   Thu Jul 25 03:38:40 2024 +0800

	    volume_manager: Handle USB CDROM that has both filesystem and partition table

	    * Unlike SATA CDROM, USB CDROM has the same major and minor number,
	      and the same block device name (sdX) as USB Disk.
	    * For SATA CDROM, sgdisk_read() would fail, but for USB CDROM it
	      won't fail if partition table is found.
	    * ISO image generated by grub-mkrescue is in such format.

	Author: Chih-Wei Huang <cwhuang@linux.org.tw>
	Date:   Sat Mar 25 16:46:42 2017 +0000

	    volume_manager: support UDF (Universal Disk Format)

	    Refer to https://en.wikipedia.org/wiki/Universal_Disk_Format

.

	    [cafebabe: Apply fixups suggested by Luca Stefani]

	Author: Chih-Wei Huang <cwhuang@linux.org.tw>
	Date:   Sat Mar 25 16:45:41 2017 +0000

	    volume_manager: auto mount CDROM

	    Luo Chunbo's ISO9660 support (commit 133632d5) is not complete. Still
	    need to handle block devices with major number of CDROM.

	Author: Luo Chunbo <luochunbo@jidemail.com>
	Date:   Wed May 25 16:16:48 2016 +0800

	    volume_manager: ISO9660 support

	    Ref: T7691

	    [cafebabe: Remove MS_DIRSYNC and utf8 flags which are "Invalid argument", Refactor iso9660::Mount() (Suggested edit by Luca Stefani)]

	    Signed-off-by: default avatarLuo Chunbo <luochunbo@jidemail.com>

Change-Id: I92cedc0b23dfc98c874fddee189ec599c409b62f
parent 7ebecd04
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ cc_library_shared {
        "fs/Exfat.cpp",
        "fs/Ext4.cpp",
        "fs/F2fs.cpp",
        "fs/Iso9660.cpp",
        "fs/Ntfs.cpp",
        "fs/Vfat.cpp",
    ],
+26 −6
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ static const unsigned int kMajorBlockScsiP = 135;
static const unsigned int kMajorBlockMmc = 179;
static const unsigned int kMajorBlockExperimentalMin = 240;
static const unsigned int kMajorBlockExperimentalMax = 254;
static const unsigned int kMajorBlockCdrom = 11;

static const char* kGptBasicData = "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7";
static const char* kGptLinuxFilesystem = "0FC63DAF-8483-4772-8E79-3D69D8477DE4";
@@ -205,6 +206,9 @@ status_t Disk::readMetadata() {
            mLabel = "Virtual";
            break;
        }
        case kMajorBlockCdrom:
             LOG(DEBUG) << "Found a CDROM: " << mSysPath;
             FALLTHROUGH_INTENDED;
        case kMajorBlockScsiA:
        case kMajorBlockScsiB:
        case kMajorBlockScsiC:
@@ -277,6 +281,12 @@ status_t Disk::readMetadata() {
}

status_t Disk::readPartitions() {
    sgdisk_partition_table ptbl;
    std::vector<sgdisk_partition> partitions;
    int res;
    Table table = Table::kUnknown;
    bool foundParts = false;

    int8_t maxMinors = getMaxMinors();
    if (maxMinors < 0) {
        return -ENOTSUP;
@@ -290,19 +300,25 @@ status_t Disk::readPartitions() {

    destroyAllVolumes();

    if (!maxMinors) {
        std::string cdFsType, cdUnused;
        if (ReadMetadataUntrusted(mDevPath, cdFsType, cdUnused, cdUnused) == OK) {
            if (cdFsType == "iso9660" || cdFsType == "udf") {
                LOG(INFO) << "Detect " << cdFsType;
                goto treat_disk_as_partition;
            }
        }
    }

    // Parse partition table
    sgdisk_partition_table ptbl;
    std::vector<sgdisk_partition> partitions;
    int res = sgdisk_read(mDevPath.c_str(), ptbl, partitions);
    res = sgdisk_read(mDevPath.c_str(), ptbl, partitions);
    if (res != 0) {
        LOG(WARNING) << "sgdisk failed to scan " << mDevPath;

        VolumeManager::Instance()->notifyEvent(ResponseCode::DiskScanned);
        return res;
    }

    Table table = Table::kUnknown;
    bool foundParts = false;

    switch (ptbl.type) {
        case MBR:
            table = Table::kMbr;
@@ -341,6 +357,7 @@ status_t Disk::readPartitions() {
        }
    }

treat_disk_as_partition:
    // Ugly last ditch effort, treat entire disk as partition
    if (table == Table::kUnknown || !foundParts) {
        LOG(WARNING) << mId << " has unknown partition table; trying entire device";
@@ -396,6 +413,9 @@ int Disk::getMaxMinors() {
            // Per Documentation/devices.txt this is static
            return 15;
        }
        case kMajorBlockCdrom: {
            return 0;
        }
        case kMajorBlockMmc: {
            // Per Documentation/devices.txt this is dynamic
            std::string tmp;
+2 −0
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ class Disk {
        kEmmc = 1 << 4,
        /* Flag that disk is non-removable */
        kNonRemovable = 1 << 5,
        /* Flag that disk is CDROM */
        kCdrom = 1 << 6,
    };

    const std::string& getId() { return mId; }
+8 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "fs/Exfat.h"
#include "fs/Ext4.h"
#include "fs/F2fs.h"
#include "fs/Iso9660.h"
#include "fs/Ntfs.h"
#include "fs/Vfat.h"

@@ -59,6 +60,11 @@ status_t PublicVolume::readMetadata() {
    status_t res = ReadMetadataUntrusted(mDevPath, mFsType, mFsUuid, label);
    if (!label.empty()) {
        setPartLabel(label);
        // iso9660 has no UUID, we use label as UUID
        if ((mFsType == "iso9660" || mFsType == "udf") && mFsUuid.empty() && !label.empty()) {
            std::replace(label.begin(), label.end(), ' ', '_');
            mFsUuid = label;
        }
    }
    VolumeManager::Instance()->notifyEvent(ResponseCode::VolumeFsTypeChanged, mFsType);
    VolumeManager::Instance()->notifyEvent(ResponseCode::VolumeFsUuidChanged, mFsUuid);
@@ -104,6 +110,8 @@ status_t PublicVolume::doMount() {
        ret = ext4::Mount(mDevPath, getPath(), false, false, true, mMntOpts, false, true);
    } else if (mFsType == "f2fs") {
        ret = f2fs::Mount(mDevPath, getPath(), mMntOpts, false, true);
    } else if (mFsType == "iso9660" || mFsType == "udf") {
        ret = iso9660::Mount(mDevPath, getPath(), AID_MEDIA_RW, AID_MEDIA_RW);
    } else if (mFsType == "ntfs") {
        ret =
            ntfs::Mount(mDevPath, getPath(), false, false, false, AID_MEDIA_RW, AID_MEDIA_RW, 0007);
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ struct selabel_handle* sehandle;
using android::fs_mgr::Fstab;
using android::fs_mgr::FstabEntry;

static const unsigned int kMajorBlockCdrom = 11;
static const unsigned int kMajorBlockMmc = 179;
static const unsigned int kMajorBlockExperimentalMin = 240;
static const unsigned int kMajorBlockExperimentalMax = 254;
@@ -305,6 +306,8 @@ void VolumeManager::handleBlockEvent(NetlinkEvent* evt) {
                        (IsRunningInEmulator() && major >= (int)kMajorBlockExperimentalMin &&
                         major <= (int)kMajorBlockExperimentalMax)) {
                        flags |= Disk::Flags::kSd;
                    } else if (major == kMajorBlockCdrom) {
                        flags |= Disk::Flags::kCdrom;
                    } else {
                        flags |= Disk::Flags::kUsb;
                    }
Loading