mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-25 01:37:22 +00:00
Implement VFS support for access()
Closes https://github.com/espressif/esp-idf/issues/1085
This commit is contained in:
@@ -267,6 +267,27 @@ static int uart_fcntl(int fd, int cmd, va_list args)
|
||||
return result;
|
||||
}
|
||||
|
||||
static int uart_access(const char *path, int amode)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (strcmp(path, "/0") == 0 || strcmp(path, "/1") == 0 || strcmp(path, "/2") == 0) {
|
||||
if (F_OK == amode) {
|
||||
ret = 0; //path exists
|
||||
} else {
|
||||
if ((((amode & R_OK) == R_OK) || ((amode & W_OK) == W_OK)) && ((amode & X_OK) != X_OK)) {
|
||||
ret = 0; //path is readable and/or writable but not executable
|
||||
} else {
|
||||
errno = EACCES;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errno = ENOENT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void esp_vfs_dev_uart_register()
|
||||
{
|
||||
esp_vfs_t vfs = {
|
||||
@@ -276,7 +297,8 @@ void esp_vfs_dev_uart_register()
|
||||
.fstat = &uart_fstat,
|
||||
.close = &uart_close,
|
||||
.read = &uart_read,
|
||||
.fcntl = &uart_fcntl
|
||||
.fcntl = &uart_fcntl,
|
||||
.access = &uart_access,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_vfs_register("/dev/uart", &vfs, NULL));
|
||||
}
|
||||
|
Reference in New Issue
Block a user