1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     fs_FileBase.h
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 31762 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_FS_CTR_MPCORE_FS_USERFILESYSTEM_H_
17 #define NN_FS_CTR_MPCORE_FS_USERFILESYSTEM_H_
18 
19 #include <nn/Handle.h>
20 #include <nn/Result.h>
21 #include <nn/types.h>
22 #include <nn/util/util_Result.h>
23 #include <nn/fs/fs_Parameters.h>
24 #include <nn/fs/fs_Result.h>
25 #include <nn/util/util_NonCopyable.h>
26 
27 #include <nn/os.h>
28 #include <nn/fnd.h>
29 
30 #include <nn/fslow/fslow_Path.h>
31 
32 namespace nn { namespace fs { namespace CTR { namespace MPCore {
33 
34 typedef nn::fslow::LowPath<const char*, const wchar_t*> Path;
35 
36 namespace detail {
37 
38 class UserFileSystem
39 {
40 public:
41     static Result Initialize(nn::Handle handle);
42     static void Finalize();
43 
44     // File directory operations
45     static void OpenDirect(void** pOut, Handle handle);
46     static void CloseDirect(void* p);
47     static Handle GetFileHandle(void* p);
48     static void DetachHandle(void *p);
49 
50     static Result DuplicateHandleForFile(Handle* pOut, void* p, s64 offset, s64 length);
51 
52     static Result TryOpenFile(void** pOut, const wchar_t* pathName, bit32 mode);
53     static void CloseFile(void* p);
54 
55     static Result TryReadFile(s32* pOut, void* p, s64 offset, void* buffer, size_t size);
56     static Result TryWriteFile(s32* pOut, void* p, s64 offset, const void* buffer, size_t size, bool flush=true);
57     static Result TryGetFileSize(s64* pOut, const void* p);
58     static Result TrySetFileSize(void* p, s64 size);
59 	static Result TryFlush(void* p);
60 
61     static Result TryOpenDirectory(void** pOut, const wchar_t* pathName);
62     static void CloseDirectory(void* p);
63 
64     static Result TryReadDirectory(s32* pOut, void* p, DirectoryEntry pEntries[], s32 numEntries);
65 
66     static Result TryDeleteFile(const wchar_t* pathName);
67     static Result TryRenameFile(const wchar_t* currentPath, const wchar_t* newPath);
68     static Result TryDeleteDirectory(const wchar_t* pathName);
69     static Result TryDeleteDirectoryRecursively(const wchar_t* pathName);
70     static Result TryCreateFile(const wchar_t* pathName, s64 size);
71     static Result TryCreateDirectory(const wchar_t* pathName);
72     static Result TryRenameDirectory(const wchar_t* currentPath, const wchar_t* newPath);
73 
74     // raw
75     static Result TryOpenFileRaw(void** pOut, ArchiveHandle archiveHandle, const Path& path, bit32 mode);
76     static Result TryOpenFileRawDirectly(void** pOut, bit32 archiveType, const Path& archivePath, const Path& path, bit32 mode);
77     static Result TryOpenDirectoryRaw(void** pOut, ArchiveHandle archiveHandle, const Path& path);
78     static Result TryDeleteFileRaw(ArchiveHandle archiveHandle, const Path& path);
79     static Result TryRenameFileRaw(ArchiveHandle currentArchiveHandle, const Path& currentPath, ArchiveHandle newArchiveHandle, const Path& newPath);
80     static Result TryDeleteDirectoryRaw(ArchiveHandle archiveHandle, const Path& path);
81     static Result TryDeleteDirectoryRecursivelyRaw(ArchiveHandle archiveHandle, const Path& path);
82     static Result TryCreateDirectoryRaw(ArchiveHandle archiveHandle, const Path& path);
83     static Result TryRenameDirectoryRaw(ArchiveHandle currentArchiveHandle, const Path& currentPath, ArchiveHandle newArchiveHandle, const Path& newPath);
84 };
85 
86 }}}}}
87 
88 #endif
89