KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches

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.
 

Detailed Description

VFS driver for accessing Visual Memory Unit storage

Macro Definition Documentation

◆ VMUFS_NOCOPY

#define VMUFS_NOCOPY   4

Set the no-copy flag.

◆ VMUFS_OVERWRITE

#define VMUFS_OVERWRITE   1

Overwrite existing files.

◆ VMUFS_VMUGAME

#define VMUFS_VMUGAME   2

This file is a VMU game.

Function Documentation

◆ vmufs_delete()

int vmufs_delete ( maple_device_t * dev,
const char * fn )

Delete a file from the VMU.

Return values
0On success.
-1If the file is not found.
-2On other failure.

◆ vmufs_dir_add()

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!

Parameters
rootThe VMU root block.
dirThe VMU directory.
newdirentThe new entry to add.
Returns
0 on success, or <0 on failure.

◆ vmufs_dir_blocks()

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.

Parameters
root_bufThe root block to check.
Returns
The amount of space, in bytes, needed.

◆ vmufs_dir_fill_time()

void vmufs_dir_fill_time ( vmu_dir_t * d)

Fill in the date on a vmu_dir_t for writing.

Parameters
dThe directory to fill in the date on.

◆ vmufs_dir_find()

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.

Parameters
rootThe VMU root block.
dirThe VMU directory.
fnThe file to find (only checked up to 12 chars).
Returns
The index into the directory array on success, or <0 on failure.

◆ vmufs_dir_free()

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.

Parameters
rootThe VMU root block.
dirThe directory in question.
Returns
The number of entries available.

◆ vmufs_dir_read()

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.

Parameters
devThe VMU to read.
root_bufThe VMU's root block.
dir_bufThe buffer to hold the directory. You must have allocated this yourself.
Returns
0 on success, <0 on failure.

◆ vmufs_dir_write()

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.

Parameters
devThe VMU to write to.
rootThe VMU's root block.
dir_bufThe VMU's directory structure.
Returns
0 on success, <0 on failure.

◆ vmufs_fat_blocks()

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.

Parameters
root_bufThe root block to check.
Returns
The amount of space, in bytes, needed.

◆ vmufs_fat_free()

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.

Parameters
rootThe VMU root block.
fatThe FAT to be examined.
Returns
The number of blocks available.

◆ vmufs_fat_read()

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.

Parameters
devThe VMU to read from.
rootThe VMU's root block.
fat_bufThe buffer to store the FAT into. You must pre-allocate this.
Returns
0 on success, <0 on failure.

◆ vmufs_fat_write()

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.

Parameters
devThe VMU to write to.
rootThe VMU's root block.
fat_bufThe buffer to write to the FAT.
Returns
0 on success, <0 on failure.

◆ vmufs_file_delete()

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.

Parameters
rootThe VMU root block.
fatThe FAT to be modified.
dirThe directory to be modified.
fnThe file name to be deleted.
Return values
0On success.
-1If fn is not found.

◆ vmufs_file_read()

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.

Parameters
devThe VMU to read from.
fatThe FAT of the VMU.
direntThe entry to read.
outbufA buffer to write the data into. You must allocate this yourself with the appropriate amount of space.
Returns
0 on success, <0 on failure.

◆ vmufs_file_write()

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.

Parameters
devThe VMU to write to.
rootThe VMU root block.
fatThe FAT of the VMU.
dirThe directory of the VMU.
newdirentThe new entry to write.
filebufThe new file data.
sizeThe size of the file in blocks (512-bytes each).
Returns
0 on success, <0 on failure.

◆ vmufs_free_blocks()

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.

Returns
The number of blocks free for writing.

◆ vmufs_init()

int vmufs_init ( void )

Initialize vmufs.

Must be called before anything else is useful.

Return values
0On success (no error conditions defined).

◆ vmufs_mutex_lock()

int vmufs_mutex_lock ( void )

Lock the vmufs mutex.

This should be done before you attempt any low-level ops.

Return values
0On success (no error conditions defined).

◆ vmufs_mutex_unlock()

int vmufs_mutex_unlock ( void )

Unlock the vmufs mutex.

This should be done once you're done with any low-level ops.

Return values
0On success (no error conditions defined).

◆ vmufs_read()

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).

Parameters
devThe VMU to read from.
fnThe name of the file to read.
outbufA buffer that will be allocated where the file data will be placed.
outsizeStorage for the size of the file, in bytes.
Returns
0 on success, or <0 on failure.

◆ vmufs_read_dirent()

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.

Parameters
devThe VMU to read from.
direntThe entry to read.
outbufA buffer that will be allocated where the file data will be placed.
outsizeStorage for the size of the file, in bytes.
Returns
0 on success, <0 on failure.

◆ vmufs_readdir()

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).

Parameters
devThe VMU to read from.
outbufA buffer that will be allocated where the directory data will be placed.
outcntThe number of entries in outbuf.
Returns
0 on success, or <0 on failure.

◆ vmufs_root_read()

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.

Parameters
devThe VMU to read from.
root_bufA buffer to hold the root block. You must allocate this yourself before calling.
Return values
-1On failure.
0On success.

◆ vmufs_root_write()

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.

Parameters
devThe VMU to write to.
root_bufThe root block to write.
Return values
-1On failure.
0On success.

◆ vmufs_shutdown()

int vmufs_shutdown ( void )

Shutdown vmufs.

Must be called after everything is finished.

◆ vmufs_write()

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.

Parameters
devThe VMU to write to.
fnThe filename to write.
inbufThe data to write to the file.
insizeThe size of the file in bytes.
flagsFlags for the write (i.e, VMUFS_OVERWRITE, VMUFS_VMUGAME, VMUFS_NOCOPY).
Returns
0 on success, or <0 for failure.