Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
19d04f3a
There was an error fetching the commit references. Please try again later.
Commit
19d04f3a
authored
10 years ago
by
Emmanuel Gil Peyrot
Browse files
Options
Downloads
Patches
Plain Diff
Kernel: Add a File object and a getter for it from an Archive object.
parent
e73caaef
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/hle/kernel/archive.cpp
+109
-0
109 additions, 0 deletions
src/core/hle/kernel/archive.cpp
src/core/hle/kernel/archive.h
+9
-0
9 additions, 0 deletions
src/core/hle/kernel/archive.h
with
118 additions
and
0 deletions
src/core/hle/kernel/archive.cpp
+
109
−
0
View file @
19d04f3a
...
@@ -3,9 +3,11 @@
...
@@ -3,9 +3,11 @@
// Refer to the license.txt file included.
// Refer to the license.txt file included.
#include
"common/common_types.h"
#include
"common/common_types.h"
#include
"common/file_util.h"
#include
"common/math_util.h"
#include
"common/math_util.h"
#include
"core/file_sys/archive.h"
#include
"core/file_sys/archive.h"
#include
"core/file_sys/archive_sdmc.h"
#include
"core/hle/service/service.h"
#include
"core/hle/service/service.h"
#include
"core/hle/kernel/archive.h"
#include
"core/hle/kernel/archive.h"
...
@@ -108,6 +110,83 @@ public:
...
@@ -108,6 +110,83 @@ public:
}
}
};
};
class
File
:
public
Object
{
public:
std
::
string
GetTypeName
()
const
{
return
"File"
;
}
std
::
string
GetName
()
const
{
return
path
;
}
static
Kernel
::
HandleType
GetStaticHandleType
()
{
return
HandleType
::
File
;
}
Kernel
::
HandleType
GetHandleType
()
const
{
return
HandleType
::
File
;
}
std
::
string
path
;
///< Path of the file
std
::
unique_ptr
<
FileSys
::
File
>
backend
;
///< File backend interface
/**
* Synchronize kernel object
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result
SyncRequest
(
bool
*
wait
)
{
u32
*
cmd_buff
=
Service
::
GetCommandBuffer
();
FileCommand
cmd
=
static_cast
<
FileCommand
>
(
cmd_buff
[
0
]);
switch
(
cmd
)
{
// Read from file...
case
FileCommand
::
Read
:
{
u64
offset
=
cmd_buff
[
1
]
|
((
u64
)
cmd_buff
[
2
])
<<
32
;
u32
length
=
cmd_buff
[
3
];
u32
address
=
cmd_buff
[
5
];
DEBUG_LOG
(
KERNEL
,
"Read %s %s: offset=0x%x length=%d address=0x%x"
,
GetTypeName
().
c_str
(),
GetName
().
c_str
(),
offset
,
length
,
address
);
cmd_buff
[
2
]
=
backend
->
Read
(
offset
,
length
,
Memory
::
GetPointer
(
address
));
break
;
}
// Write to file...
case
FileCommand
::
Write
:
{
u64
offset
=
cmd_buff
[
1
]
|
((
u64
)
cmd_buff
[
2
])
<<
32
;
u32
length
=
cmd_buff
[
3
];
u32
flush
=
cmd_buff
[
4
];
u32
address
=
cmd_buff
[
6
];
DEBUG_LOG
(
KERNEL
,
"Write %s %s: offset=0x%x length=%d address=0x%x, flush=0x%x"
,
GetTypeName
().
c_str
(),
GetName
().
c_str
(),
offset
,
length
,
address
,
flush
);
cmd_buff
[
2
]
=
backend
->
Write
(
offset
,
length
,
flush
,
Memory
::
GetPointer
(
address
));
break
;
}
case
FileCommand
::
GetSize
:
{
DEBUG_LOG
(
KERNEL
,
"GetSize %s %s"
,
GetTypeName
().
c_str
(),
GetName
().
c_str
());
u64
size
=
backend
->
GetSize
();
cmd_buff
[
2
]
=
(
u32
)
size
;
cmd_buff
[
3
]
=
size
>>
32
;
break
;
}
// Unknown command...
default
:
ERROR_LOG
(
KERNEL
,
"Unknown command=0x%08X!"
,
cmd
);
cmd_buff
[
1
]
=
-
1
;
// TODO(Link Mauve): use the correct error code for that.
return
-
1
;
}
cmd_buff
[
1
]
=
0
;
// No error
return
0
;
}
/**
* Wait for kernel object to synchronize
* @param wait Boolean wait set if current thread should wait as a result of sync operation
* @return Result of operation, 0 on success, otherwise error code
*/
Result
WaitSynchronization
(
bool
*
wait
)
{
// TODO(bunnei): ImplementMe
ERROR_LOG
(
OSHLE
,
"(UNIMPLEMENTED)"
);
return
0
;
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
std
::
map
<
FileSys
::
Archive
::
IdCode
,
Handle
>
g_archive_map
;
///< Map of file archives by IdCode
std
::
map
<
FileSys
::
Archive
::
IdCode
,
Handle
>
g_archive_map
;
///< Map of file archives by IdCode
...
@@ -171,9 +250,39 @@ Handle CreateArchive(FileSys::Archive* backend, const std::string& name) {
...
@@ -171,9 +250,39 @@ Handle CreateArchive(FileSys::Archive* backend, const std::string& name) {
return
handle
;
return
handle
;
}
}
/**
* Open a File from an Archive
* @param archive_handle Handle to an open Archive object
* @param path Path to the File inside of the Archive
* @param mode Mode under which to open the File
* @return Opened File object
*/
Handle
OpenFileFromArchive
(
Handle
archive_handle
,
const
std
::
string
&
path
,
const
FileSys
::
Mode
mode
)
{
File
*
file
=
new
File
;
Handle
handle
=
Kernel
::
g_object_pool
.
Create
(
file
);
Archive
*
archive
=
Kernel
::
g_object_pool
.
GetFast
<
Archive
>
(
archive_handle
);
file
->
path
=
path
;
file
->
backend
=
archive
->
backend
->
OpenFile
(
path
,
mode
);
return
handle
;
}
/// Initialize archives
/// Initialize archives
void
ArchiveInit
()
{
void
ArchiveInit
()
{
g_archive_map
.
clear
();
g_archive_map
.
clear
();
// TODO(Link Mauve): Add the other archive types (see here for the known types:
// http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes). Currently the only half-finished
// archive type is SDMC, so it is the only one getting exposed.
// TODO(Link Mauve): don't assume the path separator is '/'.
std
::
string
sdmc_directory
=
FileUtil
::
GetCurrentDir
()
+
"/userdata/sdmc"
;
auto
archive
=
new
FileSys
::
Archive_SDMC
(
sdmc_directory
);
if
(
archive
->
Initialize
())
CreateArchive
(
archive
,
"SDMC"
);
else
ERROR_LOG
(
KERNEL
,
"Can't instantiate SDMC archive with path %s"
,
sdmc_directory
.
c_str
());
}
}
/// Shutdown archives
/// Shutdown archives
...
...
This diff is collapsed.
Click to expand it.
src/core/hle/kernel/archive.h
+
9
−
0
View file @
19d04f3a
...
@@ -29,6 +29,15 @@ Handle OpenArchive(FileSys::Archive::IdCode id_code);
...
@@ -29,6 +29,15 @@ Handle OpenArchive(FileSys::Archive::IdCode id_code);
*/
*/
Handle
CreateArchive
(
FileSys
::
Archive
*
backend
,
const
std
::
string
&
name
);
Handle
CreateArchive
(
FileSys
::
Archive
*
backend
,
const
std
::
string
&
name
);
/**
* Open a File from an Archive
* @param archive_handle Handle to an open Archive object
* @param path Path to the File inside of the Archive
* @param mode Mode under which to open the File
* @return Opened File object
*/
Handle
OpenFileFromArchive
(
Handle
handle
,
const
std
::
string
&
name
,
const
FileSys
::
Mode
mode
);
/// Initialize archives
/// Initialize archives
void
ArchiveInit
();
void
ArchiveInit
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment