Browse Source

Use bitflags for fs services

pull/10/head
Fenrir 8 years ago
parent
commit
4991de6d39
  1. 3
      Cargo.toml
  2. 369
      ctru-sys/src/services/fs.rs
  3. 2
      src/lib.rs
  4. 40
      src/services/fs.rs

3
Cargo.toml

@ -16,3 +16,6 @@ path = "ctru-sys"
[dependencies.std] [dependencies.std]
path = "std" path = "std"
[dependencies.bitflags]
version = "0.7.0"

369
ctru-sys/src/services/fs.rs

@ -4,21 +4,27 @@
non_camel_case_types, non_camel_case_types,
non_upper_case_globals, non_upper_case_globals,
non_snake_case)] non_snake_case)]
#[derive(Copy, Clone)]
use ::{Handle, Result}; #[repr(u32)]
#[derive(Debug)]
pub const FS_OPEN_READ: u32 = 1; pub enum Enum_Unnamed1 {
pub const FS_OPEN_WRITE: u32 = 2; FS_OPEN_READ = 1,
pub const FS_OPEN_CREATE: u32 = 4; FS_OPEN_WRITE = 2,
FS_OPEN_CREATE = 4,
pub const FS_WRITE_FLUSH: u32 = 1; }
pub const FS_WRITE_UPDATE_TIME: u32 = 256; #[derive(Copy, Clone)]
#[repr(u32)]
pub const FS_ATTRIBUTE_DIRECTORY: u32 = 1; #[derive(Debug)]
pub const FS_ATTRIBUTE_HIDDEN: u32 = 256; pub enum Enum_Unnamed2 { FS_WRITE_FLUSH = 1, FS_WRITE_UPDATE_TIME = 256, }
pub const FS_ATTRIBUTE_ARCHIVE: u32 = 65536; #[derive(Copy, Clone)]
pub const FS_ATTRIBUTE_READ_ONLY: u32 = 16777216; #[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)] #[derive(Copy, Clone)]
#[repr(u32)] #[repr(u32)]
#[derive(Debug)] #[derive(Debug)]
@ -135,13 +141,13 @@ pub enum FS_DirectoryAction { DIRECTORY_ACTION_UNKNOWN = 0, }
#[repr(C)] #[repr(C)]
#[derive(Copy)] #[derive(Copy)]
pub struct FS_DirectoryEntry { pub struct FS_DirectoryEntry {
pub name: [u16; 262usize], pub name: [u16_; 262usize],
pub shortName: [u8; 10usize], pub shortName: [::libc::c_char; 10usize],
pub shortExt: [u8; 4usize], pub shortExt: [::libc::c_char; 4usize],
pub valid: u8, pub valid: u8_,
pub reserved: u8, pub reserved: u8_,
pub attributes: u32, pub attributes: u32_,
pub fileSize: u64, pub fileSize: u64_,
} }
impl ::core::clone::Clone for FS_DirectoryEntry { impl ::core::clone::Clone for FS_DirectoryEntry {
fn clone(&self) -> Self { *self } fn clone(&self) -> Self { *self }
@ -153,10 +159,10 @@ impl ::core::default::Default for FS_DirectoryEntry {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[derive(Debug)] #[derive(Debug)]
pub struct FS_ArchiveResource { pub struct FS_ArchiveResource {
pub sectorSize: u32, pub sectorSize: u32_,
pub clusterSize: u32, pub clusterSize: u32_,
pub totalClusters: u32, pub totalClusters: u32_,
pub freeClusters: u32, pub freeClusters: u32_,
} }
impl ::core::default::Default for FS_ArchiveResource { impl ::core::default::Default for FS_ArchiveResource {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
@ -165,9 +171,9 @@ impl ::core::default::Default for FS_ArchiveResource {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[derive(Debug)] #[derive(Debug)]
pub struct FS_ProgramInfo { pub struct FS_ProgramInfo {
pub programId: u64, pub programId: u64_,
pub _bindgen_bitfield_1_: FS_MediaType, pub _bindgen_bitfield_1_: FS_MediaType,
pub padding: [u8; 7usize], pub padding: [u8_; 7usize],
} }
impl ::core::default::Default for FS_ProgramInfo { impl ::core::default::Default for FS_ProgramInfo {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
@ -176,9 +182,9 @@ impl ::core::default::Default for FS_ProgramInfo {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[derive(Debug)] #[derive(Debug)]
pub struct FS_ProductInfo { pub struct FS_ProductInfo {
pub productCode: [u8; 16usize], pub productCode: [::libc::c_char; 16usize],
pub companyCode: [u8; 2usize], pub companyCode: [::libc::c_char; 2usize],
pub remasterVersion: u16, pub remasterVersion: u16_,
} }
impl ::core::default::Default for FS_ProductInfo { impl ::core::default::Default for FS_ProductInfo {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
@ -186,8 +192,8 @@ impl ::core::default::Default for FS_ProductInfo {
#[repr(C)] #[repr(C)]
#[derive(Copy)] #[derive(Copy)]
pub struct FS_IntegrityVerificationSeed { pub struct FS_IntegrityVerificationSeed {
pub aesCbcMac: [u8; 16usize], pub aesCbcMac: [u8_; 16usize],
pub movableSed: [u8; 288usize], pub movableSed: [u8_; 288usize],
} }
impl ::core::clone::Clone for FS_IntegrityVerificationSeed { impl ::core::clone::Clone for FS_IntegrityVerificationSeed {
fn clone(&self) -> Self { *self } fn clone(&self) -> Self { *self }
@ -200,10 +206,10 @@ impl ::core::default::Default for FS_IntegrityVerificationSeed {
#[derive(Debug)] #[derive(Debug)]
pub struct FS_ExtSaveDataInfo { pub struct FS_ExtSaveDataInfo {
pub _bindgen_bitfield_1_: FS_MediaType, pub _bindgen_bitfield_1_: FS_MediaType,
pub unknown: u8, pub unknown: u8_,
pub reserved1: u16, pub reserved1: u16_,
pub saveId: u64, pub saveId: u64_,
pub reserved2: u32, pub reserved2: u32_,
} }
impl ::core::default::Default for FS_ExtSaveDataInfo { impl ::core::default::Default for FS_ExtSaveDataInfo {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
@ -213,9 +219,9 @@ impl ::core::default::Default for FS_ExtSaveDataInfo {
#[derive(Debug)] #[derive(Debug)]
pub struct FS_SystemSaveDataInfo { pub struct FS_SystemSaveDataInfo {
pub _bindgen_bitfield_1_: FS_MediaType, pub _bindgen_bitfield_1_: FS_MediaType,
pub unknown: u8, pub unknown: u8_,
pub reserved: u16, pub reserved: u16_,
pub saveId: u32, pub saveId: u32_,
} }
impl ::core::default::Default for FS_SystemSaveDataInfo { impl ::core::default::Default for FS_SystemSaveDataInfo {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
@ -224,8 +230,8 @@ impl ::core::default::Default for FS_SystemSaveDataInfo {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[derive(Debug)] #[derive(Debug)]
pub struct FS_DeviceMoveContext { pub struct FS_DeviceMoveContext {
pub ivs: [u8; 16usize], pub ivs: [u8_; 16usize],
pub encryptParameter: [u8; 16usize], pub encryptParameter: [u8_; 16usize],
} }
impl ::core::default::Default for FS_DeviceMoveContext { impl ::core::default::Default for FS_DeviceMoveContext {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
@ -235,27 +241,27 @@ impl ::core::default::Default for FS_DeviceMoveContext {
#[derive(Debug)] #[derive(Debug)]
pub struct FS_Path { pub struct FS_Path {
pub type_: FS_PathType, pub type_: FS_PathType,
pub size: u32, pub size: u32_,
pub data: *const ::libc::c_void, pub data: *const ::libc::c_void,
} }
impl ::core::default::Default for FS_Path { impl ::core::default::Default for FS_Path {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
} }
pub type FS_Archive = u64; pub type FS_Archive = u64_;
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[derive(Debug)] #[derive(Debug)]
pub struct romfs_header { pub struct romfs_header {
pub headerSize: u32, pub headerSize: u32_,
pub dirHashTableOff: u32, pub dirHashTableOff: u32_,
pub dirHashTableSize: u32, pub dirHashTableSize: u32_,
pub dirTableOff: u32, pub dirTableOff: u32_,
pub dirTableSize: u32, pub dirTableSize: u32_,
pub fileHashTableOff: u32, pub fileHashTableOff: u32_,
pub fileHashTableSize: u32, pub fileHashTableSize: u32_,
pub fileTableOff: u32, pub fileTableOff: u32_,
pub fileTableSize: u32, pub fileTableSize: u32_,
pub fileDataOff: u32, pub fileDataOff: u32_,
} }
impl ::core::default::Default for romfs_header { impl ::core::default::Default for romfs_header {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
@ -264,13 +270,13 @@ impl ::core::default::Default for romfs_header {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[derive(Debug)] #[derive(Debug)]
pub struct romfs_dir { pub struct romfs_dir {
pub parent: u32, pub parent: u32_,
pub sibling: u32, pub sibling: u32_,
pub childDir: u32, pub childDir: u32_,
pub childFile: u32, pub childFile: u32_,
pub nextHash: u32, pub nextHash: u32_,
pub nameLen: u32, pub nameLen: u32_,
pub name: [u16; 0usize], pub name: [u16_; 0usize],
} }
impl ::core::default::Default for romfs_dir { impl ::core::default::Default for romfs_dir {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
@ -279,13 +285,13 @@ impl ::core::default::Default for romfs_dir {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[derive(Debug)] #[derive(Debug)]
pub struct romfs_file { pub struct romfs_file {
pub parent: u32, pub parent: u32_,
pub sibling: u32, pub sibling: u32_,
pub dataOff: u64, pub dataOff: u64_,
pub dataSize: u64, pub dataSize: u64_,
pub nextHash: u32, pub nextHash: u32_,
pub nameLen: u32, pub nameLen: u32_,
pub name: [u16; 0usize], pub name: [u16_; 0usize],
} }
impl ::core::default::Default for romfs_file { impl ::core::default::Default for romfs_file {
fn default() -> Self { unsafe { ::core::mem::zeroed() } } fn default() -> Self { unsafe { ::core::mem::zeroed() } }
@ -302,15 +308,15 @@ extern "C" {
-> FS_Path; -> FS_Path;
pub fn fsGetSessionHandle() -> *mut Handle; pub fn fsGetSessionHandle() -> *mut Handle;
pub fn FSUSER_Control(action: FS_Action, input: *mut ::libc::c_void, pub fn FSUSER_Control(action: FS_Action, input: *mut ::libc::c_void,
inputSize: u32, output: *mut ::libc::c_void, inputSize: u32_, output: *mut ::libc::c_void,
outputSize: u32) -> Result; outputSize: u32_) -> Result;
pub fn FSUSER_Initialize(session: Handle) -> Result; pub fn FSUSER_Initialize(session: Handle) -> Result;
pub fn FSUSER_OpenFile(out: *mut Handle, archive: FS_Archive, 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; -> Result;
pub fn FSUSER_OpenFileDirectly(out: *mut Handle, archiveId: FS_ArchiveID, pub fn FSUSER_OpenFileDirectly(out: *mut Handle, archiveId: FS_ArchiveID,
archivePath: FS_Path, filePath: FS_Path, archivePath: FS_Path, filePath: FS_Path,
openFlags: u32, attributes: u32) openFlags: u32_, attributes: u32_)
-> Result; -> Result;
pub fn FSUSER_DeleteFile(archive: FS_Archive, path: FS_Path) -> Result; pub fn FSUSER_DeleteFile(archive: FS_Archive, path: FS_Path) -> Result;
pub fn FSUSER_RenameFile(srcArchive: FS_Archive, srcPath: FS_Path, pub fn FSUSER_RenameFile(srcArchive: FS_Archive, srcPath: FS_Path,
@ -321,9 +327,9 @@ extern "C" {
pub fn FSUSER_DeleteDirectoryRecursively(archive: FS_Archive, pub fn FSUSER_DeleteDirectoryRecursively(archive: FS_Archive,
path: FS_Path) -> Result; path: FS_Path) -> Result;
pub fn FSUSER_CreateFile(archive: FS_Archive, path: FS_Path, 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, 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, pub fn FSUSER_RenameDirectory(srcArchive: FS_Archive, srcPath: FS_Path,
dstArchive: FS_Archive, dstPath: FS_Path) dstArchive: FS_Archive, dstPath: FS_Path)
-> Result; -> Result;
@ -333,11 +339,11 @@ extern "C" {
path: FS_Path) -> Result; path: FS_Path) -> Result;
pub fn FSUSER_ControlArchive(archive: FS_Archive, pub fn FSUSER_ControlArchive(archive: FS_Archive,
action: FS_ArchiveAction, action: FS_ArchiveAction,
input: *mut ::libc::c_void, inputSize: u32, input: *mut ::libc::c_void, inputSize: u32_,
output: *mut ::libc::c_void, output: *mut ::libc::c_void,
outputSize: u32) -> Result; outputSize: u32_) -> Result;
pub fn FSUSER_CloseArchive(archive: FS_Archive) -> 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; -> Result;
pub fn FSUSER_GetCardType(type_: *mut FS_CardType) -> Result; pub fn FSUSER_GetCardType(type_: *mut FS_CardType) -> Result;
pub fn FSUSER_GetSdmcArchiveResource(archiveResource: pub fn FSUSER_GetSdmcArchiveResource(archiveResource:
@ -346,82 +352,82 @@ extern "C" {
pub fn FSUSER_GetNandArchiveResource(archiveResource: pub fn FSUSER_GetNandArchiveResource(archiveResource:
*mut FS_ArchiveResource) *mut FS_ArchiveResource)
-> Result; -> 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_IsSdmcDetected(detected: *mut u8) -> Result;
pub fn FSUSER_IsSdmcWritable(writable: *mut u8) -> Result; pub fn FSUSER_IsSdmcWritable(writable: *mut u8) -> Result;
pub fn FSUSER_GetSdmcCid(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_GetNandCid(out: *mut u8_, length: u32_) -> Result;
pub fn FSUSER_GetSdmcSpeedInfo(speedInfo: *mut u32) -> Result; pub fn FSUSER_GetSdmcSpeedInfo(speedInfo: *mut u32_) -> Result;
pub fn FSUSER_GetNandSpeedInfo(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_GetSdmcLog(out: *mut u8_, length: u32_) -> Result;
pub fn FSUSER_GetNandLog(out: *mut u8, length: u32) -> Result; pub fn FSUSER_GetNandLog(out: *mut u8_, length: u32_) -> Result;
pub fn FSUSER_ClearSdmcLog() -> Result; pub fn FSUSER_ClearSdmcLog() -> Result;
pub fn FSUSER_ClearNandLog() -> Result; pub fn FSUSER_ClearNandLog() -> Result;
pub fn FSUSER_CardSlotIsInserted(inserted: *mut u8) -> Result; pub fn FSUSER_CardSlotIsInserted(inserted: *mut u8) -> Result;
pub fn FSUSER_CardSlotPowerOn(status: *mut u8) -> Result; pub fn FSUSER_CardSlotPowerOn(status: *mut u8) -> Result;
pub fn FSUSER_CardSlotPowerOff(status: *mut u8) -> Result; pub fn FSUSER_CardSlotPowerOff(status: *mut u8) -> Result;
pub fn FSUSER_CardSlotGetCardIFPowerStatus(status: *mut u8) -> Result; pub fn FSUSER_CardSlotGetCardIFPowerStatus(status: *mut u8) -> Result;
pub fn FSUSER_CardNorDirectCommand(commandId: u8) -> Result; pub fn FSUSER_CardNorDirectCommand(commandId: u8_) -> Result;
pub fn FSUSER_CardNorDirectCommandWithAddress(commandId: u8, pub fn FSUSER_CardNorDirectCommandWithAddress(commandId: u8_,
address: u32) -> Result; address: u32_) -> Result;
pub fn FSUSER_CardNorDirectRead(commandId: u8, size: u32, pub fn FSUSER_CardNorDirectRead(commandId: u8_, size: u32_,
output: *mut u8) -> Result; output: *mut u8_) -> Result;
pub fn FSUSER_CardNorDirectReadWithAddress(commandId: u8, address: u32, pub fn FSUSER_CardNorDirectReadWithAddress(commandId: u8_, address: u32_,
size: u32, output: *mut u8) size: u32_, output: *mut u8_)
-> Result; -> Result;
pub fn FSUSER_CardNorDirectWrite(commandId: u8, size: u32, pub fn FSUSER_CardNorDirectWrite(commandId: u8_, size: u32_,
input: *mut u8) -> Result; input: *mut u8_) -> Result;
pub fn FSUSER_CardNorDirectWriteWithAddress(commandId: u8, address: u32, pub fn FSUSER_CardNorDirectWriteWithAddress(commandId: u8_, address: u32_,
size: u32, input: *mut u8) size: u32_, input: *mut u8_)
-> Result; -> Result;
pub fn FSUSER_CardNorDirectRead_4xIO(commandId: u8, address: u32, pub fn FSUSER_CardNorDirectRead_4xIO(commandId: u8_, address: u32_,
size: u32, output: *mut u8) size: u32_, output: *mut u8_)
-> Result; -> Result;
pub fn FSUSER_CardNorDirectCpuWriteWithoutVerify(address: u32, pub fn FSUSER_CardNorDirectCpuWriteWithoutVerify(address: u32_,
size: u32, size: u32_,
input: *mut u8) input: *mut u8_)
-> Result; -> Result;
pub fn FSUSER_CardNorDirectSectorEraseWithoutVerify(address: u32) pub fn FSUSER_CardNorDirectSectorEraseWithoutVerify(address: u32_)
-> Result; -> Result;
pub fn FSUSER_GetProductInfo(info: *mut FS_ProductInfo, processId: u32) pub fn FSUSER_GetProductInfo(info: *mut FS_ProductInfo, processId: u32_)
-> Result; -> Result;
pub fn FSUSER_GetProgramLaunchInfo(info: *mut FS_ProgramInfo, 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_SetCardSpiBaudRate(baudRate: FS_CardSpiBaudRate) -> Result;
pub fn FSUSER_SetCardSpiBusMode(busMode: FS_CardSpiBusMode) -> Result; pub fn FSUSER_SetCardSpiBusMode(busMode: FS_CardSpiBusMode) -> Result;
pub fn FSUSER_SendInitializeInfoTo9() -> Result; pub fn FSUSER_SendInitializeInfoTo9() -> Result;
pub fn FSUSER_GetSpecialContentIndex(index: *mut u16, pub fn FSUSER_GetSpecialContentIndex(index: *mut u16_,
mediaType: FS_MediaType, mediaType: FS_MediaType,
programId: u64, programId: u64_,
type_: FS_SpecialContentType) type_: FS_SpecialContentType)
-> Result; -> Result;
pub fn FSUSER_GetLegacyRomHeader(mediaType: FS_MediaType, programId: u64, pub fn FSUSER_GetLegacyRomHeader(mediaType: FS_MediaType, programId: u64_,
header: *mut u8) -> Result; header: *mut u8_) -> Result;
pub fn FSUSER_GetLegacyBannerData(mediaType: FS_MediaType, pub fn FSUSER_GetLegacyBannerData(mediaType: FS_MediaType,
programId: u64, banner: *mut u8) programId: u64_, banner: *mut u8_)
-> Result; -> Result;
pub fn FSUSER_CheckAuthorityToAccessExtSaveData(access: *mut u8, pub fn FSUSER_CheckAuthorityToAccessExtSaveData(access: *mut u8,
mediaType: FS_MediaType, mediaType: FS_MediaType,
saveId: u64, saveId: u64_,
processId: u32) processId: u32_)
-> Result; -> Result;
pub fn FSUSER_QueryTotalQuotaSize(quotaSize: *mut u64, directories: u32, pub fn FSUSER_QueryTotalQuotaSize(quotaSize: *mut u64_, directories: u32_,
files: u32, fileSizeCount: u32, files: u32_, fileSizeCount: u32_,
fileSizes: *mut u64) -> Result; fileSizes: *mut u64_) -> Result;
pub fn FSUSER_AbnegateAccessRight(accessRight: u32) -> Result; pub fn FSUSER_AbnegateAccessRight(accessRight: u32_) -> Result;
pub fn FSUSER_DeleteSdmcRoot() -> Result; pub fn FSUSER_DeleteSdmcRoot() -> Result;
pub fn FSUSER_DeleteAllExtSaveDataOnNand() -> Result; pub fn FSUSER_DeleteAllExtSaveDataOnNand() -> Result;
pub fn FSUSER_InitializeCtrFileSystem() -> Result; pub fn FSUSER_InitializeCtrFileSystem() -> Result;
pub fn FSUSER_CreateSeed() -> Result; pub fn FSUSER_CreateSeed() -> Result;
pub fn FSUSER_GetFormatInfo(totalSize: *mut u32, directories: *mut u32, pub fn FSUSER_GetFormatInfo(totalSize: *mut u32_, directories: *mut u32_,
files: *mut u32, duplicateData: *mut u8, files: *mut u32_, duplicateData: *mut u8,
archiveId: FS_ArchiveID, path: FS_Path) archiveId: FS_ArchiveID, path: FS_Path)
-> Result; -> Result;
pub fn FSUSER_GetLegacyRomHeader2(headerSize: u32, pub fn FSUSER_GetLegacyRomHeader2(headerSize: u32_,
mediaType: FS_MediaType, mediaType: FS_MediaType,
programId: u64, header: *mut u8) programId: u64_, header: *mut u8_)
-> Result; -> 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, pub fn FSUSER_GetArchiveResource(archiveResource: *mut FS_ArchiveResource,
mediaType: FS_SystemMediaType) -> Result; mediaType: FS_SystemMediaType) -> Result;
pub fn FSUSER_ExportIntegrityVerificationSeed(seed: pub fn FSUSER_ExportIntegrityVerificationSeed(seed:
@ -431,106 +437,111 @@ extern "C" {
*mut FS_IntegrityVerificationSeed) *mut FS_IntegrityVerificationSeed)
-> Result; -> Result;
pub fn FSUSER_FormatSaveData(archiveId: FS_ArchiveID, path: FS_Path, pub fn FSUSER_FormatSaveData(archiveId: FS_ArchiveID, path: FS_Path,
blocks: u32, directories: u32, files: u32, blocks: u32_, directories: u32_, files: u32_,
directoryBuckets: u32, fileBuckets: u32, directoryBuckets: u32_, fileBuckets: u32_,
duplicateData: u8) -> Result; duplicateData: u8) -> Result;
pub fn FSUSER_GetLegacySubBannerData(bannerSize: u32, pub fn FSUSER_GetLegacySubBannerData(bannerSize: u32_,
mediaType: FS_MediaType, mediaType: FS_MediaType,
programId: u64, banner: *mut u8) programId: u64_, banner: *mut u8_)
-> Result; -> Result;
pub fn FSUSER_ReadSpecialFile(bytesRead: *mut u32, fileOffset: u64, pub fn FSUSER_UpdateSha256Context(data: *const ::libc::c_void,
size: u32, data: *mut u8) -> Result; inputSize: u32_, hash: *mut u8_)
pub fn FSUSER_GetSpecialFileSize(fileSize: *mut u64) -> Result; -> 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, pub fn FSUSER_CreateExtSaveData(info: FS_ExtSaveDataInfo,
directories: u32, files: u32, directories: u32_, files: u32_,
sizeLimit: u64, smdhSize: u32, sizeLimit: u64_, smdhSize: u32_,
smdh: *mut u8) -> Result; smdh: *mut u8_) -> Result;
pub fn FSUSER_DeleteExtSaveData(info: FS_ExtSaveDataInfo) -> 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, info: FS_ExtSaveDataInfo,
smdhSize: u32, smdh: *mut u8) smdhSize: u32_, smdh: *mut u8_)
-> Result; -> Result;
pub fn FSUSER_GetExtDataBlockSize(totalBlocks: *mut u64, pub fn FSUSER_GetExtDataBlockSize(totalBlocks: *mut u64_,
freeBlocks: *mut u64, freeBlocks: *mut u64_,
blockSize: *mut u32, blockSize: *mut u32_,
info: FS_ExtSaveDataInfo) -> Result; info: FS_ExtSaveDataInfo) -> Result;
pub fn FSUSER_EnumerateExtSaveData(idsWritten: *mut u32, idsSize: u32, pub fn FSUSER_EnumerateExtSaveData(idsWritten: *mut u32_, idsSize: u32_,
mediaType: FS_MediaType, idSize: u32, mediaType: FS_MediaType, idSize: u32_,
shared: u8, ids: *mut u8) -> Result; shared: u8, ids: *mut u8_) -> Result;
pub fn FSUSER_CreateSystemSaveData(info: FS_SystemSaveDataInfo, pub fn FSUSER_CreateSystemSaveData(info: FS_SystemSaveDataInfo,
totalSize: u32, blockSize: u32, totalSize: u32_, blockSize: u32_,
directories: u32, files: u32, directories: u32_, files: u32_,
directoryBuckets: u32, directoryBuckets: u32_,
fileBuckets: u32, duplicateData: u8) fileBuckets: u32_, duplicateData: u8)
-> Result; -> Result;
pub fn FSUSER_DeleteSystemSaveData(info: FS_SystemSaveDataInfo) -> Result; pub fn FSUSER_DeleteSystemSaveData(info: FS_SystemSaveDataInfo) -> Result;
pub fn FSUSER_StartDeviceMoveAsSource(context: *mut FS_DeviceMoveContext) pub fn FSUSER_StartDeviceMoveAsSource(context: *mut FS_DeviceMoveContext)
-> Result; -> Result;
pub fn FSUSER_StartDeviceMoveAsDestination(context: FS_DeviceMoveContext, pub fn FSUSER_StartDeviceMoveAsDestination(context: FS_DeviceMoveContext,
clear: u8) -> Result; clear: u8) -> Result;
pub fn FSUSER_SetArchivePriority(archive: FS_Archive, priority: u32) pub fn FSUSER_SetArchivePriority(archive: FS_Archive, priority: u32_)
-> Result; -> Result;
pub fn FSUSER_GetArchivePriority(priority: *mut u32, archive: FS_Archive) pub fn FSUSER_GetArchivePriority(priority: *mut u32_, archive: FS_Archive)
-> Result; -> Result;
pub fn FSUSER_SetCtrCardLatencyParameter(latency: u64, pub fn FSUSER_SetCtrCardLatencyParameter(latency: u64_,
emulateEndurance: u8) -> Result; emulateEndurance: u8) -> Result;
pub fn FSUSER_SwitchCleanupInvalidSaveData(enable: u8) -> Result; pub fn FSUSER_SwitchCleanupInvalidSaveData(enable: u8) -> Result;
pub fn FSUSER_EnumerateSystemSaveData(idsWritten: *mut u32, pub fn FSUSER_EnumerateSystemSaveData(idsWritten: *mut u32_,
idsSize: u32, ids: *mut u32) idsSize: u32_, ids: *mut u32_)
-> Result; -> Result;
pub fn FSUSER_InitializeWithSdkVersion(session: Handle, version: u32) pub fn FSUSER_InitializeWithSdkVersion(session: Handle, version: u32_)
-> Result; -> Result;
pub fn FSUSER_SetPriority(priority: u32) -> Result; pub fn FSUSER_SetPriority(priority: u32_) -> Result;
pub fn FSUSER_GetPriority(priority: *mut u32) -> Result; pub fn FSUSER_GetPriority(priority: *mut u32_) -> Result;
pub fn FSUSER_SetSaveDataSecureValue(value: u64, pub fn FSUSER_SetSaveDataSecureValue(value: u64_,
slot: FS_SecureValueSlot, slot: FS_SecureValueSlot,
titleUniqueId: u32, titleUniqueId: u32_,
titleVariation: u8) -> Result; titleVariation: u8_) -> Result;
pub fn FSUSER_GetSaveDataSecureValue(exists: *mut u8, value: *mut u64, pub fn FSUSER_GetSaveDataSecureValue(exists: *mut u8, value: *mut u64_,
slot: FS_SecureValueSlot, slot: FS_SecureValueSlot,
titleUniqueId: u32, titleUniqueId: u32_,
titleVariation: u8) -> Result; titleVariation: u8_) -> Result;
pub fn FSUSER_ControlSecureSave(action: FS_SecureSaveAction, pub fn FSUSER_ControlSecureSave(action: FS_SecureSaveAction,
input: *mut ::libc::c_void, input: *mut ::libc::c_void,
inputSize: u32, inputSize: u32_,
output: *mut ::libc::c_void, output: *mut ::libc::c_void,
outputSize: u32) -> Result; outputSize: u32_) -> Result;
pub fn FSUSER_GetMediaType(mediaType: *mut FS_MediaType) -> Result; pub fn FSUSER_GetMediaType(mediaType: *mut FS_MediaType) -> Result;
pub fn FSFILE_Control(handle: Handle, action: FS_FileAction, pub fn FSFILE_Control(handle: Handle, action: FS_FileAction,
input: *mut ::libc::c_void, inputSize: u32, input: *mut ::libc::c_void, inputSize: u32_,
output: *mut ::libc::c_void, outputSize: u32) output: *mut ::libc::c_void, outputSize: u32_)
-> Result; -> Result;
pub fn FSFILE_OpenSubFile(handle: Handle, subFile: *mut Handle, pub fn FSFILE_OpenSubFile(handle: Handle, subFile: *mut Handle,
offset: u64, size: u64) -> Result; offset: u64_, size: u64_) -> Result;
pub fn FSFILE_Read(handle: Handle, bytesRead: *mut u32, offset: u64, pub fn FSFILE_Read(handle: Handle, bytesRead: *mut u32_, offset: u64_,
buffer: *mut ::libc::c_void, size: u32) -> Result; buffer: *mut ::libc::c_void, size: u32_) -> Result;
pub fn FSFILE_Write(handle: Handle, bytesWritten: *mut u32, offset: u64, pub fn FSFILE_Write(handle: Handle, bytesWritten: *mut u32_, offset: u64_,
buffer: *const ::libc::c_void, size: u32, buffer: *const ::libc::c_void, size: u32_,
flags: u32) -> Result; flags: u32_) -> Result;
pub fn FSFILE_GetSize(handle: Handle, size: *mut u64) -> Result; pub fn FSFILE_GetSize(handle: Handle, size: *mut u64_) -> Result;
pub fn FSFILE_SetSize(handle: Handle, size: u64) -> Result; pub fn FSFILE_SetSize(handle: Handle, size: u64_) -> Result;
pub fn FSFILE_GetAttributes(handle: Handle, attributes: *mut u32) pub fn FSFILE_GetAttributes(handle: Handle, attributes: *mut u32_)
-> Result; -> Result;
pub fn FSFILE_SetAttributes(handle: Handle, attributes: u32) -> Result; pub fn FSFILE_SetAttributes(handle: Handle, attributes: u32_) -> Result;
pub fn FSFILE_Close(handle: Handle) -> Result; pub fn FSFILE_Close(handle: Handle) -> Result;
pub fn FSFILE_Flush(handle: Handle) -> Result; pub fn FSFILE_Flush(handle: Handle) -> Result;
pub fn FSFILE_SetPriority(handle: Handle, priority: u32) -> Result; pub fn FSFILE_SetPriority(handle: Handle, priority: u32_) -> Result;
pub fn FSFILE_GetPriority(handle: Handle, priority: *mut u32) -> Result; pub fn FSFILE_GetPriority(handle: Handle, priority: *mut u32_) -> Result;
pub fn FSFILE_OpenLinkFile(handle: Handle, linkFile: *mut Handle) pub fn FSFILE_OpenLinkFile(handle: Handle, linkFile: *mut Handle)
-> Result; -> Result;
pub fn FSDIR_Control(handle: Handle, action: FS_DirectoryAction, pub fn FSDIR_Control(handle: Handle, action: FS_DirectoryAction,
input: *mut ::libc::c_void, inputSize: u32, input: *mut ::libc::c_void, inputSize: u32_,
output: *mut ::libc::c_void, outputSize: u32) output: *mut ::libc::c_void, outputSize: u32_)
-> Result; -> Result;
pub fn FSDIR_Read(handle: Handle, entriesRead: *mut u32, pub fn FSDIR_Read(handle: Handle, entriesRead: *mut u32_,
entryCount: u32, entries: *mut FS_DirectoryEntry) entryCount: u32_, entries: *mut FS_DirectoryEntry)
-> Result; -> Result;
pub fn FSDIR_Close(handle: Handle) -> Result; pub fn FSDIR_Close(handle: Handle) -> Result;
pub fn FSDIR_SetPriority(handle: Handle, priority: u32) -> Result; pub fn FSDIR_SetPriority(handle: Handle, priority: u32_) -> Result;
pub fn FSDIR_GetPriority(handle: Handle, priority: *mut u32) -> Result; pub fn FSDIR_GetPriority(handle: Handle, priority: *mut u32_) -> Result;
pub fn romfsMount(mount: *mut *mut romfs_mount) -> 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; mount: *mut *mut romfs_mount) -> Result;
pub fn romfsBind(mount: *mut romfs_mount) -> Result; pub fn romfsBind(mount: *mut romfs_mount) -> Result;
pub fn romfsUnmount(mount: *mut romfs_mount) -> Result; pub fn romfsUnmount(mount: *mut romfs_mount) -> Result;
} }
use ::types::*;

2
src/lib.rs

@ -1,6 +1,8 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#![crate_name = "ctru"] #![crate_name = "ctru"]
#[macro_use]
extern crate bitflags;
extern crate ctru_sys as libctru; extern crate ctru_sys as libctru;
pub mod console; pub mod console;

40
src/services/fs.rs

@ -15,6 +15,30 @@ use std::ffi::OsString;
use libctru::services::fs::*; 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)] #[derive(Copy, Clone, Debug)]
pub enum PathType { pub enum PathType {
Invalid, Invalid,
@ -382,7 +406,7 @@ impl File {
self.offset, self.offset,
buf.as_ptr() as _, buf.as_ptr() as _,
buf.len() as u32, buf.len() as u32,
FS_WRITE_UPDATE_TIME FS_WRITE_UPDATE_TIME.bits
); );
self.offset += n_written as u64; self.offset += n_written as u64;
if r < 0 { if r < 0 {
@ -397,7 +421,7 @@ impl File {
impl Metadata { impl Metadata {
/// Returns whether this metadata is for a directory. /// Returns whether this metadata is for a directory.
pub fn is_dir(&self) -> bool { 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. /// Returns whether this metadata is for a regular file.
@ -510,12 +534,12 @@ impl OpenOptions {
self._open(path.as_ref(), self.get_open_flags()) self._open(path.as_ref(), self.get_open_flags())
} }
fn _open(&self, path: &Path, flags: u32) -> Result<File, i32> { fn _open(&self, path: &Path, flags: FsOpen) -> Result<File, i32> {
unsafe { unsafe {
let mut file_handle = 0; let mut file_handle = 0;
let path = to_utf16(path); let path = to_utf16(path);
let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); 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 { if r < 0 {
return Err(r); 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) { match (self.read, self.write || self.append, self.create) {
(true, false, false) => FS_OPEN_READ, (true, false, false) => FS_OPEN_READ,
(false, true, false) => FS_OPEN_WRITE, (false, true, false) => FS_OPEN_WRITE,
@ -545,7 +569,7 @@ impl OpenOptions {
(true, false, true) => FS_OPEN_READ | FS_OPEN_CREATE, (true, false, true) => FS_OPEN_READ | FS_OPEN_CREATE,
(true, true, false) => FS_OPEN_READ | FS_OPEN_WRITE, (true, true, false) => FS_OPEN_READ | FS_OPEN_WRITE,
(true, true, true) => FS_OPEN_READ | FS_OPEN_WRITE | FS_OPEN_CREATE, (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<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<(), i32> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); 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 { if r < 0 {
Err(r) Err(r)
} else { } else {
@ -646,7 +670,7 @@ pub fn metadata<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<Metadata, i32
let maybe_dir = read_dir(&arch, path.as_ref()); let maybe_dir = read_dir(&arch, path.as_ref());
match (maybe_file, maybe_dir) { match (maybe_file, maybe_dir) {
(Ok(file), _) => file.metadata(), (Ok(file), _) => 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), (Err(r), _) => Err(r),
} }
} }

Loading…
Cancel
Save