Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4438 → Rev 4439

/branches/dd/uspace/srv/vfs/vfs_ops.c
74,7 → 74,6
*/
RWLOCK_INITIALIZE(namespace_rwlock);
 
futex_t rootfs_futex = FUTEX_INITIALIZER;
vfs_pair_t rootfs = {
.fs_handle = 0,
.dev_handle = 0
95,17 → 94,14
aid_t msg;
ipc_call_t answer;
 
/* Resolve the path to the mountpoint. */
futex_down(&rootfs_futex);
rwlock_write_lock(&namespace_rwlock);
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 */
ipc_answer_0(rid, EBUSY);
rwlock_write_unlock(&namespace_rwlock);
futex_up(&rootfs_futex);
ipc_answer_0(rid, EBUSY);
return;
}
112,17 → 108,15
rc = vfs_lookup_internal(mp, L_DIRECTORY, &mp_res, NULL);
if (rc != EOK) {
/* The lookup failed for some reason. */
ipc_answer_0(rid, rc);
rwlock_write_unlock(&namespace_rwlock);
futex_up(&rootfs_futex);
ipc_answer_0(rid, rc);
return;
}
mp_node = vfs_node_get(&mp_res);
if (!mp_node) {
ipc_answer_0(rid, ENOMEM);
rwlock_write_unlock(&namespace_rwlock);
futex_up(&rootfs_futex);
ipc_answer_0(rid, ENOMEM);
return;
}
131,7 → 125,6
* 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) {
150,8 → 143,8
if (rc != EOK) {
async_wait_for(msg, NULL);
vfs_release_phone(phone);
futex_up(&rootfs_futex);
ipc_answer_0(rid, rc);
rwlock_write_unlock(&namespace_rwlock);
return;
}
async_wait_for(msg, &rc);
158,8 → 151,8
vfs_release_phone(phone);
if (rc != EOK) {
futex_up(&rootfs_futex);
ipc_answer_0(rid, rc);
rwlock_write_unlock(&namespace_rwlock);
return;
}
 
176,7 → 169,6
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);
183,6 → 175,7
assert(mr_node);
ipc_answer_0(rid, rc);
rwlock_write_unlock(&namespace_rwlock);
return;
} else {
/*
189,12 → 182,11
* We can't resolve this without the root filesystem
* being mounted first.
*/
futex_up(&rootfs_futex);
ipc_answer_0(rid, ENOENT);
rwlock_write_unlock(&namespace_rwlock);
return;
}
}
futex_up(&rootfs_futex);
/*
* At this point, we have all necessary pieces: file system and device
221,6 → 213,7
if (mp_node)
vfs_node_put(mp_node);
ipc_answer_0(rid, rc);
rwlock_write_unlock(&namespace_rwlock);
return;
}
233,37 → 226,39
if (mp_node)
vfs_node_put(mp_node);
ipc_answer_0(rid, rc);
rwlock_write_unlock(&namespace_rwlock);
return;
}
async_wait_for(msg, &rc);
vfs_release_phone(phone);
if (rc != EOK) {
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 {
/* Mount failed, drop reference to mp_node. */
if (mp_node)
vfs_node_put(mp_node);
}
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);
 
ipc_answer_0(rid, rc);
rwlock_write_unlock(&namespace_rwlock);
}
 
/** Process pending mount requests */
void vfs_process_pending_mount()
void vfs_process_pending_mount(void)
{
link_t *cur;
1030,7 → 1025,7
free(new);
return;
}
char *lastsl = str_rchr(parentc + 1, L'/');
char *lastsl = str_rchr(parentc + 1, '/');
if (lastsl)
*lastsl = '\0';
else
/branches/dd/uspace/srv/vfs/vfs_file.c
78,19 → 78,23
*/
int vfs_fd_alloc(void)
{
int i;
 
if (!vfs_files_init())
return ENOMEM;
unsigned int i;
for (i = 0; i < MAX_OPEN_FILES; i++) {
if (!files[i]) {
files[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t));
if (!files[i])
return ENOMEM;
memset(files[i], 0, sizeof(vfs_file_t));
futex_initialize(&files[i]->lock, 1);
vfs_file_addref(files[i]);
return i;
return (int) i;
}
}
return EMFILE;
}
 
103,10 → 107,15
*/
int vfs_fd_free(int fd)
{
if (!vfs_files_init())
return ENOMEM;
if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (files[fd] == NULL))
return EBADF;
vfs_file_delref(files[fd]);
files[fd] = NULL;
return EOK;
}
 
150,11 → 159,15
*/
vfs_file_t *vfs_file_get(int fd)
{
if (!vfs_files_init())
return NULL;
if ((fd >= 0) && (fd < MAX_OPEN_FILES))
return files[fd];
return NULL;
}
 
/**
* @}
*/
*/