resonance 1.0.1
Loading...
Searching...
No Matches
loadfile.h File Reference

Go to the source code of this file.

Functions

void * LoadWholeFile (const char *pszPath, void *pBuffer, unsigned nBufferSize, unsigned *pnSize)
 Read a whole file.
void * LoadGzFile (const char *pszPath, void *pBuffer, unsigned nBufferSize, unsigned *pnSize)
 Read a whole compressed file, decompressing it.
int OpenStreamByPath (const char *pszPath)
 Open a file, whether it resolves to an ark stream or a loose file.
void ReadStreamChunk (int nFile, int nSector, void *pBuffer, unsigned nLength)
 Read one chunk of a file into a buffer.
void FilenameToISO9660 (const char *pszComponent, char *pszPath)
 Append a component to a device path.
void CloseLoadFile (int nFile)
 Close an open file, whether it is an ark stream or a loose file.
int FindOpenFileInArkTrueSize (int nStream)
 Report the decompressed size of the file an ark stream reads.
unsigned GetGzFileSize (int nFile)
 Report the decompressed size of a compressed loose file.
void GzipDecompressFdToRam (int nFile, void *pBuffer)
 Decompress a whole file into a buffer.
int GzipDecompressRamToRam (const void *pSource, int nSourceLength, void *pDest)
 Inflate a gzip member that is already in memory.
int FileSize (const char *pszPath)
 Report the stored length of a file.
int FileTrueSize (const char *pszPath)
 Report the uncompressed length of a file.
int GzipRefillInputBuffer (int nSilentEof)
 Refill the staging buffer from the memory source or the file and report its first byte.
void GzipFlushWindow ()
 Checksum the filled part of gzipWindow, copy it to the output, and rewind the window.
int GzipGetByte ()
 Read one byte through the staging buffer, refilling the buffer when it is exhausted.

Variables

constexpr char kGzExtension [] = ".gz"
 Extension that routes a load through the decompressing path.
constexpr unsigned kGzipWindowSize = 0x8000
 The window length the decompressor fills before each flush.
unsigned char gzipWindow [2 *kGzipWindowSize]
 The decompressor window.
unsigned gzipOutcnt
 The write position in gzipWindow.
unsigned char gzipInbuf []
 The staging buffer refilled from the memory source or the file.
unsigned gzipInsize
 The valid byte count in gzipInbuf.
unsigned gzipInptr
 The read position in gzipInbuf.

Function Documentation

◆ LoadWholeFile()

void * LoadWholeFile ( const char * pszPath,
void * pBuffer,
unsigned nBufferSize,
unsigned * pnSize )

Read a whole file.

A path whose last three characters match kGzExtension, tested without regard to case, is handed to LoadGzFile() instead. Any other path is opened, measured, and read in one call.

With no buffer supplied the routine allocates one, from the selected zone when there is one and from MemAllocTagged() otherwise. With a buffer supplied that is too small the file is closed and the load reports null.

Parameters
pszPathThe file to read.
pBufferThe destination, or null to have one allocated.
nBufferSizeThe destination size, which is ignored when pBuffer is null.
pnSizeReceives the file size, and is written even when the allocation failed.
Returns
The destination, or null when the file could not be opened or read.
Ghidra address:
NTSC-U/C: 0x00555538
Ghidra address:
PAL: 0x00595bc0

◆ LoadGzFile()

void * LoadGzFile ( const char * pszPath,
void * pBuffer,
unsigned nBufferSize,
unsigned * pnSize )

Read a whole compressed file, decompressing it.

The size queried and reported is the decompressed size, and the reader inflates the whole file in one call. Whether the query and the read address an ark stream or a loose file depends on UsingArkFiles().

A supplied buffer that is too small is fatal here rather than a null report, the one behavioural difference from LoadWholeFile(). The file is not closed on the success path.

