KallistiOS git master
Independent SDK for the Sega Dreamcast
|
VFS driver for accessing Visual Memory Unit storage More...
Files | |
file | fs_vmu.h |
VMU filesystem driver. | |
file | vmufs.h |
Low-level VMU filesystem driver. | |
Data Structures | |
struct | vmu_timestamp_t |
BCD timestamp, used several places in the vmufs. More... | |
struct | vmu_root_t |
VMU FS Root block layout. More... | |
struct | vmu_dir_t |
VMU FS Directory entries, 32 bytes each. More... | |
Macros | |
#define | VMUFS_OVERWRITE 1 |
Overwrite existing files. | |
#define | VMUFS_VMUGAME 2 |
This file is a VMU game. | |
#define | VMUFS_NOCOPY 4 |
Set the no-copy flag. | |
Functions | |
void | vmufs_dir_fill_time (vmu_dir_t *d) |
Fill in the date on a vmu_dir_t for writing. | |
int | vmufs_root_read (maple_device_t *dev, vmu_root_t *root_buf) |
Reads a selected VMU's root block. | |
int | vmufs_root_write (maple_device_t *dev, vmu_root_t *root_buf) |
Writes a selected VMU's root block. | |
int | vmufs_dir_blocks (vmu_root_t *root_buf) |
Given a VMU's root block, return the amount of space in bytes required to hold its directory. | |
int | vmufs_fat_blocks (vmu_root_t *root_buf) |
Given a VMU's root block, return the amount of space in bytes required to hold its FAT. | |
int | vmufs_dir_read (maple_device_t *dev, vmu_root_t *root_buf, vmu_dir_t *dir_buf) |
Given a selected VMU's root block, read its directory. | |
int | vmufs_dir_write (maple_device_t *dev, vmu_root_t *root, vmu_dir_t *dir_buf) |
Given a selected VMU's root block and dir blocks, write the dirty dir blocks back to the VMU. | |
int | vmufs_fat_read (maple_device_t *dev, vmu_root_t *root, uint16 *fat_buf) |
Given a selected VMU's root block, read its FAT. | |
int | vmufs_fat_write (maple_device_t *dev, vmu_root_t *root, uint16 *fat_buf) |
Given a selected VMU's root block and its FAT, write the FAT blocks back to the VMU. | |
int | vmufs_dir_find (vmu_root_t *root, vmu_dir_t *dir, const char *fn) |
Given a previously-read directory, locate a file by filename. | |
int | vmufs_dir_add (vmu_root_t *root, vmu_dir_t *dir, vmu_dir_t *newdirent) |
Given a previously-read directory, add a new dirent to the dir. | |
int | vmufs_file_read (maple_device_t *dev, uint16 *fat, vmu_dir_t *dirent, void *outbuf) |
Given a pointer to a directory struct and a previously loaded FAT, load the indicated file from the VMU. | |
int | vmufs_file_write (maple_device_t *dev, vmu_root_t *root, uint16 *fat, vmu_dir_t *dir, vmu_dir_t *newdirent, void *filebuf, int size) |
Given a pointer to a mostly-filled directory struct and a previously loaded directory and FAT, write the indicated file to the VMU. | |
int | vmufs_file_delete (vmu_root_t *root, uint16 *fat, vmu_dir_t *dir, const char *fn) |
Given a previously-read FAT and directory, delete the named file. | |
int | vmufs_fat_free (vmu_root_t *root, uint16 *fat) |
Given a previously-read FAT, return the number of blocks available to write out new file data. | |
int | vmufs_dir_free (vmu_root_t *root, vmu_dir_t *dir) |
Given a previously-read directory, return the number of dirents available for new files. | |
int | vmufs_mutex_lock (void) |
Lock the vmufs mutex. | |
int | vmufs_mutex_unlock (void) |
Unlock the vmufs mutex. | |
int | vmufs_readdir (maple_device_t *dev, vmu_dir_t **outbuf, int *outcnt) |
Read the directory from a VMU. | |
int | vmufs_read (maple_device_t *dev, const char *fn, void **outbuf, int *outsize) |
Read a file from the VMU. | |
int | vmufs_read_dirent (maple_device_t *dev, vmu_dir_t *dirent, void **outbuf, int *outsize) |
Read a file from the VMU, using a pre-read dirent. | |
int | vmufs_write (maple_device_t *dev, const char *fn, void *inbuf, int insize, int flags) |
Write a file to the VMU. | |
int | vmufs_delete (maple_device_t *dev, const char *fn) |
Delete a file from the VMU. | |
int | vmufs_free_blocks (maple_device_t *dev) |
Return the number of user blocks free for file writing. | |
int | vmufs_init (void) |
Initialize vmufs. | |
int | vmufs_shutdown (void) |
Shutdown vmufs. | |
VFS driver for accessing Visual Memory Unit storage
#define VMUFS_NOCOPY 4 |
Set the no-copy flag.
#define VMUFS_OVERWRITE 1 |
Overwrite existing files.
#define VMUFS_VMUGAME 2 |
This file is a VMU game.
int vmufs_delete | ( | maple_device_t * | dev, |
const char * | fn ) |
Delete a file from the VMU.
0 | On success. |
-1 | If the file is not found. |
-2 | On other failure. |
int vmufs_dir_add | ( | vmu_root_t * | root, |
vmu_dir_t * | dir, | ||
vmu_dir_t * | newdirent ) |
Given a previously-read directory, add a new dirent to the dir.
Another file with the same name should not exist (delete it first if it does). This function will not check for dupes!
root | The VMU root block. |
dir | The VMU directory. |
newdirent | The new entry to add. |
int vmufs_dir_blocks | ( | vmu_root_t * | root_buf | ) |
Given a VMU's root block, return the amount of space in bytes required to hold its directory.
root_buf | The root block to check. |
void vmufs_dir_fill_time | ( | vmu_dir_t * | d | ) |
Fill in the date on a vmu_dir_t for writing.
d | The directory to fill in the date on. |
int vmufs_dir_find | ( | vmu_root_t * | root, |
vmu_dir_t * | dir, | ||
const char * | fn ) |
Given a previously-read directory, locate a file by filename.
root | The VMU root block. |
dir | The VMU directory. |
fn | The file to find (only checked up to 12 chars). |
int vmufs_dir_free | ( | vmu_root_t * | root, |
vmu_dir_t * | dir ) |
Given a previously-read directory, return the number of dirents available for new files.
root | The VMU root block. |
dir | The directory in question. |
int vmufs_dir_read | ( | maple_device_t * | dev, |
vmu_root_t * | root_buf, | ||
vmu_dir_t * | dir_buf ) |
Given a selected VMU's root block, read its directory.
This function reads the directory of a given VMU root block. It assumes the mutex is held. There must be at least the number of bytes returned by vmufs_dir_blocks() available in the buffer for this to succeed.
dev | The VMU to read. |
root_buf | The VMU's root block. |
dir_buf | The buffer to hold the directory. You must have allocated this yourself. |
int vmufs_dir_write | ( | maple_device_t * | dev, |
vmu_root_t * | root, | ||
vmu_dir_t * | dir_buf ) |
Given a selected VMU's root block and dir blocks, write the dirty dir blocks back to the VMU.
Assumes the mutex is held.
dev | The VMU to write to. |
root | The VMU's root block. |
dir_buf | The VMU's directory structure. |
int vmufs_fat_blocks | ( | vmu_root_t * | root_buf | ) |
Given a VMU's root block, return the amount of space in bytes required to hold its FAT.
root_buf | The root block to check. |
int vmufs_fat_free | ( | vmu_root_t * | root, |
uint16 * | fat ) |
Given a previously-read FAT, return the number of blocks available to write out new file data.
root | The VMU root block. |
fat | The FAT to be examined. |
int vmufs_fat_read | ( | maple_device_t * | dev, |
vmu_root_t * | root, | ||
uint16 * | fat_buf ) |
Given a selected VMU's root block, read its FAT.
This function reads the FAT of a VMU, given its root block. It assumes the mutex is held. There must be at least the number of bytes returned by vmufs_fat_blocks() available in the buffer for this to succeed.
dev | The VMU to read from. |
root | The VMU's root block. |
fat_buf | The buffer to store the FAT into. You must pre-allocate this. |
int vmufs_fat_write | ( | maple_device_t * | dev, |
vmu_root_t * | root, | ||
uint16 * | fat_buf ) |
Given a selected VMU's root block and its FAT, write the FAT blocks back to the VMU.
This function assumes the mutex is held.
dev | The VMU to write to. |
root | The VMU's root block. |
fat_buf | The buffer to write to the FAT. |
int vmufs_file_delete | ( | vmu_root_t * | root, |
uint16 * | fat, | ||
vmu_dir_t * | dir, | ||
const char * | fn ) |
Given a previously-read FAT and directory, delete the named file.
No changes are made to the VMU itself, just the in-memory structs.
root | The VMU root block. |
fat | The FAT to be modified. |
dir | The directory to be modified. |
fn | The file name to be deleted. |
0 | On success. |
-1 | If fn is not found. |
int vmufs_file_read | ( | maple_device_t * | dev, |
uint16 * | fat, | ||
vmu_dir_t * | dirent, | ||
void * | outbuf ) |
Given a pointer to a directory struct and a previously loaded FAT, load the indicated file from the VMU.
An appropriate amount of space must have been allocated previously in the buffer. Assumes the mutex is held.
dev | The VMU to read from. |
fat | The FAT of the VMU. |
dirent | The entry to read. |
outbuf | A buffer to write the data into. You must allocate this yourself with the appropriate amount of space. |
int vmufs_file_write | ( | maple_device_t * | dev, |
vmu_root_t * | root, | ||
uint16 * | fat, | ||
vmu_dir_t * | dir, | ||
vmu_dir_t * | newdirent, | ||
void * | filebuf, | ||
int | size ) |
Given a pointer to a mostly-filled directory struct and a previously loaded directory and FAT, write the indicated file to the VMU.
The named file should not exist in the directory already. The directory and FAT will not be sync'd back to the VMU, this must be done manually. Assumes the mutex is held.
dev | The VMU to write to. |
root | The VMU root block. |
fat | The FAT of the VMU. |
dir | The directory of the VMU. |
newdirent | The new entry to write. |
filebuf | The new file data. |
size | The size of the file in blocks (512-bytes each). |
int vmufs_free_blocks | ( | maple_device_t * | dev | ) |
Return the number of user blocks free for file writing.
You should check this number before attempting to write.
int vmufs_init | ( | void | ) |
Initialize vmufs.
Must be called before anything else is useful.
0 | On success (no error conditions defined). |
int vmufs_mutex_lock | ( | void | ) |
Lock the vmufs mutex.
This should be done before you attempt any low-level ops.
0 | On success (no error conditions defined). |
int vmufs_mutex_unlock | ( | void | ) |
Unlock the vmufs mutex.
This should be done once you're done with any low-level ops.
0 | On success (no error conditions defined). |
int vmufs_read | ( | maple_device_t * | dev, |
const char * | fn, | ||
void ** | outbuf, | ||
int * | outsize ) |
Read a file from the VMU.
The output buffer will be allocated for you using malloc(), and the size of the file will be returned. On failure, outbuf will not contain a dangling buffer that needs to be freed (no further action required).
dev | The VMU to read from. |
fn | The name of the file to read. |
outbuf | A buffer that will be allocated where the file data will be placed. |
outsize | Storage for the size of the file, in bytes. |
int vmufs_read_dirent | ( | maple_device_t * | dev, |
vmu_dir_t * | dirent, | ||
void ** | outbuf, | ||
int * | outsize ) |
Read a file from the VMU, using a pre-read dirent.
This function is faster to use than vmufs_read() if you already have done the lookup, since it won't need to do that.
dev | The VMU to read from. |
dirent | The entry to read. |
outbuf | A buffer that will be allocated where the file data will be placed. |
outsize | Storage for the size of the file, in bytes. |
int vmufs_readdir | ( | maple_device_t * | dev, |
vmu_dir_t ** | outbuf, | ||
int * | outcnt ) |
Read the directory from a VMU.
The output buffer will be allocated for you using malloc(), and the number of entries will be returned. On failure, outbuf will not contain a dangling buffer that needs to be freed (no further action required).
dev | The VMU to read from. |
outbuf | A buffer that will be allocated where the directory data will be placed. |
outcnt | The number of entries in outbuf. |
int vmufs_root_read | ( | maple_device_t * | dev, |
vmu_root_t * | root_buf ) |
Reads a selected VMU's root block.
This function assumes the mutex is held.
dev | The VMU to read from. |
root_buf | A buffer to hold the root block. You must allocate this yourself before calling. |
-1 | On failure. |
0 | On success. |
int vmufs_root_write | ( | maple_device_t * | dev, |
vmu_root_t * | root_buf ) |
Writes a selected VMU's root block.
This function assumes the mutex is held.
dev | The VMU to write to. |
root_buf | The root block to write. |
-1 | On failure. |
0 | On success. |
int vmufs_shutdown | ( | void | ) |
Shutdown vmufs.
Must be called after everything is finished.
int vmufs_write | ( | maple_device_t * | dev, |
const char * | fn, | ||
void * | inbuf, | ||
int | insize, | ||
int | flags ) |
Write a file to the VMU.
If the named file already exists, then the function checks 'flags'. If VMUFS_OVERWRITE is set, then the old file is deleted first before the new one is written (this all happens atomically). On partial failure, some data blocks may have been written, but in general the card should not be damaged.
dev | The VMU to write to. |
fn | The filename to write. |
inbuf | The data to write to the file. |
insize | The size of the file in bytes. |
flags | Flags for the write (i.e, VMUFS_OVERWRITE, VMUFS_VMUGAME, VMUFS_NOCOPY). |