Loading...
Searching...
No Matches

Detailed Description

Files

file  vfs_util.h
 VFS helper functions.
 

Functions

int vfs_file_from_buffer (const char *file, const void *buf, size_t len)
 Writes the content of a buffer to a file If the file already exists, it will be overwritten.
 
int vfs_file_to_buffer (const char *file, void *buf, size_t len)
 Reads the content of a file to a buffer.
 
int vfs_file_md5 (const char *file, void *digest, void *work_buf, size_t work_buf_len)
 Compute the MD5 message digest of a file.
 
int vfs_file_sha1 (const char *file, void *digest, void *work_buf, size_t work_buf_len)
 Compute the SHA1 message digest of a file.
 
int vfs_file_sha256 (const char *file, void *digest, void *work_buf, size_t work_buf_len)
 Compute the SHA256 message digest of a file.
 
int vfs_is_dir (const char *path)
 Checks if path is a file or a directory.
 
bool vfs_file_exists (const char *path)
 Checks if path is a file and can be read.
 
int vfs_unlink_recursive (const char *root, char *path_buf, size_t max_size)
 Behaves like rm -r @p root.
 

Function Documentation

◆ vfs_file_exists()

bool vfs_file_exists ( const char *  path)

Checks if path is a file and can be read.

Parameters
[in]pathPath to check
Returns
true if the file exists, false otherwise

◆ vfs_file_from_buffer()

int vfs_file_from_buffer ( const char *  file,
const void *  buf,
size_t  len 
)

Writes the content of a buffer to a file If the file already exists, it will be overwritten.

Parameters
[in]fileDestination file path
[in]bufSource buffer
[in]lenBuffer size
Returns
0 on success
negative error from vfs_open, vfs_write

◆ vfs_file_md5()

int vfs_file_md5 ( const char *  file,
void *  digest,
void *  work_buf,
size_t  work_buf_len 
)

Compute the MD5 message digest of a file.

     Requires the `hashes` module.
Parameters
[in]fileSource file path
[out]digestDestination buffer, must fit MD5_DIGEST_LENGTH bytes
[out]work_bufWork buffer
[in]work_buf_lenSize of the work buffer
Returns
0 on success
negative error

◆ vfs_file_sha1()

int vfs_file_sha1 ( const char *  file,
void *  digest,
void *  work_buf,
size_t  work_buf_len 
)

Compute the SHA1 message digest of a file.

     Requires the `hashes` module.
Parameters
[in]fileSource file path
[out]digestDestination buffer, must fit SHA1_DIGEST_LENGTH bytes
[out]work_bufWork buffer
[in]work_buf_lenSize of the work buffer
Returns
0 on success
negative error

◆ vfs_file_sha256()

int vfs_file_sha256 ( const char *  file,
void *  digest,
void *  work_buf,
size_t  work_buf_len 
)

Compute the SHA256 message digest of a file.

     Requires the `hashes` module.
Parameters
[in]fileSource file path
[out]digestDestination buffer, must fit SHA256_DIGEST_LENGTH bytes
[out]work_bufWork buffer
[in]work_buf_lenSize of the work buffer
Returns
0 on success
negative error

◆ vfs_file_to_buffer()

int vfs_file_to_buffer ( const char *  file,
void *  buf,
size_t  len 
)

Reads the content of a file to a buffer.

Parameters
[in]fileSource file path
[out]bufDestination buffer
[in]lenBuffer size
Returns
number of bytes read on success
-ENOSPC if the file was read successfully but is larger than the provided buffer. Only the first len bytes were read.
negative error from vfs_open, vfs_read

◆ vfs_is_dir()

int vfs_is_dir ( const char *  path)

Checks if path is a file or a directory.

This function uses vfs_stat(), so if you need vfs_stat() anyway, you should not do double work and check it yourself.

Parameters
[in]pathPath to check
Returns
< 0 on FS error
0 if path is a file
> 0 if path is a directory

◆ vfs_unlink_recursive()

int vfs_unlink_recursive ( const char *  root,
char *  path_buf,
size_t  max_size 
)

Behaves like rm -r @p root.

Parameters
[in]rootFS root directory to be deleted
[in]path_bufBuffer that must be able to store the longest path of the file or directory being deleted
[in]max_sizeSize of path_buf
Returns
< 0 on error
0