Parameters
pszPathThe file to read.
pBufferThe destination, or null to have one allocated.
nBufferSizeThe destination size, which is ignored when pBuffer is null.
pnSizeReceives the decompressed size.
Returns
The destination, or null when the file could not be opened.
Ghidra address:
NTSC-U/C: 0x00555678
Ghidra address:
PAL: 0x00595d00

◆ OpenStreamByPath()

int OpenStreamByPath ( const char * pszPath)

Open a file, whether it resolves to an ark stream or a loose file.

The CD drive is synchronised first, and the path is opened read-only through sceOpen().

Parameters
pszPathThe path to open, device prefix included.
Returns
The handle, or a negative value on failure.
Ghidra address:
NTSC-U/C: 0x0055c400
Ghidra address:
PAL: 0x0059d620

◆ ReadStreamChunk()

void ReadStreamChunk ( int nFile,
int nSector,
void * pBuffer,
unsigned nLength )

Read one chunk of a file into a buffer.

The chunk index is mapped through ArkfileLogicalToPhysicalSector() before the seek, even though ReadArkStreamThroughCache(), the one caller, has already mapped it. An optimized archive is therefore read at a doubly mapped position.

Parameters
nFileThe file to read.
nSectorThe chunk index.
pBufferThe destination.
nLengthThe number of bytes to read.
Ghidra address:
NTSC-U/C: 0x0055c498
Ghidra address:
PAL: 0x0059d6b8

◆ FilenameToISO9660()

void FilenameToISO9660 ( const char * pszComponent,
char * pszPath )

Append a component to a device path.

A backslash is appended first when the component is not empty, and the component is normalised as it is copied. The argument order (the component before the buffer) matches the image.

Parameters
pszComponentThe component to append.
pszPathThe buffer to append to.
Ghidra address:
NTSC-U/C: 0x0047dec0
Ghidra address:
PAL: 0x004bbb98

◆ CloseLoadFile()

void CloseLoadFile ( int nFile)

Close an open file, whether it is an ark stream or a loose file.

The whole body forwards to the SDK primitive at 0x0056af88 with the argument passed through.

Parameters
nFileThe file to close.
Ghidra address:
NTSC-U/C: 0x0055c438
Ghidra address:
PAL: 0x0059d658

◆ FindOpenFileInArkTrueSize()

int FindOpenFileInArkTrueSize ( int nStream)

Report the decompressed size of the file an ark stream reads.

The routine clears bit 0x4000 from the handle, finds the matching record in the stream table, and reports its directory entry's decompressed size. Nothing about it is specific to compression. LoadGzFile() simply needs that size, and the ark reader at 0x0055a280 uses the same entry's stored size to measure how much of the stream remains.

Parameters
nStreamThe ark stream handle.
Returns
The decompressed size in bytes, or -1 when no record has that handle.
Ghidra address:
NTSC-U/C: 0x0055bf88
Ghidra address:
PAL: 0x0059d1a8

◆ GetGzFileSize()

unsigned GetGzFileSize ( int nFile)

Report the decompressed size of a compressed loose file.

Parameters
nFileThe file.
Returns
The decompressed size in bytes.
Ghidra address:
NTSC-U/C: 0x005638c8
Ghidra address:
PAL: 0x005a2038

◆ GzipDecompressFdToRam()

void GzipDecompressFdToRam ( int nFile,
void * pBuffer )

Decompress a whole file into a buffer.

Vendored gzip glue, declared by title only. The body stores the file in the bundled gzip code's input-descriptor global at 0x00761488, copies unknown into its input-name global at 0x00761490, and drives the gzip routines at 0x006125b8, 0x00612468, 0x00562f88, 0x0061d778, and 0x006125d0. Both exits close the file with close() unless the descriptor reads -1. The failure exit puts -1 in the result register. LoadGzFile(), the one caller, ignores the result.

Parameters
nFileThe file to read.
pBufferThe destination, which must take the whole decompressed size.
Ghidra address:
NTSC-U/C: 0x005635b8
Ghidra address:
PAL: 0x005a1d28

