43,8 → 43,9 |
#include <stdlib.h> |
#include <string.h> |
#include <bool.h> |
#include <fibril_sync.h> |
#include <adt/list.h> |
#include <futex.h> |
#include <rwlock.h> |
#include <libadt/list.h> |
#include <unistd.h> |
#include <ctype.h> |
#include <fcntl.h> |
54,12 → 55,26 |
/* Forward declarations of static functions. */ |
static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, size_t); |
|
/** Pending mount structure. */ |
typedef struct { |
link_t link; |
char *fs_name; /**< File system name */ |
char *mp; /**< Mount point */ |
char *opts; /**< Mount options. */ |
ipc_callid_t callid; /**< Call ID waiting for the mount */ |
ipc_callid_t rid; /**< Request ID */ |
dev_handle_t dev_handle; /**< Device handle */ |
} pending_req_t; |
|
LIST_INITIALIZE(pending_req); |
|
/** |
* This rwlock prevents the race between a triplet-to-VFS-node resolution and a |
* concurrent VFS operation which modifies the file system namespace. |
*/ |
FIBRIL_RWLOCK_INITIALIZE(namespace_rwlock); |
RWLOCK_INITIALIZE(namespace_rwlock); |
|
futex_t rootfs_futex = FUTEX_INITIALIZER; |
vfs_pair_t rootfs = { |
.fs_handle = 0, |
.dev_handle = 0 |
69,12 → 84,7 |
fs_handle_t fs_handle, char *mp, char *opts) |
{ |
vfs_lookup_res_t mp_res; |
vfs_lookup_res_t mr_res; |
vfs_node_t *mp_node = NULL; |
vfs_node_t *mr_node; |
fs_index_t rindex; |
size_t rsize; |
unsigned rlnkcnt; |
ipcarg_t rc; |
int phone; |
aid_t msg; |
81,12 → 91,14 |
ipc_call_t answer; |
|
/* Resolve the path to the mountpoint. */ |
fibril_rwlock_write_lock(&namespace_rwlock); |
futex_down(&rootfs_futex); |
if (rootfs.fs_handle) { |
/* We already have the root FS. */ |
rwlock_write_lock(&namespace_rwlock); |
if (str_cmp(mp, "/") == 0) { |
/* Trying to mount root FS over root FS */ |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
futex_up(&rootfs_futex); |
ipc_answer_0(rid, EBUSY); |
return; |
} |
94,7 → 106,8 |
rc = vfs_lookup_internal(mp, L_DIRECTORY, &mp_res, NULL); |
if (rc != EOK) { |
/* The lookup failed for some reason. */ |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
futex_up(&rootfs_futex); |
ipc_answer_0(rid, rc); |
return; |
} |
101,7 → 114,8 |
|
mp_node = vfs_node_get(&mp_res); |
if (!mp_node) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
futex_up(&rootfs_futex); |
ipc_answer_0(rid, ENOMEM); |
return; |
} |
111,9 → 125,16 |
* It will be dropped upon the corresponding VFS_UNMOUNT. |
* This prevents the mount point from being deleted. |
*/ |
rwlock_write_unlock(&namespace_rwlock); |
} else { |
/* We still don't have the root file system mounted. */ |
if (str_cmp(mp, "/") == 0) { |
vfs_lookup_res_t mr_res; |
vfs_node_t *mr_node; |
fs_index_t rindex; |
size_t rsize; |
unsigned rlnkcnt; |
|
/* |
* For this simple, but important case, |
* we are almost done. |
129,7 → 150,7 |
if (rc != EOK) { |
async_wait_for(msg, NULL); |
vfs_release_phone(phone); |
fibril_rwlock_write_unlock(&namespace_rwlock); |
futex_up(&rootfs_futex); |
ipc_answer_0(rid, rc); |
return; |
} |
137,7 → 158,7 |
vfs_release_phone(phone); |
|
if (rc != EOK) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
futex_up(&rootfs_futex); |
ipc_answer_0(rid, rc); |
return; |
} |
155,12 → 176,12 |
|
rootfs.fs_handle = fs_handle; |
rootfs.dev_handle = dev_handle; |
futex_up(&rootfs_futex); |
|
/* Add reference to the mounted root. */ |
mr_node = vfs_node_get(&mr_res); |
assert(mr_node); |
|
fibril_rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, rc); |
return; |
} else { |
168,11 → 189,12 |
* We can't resolve this without the root filesystem |
* being mounted first. |
*/ |
fibril_rwlock_write_unlock(&namespace_rwlock); |
futex_up(&rootfs_futex); |
ipc_answer_0(rid, ENOENT); |
return; |
} |
} |
futex_up(&rootfs_futex); |
|
/* |
* At this point, we have all necessary pieces: file system and device |
179,9 → 201,6 |
* handles, and we know the mount point VFS node. |
*/ |
|
int mountee_phone = vfs_grab_phone(fs_handle); |
assert(mountee_phone >= 0); |
|
phone = vfs_grab_phone(mp_res.triplet.fs_handle); |
msg = async_send_4(phone, VFS_MOUNT, |
(ipcarg_t) mp_res.triplet.dev_handle, |
188,23 → 207,6 |
(ipcarg_t) mp_res.triplet.index, |
(ipcarg_t) fs_handle, |
(ipcarg_t) dev_handle, &answer); |
|
/* send connection */ |
rc = async_req_1_0(phone, IPC_M_CONNECTION_CLONE, mountee_phone); |
if (rc != EOK) { |
async_wait_for(msg, NULL); |
vfs_release_phone(mountee_phone); |
vfs_release_phone(phone); |
/* Mount failed, drop reference to mp_node. */ |
if (mp_node) |
vfs_node_put(mp_node); |
ipc_answer_0(rid, rc); |
fibril_rwlock_write_unlock(&namespace_rwlock); |
return; |
} |
|
vfs_release_phone(mountee_phone); |
|
/* send the mount options */ |
rc = ipc_data_write_start(phone, (void *)opts, str_size(opts)); |
if (rc != EOK) { |
213,7 → 215,6 |
/* Mount failed, drop reference to mp_node. */ |
if (mp_node) |
vfs_node_put(mp_node); |
fibril_rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, rc); |
return; |
} |
220,22 → 221,7 |
async_wait_for(msg, &rc); |
vfs_release_phone(phone); |
|
if (rc == EOK) { |
rindex = (fs_index_t) IPC_GET_ARG1(answer); |
rsize = (size_t) IPC_GET_ARG2(answer); |
rlnkcnt = (unsigned) IPC_GET_ARG3(answer); |
|
mr_res.triplet.fs_handle = fs_handle; |
mr_res.triplet.dev_handle = dev_handle; |
mr_res.triplet.index = rindex; |
mr_res.size = rsize; |
mr_res.lnkcnt = rlnkcnt; |
mr_res.type = VFS_NODE_DIRECTORY; |
|
/* Add reference to the mounted root. */ |
mr_node = vfs_node_get(&mr_res); |
assert(mr_node); |
} else { |
if (rc != EOK) { |
/* Mount failed, drop reference to mp_node. */ |
if (mp_node) |
vfs_node_put(mp_node); |
242,9 → 228,37 |
} |
|
ipc_answer_0(rid, rc); |
fibril_rwlock_write_unlock(&namespace_rwlock); |
} |
|
/** Process pending mount requests */ |
void vfs_process_pending_mount() |
{ |
link_t *cur; |
|
loop: |
for (cur = pending_req.next; cur != &pending_req; cur = cur->next) { |
pending_req_t *pr = list_get_instance(cur, pending_req_t, link); |
|
fs_handle_t fs_handle = fs_name_to_handle(pr->fs_name, true); |
if (!fs_handle) |
continue; |
|
/* Acknowledge that we know fs_name. */ |
ipc_answer_0(pr->callid, EOK); |
|
/* Do the mount */ |
vfs_mount_internal(pr->rid, pr->dev_handle, fs_handle, pr->mp, |
pr->opts); |
|
free(pr->fs_name); |
free(pr->mp); |
free(pr->opts); |
list_remove(cur); |
free(pr); |
goto loop; |
} |
} |
|
void vfs_mount(ipc_callid_t rid, ipc_call_t *request) |
{ |
/* |
398,17 → 412,33 |
* Check if we know a file system with the same name as is in fs_name. |
* This will also give us its file system handle. |
*/ |
fibril_mutex_lock(&fs_head_lock); |
fs_handle_t fs_handle; |
recheck: |
fs_handle = fs_name_to_handle(fs_name, false); |
fs_handle_t fs_handle = fs_name_to_handle(fs_name, true); |
if (!fs_handle) { |
if (flags & IPC_FLAG_BLOCKING) { |
fibril_condvar_wait(&fs_head_cv, &fs_head_lock); |
goto recheck; |
pending_req_t *pr; |
|
/* Blocking mount, add to pending list */ |
pr = (pending_req_t *) malloc(sizeof(pending_req_t)); |
if (!pr) { |
ipc_answer_0(callid, ENOMEM); |
ipc_answer_0(rid, ENOMEM); |
free(mp); |
free(fs_name); |
free(opts); |
return; |
} |
|
fibril_mutex_unlock(&fs_head_lock); |
pr->fs_name = fs_name; |
pr->mp = mp; |
pr->opts = opts; |
pr->callid = callid; |
pr->rid = rid; |
pr->dev_handle = dev_handle; |
link_initialize(&pr->link); |
list_append(&pr->link, &pending_req); |
return; |
} |
|
ipc_answer_0(callid, ENOENT); |
ipc_answer_0(rid, ENOENT); |
free(mp); |
416,7 → 446,6 |
free(opts); |
return; |
} |
fibril_mutex_unlock(&fs_head_lock); |
|
/* Acknowledge that we know fs_name. */ |
ipc_answer_0(callid, EOK); |
450,11 → 479,10 |
|
/* |
* Make sure that we are called with exactly one of L_FILE and |
* L_DIRECTORY. Make sure that the user does not pass L_OPEN. |
* L_DIRECTORY. |
*/ |
if (((lflag & (L_FILE | L_DIRECTORY)) == 0) || |
((lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) || |
((lflag & L_OPEN) != 0)) { |
if ((lflag & (L_FILE | L_DIRECTORY)) == 0 || |
(lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) { |
ipc_answer_0(rid, EINVAL); |
return; |
} |
465,12 → 493,12 |
lflag |= L_EXCLUSIVE; |
|
ipc_callid_t callid; |
|
if (!ipc_data_write_receive(&callid, &len)) { |
ipc_answer_0(callid, EINVAL); |
ipc_answer_0(rid, EINVAL); |
return; |
} |
|
char *path = malloc(len + 1); |
if (!path) { |
ipc_answer_0(callid, ENOMEM); |
477,7 → 505,6 |
ipc_answer_0(rid, ENOMEM); |
return; |
} |
|
int rc; |
if ((rc = ipc_data_write_finalize(callid, path, len))) { |
ipc_answer_0(rid, rc); |
492,18 → 519,18 |
* triplet. |
*/ |
if (lflag & L_CREATE) |
fibril_rwlock_write_lock(&namespace_rwlock); |
rwlock_write_lock(&namespace_rwlock); |
else |
fibril_rwlock_read_lock(&namespace_rwlock); |
rwlock_read_lock(&namespace_rwlock); |
|
/* The path is now populated and we can call vfs_lookup_internal(). */ |
vfs_lookup_res_t lr; |
rc = vfs_lookup_internal(path, lflag | L_OPEN, &lr, NULL); |
if (rc != EOK) { |
rc = vfs_lookup_internal(path, lflag, &lr, NULL); |
if (rc) { |
if (lflag & L_CREATE) |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
else |
fibril_rwlock_read_unlock(&namespace_rwlock); |
rwlock_read_unlock(&namespace_rwlock); |
ipc_answer_0(rid, rc); |
free(path); |
return; |
514,18 → 541,18 |
|
vfs_node_t *node = vfs_node_get(&lr); |
if (lflag & L_CREATE) |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
else |
fibril_rwlock_read_unlock(&namespace_rwlock); |
rwlock_read_unlock(&namespace_rwlock); |
|
/* Truncate the file if requested and if necessary. */ |
if (oflag & O_TRUNC) { |
fibril_rwlock_write_lock(&node->contents_rwlock); |
rwlock_write_lock(&node->contents_rwlock); |
if (node->size) { |
rc = vfs_truncate_internal(node->fs_handle, |
node->dev_handle, node->index, 0); |
if (rc) { |
fibril_rwlock_write_unlock(&node->contents_rwlock); |
rwlock_write_unlock(&node->contents_rwlock); |
vfs_node_put(node); |
ipc_answer_0(rid, rc); |
return; |
532,7 → 559,7 |
} |
node->size = 0; |
} |
fibril_rwlock_write_unlock(&node->contents_rwlock); |
rwlock_write_unlock(&node->contents_rwlock); |
} |
|
/* |
564,205 → 591,13 |
ipc_answer_1(rid, EOK, fd); |
} |
|
void vfs_open_node(ipc_callid_t rid, ipc_call_t *request) |
void vfs_close(ipc_callid_t rid, ipc_call_t *request) |
{ |
// FIXME: check for sanity of the supplied fs, dev and index |
|
if (!vfs_files_init()) { |
ipc_answer_0(rid, ENOMEM); |
return; |
} |
|
/* |
* The interface is open_node(fs, dev, index, oflag). |
*/ |
vfs_lookup_res_t lr; |
|
lr.triplet.fs_handle = IPC_GET_ARG1(*request); |
lr.triplet.dev_handle = IPC_GET_ARG2(*request); |
lr.triplet.index = IPC_GET_ARG3(*request); |
int oflag = IPC_GET_ARG4(*request); |
|
fibril_rwlock_read_lock(&namespace_rwlock); |
|
int rc = vfs_open_node_internal(&lr); |
if (rc != EOK) { |
fibril_rwlock_read_unlock(&namespace_rwlock); |
ipc_answer_0(rid, rc); |
return; |
} |
|
vfs_node_t *node = vfs_node_get(&lr); |
fibril_rwlock_read_unlock(&namespace_rwlock); |
|
/* Truncate the file if requested and if necessary. */ |
if (oflag & O_TRUNC) { |
fibril_rwlock_write_lock(&node->contents_rwlock); |
if (node->size) { |
rc = vfs_truncate_internal(node->fs_handle, |
node->dev_handle, node->index, 0); |
if (rc) { |
fibril_rwlock_write_unlock(&node->contents_rwlock); |
vfs_node_put(node); |
ipc_answer_0(rid, rc); |
return; |
} |
node->size = 0; |
} |
fibril_rwlock_write_unlock(&node->contents_rwlock); |
} |
|
/* |
* Get ourselves a file descriptor and the corresponding vfs_file_t |
* structure. |
*/ |
int fd = vfs_fd_alloc(); |
if (fd < 0) { |
vfs_node_put(node); |
ipc_answer_0(rid, fd); |
return; |
} |
vfs_file_t *file = vfs_file_get(fd); |
file->node = node; |
if (oflag & O_APPEND) |
file->append = true; |
|
/* |
* The following increase in reference count is for the fact that the |
* file is being opened and that a file structure is pointing to it. |
* It is necessary so that the file will not disappear when |
* vfs_node_put() is called. The reference will be dropped by the |
* respective VFS_CLOSE. |
*/ |
vfs_node_addref(node); |
vfs_node_put(node); |
|
/* Success! Return the new file descriptor to the client. */ |
ipc_answer_1(rid, EOK, fd); |
} |
|
void vfs_node(ipc_callid_t rid, ipc_call_t *request) |
{ |
int fd = IPC_GET_ARG1(*request); |
|
/* Lookup the file structure corresponding to the file descriptor. */ |
vfs_file_t *file = vfs_file_get(fd); |
if (!file) { |
ipc_answer_0(rid, ENOENT); |
return; |
} |
|
ipc_answer_3(rid, EOK, file->node->fs_handle, file->node->dev_handle, |
file->node->index); |
} |
|
void vfs_device(ipc_callid_t rid, ipc_call_t *request) |
{ |
int fd = IPC_GET_ARG1(*request); |
|
/* Lookup the file structure corresponding to the file descriptor. */ |
vfs_file_t *file = vfs_file_get(fd); |
if (!file) { |
ipc_answer_0(rid, ENOENT); |
return; |
} |
|
/* |
* Lock the open file structure so that no other thread can manipulate |
* the same open file at a time. |
*/ |
fibril_mutex_lock(&file->lock); |
int fs_phone = vfs_grab_phone(file->node->fs_handle); |
|
/* Make a VFS_DEVICE request at the destination FS server. */ |
aid_t msg; |
ipc_call_t answer; |
msg = async_send_2(fs_phone, IPC_GET_METHOD(*request), |
file->node->dev_handle, file->node->index, &answer); |
|
/* Wait for reply from the FS server. */ |
ipcarg_t rc; |
async_wait_for(msg, &rc); |
|
vfs_release_phone(fs_phone); |
fibril_mutex_unlock(&file->lock); |
|
ipc_answer_1(rid, EOK, IPC_GET_ARG1(answer)); |
} |
|
void vfs_sync(ipc_callid_t rid, ipc_call_t *request) |
{ |
int fd = IPC_GET_ARG1(*request); |
|
/* Lookup the file structure corresponding to the file descriptor. */ |
vfs_file_t *file = vfs_file_get(fd); |
if (!file) { |
ipc_answer_0(rid, ENOENT); |
return; |
} |
|
/* |
* Lock the open file structure so that no other thread can manipulate |
* the same open file at a time. |
*/ |
fibril_mutex_lock(&file->lock); |
int fs_phone = vfs_grab_phone(file->node->fs_handle); |
|
/* Make a VFS_SYMC request at the destination FS server. */ |
aid_t msg; |
ipc_call_t answer; |
msg = async_send_2(fs_phone, IPC_GET_METHOD(*request), |
file->node->dev_handle, file->node->index, &answer); |
|
/* Wait for reply from the FS server. */ |
ipcarg_t rc; |
async_wait_for(msg, &rc); |
|
vfs_release_phone(fs_phone); |
fibril_mutex_unlock(&file->lock); |
|
int rc = vfs_fd_free(fd); |
ipc_answer_0(rid, rc); |
} |
|
void vfs_close(ipc_callid_t rid, ipc_call_t *request) |
{ |
int fd = IPC_GET_ARG1(*request); |
|
/* Lookup the file structure corresponding to the file descriptor. */ |
vfs_file_t *file = vfs_file_get(fd); |
if (!file) { |
ipc_answer_0(rid, ENOENT); |
return; |
} |
|
/* |
* Lock the open file structure so that no other thread can manipulate |
* the same open file at a time. |
*/ |
fibril_mutex_lock(&file->lock); |
int fs_phone = vfs_grab_phone(file->node->fs_handle); |
|
/* Make a VFS_CLOSE request at the destination FS server. */ |
aid_t msg; |
ipc_call_t answer; |
msg = async_send_2(fs_phone, IPC_GET_METHOD(*request), |
file->node->dev_handle, file->node->index, &answer); |
|
/* Wait for reply from the FS server. */ |
ipcarg_t rc; |
async_wait_for(msg, &rc); |
|
vfs_release_phone(fs_phone); |
fibril_mutex_unlock(&file->lock); |
|
int retval = IPC_GET_ARG1(answer); |
if (retval != EOK) |
ipc_answer_0(rid, retval); |
|
retval = vfs_fd_free(fd); |
ipc_answer_0(rid, retval); |
} |
|
static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read) |
{ |
|
805,7 → 640,7 |
* Lock the open file structure so that no other thread can manipulate |
* the same open file at a time. |
*/ |
fibril_mutex_lock(&file->lock); |
futex_down(&file->lock); |
|
/* |
* Lock the file's node so that no other client can read/write to it at |
812,9 → 647,9 |
* the same time. |
*/ |
if (read) |
fibril_rwlock_read_lock(&file->node->contents_rwlock); |
rwlock_read_lock(&file->node->contents_rwlock); |
else |
fibril_rwlock_write_lock(&file->node->contents_rwlock); |
rwlock_write_lock(&file->node->contents_rwlock); |
|
if (file->node->type == VFS_NODE_DIRECTORY) { |
/* |
822,7 → 657,7 |
* while we are in readdir(). |
*/ |
assert(read); |
fibril_rwlock_read_lock(&namespace_rwlock); |
rwlock_read_lock(&namespace_rwlock); |
} |
|
int fs_phone = vfs_grab_phone(file->node->fs_handle); |
843,31 → 678,30 |
*/ |
ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); |
|
vfs_release_phone(fs_phone); |
|
/* Wait for reply from the FS server. */ |
ipcarg_t rc; |
async_wait_for(msg, &rc); |
|
vfs_release_phone(fs_phone); |
|
size_t bytes = IPC_GET_ARG1(answer); |
|
if (file->node->type == VFS_NODE_DIRECTORY) |
fibril_rwlock_read_unlock(&namespace_rwlock); |
rwlock_read_unlock(&namespace_rwlock); |
|
/* Unlock the VFS node. */ |
if (read) |
fibril_rwlock_read_unlock(&file->node->contents_rwlock); |
rwlock_read_unlock(&file->node->contents_rwlock); |
else { |
/* Update the cached version of node's size. */ |
if (rc == EOK) |
file->node->size = IPC_GET_ARG2(answer); |
fibril_rwlock_write_unlock(&file->node->contents_rwlock); |
rwlock_write_unlock(&file->node->contents_rwlock); |
} |
|
/* Update the position pointer and unlock the open file. */ |
if (rc == EOK) |
file->pos += bytes; |
fibril_mutex_unlock(&file->lock); |
futex_up(&file->lock); |
|
/* |
* FS server's reply is the final result of the whole operation we |
901,40 → 735,40 |
} |
|
off_t newpos; |
fibril_mutex_lock(&file->lock); |
futex_down(&file->lock); |
if (whence == SEEK_SET) { |
file->pos = off; |
fibril_mutex_unlock(&file->lock); |
futex_up(&file->lock); |
ipc_answer_1(rid, EOK, off); |
return; |
} |
if (whence == SEEK_CUR) { |
if (file->pos + off < file->pos) { |
fibril_mutex_unlock(&file->lock); |
futex_up(&file->lock); |
ipc_answer_0(rid, EOVERFLOW); |
return; |
} |
file->pos += off; |
newpos = file->pos; |
fibril_mutex_unlock(&file->lock); |
futex_up(&file->lock); |
ipc_answer_1(rid, EOK, newpos); |
return; |
} |
if (whence == SEEK_END) { |
fibril_rwlock_read_lock(&file->node->contents_rwlock); |
rwlock_read_lock(&file->node->contents_rwlock); |
size_t size = file->node->size; |
fibril_rwlock_read_unlock(&file->node->contents_rwlock); |
rwlock_read_unlock(&file->node->contents_rwlock); |
if (size + off < size) { |
fibril_mutex_unlock(&file->lock); |
futex_up(&file->lock); |
ipc_answer_0(rid, EOVERFLOW); |
return; |
} |
newpos = size + off; |
fibril_mutex_unlock(&file->lock); |
futex_up(&file->lock); |
ipc_answer_1(rid, EOK, newpos); |
return; |
} |
fibril_mutex_unlock(&file->lock); |
futex_up(&file->lock); |
ipc_answer_0(rid, EINVAL); |
} |
|
963,16 → 797,16 |
ipc_answer_0(rid, ENOENT); |
return; |
} |
fibril_mutex_lock(&file->lock); |
futex_down(&file->lock); |
|
fibril_rwlock_write_lock(&file->node->contents_rwlock); |
rwlock_write_lock(&file->node->contents_rwlock); |
rc = vfs_truncate_internal(file->node->fs_handle, |
file->node->dev_handle, file->node->index, size); |
if (rc == EOK) |
file->node->size = size; |
fibril_rwlock_write_unlock(&file->node->contents_rwlock); |
rwlock_write_unlock(&file->node->contents_rwlock); |
|
fibril_mutex_unlock(&file->lock); |
futex_up(&file->lock); |
ipc_answer_0(rid, (ipcarg_t)rc); |
} |
|
1002,10 → 836,10 |
} |
path[len] = '\0'; |
|
fibril_rwlock_write_lock(&namespace_rwlock); |
rwlock_write_lock(&namespace_rwlock); |
int lflag = L_DIRECTORY | L_CREATE | L_EXCLUSIVE; |
rc = vfs_lookup_internal(path, lflag, NULL, NULL); |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
free(path); |
ipc_answer_0(rid, rc); |
} |
1036,13 → 870,13 |
} |
path[len] = '\0'; |
|
fibril_rwlock_write_lock(&namespace_rwlock); |
rwlock_write_lock(&namespace_rwlock); |
lflag &= L_DIRECTORY; /* sanitize lflag */ |
vfs_lookup_res_t lr; |
rc = vfs_lookup_internal(path, lflag | L_UNLINK, &lr, NULL); |
free(path); |
if (rc != EOK) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, rc); |
return; |
} |
1053,10 → 887,10 |
* VFS_DESTROY'ed after the last reference to it is dropped. |
*/ |
vfs_node_t *node = vfs_node_get(&lr); |
fibril_mutex_lock(&nodes_mutex); |
futex_down(&nodes_futex); |
node->lnkcnt--; |
fibril_mutex_unlock(&nodes_mutex); |
fibril_rwlock_write_unlock(&namespace_rwlock); |
futex_up(&nodes_futex); |
rwlock_write_unlock(&namespace_rwlock); |
vfs_node_put(node); |
ipc_answer_0(rid, EOK); |
} |
1118,16 → 952,8 |
} |
oldc[olen] = '\0'; |
newc[nlen] = '\0'; |
if ((!str_lcmp(newc, oldc, str_length(oldc))) && |
((newc[str_length(oldc)] == '/') || |
(str_length(oldc) == 1) || |
(str_length(oldc) == str_length(newc)))) { |
/* |
* oldc is a prefix of newc and either |
* - newc continues with a / where oldc ends, or |
* - oldc was / itself, or |
* - oldc and newc are equal. |
*/ |
if (!str_lcmp(newc, oldc, str_length(oldc))) { |
/* oldc is a prefix of newc */ |
ipc_answer_0(rid, EINVAL); |
free(old); |
free(new); |
1137,11 → 963,11 |
vfs_lookup_res_t old_lr; |
vfs_lookup_res_t new_lr; |
vfs_lookup_res_t new_par_lr; |
fibril_rwlock_write_lock(&namespace_rwlock); |
rwlock_write_lock(&namespace_rwlock); |
/* Lookup the node belonging to the old file name. */ |
rc = vfs_lookup_internal(oldc, L_NONE, &old_lr, NULL); |
if (rc != EOK) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, rc); |
free(old); |
free(new); |
1149,31 → 975,16 |
} |
vfs_node_t *old_node = vfs_node_get(&old_lr); |
if (!old_node) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, ENOMEM); |
free(old); |
free(new); |
return; |
} |
/* Determine the path to the parent of the node with the new name. */ |
char *parentc = str_dup(newc); |
if (!parentc) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, rc); |
free(old); |
free(new); |
return; |
} |
char *lastsl = str_rchr(parentc + 1, '/'); |
if (lastsl) |
*lastsl = '\0'; |
else |
parentc[1] = '\0'; |
/* Lookup parent of the new file name. */ |
rc = vfs_lookup_internal(parentc, L_NONE, &new_par_lr, NULL); |
free(parentc); /* not needed anymore */ |
rc = vfs_lookup_internal(newc, L_PARENT, &new_par_lr, NULL); |
if (rc != EOK) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, rc); |
free(old); |
free(new); |
1182,7 → 993,7 |
/* Check whether linking to the same file system instance. */ |
if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) || |
(old_node->dev_handle != new_par_lr.triplet.dev_handle)) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, EXDEV); /* different file systems */ |
free(old); |
free(new); |
1198,18 → 1009,18 |
case EOK: |
new_node = vfs_node_get(&new_lr); |
if (!new_node) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, ENOMEM); |
free(old); |
free(new); |
return; |
} |
fibril_mutex_lock(&nodes_mutex); |
futex_down(&nodes_futex); |
new_node->lnkcnt--; |
fibril_mutex_unlock(&nodes_mutex); |
futex_up(&nodes_futex); |
break; |
default: |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
ipc_answer_0(rid, ENOTEMPTY); |
free(old); |
free(new); |
1218,7 → 1029,7 |
/* Create the new link for the new name. */ |
rc = vfs_lookup_internal(newc, L_LINK, NULL, NULL, old_node->index); |
if (rc != EOK) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
if (new_node) |
vfs_node_put(new_node); |
ipc_answer_0(rid, rc); |
1226,13 → 1037,13 |
free(new); |
return; |
} |
fibril_mutex_lock(&nodes_mutex); |
futex_down(&nodes_futex); |
old_node->lnkcnt++; |
fibril_mutex_unlock(&nodes_mutex); |
futex_up(&nodes_futex); |
/* Destroy the link for the old name. */ |
rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL); |
if (rc != EOK) { |
fibril_rwlock_write_unlock(&namespace_rwlock); |
rwlock_write_unlock(&namespace_rwlock); |
vfs_node_put(old_node); |
if (new_node) |
vfs_node_put(new_node); |
1241,10 → 1052,10 |
free(new); |
return; |
} |
fibril_mutex_lock(&nodes_mutex); |
futex_down(&nodes_futex); |
old_node->lnkcnt--; |
fibril_mutex_unlock(&nodes_mutex); |
fibril_rwlock_write_unlock(&namespace_rwlock); |
futex_up(&nodes_futex); |
rwlock_write_unlock(&namespace_rwlock); |
vfs_node_put(old_node); |
if (new_node) |
vfs_node_put(new_node); |