vfs, fatfs: Add file truncate for fatfs

This commit is contained in:
Renz Bagaporo
2018-06-12 18:29:05 +08:00
committed by Renz Christian Bagaporo
parent 0e501e5edd
commit ea711f2ee9
9 changed files with 214 additions and 2 deletions
+4
View File
@@ -174,6 +174,10 @@ typedef struct
int (*access_p)(void* ctx, const char *path, int amode);
int (*access)(const char *path, int amode);
};
union {
int (*truncate_p)(void* ctx, const char *path, off_t length);
int (*truncate)(const char *path, off_t length);
};
/** start_select is called for setting up synchronous I/O multiplexing of the desired file descriptors in the given VFS */
esp_err_t (*start_select)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, SemaphoreHandle_t *signal_sem);
/** socket select function for socket FDs with the functionality of POSIX select(); this should be set only for the socket VFS */
+14
View File
@@ -717,6 +717,20 @@ int access(const char *path, int amode)
return ret;
}
int truncate(const char *path, off_t length)
{
int ret;
const vfs_entry_t* vfs = get_vfs_for_path(path);
struct _reent* r = __getreent();
if (vfs == NULL) {
__errno_r(r) = ENOENT;
return -1;
}
const char* path_within_vfs = translate_path(vfs, path);
CHECK_AND_CALL(ret, r, vfs, truncate, path_within_vfs, length);
return ret;
}
static void call_end_selects(int end_index, const fds_triple_t *vfs_fds_triple)
{
for (int i = 0; i < end_index; ++i) {