◆ GzipDecompressRamToRam()

int GzipDecompressRamToRam ( const void * pSource,
int nSourceLength,
void * pDest )

Inflate a gzip member that is already in memory.

The source and destination windows may overlap, and every caller in the async layer relies on the overlap. The stored bytes sit against the end of the destination, and the inflate runs forward over the whole destination.

Parameters
pSourceThe stored bytes.
nSourceLengthThe number of stored bytes.
pDestThe destination.
Returns
Positive once the data is in place, and not positive on failure.
Ghidra address:
NTSC-U/C: 0x005636a0
Ghidra address:
PAL: 0x005a1e10

◆ FileSize()

int FileSize ( const char * pszPath)

Report the stored length of a file.

The path is opened, measured by seeking to its end, rewound, and closed. A gzip file reports its compressed size, unlike FileTrueSize().

Parameters
pszPathThe file to measure.
Returns
The length in bytes, or 0 when the file could not be opened.
Ghidra address:
NTSC-U/C: 0x00555790
Ghidra address:
PAL: 0x00595e18

◆ FileTrueSize()

int FileTrueSize ( const char * pszPath)

Report the uncompressed length of a file.

It opens the path, measures it from the ark directory record, the gzip trailer, or the file size, and reports the length without reporting the handle. A caller that needs the file opens it again.

Parameters
pszPathThe file to measure.
Returns
The uncompressed length, or zero or less when the file could not be opened.
Ghidra address:
NTSC-U/C: 0x00555800
Ghidra address:
PAL: 0x00595e88

◆ GzipRefillInputBuffer()

int GzipRefillInputBuffer ( int nSilentEof)

Refill the staging buffer from the memory source or the file and report its first byte.

Parameters
nSilentEofNonzero to report -1 rather than an error when a file has no more bytes.
Returns
The first byte of the refilled buffer, or -1 at a silent end of file.
Ghidra address:
NTSC-U/C: 0x006121a0
Ghidra address:
PAL: 0x00652d30

◆ GzipFlushWindow()

void GzipFlushWindow ( )

Checksum the filled part of gzipWindow, copy it to the output, and rewind the window.

An empty window is not flushed.

Ghidra address:
NTSC-U/C: 0x006122f8
Ghidra address:
PAL: 0x00652e88

◆ GzipGetByte()

int GzipGetByte ( )
inline

Read one byte through the staging buffer, refilling the buffer when it is exhausted.

Returns
The byte.

Variable Documentation

◆ kGzExtension

char kGzExtension[] = ".gz"
constexpr

Extension that routes a load through the decompressing path.

◆ kGzipWindowSize

unsigned kGzipWindowSize = 0x8000
constexpr

The window length the decompressor fills before each flush.

◆ gzipWindow

unsigned char gzipWindow[2 *kGzipWindowSize]
extern

The decompressor window.

The image reserves two window lengths, and only the first is written.

Ghidra address:
NTSC-U/C: 0x00731468
Ghidra address:
PAL: 0x00774398

◆ gzipOutcnt

unsigned gzipOutcnt
extern

The write position in gzipWindow.

Ghidra address:
NTSC-U/C: 0x00761470
Ghidra address:
PAL: 0x007a43a0

◆ gzipInbuf

unsigned char gzipInbuf[]
extern

The staging buffer refilled from the memory source or the file.

Ghidra address:
NTSC-U/C: 0x00728c28
Ghidra address:
PAL: 0x0076bb58

◆ gzipInsize

unsigned gzipInsize
extern

The valid byte count in gzipInbuf.

Ghidra address:
NTSC-U/C: 0x00761468
Ghidra address:
PAL: 0x007a4398

◆ gzipInptr

unsigned gzipInptr
extern

The read position in gzipInbuf.

Ghidra address:
NTSC-U/C: 0x0076146c
Ghidra address:
PAL: 0x007a439c