diff --git a/Cargo.toml b/Cargo.toml index 18944a4..0c09f23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,6 @@ path = "ctru-sys" [dependencies.std] path = "std" + +[dependencies.bitflags] +version = "0.7.0" diff --git a/ctru-sys/src/services/fs.rs b/ctru-sys/src/services/fs.rs index 421bbcb..c94c2b6 100644 --- a/ctru-sys/src/services/fs.rs +++ b/ctru-sys/src/services/fs.rs @@ -4,21 +4,27 @@ non_camel_case_types, non_upper_case_globals, non_snake_case)] - -use ::{Handle, Result}; - -pub const FS_OPEN_READ: u32 = 1; -pub const FS_OPEN_WRITE: u32 = 2; -pub const FS_OPEN_CREATE: u32 = 4; - -pub const FS_WRITE_FLUSH: u32 = 1; -pub const FS_WRITE_UPDATE_TIME: u32 = 256; - -pub const FS_ATTRIBUTE_DIRECTORY: u32 = 1; -pub const FS_ATTRIBUTE_HIDDEN: u32 = 256; -pub const FS_ATTRIBUTE_ARCHIVE: u32 = 65536; -pub const FS_ATTRIBUTE_READ_ONLY: u32 = 16777216; - +#[derive(Copy, Clone)] +#[repr(u32)] +#[derive(Debug)] +pub enum Enum_Unnamed1 { + FS_OPEN_READ = 1, + FS_OPEN_WRITE = 2, + FS_OPEN_CREATE = 4, +} +#[derive(Copy, Clone)] +#[repr(u32)] +#[derive(Debug)] +pub enum Enum_Unnamed2 { FS_WRITE_FLUSH = 1, FS_WRITE_UPDATE_TIME = 256, } +#[derive(Copy, Clone)] +#[repr(u32)] +#[derive(Debug)] +pub enum Enum_Unnamed3 { + FS_ATTRIBUTE_DIRECTORY = 1, + FS_ATTRIBUTE_HIDDEN = 256, + FS_ATTRIBUTE_ARCHIVE = 65536, + FS_ATTRIBUTE_READ_ONLY = 16777216, +} #[derive(Copy, Clone)] #[repr(u32)] #[derive(Debug)] @@ -135,13 +141,13 @@ pub enum FS_DirectoryAction { DIRECTORY_ACTION_UNKNOWN = 0, } #[repr(C)] #[derive(Copy)] pub struct FS_DirectoryEntry { - pub name: [u16; 262usize], - pub shortName: [u8; 10usize], - pub shortExt: [u8; 4usize], - pub valid: u8, - pub reserved: u8, - pub attributes: u32, - pub fileSize: u64, + pub name: [u16_; 262usize], + pub shortName: [::libc::c_char; 10usize], + pub shortExt: [::libc::c_char; 4usize], + pub valid: u8_, + pub reserved: u8_, + pub attributes: u32_, + pub fileSize: u64_, } impl ::core::clone::Clone for FS_DirectoryEntry { fn clone(&self) -> Self { *self } @@ -153,10 +159,10 @@ impl ::core::default::Default for FS_DirectoryEntry { #[derive(Copy, Clone)] #[derive(Debug)] pub struct FS_ArchiveResource { - pub sectorSize: u32, - pub clusterSize: u32, - pub totalClusters: u32, - pub freeClusters: u32, + pub sectorSize: u32_, + pub clusterSize: u32_, + pub totalClusters: u32_, + pub freeClusters: u32_, } impl ::core::default::Default for FS_ArchiveResource { fn default() -> Self { unsafe { ::core::mem::zeroed() } } @@ -165,9 +171,9 @@ impl ::core::default::Default for FS_ArchiveResource { #[derive(Copy, Clone)] #[derive(Debug)] pub struct FS_ProgramInfo { - pub programId: u64, + pub programId: u64_, pub _bindgen_bitfield_1_: FS_MediaType, - pub padding: [u8; 7usize], + pub padding: [u8_; 7usize], } impl ::core::default::Default for FS_ProgramInfo { fn default() -> Self { unsafe { ::core::mem::zeroed() } } @@ -176,9 +182,9 @@ impl ::core::default::Default for FS_ProgramInfo { #[derive(Copy, Clone)] #[derive(Debug)] pub struct FS_ProductInfo { - pub productCode: [u8; 16usize], - pub companyCode: [u8; 2usize], - pub remasterVersion: u16, + pub productCode: [::libc::c_char; 16usize], + pub companyCode: [::libc::c_char; 2usize], + pub remasterVersion: u16_, } impl ::core::default::Default for FS_ProductInfo { fn default() -> Self { unsafe { ::core::mem::zeroed() } } @@ -186,8 +192,8 @@ impl ::core::default::Default for FS_ProductInfo { #[repr(C)] #[derive(Copy)] pub struct FS_IntegrityVerificationSeed { - pub aesCbcMac: [u8; 16usize], - pub movableSed: [u8; 288usize], + pub aesCbcMac: [u8_; 16usize], + pub movableSed: [u8_; 288usize], } impl ::core::clone::Clone for FS_IntegrityVerificationSeed { fn clone(&self) -> Self { *self } @@ -200,10 +206,10 @@ impl ::core::default::Default for FS_IntegrityVerificationSeed { #[derive(Debug)] pub struct FS_ExtSaveDataInfo { pub _bindgen_bitfield_1_: FS_MediaType, - pub unknown: u8, - pub reserved1: u16, - pub saveId: u64, - pub reserved2: u32, + pub unknown: u8_, + pub reserved1: u16_, + pub saveId: u64_, + pub reserved2: u32_, } impl ::core::default::Default for FS_ExtSaveDataInfo { fn default() -> Self { unsafe { ::core::mem::zeroed() } } @@ -213,9 +219,9 @@ impl ::core::default::Default for FS_ExtSaveDataInfo { #[derive(Debug)] pub struct FS_SystemSaveDataInfo { pub _bindgen_bitfield_1_: FS_MediaType, - pub unknown: u8, - pub reserved: u16, - pub saveId: u32, + pub unknown: u8_, + pub reserved: u16_, + pub saveId: u32_, } impl ::core::default::Default for FS_SystemSaveDataInfo { fn default() -> Self { unsafe { ::core::mem::zeroed() } } @@ -224,8 +230,8 @@ impl ::core::default::Default for FS_SystemSaveDataInfo { #[derive(Copy, Clone)] #[derive(Debug)] pub struct FS_DeviceMoveContext { - pub ivs: [u8; 16usize], - pub encryptParameter: [u8; 16usize], + pub ivs: [u8_; 16usize], + pub encryptParameter: [u8_; 16usize], } impl ::core::default::Default for FS_DeviceMoveContext { fn default() -> Self { unsafe { ::core::mem::zeroed() } } @@ -235,27 +241,27 @@ impl ::core::default::Default for FS_DeviceMoveContext { #[derive(Debug)] pub struct FS_Path { pub type_: FS_PathType, - pub size: u32, + pub size: u32_, pub data: *const ::libc::c_void, } impl ::core::default::Default for FS_Path { fn default() -> Self { unsafe { ::core::mem::zeroed() } } } -pub type FS_Archive = u64; +pub type FS_Archive = u64_; #[repr(C)] #[derive(Copy, Clone)] #[derive(Debug)] pub struct romfs_header { - pub headerSize: u32, - pub dirHashTableOff: u32, - pub dirHashTableSize: u32, - pub dirTableOff: u32, - pub dirTableSize: u32, - pub fileHashTableOff: u32, - pub fileHashTableSize: u32, - pub fileTableOff: u32, - pub fileTableSize: u32, - pub fileDataOff: u32, + pub headerSize: u32_, + pub dirHashTableOff: u32_, + pub dirHashTableSize: u32_, + pub dirTableOff: u32_, + pub dirTableSize: u32_, + pub fileHashTableOff: u32_, + pub fileHashTableSize: u32_, + pub fileTableOff: u32_, + pub fileTableSize: u32_, + pub fileDataOff: u32_, } impl ::core::default::Default for romfs_header { fn default() -> Self { unsafe { ::core::mem::zeroed() } } @@ -264,13 +270,13 @@ impl ::core::default::Default for romfs_header { #[derive(Copy, Clone)] #[derive(Debug)] pub struct romfs_dir { - pub parent: u32, - pub sibling: u32, - pub childDir: u32, - pub childFile: u32, - pub nextHash: u32, - pub nameLen: u32, - pub name: [u16; 0usize], + pub parent: u32_, + pub sibling: u32_, + pub childDir: u32_, + pub childFile: u32_, + pub nextHash: u32_, + pub nameLen: u32_, + pub name: [u16_; 0usize], } impl ::core::default::Default for romfs_dir { fn default() -> Self { unsafe { ::core::mem::zeroed() } } @@ -279,13 +285,13 @@ impl ::core::default::Default for romfs_dir { #[derive(Copy, Clone)] #[derive(Debug)] pub struct romfs_file { - pub parent: u32, - pub sibling: u32, - pub dataOff: u64, - pub dataSize: u64, - pub nextHash: u32, - pub nameLen: u32, - pub name: [u16; 0usize], + pub parent: u32_, + pub sibling: u32_, + pub dataOff: u64_, + pub dataSize: u64_, + pub nextHash: u32_, + pub nameLen: u32_, + pub name: [u16_; 0usize], } impl ::core::default::Default for romfs_file { fn default() -> Self { unsafe { ::core::mem::zeroed() } } @@ -302,15 +308,15 @@ extern "C" { -> FS_Path; pub fn fsGetSessionHandle() -> *mut Handle; pub fn FSUSER_Control(action: FS_Action, input: *mut ::libc::c_void, - inputSize: u32, output: *mut ::libc::c_void, - outputSize: u32) -> Result; + inputSize: u32_, output: *mut ::libc::c_void, + outputSize: u32_) -> Result; pub fn FSUSER_Initialize(session: Handle) -> Result; pub fn FSUSER_OpenFile(out: *mut Handle, archive: FS_Archive, - path: FS_Path, openFlags: u32, attributes: u32) + path: FS_Path, openFlags: u32_, attributes: u32_) -> Result; pub fn FSUSER_OpenFileDirectly(out: *mut Handle, archiveId: FS_ArchiveID, archivePath: FS_Path, filePath: FS_Path, - openFlags: u32, attributes: u32) + openFlags: u32_, attributes: u32_) -> Result; pub fn FSUSER_DeleteFile(archive: FS_Archive, path: FS_Path) -> Result; pub fn FSUSER_RenameFile(srcArchive: FS_Archive, srcPath: FS_Path, @@ -321,9 +327,9 @@ extern "C" { pub fn FSUSER_DeleteDirectoryRecursively(archive: FS_Archive, path: FS_Path) -> Result; pub fn FSUSER_CreateFile(archive: FS_Archive, path: FS_Path, - attributes: u32, fileSize: u64) -> Result; + attributes: u32_, fileSize: u64_) -> Result; pub fn FSUSER_CreateDirectory(archive: FS_Archive, path: FS_Path, - attributes: u32) -> Result; + attributes: u32_) -> Result; pub fn FSUSER_RenameDirectory(srcArchive: FS_Archive, srcPath: FS_Path, dstArchive: FS_Archive, dstPath: FS_Path) -> Result; @@ -333,11 +339,11 @@ extern "C" { path: FS_Path) -> Result; pub fn FSUSER_ControlArchive(archive: FS_Archive, action: FS_ArchiveAction, - input: *mut ::libc::c_void, inputSize: u32, + input: *mut ::libc::c_void, inputSize: u32_, output: *mut ::libc::c_void, - outputSize: u32) -> Result; + outputSize: u32_) -> Result; pub fn FSUSER_CloseArchive(archive: FS_Archive) -> Result; - pub fn FSUSER_GetFreeBytes(freeBytes: *mut u64, archive: FS_Archive) + pub fn FSUSER_GetFreeBytes(freeBytes: *mut u64_, archive: FS_Archive) -> Result; pub fn FSUSER_GetCardType(type_: *mut FS_CardType) -> Result; pub fn FSUSER_GetSdmcArchiveResource(archiveResource: @@ -346,82 +352,82 @@ extern "C" { pub fn FSUSER_GetNandArchiveResource(archiveResource: *mut FS_ArchiveResource) -> Result; - pub fn FSUSER_GetSdmcFatfsError(error: *mut u32) -> Result; + pub fn FSUSER_GetSdmcFatfsError(error: *mut u32_) -> Result; pub fn FSUSER_IsSdmcDetected(detected: *mut u8) -> Result; pub fn FSUSER_IsSdmcWritable(writable: *mut u8) -> Result; - pub fn FSUSER_GetSdmcCid(out: *mut u8, length: u32) -> Result; - pub fn FSUSER_GetNandCid(out: *mut u8, length: u32) -> Result; - pub fn FSUSER_GetSdmcSpeedInfo(speedInfo: *mut u32) -> Result; - pub fn FSUSER_GetNandSpeedInfo(speedInfo: *mut u32) -> Result; - pub fn FSUSER_GetSdmcLog(out: *mut u8, length: u32) -> Result; - pub fn FSUSER_GetNandLog(out: *mut u8, length: u32) -> Result; + pub fn FSUSER_GetSdmcCid(out: *mut u8_, length: u32_) -> Result; + pub fn FSUSER_GetNandCid(out: *mut u8_, length: u32_) -> Result; + pub fn FSUSER_GetSdmcSpeedInfo(speedInfo: *mut u32_) -> Result; + pub fn FSUSER_GetNandSpeedInfo(speedInfo: *mut u32_) -> Result; + pub fn FSUSER_GetSdmcLog(out: *mut u8_, length: u32_) -> Result; + pub fn FSUSER_GetNandLog(out: *mut u8_, length: u32_) -> Result; pub fn FSUSER_ClearSdmcLog() -> Result; pub fn FSUSER_ClearNandLog() -> Result; pub fn FSUSER_CardSlotIsInserted(inserted: *mut u8) -> Result; pub fn FSUSER_CardSlotPowerOn(status: *mut u8) -> Result; pub fn FSUSER_CardSlotPowerOff(status: *mut u8) -> Result; pub fn FSUSER_CardSlotGetCardIFPowerStatus(status: *mut u8) -> Result; - pub fn FSUSER_CardNorDirectCommand(commandId: u8) -> Result; - pub fn FSUSER_CardNorDirectCommandWithAddress(commandId: u8, - address: u32) -> Result; - pub fn FSUSER_CardNorDirectRead(commandId: u8, size: u32, - output: *mut u8) -> Result; - pub fn FSUSER_CardNorDirectReadWithAddress(commandId: u8, address: u32, - size: u32, output: *mut u8) + pub fn FSUSER_CardNorDirectCommand(commandId: u8_) -> Result; + pub fn FSUSER_CardNorDirectCommandWithAddress(commandId: u8_, + address: u32_) -> Result; + pub fn FSUSER_CardNorDirectRead(commandId: u8_, size: u32_, + output: *mut u8_) -> Result; + pub fn FSUSER_CardNorDirectReadWithAddress(commandId: u8_, address: u32_, + size: u32_, output: *mut u8_) -> Result; - pub fn FSUSER_CardNorDirectWrite(commandId: u8, size: u32, - input: *mut u8) -> Result; - pub fn FSUSER_CardNorDirectWriteWithAddress(commandId: u8, address: u32, - size: u32, input: *mut u8) + pub fn FSUSER_CardNorDirectWrite(commandId: u8_, size: u32_, + input: *mut u8_) -> Result; + pub fn FSUSER_CardNorDirectWriteWithAddress(commandId: u8_, address: u32_, + size: u32_, input: *mut u8_) -> Result; - pub fn FSUSER_CardNorDirectRead_4xIO(commandId: u8, address: u32, - size: u32, output: *mut u8) + pub fn FSUSER_CardNorDirectRead_4xIO(commandId: u8_, address: u32_, + size: u32_, output: *mut u8_) -> Result; - pub fn FSUSER_CardNorDirectCpuWriteWithoutVerify(address: u32, - size: u32, - input: *mut u8) + pub fn FSUSER_CardNorDirectCpuWriteWithoutVerify(address: u32_, + size: u32_, + input: *mut u8_) -> Result; - pub fn FSUSER_CardNorDirectSectorEraseWithoutVerify(address: u32) + pub fn FSUSER_CardNorDirectSectorEraseWithoutVerify(address: u32_) -> Result; - pub fn FSUSER_GetProductInfo(info: *mut FS_ProductInfo, processId: u32) + pub fn FSUSER_GetProductInfo(info: *mut FS_ProductInfo, processId: u32_) -> Result; pub fn FSUSER_GetProgramLaunchInfo(info: *mut FS_ProgramInfo, - processId: u32) -> Result; + processId: u32_) -> Result; pub fn FSUSER_SetCardSpiBaudRate(baudRate: FS_CardSpiBaudRate) -> Result; pub fn FSUSER_SetCardSpiBusMode(busMode: FS_CardSpiBusMode) -> Result; pub fn FSUSER_SendInitializeInfoTo9() -> Result; - pub fn FSUSER_GetSpecialContentIndex(index: *mut u16, + pub fn FSUSER_GetSpecialContentIndex(index: *mut u16_, mediaType: FS_MediaType, - programId: u64, + programId: u64_, type_: FS_SpecialContentType) -> Result; - pub fn FSUSER_GetLegacyRomHeader(mediaType: FS_MediaType, programId: u64, - header: *mut u8) -> Result; + pub fn FSUSER_GetLegacyRomHeader(mediaType: FS_MediaType, programId: u64_, + header: *mut u8_) -> Result; pub fn FSUSER_GetLegacyBannerData(mediaType: FS_MediaType, - programId: u64, banner: *mut u8) + programId: u64_, banner: *mut u8_) -> Result; pub fn FSUSER_CheckAuthorityToAccessExtSaveData(access: *mut u8, mediaType: FS_MediaType, - saveId: u64, - processId: u32) + saveId: u64_, + processId: u32_) -> Result; - pub fn FSUSER_QueryTotalQuotaSize(quotaSize: *mut u64, directories: u32, - files: u32, fileSizeCount: u32, - fileSizes: *mut u64) -> Result; - pub fn FSUSER_AbnegateAccessRight(accessRight: u32) -> Result; + pub fn FSUSER_QueryTotalQuotaSize(quotaSize: *mut u64_, directories: u32_, + files: u32_, fileSizeCount: u32_, + fileSizes: *mut u64_) -> Result; + pub fn FSUSER_AbnegateAccessRight(accessRight: u32_) -> Result; pub fn FSUSER_DeleteSdmcRoot() -> Result; pub fn FSUSER_DeleteAllExtSaveDataOnNand() -> Result; pub fn FSUSER_InitializeCtrFileSystem() -> Result; pub fn FSUSER_CreateSeed() -> Result; - pub fn FSUSER_GetFormatInfo(totalSize: *mut u32, directories: *mut u32, - files: *mut u32, duplicateData: *mut u8, + pub fn FSUSER_GetFormatInfo(totalSize: *mut u32_, directories: *mut u32_, + files: *mut u32_, duplicateData: *mut u8, archiveId: FS_ArchiveID, path: FS_Path) -> Result; - pub fn FSUSER_GetLegacyRomHeader2(headerSize: u32, + pub fn FSUSER_GetLegacyRomHeader2(headerSize: u32_, mediaType: FS_MediaType, - programId: u64, header: *mut u8) + programId: u64_, header: *mut u8_) -> Result; - pub fn FSUSER_GetSdmcCtrRootPath(out: *mut u8, length: u32) -> Result; + pub fn FSUSER_GetSdmcCtrRootPath(out: *mut u8_, length: u32_) -> Result; pub fn FSUSER_GetArchiveResource(archiveResource: *mut FS_ArchiveResource, mediaType: FS_SystemMediaType) -> Result; pub fn FSUSER_ExportIntegrityVerificationSeed(seed: @@ -431,106 +437,111 @@ extern "C" { *mut FS_IntegrityVerificationSeed) -> Result; pub fn FSUSER_FormatSaveData(archiveId: FS_ArchiveID, path: FS_Path, - blocks: u32, directories: u32, files: u32, - directoryBuckets: u32, fileBuckets: u32, + blocks: u32_, directories: u32_, files: u32_, + directoryBuckets: u32_, fileBuckets: u32_, duplicateData: u8) -> Result; - pub fn FSUSER_GetLegacySubBannerData(bannerSize: u32, + pub fn FSUSER_GetLegacySubBannerData(bannerSize: u32_, mediaType: FS_MediaType, - programId: u64, banner: *mut u8) + programId: u64_, banner: *mut u8_) -> Result; - pub fn FSUSER_ReadSpecialFile(bytesRead: *mut u32, fileOffset: u64, - size: u32, data: *mut u8) -> Result; - pub fn FSUSER_GetSpecialFileSize(fileSize: *mut u64) -> Result; + pub fn FSUSER_UpdateSha256Context(data: *const ::libc::c_void, + inputSize: u32_, hash: *mut u8_) + -> Result; + pub fn FSUSER_ReadSpecialFile(bytesRead: *mut u32_, fileOffset: u64_, + size: u32_, data: *mut u8_) -> Result; + pub fn FSUSER_GetSpecialFileSize(fileSize: *mut u64_) -> Result; pub fn FSUSER_CreateExtSaveData(info: FS_ExtSaveDataInfo, - directories: u32, files: u32, - sizeLimit: u64, smdhSize: u32, - smdh: *mut u8) -> Result; + directories: u32_, files: u32_, + sizeLimit: u64_, smdhSize: u32_, + smdh: *mut u8_) -> Result; pub fn FSUSER_DeleteExtSaveData(info: FS_ExtSaveDataInfo) -> Result; - pub fn FSUSER_ReadExtSaveDataIcon(bytesRead: *mut u32, + pub fn FSUSER_ReadExtSaveDataIcon(bytesRead: *mut u32_, info: FS_ExtSaveDataInfo, - smdhSize: u32, smdh: *mut u8) + smdhSize: u32_, smdh: *mut u8_) -> Result; - pub fn FSUSER_GetExtDataBlockSize(totalBlocks: *mut u64, - freeBlocks: *mut u64, - blockSize: *mut u32, + pub fn FSUSER_GetExtDataBlockSize(totalBlocks: *mut u64_, + freeBlocks: *mut u64_, + blockSize: *mut u32_, info: FS_ExtSaveDataInfo) -> Result; - pub fn FSUSER_EnumerateExtSaveData(idsWritten: *mut u32, idsSize: u32, - mediaType: FS_MediaType, idSize: u32, - shared: u8, ids: *mut u8) -> Result; + pub fn FSUSER_EnumerateExtSaveData(idsWritten: *mut u32_, idsSize: u32_, + mediaType: FS_MediaType, idSize: u32_, + shared: u8, ids: *mut u8_) -> Result; pub fn FSUSER_CreateSystemSaveData(info: FS_SystemSaveDataInfo, - totalSize: u32, blockSize: u32, - directories: u32, files: u32, - directoryBuckets: u32, - fileBuckets: u32, duplicateData: u8) + totalSize: u32_, blockSize: u32_, + directories: u32_, files: u32_, + directoryBuckets: u32_, + fileBuckets: u32_, duplicateData: u8) -> Result; pub fn FSUSER_DeleteSystemSaveData(info: FS_SystemSaveDataInfo) -> Result; pub fn FSUSER_StartDeviceMoveAsSource(context: *mut FS_DeviceMoveContext) -> Result; pub fn FSUSER_StartDeviceMoveAsDestination(context: FS_DeviceMoveContext, clear: u8) -> Result; - pub fn FSUSER_SetArchivePriority(archive: FS_Archive, priority: u32) + pub fn FSUSER_SetArchivePriority(archive: FS_Archive, priority: u32_) -> Result; - pub fn FSUSER_GetArchivePriority(priority: *mut u32, archive: FS_Archive) + pub fn FSUSER_GetArchivePriority(priority: *mut u32_, archive: FS_Archive) -> Result; - pub fn FSUSER_SetCtrCardLatencyParameter(latency: u64, + pub fn FSUSER_SetCtrCardLatencyParameter(latency: u64_, emulateEndurance: u8) -> Result; pub fn FSUSER_SwitchCleanupInvalidSaveData(enable: u8) -> Result; - pub fn FSUSER_EnumerateSystemSaveData(idsWritten: *mut u32, - idsSize: u32, ids: *mut u32) + pub fn FSUSER_EnumerateSystemSaveData(idsWritten: *mut u32_, + idsSize: u32_, ids: *mut u32_) -> Result; - pub fn FSUSER_InitializeWithSdkVersion(session: Handle, version: u32) + pub fn FSUSER_InitializeWithSdkVersion(session: Handle, version: u32_) -> Result; - pub fn FSUSER_SetPriority(priority: u32) -> Result; - pub fn FSUSER_GetPriority(priority: *mut u32) -> Result; - pub fn FSUSER_SetSaveDataSecureValue(value: u64, + pub fn FSUSER_SetPriority(priority: u32_) -> Result; + pub fn FSUSER_GetPriority(priority: *mut u32_) -> Result; + pub fn FSUSER_SetSaveDataSecureValue(value: u64_, slot: FS_SecureValueSlot, - titleUniqueId: u32, - titleVariation: u8) -> Result; - pub fn FSUSER_GetSaveDataSecureValue(exists: *mut u8, value: *mut u64, + titleUniqueId: u32_, + titleVariation: u8_) -> Result; + pub fn FSUSER_GetSaveDataSecureValue(exists: *mut u8, value: *mut u64_, slot: FS_SecureValueSlot, - titleUniqueId: u32, - titleVariation: u8) -> Result; + titleUniqueId: u32_, + titleVariation: u8_) -> Result; pub fn FSUSER_ControlSecureSave(action: FS_SecureSaveAction, input: *mut ::libc::c_void, - inputSize: u32, + inputSize: u32_, output: *mut ::libc::c_void, - outputSize: u32) -> Result; + outputSize: u32_) -> Result; pub fn FSUSER_GetMediaType(mediaType: *mut FS_MediaType) -> Result; pub fn FSFILE_Control(handle: Handle, action: FS_FileAction, - input: *mut ::libc::c_void, inputSize: u32, - output: *mut ::libc::c_void, outputSize: u32) + input: *mut ::libc::c_void, inputSize: u32_, + output: *mut ::libc::c_void, outputSize: u32_) -> Result; pub fn FSFILE_OpenSubFile(handle: Handle, subFile: *mut Handle, - offset: u64, size: u64) -> Result; - pub fn FSFILE_Read(handle: Handle, bytesRead: *mut u32, offset: u64, - buffer: *mut ::libc::c_void, size: u32) -> Result; - pub fn FSFILE_Write(handle: Handle, bytesWritten: *mut u32, offset: u64, - buffer: *const ::libc::c_void, size: u32, - flags: u32) -> Result; - pub fn FSFILE_GetSize(handle: Handle, size: *mut u64) -> Result; - pub fn FSFILE_SetSize(handle: Handle, size: u64) -> Result; - pub fn FSFILE_GetAttributes(handle: Handle, attributes: *mut u32) - -> Result; - pub fn FSFILE_SetAttributes(handle: Handle, attributes: u32) -> Result; + offset: u64_, size: u64_) -> Result; + pub fn FSFILE_Read(handle: Handle, bytesRead: *mut u32_, offset: u64_, + buffer: *mut ::libc::c_void, size: u32_) -> Result; + pub fn FSFILE_Write(handle: Handle, bytesWritten: *mut u32_, offset: u64_, + buffer: *const ::libc::c_void, size: u32_, + flags: u32_) -> Result; + pub fn FSFILE_GetSize(handle: Handle, size: *mut u64_) -> Result; + pub fn FSFILE_SetSize(handle: Handle, size: u64_) -> Result; + pub fn FSFILE_GetAttributes(handle: Handle, attributes: *mut u32_) + -> Result; + pub fn FSFILE_SetAttributes(handle: Handle, attributes: u32_) -> Result; pub fn FSFILE_Close(handle: Handle) -> Result; pub fn FSFILE_Flush(handle: Handle) -> Result; - pub fn FSFILE_SetPriority(handle: Handle, priority: u32) -> Result; - pub fn FSFILE_GetPriority(handle: Handle, priority: *mut u32) -> Result; + pub fn FSFILE_SetPriority(handle: Handle, priority: u32_) -> Result; + pub fn FSFILE_GetPriority(handle: Handle, priority: *mut u32_) -> Result; pub fn FSFILE_OpenLinkFile(handle: Handle, linkFile: *mut Handle) -> Result; pub fn FSDIR_Control(handle: Handle, action: FS_DirectoryAction, - input: *mut ::libc::c_void, inputSize: u32, - output: *mut ::libc::c_void, outputSize: u32) + input: *mut ::libc::c_void, inputSize: u32_, + output: *mut ::libc::c_void, outputSize: u32_) -> Result; - pub fn FSDIR_Read(handle: Handle, entriesRead: *mut u32, - entryCount: u32, entries: *mut FS_DirectoryEntry) + pub fn FSDIR_Read(handle: Handle, entriesRead: *mut u32_, + entryCount: u32_, entries: *mut FS_DirectoryEntry) -> Result; pub fn FSDIR_Close(handle: Handle) -> Result; - pub fn FSDIR_SetPriority(handle: Handle, priority: u32) -> Result; - pub fn FSDIR_GetPriority(handle: Handle, priority: *mut u32) -> Result; + pub fn FSDIR_SetPriority(handle: Handle, priority: u32_) -> Result; + pub fn FSDIR_GetPriority(handle: Handle, priority: *mut u32_) -> Result; pub fn romfsMount(mount: *mut *mut romfs_mount) -> Result; - pub fn romfsMountFromFile(file: Handle, offset: u32, + pub fn romfsMountFromFile(file: Handle, offset: u32_, mount: *mut *mut romfs_mount) -> Result; pub fn romfsBind(mount: *mut romfs_mount) -> Result; pub fn romfsUnmount(mount: *mut romfs_mount) -> Result; } + +use ::types::*; diff --git a/src/lib.rs b/src/lib.rs index 56ab565..56e7011 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ #![crate_type = "rlib"] #![crate_name = "ctru"] +#[macro_use] +extern crate bitflags; extern crate ctru_sys as libctru; pub mod console; diff --git a/src/services/fs.rs b/src/services/fs.rs index 33eef9f..7e80607 100644 --- a/src/services/fs.rs +++ b/src/services/fs.rs @@ -15,6 +15,30 @@ use std::ffi::OsString; use libctru::services::fs::*; +bitflags! { + flags FsOpen: u32 { + const FS_OPEN_READ = 1, + const FS_OPEN_WRITE = 2, + const FS_OPEN_CREATE = 4, + } +} + +bitflags! { + flags FsWrite: u32 { + const FS_WRITE_FLUSH = 1, + const FS_WRITE_UPDATE_TIME = 256, + } +} + +bitflags! { + flags FsAttribute: u32 { + const FS_ATTRIBUTE_DIRECTORY = 1, + const FS_ATTRIBUTE_HIDDEN = 256, + const FS_ATTRIBUTE_ARCHIVE = 65536, + const FS_ATTRIBUTE_READ_ONLY = 16777216, + } +} + #[derive(Copy, Clone, Debug)] pub enum PathType { Invalid, @@ -382,7 +406,7 @@ impl File { self.offset, buf.as_ptr() as _, buf.len() as u32, - FS_WRITE_UPDATE_TIME + FS_WRITE_UPDATE_TIME.bits ); self.offset += n_written as u64; if r < 0 { @@ -397,7 +421,7 @@ impl File { impl Metadata { /// Returns whether this metadata is for a directory. pub fn is_dir(&self) -> bool { - self.attributes == self.attributes | FS_ATTRIBUTE_DIRECTORY + self.attributes == self.attributes | FS_ATTRIBUTE_DIRECTORY.bits } /// Returns whether this metadata is for a regular file. @@ -510,12 +534,12 @@ impl OpenOptions { self._open(path.as_ref(), self.get_open_flags()) } - fn _open(&self, path: &Path, flags: u32) -> Result { + fn _open(&self, path: &Path, flags: FsOpen) -> Result { unsafe { let mut file_handle = 0; let path = to_utf16(path); let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); - let r = FSUSER_OpenFile(&mut file_handle, self.arch_handle, fs_path, flags, 0); + let r = FSUSER_OpenFile(&mut file_handle, self.arch_handle, fs_path, flags.bits, 0); if r < 0 { return Err(r); } @@ -537,7 +561,7 @@ impl OpenOptions { } } - fn get_open_flags(&self) -> u32 { + fn get_open_flags(&self) -> FsOpen { match (self.read, self.write || self.append, self.create) { (true, false, false) => FS_OPEN_READ, (false, true, false) => FS_OPEN_WRITE, @@ -545,7 +569,7 @@ impl OpenOptions { (true, false, true) => FS_OPEN_READ | FS_OPEN_CREATE, (true, true, false) => FS_OPEN_READ | FS_OPEN_WRITE, (true, true, true) => FS_OPEN_READ | FS_OPEN_WRITE | FS_OPEN_CREATE, - _ => 0, //failure case + _ => FsOpen::empty(), //failure case } } } @@ -609,7 +633,7 @@ pub fn create_dir>(arch: &Archive, path: P) -> Result<(), i32> { unsafe { let path = to_utf16(path.as_ref()); let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); - let r = FSUSER_CreateDirectory(arch.handle, fs_path, FS_ATTRIBUTE_DIRECTORY); + let r = FSUSER_CreateDirectory(arch.handle, fs_path, FS_ATTRIBUTE_DIRECTORY.bits); if r < 0 { Err(r) } else { @@ -646,7 +670,7 @@ pub fn metadata>(arch: &Archive, path: P) -> Result file.metadata(), - (_, Ok(_dir)) => Ok(Metadata { attributes: FS_ATTRIBUTE_DIRECTORY, size: 0 }), + (_, Ok(_dir)) => Ok(Metadata { attributes: FS_ATTRIBUTE_DIRECTORY.bits, size: 0 }), (Err(r), _) => Err(r), } }