Skip to content

Commit

Permalink
Provide an enum for the mount flags instead of preprocessor definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkMatterCore committed Dec 17, 2020
1 parent 3f66f8d commit 5015215
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
38 changes: 19 additions & 19 deletions include/usbhsfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,6 @@ extern "C" {
#define LIBUSBHSFS_VERSION_MINOR 1
#define LIBUSBHSFS_VERSION_MICRO 0

/// Filesystem mount flags.
/// Not all supported filesystems are compatible with these flags.
/// The default, not configured mount flags bitmask is `USB_MOUNT_UPDATE_ACCESS_TIMES | USB_MOUNT_SHOW_HIDDEN_FILES`.
#define USB_MOUNT_DEFAULT 0x00000000 /* Default options, don't do anything special. */

#define USB_MOUNT_IGNORE_CASE 0x00000001 /* Ignore case sensitivity. Everything will be lowercase (NTFS only). */
#define USB_MOUNT_UPDATE_ACCESS_TIMES 0x00000002 /* Update file and directory access times (NTFS only). */
#define USB_MOUNT_SHOW_HIDDEN_FILES 0x00000004 /* Display hidden files when enumerating directories (NTFS only). */
#define USB_MOUNT_SHOW_SYSTEM_FILES 0x00000008 /* Display system files when enumerating directories (NTFS only). */
#define USB_MOUNT_IGNORE_READ_ONLY_ATTR 0x00000010 /* Allow writing to files even if they are marked as read-only (NTFS only). */

#define USB_MOUNT_READ_ONLY 0x00000100 /* Mount in read-only mode (NTFS only). */
#define USB_MOUNT_RECOVER 0x00000200 /* Replay the log/journal to restore filesystem consistency (e.g. fix unsafe device ejections) (NTFS only). */

#define USB_MOUNT_IGNORE_HIBERNATION 0x00010000 /* Mount even if filesystem is hibernated (NTFS only). */

#define USB_MOUNT_SU (USB_MOUNT_SHOW_HIDDEN_FILES | USB_MOUNT_SHOW_SYSTEM_FILES | USB_MOUNT_IGNORE_READ_ONLY_ATTR)
#define USB_MOUNT_FORCE (USB_MOUNT_RECOVER | USB_MOUNT_IGNORE_HIBERNATION)

/// Used to identify the filesystem type from a mounted filesystem (e.g. filesize limitations, etc.).
typedef enum {
UsbHsFsDeviceFileSystemType_Invalid = 0,
Expand All @@ -52,6 +33,25 @@ typedef enum {
UsbHsFsDeviceFileSystemType_NTFS = 5 ///< Only returned by the GPL build of the library.
} UsbHsFsDeviceFileSystemType;

/// Filesystem mount flags.
/// Not all supported filesystems are compatible with these flags.
/// The default mount bitmask is `UsbHsFsMountFlags_UpdateAccessTimes | UsbHsFsMountFlags_ShowHiddenFiles`. It can be overriden via usbHsFsSetFileSystemMountFlags() (see below).
typedef enum {
UsbHsFsMountFlags_None = 0x00000000, ///< No special action is taken.
UsbHsFsMountFlags_IgnoreCaseSensitivity = 0x00000001, ///< NTFS only. Case sensitivity is ignored for all filesystem operations.
UsbHsFsMountFlags_UpdateAccessTimes = 0x00000002, ///< NTFS only. File/directory access times are updated after each successful R/W operation.
UsbHsFsMountFlags_ShowHiddenFiles = 0x00000004, ///< NTFS only. Hidden file entries are returned while enumerating directories.
UsbHsFsMountFlags_ShowSystemFiles = 0x00000008, ///< NTFS only. System file entries are returned while enumerating directories.
UsbHsFsMountFlags_IgnoreFileReadOnlyAttribute = 0x00000010, ///< NTFS only. Allows writing to files even if they are marked as read-only.
UsbHsFsMountFlags_ReadOnly = 0x00000100, ///< NTFS only. Filesystem is mounted as read-only.
UsbHsFsMountFlags_ReplayJournal = 0x00000200, ///< NTFS only. Replays the log/journal to restore filesystem consistency (e.g. fix unsafe device ejections).
UsbHsFsMountFlags_IgnoreHibernation = 0x00010000, ///< NTFS only. Filesystem is mounted even if it's in a hibernated state.

///< Pre-generated bitmasks provided for convenience.
UsbHsFsMountFlags_SuperUser = (UsbHsFsMountFlags_ShowHiddenFiles | UsbHsFsMountFlags_ShowSystemFiles | UsbHsFsMountFlags_IgnoreFileReadOnlyAttribute),
UsbHsFsMountFlags_Force = (UsbHsFsMountFlags_ReplayJournal | UsbHsFsMountFlags_IgnoreHibernation)
} UsbHsFsMountFlags;

/// Struct used to list mounted filesystems as devoptab devices.
/// Everything but the vendor_id, product_id, product_revision and name fields is empty/zeroed-out under SX OS.
typedef struct {
Expand Down
18 changes: 9 additions & 9 deletions source/usbhsfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static bool g_fatFsVolumeTable[FF_VOLUMES] = { false };
static const u8 g_microsoftBasicDataPartitionGuid[0x10] = { 0xA2, 0xA0, 0xD0, 0xEB, 0xE5, 0xB9, 0x33, 0x44, 0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7 }; /* EBD0A0A2-B9E5-4433-87C0-68B6B72699C7. */
static const u8 g_linuxFilesystemDataGuid[0x10] = { 0xAF, 0x3D, 0xC6, 0x0F, 0x83, 0x84, 0x72, 0x47, 0x8E, 0x79, 0x3D, 0x69, 0xD8, 0x47, 0x7D, 0xE4 }; /* 0FC63DAF-8483-4772-8E79-3D69D8477DE4. */

static u32 g_fileSystemMountFlags = (USB_MOUNT_UPDATE_ACCESS_TIMES | USB_MOUNT_SHOW_HIDDEN_FILES);
static u32 g_fileSystemMountFlags = (UsbHsFsMountFlags_UpdateAccessTimes | UsbHsFsMountFlags_ShowHiddenFiles);

__thread char __usbhsfs_dev_path_buf[USB_MAX_PATH_LENGTH] = {0};

Expand Down Expand Up @@ -867,14 +867,14 @@ static bool usbHsFsMountRegisterNtfsVolume(UsbHsFsDriveLogicalUnitFileSystemCont

/* Setup NTFS volume descriptor. */
fs_ctx->ntfs->id = fs_ctx->device_id;
fs_ctx->ntfs->atime = ((flags & USB_MOUNT_UPDATE_ACCESS_TIMES) ? ATIME_ENABLED : ATIME_DISABLED);
fs_ctx->ntfs->ignore_read_only_attr = (flags & USB_MOUNT_IGNORE_READ_ONLY_ATTR);
fs_ctx->ntfs->show_hidden_files = (flags & USB_MOUNT_SHOW_HIDDEN_FILES);
fs_ctx->ntfs->show_system_files = (flags & USB_MOUNT_SHOW_SYSTEM_FILES);
fs_ctx->ntfs->atime = ((flags & UsbHsFsMountFlags_UpdateAccessTimes) ? ATIME_ENABLED : ATIME_DISABLED);
fs_ctx->ntfs->ignore_read_only_attr = (flags & UsbHsFsMountFlags_IgnoreFileReadOnlyAttribute);
fs_ctx->ntfs->show_hidden_files = (flags & UsbHsFsMountFlags_ShowHiddenFiles);
fs_ctx->ntfs->show_system_files = (flags & UsbHsFsMountFlags_ShowSystemFiles);

if ((flags & USB_MOUNT_READ_ONLY) || lun_ctx->write_protect) fs_ctx->ntfs->flags |= NTFS_MNT_RDONLY;
if (flags & USB_MOUNT_RECOVER) fs_ctx->ntfs->flags |= NTFS_MNT_RECOVER;
if (flags & USB_MOUNT_IGNORE_HIBERNATION) fs_ctx->ntfs->flags |= NTFS_MNT_IGNORE_HIBERFILE;
if ((flags & UsbHsFsMountFlags_ReadOnly) || lun_ctx->write_protect) fs_ctx->ntfs->flags |= NTFS_MNT_RDONLY;
if (flags & UsbHsFsMountFlags_ReplayJournal) fs_ctx->ntfs->flags |= NTFS_MNT_RECOVER;
if (flags & UsbHsFsMountFlags_IgnoreHibernation) fs_ctx->ntfs->flags |= NTFS_MNT_IGNORE_HIBERFILE;

/* Try to mount NTFS volume. */
fs_ctx->ntfs->vol = ntfs_device_mount(fs_ctx->ntfs->dev, fs_ctx->ntfs->flags);
Expand All @@ -885,7 +885,7 @@ static bool usbHsFsMountRegisterNtfsVolume(UsbHsFsDriveLogicalUnitFileSystemCont
}

/* Setup volume case sensitivity. */
if (flags & USB_MOUNT_IGNORE_CASE) ntfs_set_ignore_case(fs_ctx->ntfs->vol);
if (flags & UsbHsFsMountFlags_IgnoreCaseSensitivity) ntfs_set_ignore_case(fs_ctx->ntfs->vol);

/* Register devoptab device. */
if (!usbHsFsMountRegisterDevoptabDevice(fs_ctx)) goto end;
Expand Down

0 comments on commit 5015215

Please sign in to comment.