38,8 → 38,8 |
#include <unistd.h> |
#include <dirent.h> |
#include <fcntl.h> |
#include <stdio.h> |
#include <sys/stat.h> |
#include <stdio.h> |
#include <sys/types.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
48,13 → 48,14 |
#include <futex.h> |
#include <errno.h> |
#include <string.h> |
#include <devmap.h> |
#include <ipc/vfs.h> |
#include <ipc/devmap.h> |
#include "../../../srv/vfs/vfs.h" |
|
int vfs_phone = -1; |
futex_t vfs_phone_futex = FUTEX_INITIALIZER; |
static int vfs_phone = -1; |
static futex_t vfs_phone_futex = FUTEX_INITIALIZER; |
static futex_t cwd_futex = FUTEX_INITIALIZER; |
|
futex_t cwd_futex = FUTEX_INITIALIZER; |
DIR *cwd_dir = NULL; |
char *cwd_path = NULL; |
size_t cwd_size = 0; |
115,47 → 116,8 |
vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); |
} |
|
static int device_get_handle(const char *name, dev_handle_t *handle, |
const unsigned int flags) |
{ |
int phone; |
|
if (flags & IPC_FLAG_BLOCKING) |
phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0); |
else |
phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0); |
|
if (phone < 0) |
return phone; |
|
ipc_call_t answer; |
aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0, |
&answer); |
|
ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1); |
|
if (retval != EOK) { |
async_wait_for(req, NULL); |
ipc_hangup(phone); |
return retval; |
} |
|
async_wait_for(req, &retval); |
|
if (handle != NULL) |
*handle = -1; |
|
if (retval == EOK) { |
if (handle != NULL) |
*handle = (dev_handle_t) IPC_GET_ARG1(answer); |
} |
|
ipc_hangup(phone); |
return retval; |
} |
|
int mount(const char *fs_name, const char *mp, const char *dev, |
const char *opts, const unsigned int flags) |
const char *opts, unsigned int flags) |
{ |
int res; |
ipcarg_t rc; |
162,7 → 124,7 |
aid_t req; |
dev_handle_t dev_handle; |
|
res = device_get_handle(dev, &dev_handle, flags); |
res = devmap_device_get_handle(dev, &dev_handle, flags); |
if (res != EOK) |
return res; |
|
175,7 → 137,7 |
async_serialize_start(); |
vfs_connect(); |
|
req = async_send_2(vfs_phone, VFS_MOUNT, dev_handle, flags, NULL); |
req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL); |
rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_size); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
236,7 → 198,7 |
async_serialize_start(); |
vfs_connect(); |
|
req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer); |
req = async_send_3(vfs_phone, VFS_IN_OPEN, lflag, oflag, 0, &answer); |
rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
249,9 → 211,10 |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
free(pa); |
|
|
if (rc != EOK) |
return (int) rc; |
|
return (int) IPC_GET_ARG1(answer); |
} |
|
260,6 → 223,27 |
return _open(path, L_FILE, oflag); |
} |
|
int open_node(fdi_node_t *node, int oflag) |
{ |
futex_down(&vfs_phone_futex); |
async_serialize_start(); |
vfs_connect(); |
|
ipc_call_t answer; |
aid_t req = async_send_4(vfs_phone, VFS_IN_OPEN_NODE, node->fs_handle, |
node->dev_handle, node->index, oflag, &answer); |
|
ipcarg_t rc; |
async_wait_for(req, &rc); |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
|
if (rc != EOK) |
return (int) rc; |
|
return (int) IPC_GET_ARG1(answer); |
} |
|
int close(int fildes) |
{ |
ipcarg_t rc; |
268,7 → 252,7 |
async_serialize_start(); |
vfs_connect(); |
|
rc = async_req_1_0(vfs_phone, VFS_CLOSE, fildes); |
rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes); |
|
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
286,7 → 270,7 |
async_serialize_start(); |
vfs_connect(); |
|
req = async_send_1(vfs_phone, VFS_READ, fildes, &answer); |
req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer); |
rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
313,7 → 297,7 |
async_serialize_start(); |
vfs_connect(); |
|
req = async_send_1(vfs_phone, VFS_WRITE, fildes, &answer); |
req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer); |
rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
330,6 → 314,20 |
return -1; |
} |
|
int fsync(int fildes) |
{ |
futex_down(&vfs_phone_futex); |
async_serialize_start(); |
vfs_connect(); |
|
ipcarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes); |
|
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
|
return (int) rc; |
} |
|
off_t lseek(int fildes, off_t offset, int whence) |
{ |
ipcarg_t rc; |
339,7 → 337,7 |
vfs_connect(); |
|
ipcarg_t newoffs; |
rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence, |
rc = async_req_3_1(vfs_phone, VFS_IN_SEEK, fildes, offset, whence, |
&newoffs); |
|
async_serialize_end(); |
359,12 → 357,74 |
async_serialize_start(); |
vfs_connect(); |
|
rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length); |
rc = async_req_2_0(vfs_phone, VFS_IN_TRUNCATE, fildes, length); |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
return (int) rc; |
} |
|
int fstat(int fildes, struct stat *stat) |
{ |
ipcarg_t rc; |
aid_t req; |
|
futex_down(&vfs_phone_futex); |
async_serialize_start(); |
vfs_connect(); |
|
req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL); |
rc = ipc_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat)); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
return (ssize_t) rc; |
} |
async_wait_for(req, &rc); |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
|
return rc; |
} |
|
int stat(const char *path, struct stat *stat) |
{ |
ipcarg_t rc; |
aid_t req; |
|
size_t pa_size; |
char *pa = absolutize(path, &pa_size); |
if (!pa) |
return ENOMEM; |
|
futex_down(&vfs_phone_futex); |
async_serialize_start(); |
vfs_connect(); |
|
req = async_send_0(vfs_phone, VFS_IN_STAT, NULL); |
rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
free(pa); |
return (int) rc; |
} |
rc = ipc_data_read_start(vfs_phone, stat, sizeof(struct stat)); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
free(pa); |
return (int) rc; |
} |
async_wait_for(req, &rc); |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
free(pa); |
return rc; |
} |
|
DIR *opendir(const char *dirname) |
{ |
DIR *dirp = malloc(sizeof(DIR)); |
412,7 → 472,7 |
async_serialize_start(); |
vfs_connect(); |
|
req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL); |
req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL); |
rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
425,7 → 485,7 |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
free(pa); |
return rc; |
return rc; |
} |
|
static int _unlink(const char *path, int lflag) |
442,7 → 502,7 |
async_serialize_start(); |
vfs_connect(); |
|
req = async_send_0(vfs_phone, VFS_UNLINK, NULL); |
req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL); |
rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
455,7 → 515,7 |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
free(pa); |
return rc; |
return rc; |
} |
|
int unlink(const char *path) |
489,7 → 549,7 |
async_serialize_start(); |
vfs_connect(); |
|
req = async_send_0(vfs_phone, VFS_RENAME, NULL); |
req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL); |
rc = ipc_data_write_start(vfs_phone, olda, olda_size); |
if (rc != EOK) { |
async_wait_for(req, NULL); |
558,5 → 618,34 |
return buf; |
} |
|
int fd_phone(int fildes) |
{ |
struct stat stat; |
int rc; |
|
rc = fstat(fildes, &stat); |
|
if (!stat.devfs_stat.device) |
return -1; |
|
return devmap_device_connect(stat.devfs_stat.device, 0); |
} |
|
int fd_node(int fildes, fdi_node_t *node) |
{ |
struct stat stat; |
int rc; |
|
rc = fstat(fildes, &stat); |
|
if (rc == EOK) { |
node->fs_handle = stat.fs_handle; |
node->dev_handle = stat.dev_handle; |
node->index = stat.index; |
} |
|
return rc; |
} |
|
/** @} |
*/ |