Implement VFS support for access()

Closes https://github.com/espressif/esp-idf/issues/1085
This commit is contained in:
Roland Dobai
2018-05-04 11:44:38 +02:00
parent adc3315677
commit 4345e198ce
5 changed files with 202 additions and 2 deletions

View File

@@ -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));
}