OpenCore
1.0.4
OpenCore Bootloader
|
#include "fsw_core.h"
Go to the source code of this file.
Macros | |
#define | MAX_CACHE_LEVEL (5) |
#define | START_BUF_SIZE 5 |
#define | SEP_CHAR L'\\' |
Functions | |
fsw_status_t | fsw_mount (void *host_data, struct fsw_host_table *host_table, struct fsw_fstype_table *fstype_table, struct fsw_volume **vol_out) |
void | fsw_unmount (struct fsw_volume *vol) |
fsw_status_t | fsw_volume_stat (struct fsw_volume *vol, struct fsw_volume_stat *sb) |
void | fsw_set_blocksize (struct fsw_volume *vol, fsw_u32 phys_blocksize, fsw_u32 log_blocksize) |
fsw_status_t | fsw_block_get (struct VOLSTRUCTNAME *vol, fsw_u32 phys_bno, fsw_u32 cache_level, void **buffer_out) |
void | fsw_block_release (struct VOLSTRUCTNAME *vol, fsw_u32 phys_bno, void *buffer) |
fsw_status_t | fsw_dnode_create_root (struct fsw_volume *vol, fsw_u32 dnode_id, struct fsw_dnode **dno_out) |
int | fsw_dnode_is_root (struct fsw_dnode *dno) |
fsw_status_t | fsw_dnode_create (struct fsw_volume *vol, struct fsw_dnode *parent_dno, fsw_u32 dnode_id, int type, struct fsw_string *name, struct fsw_dnode **dno_out) |
void | fsw_dnode_mkcomplete (struct fsw_dnode *dno) |
void | fsw_dnode_retain (struct fsw_dnode *dno) |
void | fsw_dnode_release (struct fsw_dnode *dno) |
fsw_status_t | fsw_dnode_fill (struct fsw_dnode *dno) |
fsw_status_t | fsw_dnode_stat (struct fsw_dnode *dno, struct fsw_dnode_stat *sb) |
fsw_status_t | fsw_dnode_lookup (struct fsw_dnode *dno, struct fsw_string *lookup_name, struct fsw_dnode **child_dno_out) |
fsw_status_t | fsw_dnode_lookup_path (struct fsw_dnode *dno, struct fsw_string *lookup_path, char separator, struct fsw_dnode **child_dno_out) |
fsw_status_t | fsw_dnode_dir_read (struct fsw_shandle *shand, struct fsw_dnode **child_dno_out) |
fsw_status_t | fsw_dnode_readlink (struct fsw_dnode *dno, struct fsw_string *target_name) |
fsw_status_t | fsw_dnode_readlink_data (struct fsw_dnode *dno, struct fsw_string *link_target) |
fsw_status_t | fsw_dnode_resolve (struct fsw_dnode *dno, struct fsw_dnode **target_dno_out) |
fsw_status_t | fsw_shandle_open (struct fsw_dnode *dno, struct fsw_shandle *shand) |
void | fsw_shandle_close (struct fsw_shandle *shand) |
fsw_status_t | fsw_shandle_read (struct fsw_shandle *shand, fsw_u32 *buffer_size_inout, void *buffer_in) |
fsw_status_t | fsw_dnode_get_path (struct fsw_volume *vol, struct fsw_dnode *dno, struct fsw_string *out_path) |
fsw_status_t | fsw_get_bless_info (struct fsw_volume *vol, int type, struct fsw_string *out_path) |
Core file system wrapper abstraction layer code.
Definition in file fsw_core.c.
#define MAX_CACHE_LEVEL (5) |
Definition at line 45 of file fsw_core.c.
#define SEP_CHAR L'\\' |
#define START_BUF_SIZE 5 |
fsw_status_t fsw_block_get | ( | struct VOLSTRUCTNAME * | vol, |
fsw_u32 | phys_bno, | ||
fsw_u32 | cache_level, | ||
void ** | buffer_out ) |
Get a block of data from the disk. This function is called by the file system driver or by core functions. It calls through to the host driver's device access routine. Given a physical block number, it reads the block into memory (or fetches it from the block cache) and returns the address of the memory buffer. The caller should provide an indication of how important the block is in the cache_level parameter. Blocks with a low level are purged first. Some suggestions for cache levels:
If this function returns successfully, the returned data pointer is valid until the caller calls fsw_block_release.
Definition at line 179 of file fsw_core.c.
void fsw_block_release | ( | struct VOLSTRUCTNAME * | vol, |
fsw_u32 | phys_bno, | ||
void * | buffer ) |
Releases a disk block. This function must be called to release disk blocks returned from fsw_block_get.
Definition at line 267 of file fsw_core.c.
fsw_status_t fsw_dnode_create | ( | struct fsw_volume * | vol, |
struct fsw_dnode * | parent_dno, | ||
fsw_u32 | dnode_id, | ||
int | type, | ||
struct fsw_string * | name, | ||
struct fsw_dnode ** | dno_out ) |
Create a new dnode representing a file system object. This function is called by the file system driver in response to directory lookup or read requests. Note that if there already is a dnode with the given dnode_id on record, then no new object is created. Instead, the existing dnode is returned and its reference count increased. All other parameters are ignored in this case.
The type passed into this function may be FSW_DNODE_TYPE_UNKNOWN. It is sufficient to fill the type field during the dnode_fill call.
The name parameter must describe a string with the object's name. A copy will be stored in the dnode structure for future reference. The name will not be used to shortcut directory lookups, but may be used to reconstruct paths.
If the function returns successfully, *dno_out contains a pointer to the dnode that must be released by the caller with fsw_dnode_release.
Definition at line 372 of file fsw_core.c.
fsw_status_t fsw_dnode_create_root | ( | struct fsw_volume * | vol, |
fsw_u32 | dnode_id, | ||
struct fsw_dnode ** | dno_out ) |
Create a dnode representing the root directory. This function is called by the file system driver while mounting the file system. The root directory is special because it has no parent dnode, its name is defined to be empty, and its type is also fixed. Otherwise, this functions behaves in the same way as fsw_dnode_create.
Definition at line 323 of file fsw_core.c.
fsw_status_t fsw_dnode_dir_read | ( | struct fsw_shandle * | shand, |
struct fsw_dnode ** | child_dno_out ) |
Get the next directory item in sequential order. This function is called by the host driver to read the complete contents of a directory in sequential (file system defined) order. Calling this function returns the next entry. Iteration state is kept by a shandle on the directory's dnode. The caller must set up the shandle when starting the iteration.
When the end of the directory is reached, this function returns FSW_NOT_FOUND. If the function returns FSW_SUCCESS, *child_dno_out points to the next directory entry. The caller must call fsw_dnode_release on it.
Definition at line 669 of file fsw_core.c.
fsw_status_t fsw_dnode_fill | ( | struct fsw_dnode * | dno | ) |
Get full information about a dnode from disk. This function is called by the host driver as well as by the core functions. Some file systems defer reading full information on a dnode until it is actually needed (i.e. separation between directory and inode information). This function makes sure that all information is available in the dnode structure. The following fields may not have a correct value until fsw_dnode_fill has been called:
type, size
Definition at line 483 of file fsw_core.c.
fsw_status_t fsw_dnode_get_path | ( | struct fsw_volume * | vol, |
struct fsw_dnode * | dno, | ||
struct fsw_string * | out_path ) |
Definition at line 948 of file fsw_core.c.
int fsw_dnode_is_root | ( | struct fsw_dnode * | dno | ) |
Definition at line 350 of file fsw_core.c.
fsw_status_t fsw_dnode_lookup | ( | struct fsw_dnode * | dno, |
struct fsw_string * | lookup_name, | ||
struct fsw_dnode ** | child_dno_out ) |
Lookup a directory entry by name. This function is called by the host driver. Given a directory dnode and a file name, it looks up the named entry in the directory.
If the dnode is not a directory, the call will fail. The caller is responsible for resolving symbolic links before calling this function.
If the function returns FSW_SUCCESS, *child_dno_out points to the requested directory entry. The caller must call fsw_dnode_release on it.
Definition at line 529 of file fsw_core.c.
fsw_status_t fsw_dnode_lookup_path | ( | struct fsw_dnode * | dno, |
struct fsw_string * | lookup_path, | ||
char | separator, | ||
struct fsw_dnode ** | child_dno_out ) |
Find a file system object by path. This function is called by the host driver. Given a directory dnode and a relative or absolute path, it walks the directory tree until it finds the target dnode. If an intermediate node turns out to be a symlink, it is resolved automatically. If the target node is a symlink, it is not resolved.
If the function returns FSW_SUCCESS, *child_dno_out points to the requested directory entry. The caller must call fsw_dnode_release on it.
Definition at line 554 of file fsw_core.c.
void fsw_dnode_mkcomplete | ( | struct fsw_dnode * | dno | ) |
Mark dnode as 'complete' one
Definition at line 420 of file fsw_core.c.
fsw_status_t fsw_dnode_readlink | ( | struct fsw_dnode * | dno, |
struct fsw_string * | target_name ) |
Read the target path of a symbolic link. This function is called by the host driver to read the "content" of a symbolic link, that is the relative or absolute path it points to.
If the function returns FSW_SUCCESS, the string handle provided by the caller is filled with a string in the host's preferred encoding. The caller is responsible for calling fsw_strfree on the string.
Definition at line 695 of file fsw_core.c.
fsw_status_t fsw_dnode_readlink_data | ( | struct fsw_dnode * | dno, |
struct fsw_string * | link_target ) |
Read the target path of a symbolic link by accessing file data. This function can be called by the file system driver if the file system stores the target path as normal file data. This function will open an shandle, read the whole content of the file into a buffer, and build a string from that. Currently the encoding for the string is fixed as FSW_STRING_TYPE_ISO88591.
If the function returns FSW_SUCCESS, the string handle provided by the caller is filled with a string in the host's preferred encoding. The caller is responsible for calling fsw_strfree on the string.
Definition at line 720 of file fsw_core.c.
void fsw_dnode_release | ( | struct fsw_dnode * | dno | ) |
Release a dnode pointer, deallocating it if this was the last reference. This function decrements the reference counter of the dnode. If the counter reaches zero, the dnode is freed. Since the parent dnode is released during that process, this function may cause it to be freed, too.
Definition at line 442 of file fsw_core.c.
fsw_status_t fsw_dnode_resolve | ( | struct fsw_dnode * | dno, |
struct fsw_dnode ** | target_dno_out ) |
Resolve a symbolic link. This function can be called by the host driver to make sure the a dnode is fully resolved instead of pointing at a symlink. If the dnode passed in is not a symlink, it is returned unmodified.
Note that absolute paths will be resolved relative to the root directory of the volume. If the host is an operating system with its own VFS layer, it should resolve symlinks on its own.
If the function returns FSW_SUCCESS, *target_dno_out points at a dnode that is not a symlink. The caller is responsible for calling fsw_dnode_release on it.
Definition at line 764 of file fsw_core.c.
void fsw_dnode_retain | ( | struct fsw_dnode * | dno | ) |
Increases the reference count of a dnode. This must be balanced with fsw_dnode_release calls. Note that some dnode functions return a retained dnode pointer to their caller.
Definition at line 430 of file fsw_core.c.
fsw_status_t fsw_dnode_stat | ( | struct fsw_dnode * | dno, |
struct fsw_dnode_stat * | sb ) |
Get extended information about a dnode. This function can be called by the host driver to get a full compliment of information about a dnode in addition to the fields of the fsw_dnode structure itself.
Some data requires host-specific conversion to be useful (i.e. timestamps) and will be passed to callback functions instead of being written into the structure. These callbacks must be filled in by the caller.
Definition at line 502 of file fsw_core.c.
fsw_status_t fsw_get_bless_info | ( | struct fsw_volume * | vol, |
int | type, | ||
struct fsw_string * | out_path ) |
Definition at line 1039 of file fsw_core.c.
fsw_status_t fsw_mount | ( | void * | host_data, |
struct fsw_host_table * | host_table, | ||
struct fsw_fstype_table * | fstype_table, | ||
struct fsw_volume ** | vol_out ) |
Mount a volume with a given file system driver. This function is called by the host driver to make a volume accessible. The file system driver to use is specified by a pointer to its dispatch table. The file system driver will look at the data on the volume to determine if it can read the format. If the volume is found unsuitable, FSW_UNSUPPORTED is returned.
If this function returns FSW_SUCCESS, *vol_out points at a valid volume data structure. The caller must release it later by calling fsw_unmount.
If this function returns an error status, the caller only needs to clean up its own buffers that may have been allocated through the read_block interface.
Definition at line 62 of file fsw_core.c.
void fsw_set_blocksize | ( | struct fsw_volume * | vol, |
fsw_u32 | phys_blocksize, | ||
fsw_u32 | log_blocksize ) |
Set the physical and logical block sizes of the volume. This functions is called by the file system driver to announce the block sizes it wants to use for accessing the disk (physical) and for addressing file contents (logical). Usually both sizes will be the same but there may be file systems that need to access metadata at a smaller block size than the allocation unit for files.
Calling this function causes the block cache to be dropped. All pointers returned from fsw_block_get become invalid. This function should only be called while mounting the file system, not as a part of file access operations.
Both sizes are measured in bytes, must be powers of 2, and must not be smaller than 512 bytes. The logical block size cannot be smaller than the physical block size.
Definition at line 145 of file fsw_core.c.
void fsw_shandle_close | ( | struct fsw_shandle * | shand | ) |
Close a shandle after accessing the dnode's data. This function is called by the host driver or core functions when they are finished with accessing a file's data. It releases the dnode reference and frees any buffers associated with the shandle itself. The dnode is only released if this was the last reference using it.
Definition at line 848 of file fsw_core.c.
fsw_status_t fsw_shandle_open | ( | struct fsw_dnode * | dno, |
struct fsw_shandle * | shand ) |
Set up a shandle (storage handle) to access a file's data. This function is called by the host driver and by the core when they need to access a file's data. It is also used in accessing the raw data of directories and symlinks if the file system uses the same mechanisms for storing the data of those items.
The storage for the fsw_shandle structure is provided by the caller. The dnode and pos fields may be accessed, pos may also be written to to set the file pointer. The file's data size is available as shand->dnode->size.
If this function returns FSW_SUCCESS, the caller must call fsw_shandle_close to release the dnode reference held by the shandle.
Definition at line 822 of file fsw_core.c.
fsw_status_t fsw_shandle_read | ( | struct fsw_shandle * | shand, |
fsw_u32 * | buffer_size_inout, | ||
void * | buffer_in ) |
Read data from a shandle (storage handle for a dnode). This function is called by the host driver or internally when data is read from a file. TODO: more
Definition at line 860 of file fsw_core.c.
void fsw_unmount | ( | struct fsw_volume * | vol | ) |
Unmount a volume by releasing all memory associated with it. This function is called by the host driver when a volume is no longer needed. It is also called by the core after a failed mount to clean up any allocated memory.
Note that all dnodes must have been released before calling this function.
Definition at line 107 of file fsw_core.c.
fsw_status_t fsw_volume_stat | ( | struct fsw_volume * | vol, |
struct fsw_volume_stat * | sb ) |
Get in-depth information on the volume. This function can be called by the host driver to get additional information on the volume.
Definition at line 125 of file fsw_core.c.