/*** Copyright (C) 2023 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved. File: Devices.hpp Date: 2023-08-11 Date: 2023-12-05 Author: Reece ***/ #pragma once namespace Aurora::IO::FS { AUE_DEFINE(EFSDeviceType, ( eDeviceUnknown, eDeviceDisk, eDeviceSCSI, eDeviceCD, eDeviceUSBMass, eDeviceFloppy, eDeviceNetworkMount, eDeviceRamDisk, eDeviceTempRamDisk, eDeviceROMWindow, eDeviceVirtualFileSystem, eDeviceKernelConfig )) AUE_DEFINE(EFSBusType, ( eBusGeneric, eBusSCSI, eBusSATA, eBusUSB, eBusNetwork, eBusNVMePCIe )) struct LogicalUsedResponse { AuUInt64 uLogicalSize {}; AuUInt64 uLogicalUsed {}; }; struct LogicalOffsetResponse { AuUInt64 uLogicalSize {}; AuUInt64 uLogicalOffset {}; }; struct FSLogicalPartition { /** * The logical volume as a filesystem path. Under Windows, this will be a global path to the device object. * Under Linux, this will be your /dev/. */ AuString devicePath; /** * The logical volume as a filesystem path. Under Windows, this will be a global path to the volume object. * Under Linux, this will be your /dev/. */ AuString logicalMount; /** * Drive letter, NTFS volume mount path, Linux filesystem mount directory, etc */ AuList filesystemMountPoints; /** * GPT or other filesystem label */ AuOptional name; /* * Do I really need to document this? */ bool bIsReadOnly {}; /* * GPT or other UUID-like ID */ uuids::uuid uuid; /* * Often globally unique drive or volume ID */ AuOptional altID; /* * Do I really need to document this? */ LogicalUsedResponse space; /* * The physical offset of the logical filesystem/volume/partition relative to the parent FSDevice's block device object. */ LogicalOffsetResponse offset; // ... ? }; struct FSDevice { EFSDeviceType type; EFSBusType bus; AuString devicePath; uuids::uuid uuid; AuString productModel; AuOptional altLabel; AuOptional altProductDescription; AuList partitions; AuUInt64 uFSDeviceSizeInBytes {}; AuUInt64 uFSDevicePageSizeInBytes {}; }; /** * Provides the best-fit FSLogicalPartition::filesystemMountPoints of a string. * Sometimes the platform shell can help, some platforms need to pull the fs devices cache. */ AUKN_SYM AuString GetRootFromPath(const AuString &fileOrDirPath); /** * Provides a FSDevice::devicePath of a file or directory. */ AUKN_SYM AuResult GetDeviceFromPath(const AuString &fileOrDirPath); /** * Provides a FSDevice::devicePath of a root mountpoint. */ AUKN_SYM AuResult GetDeviceFromRoot(const AuString &root); /** * Provides the FSLogicalPartition::logicalMount of a file or directory. */ AUKN_SYM AuResult GetLogicalMountFromPath(const AuString &fileOrDirPath); AUKN_SYM AuString TrySimplifyDevicePath(const AuString &deviceOrLogicalMountPath); // max: unbuffered pipe io AUKN_SYM AuUInt32 GetPerformanceBufferSizeFromPath(const AuString &fileOrDirPath); // min: unbuffered pipe io AUKN_SYM AuUInt32 GetPhysicalSectorSizeFromPath(const AuString &fileOrDirPath); // min viable sector size with abstractions on top of the disk AUKN_SYM AuUInt32 GetLogicalSectorSizeFromPath(const AuString &fileOrDirPath); /** * Provides a FSLogicalPartition::space of a file or directory. */ AUKN_SYM LogicalUsedResponse GetLogicalUsedFromPath(const AuString &fileOrDirPath); /** * Provides a FSLogicalPartition::space of a logical volume path / FSLogicalPartition::logicalMount string. */ AUKN_SYM LogicalUsedResponse GetLogicalUsedFromLogicalDevice(const AuString &logicalMountPath); // Convenience function AUKN_SYM AuUInt64 GetDeviceSizeInBytes(const AuString& physicalDevicePath); // Convenience function AUKN_SYM AuResult GetDeviceModel(const AuString& physicalDevicePath); // Convenience function AUKN_SYM AuResult GetFSDeviceByFilePath(const AuString &fileOrDirPath); // Convenience function AUKN_SYM AuResult GetFSDeviceByDevice(const AuString &physicalDevicePath); /* * Provides a copy of the internal FSDevice cache under lock */ AUKN_SYM AuList GetFSDevices(); /** * Provides a reference/pointer to the internal cache without a consumer interface for read/write locking */ AUKN_SYM const AuList &GetFSDevicesCachedUnsafe(); /* * Erases the FDDevice cache */ AUKN_SYM void ResetDeviceCache(); }