/branches/dd/uspace/srv/fs/devfs/devfs.c |
---|
65,37 → 65,39 |
ipc_callid_t callid = async_get_call(&call); |
switch (IPC_GET_METHOD(call)) { |
case VFS_MOUNTED: |
case IPC_M_PHONE_HUNGUP: |
return; |
case VFS_OUT_MOUNTED: |
devfs_mounted(callid, &call); |
break; |
case VFS_MOUNT: |
case VFS_OUT_MOUNT: |
devfs_mount(callid, &call); |
break; |
case VFS_LOOKUP: |
case VFS_OUT_LOOKUP: |
devfs_lookup(callid, &call); |
break; |
case VFS_OPEN_NODE: |
case VFS_OUT_OPEN_NODE: |
devfs_open_node(callid, &call); |
break; |
case VFS_DEVICE: |
devfs_device(callid, &call); |
case VFS_OUT_STAT: |
devfs_stat(callid, &call); |
break; |
case VFS_READ: |
case VFS_OUT_READ: |
devfs_read(callid, &call); |
break; |
case VFS_WRITE: |
case VFS_OUT_WRITE: |
devfs_write(callid, &call); |
break; |
case VFS_TRUNCATE: |
case VFS_OUT_TRUNCATE: |
devfs_truncate(callid, &call); |
break; |
case VFS_CLOSE: |
case VFS_OUT_CLOSE: |
devfs_close(callid, &call); |
break; |
case VFS_SYNC: |
case VFS_OUT_SYNC: |
devfs_sync(callid, &call); |
break; |
case VFS_DESTROY: |
case VFS_OUT_DESTROY: |
devfs_destroy(callid, &call); |
break; |
default: |
/branches/dd/uspace/srv/fs/devfs/devfs_ops.c |
---|
41,7 → 41,9 |
#include <malloc.h> |
#include <string.h> |
#include <libfs.h> |
#include <fibril_sync.h> |
#include <adt/hash_table.h> |
#include <sys/stat.h> |
#include "devfs.h" |
#include "devfs_ops.h" |
58,6 → 60,9 |
/** Hash table of opened devices */ |
static hash_table_t devices; |
/** Hash table mutex */ |
static FIBRIL_MUTEX_INITIALIZE(devices_mutex); |
#define DEVICES_KEYS 1 |
#define DEVICES_KEY_HANDLE 0 |
#define DEVICES_BUCKETS 256 |
159,12 → 164,12 |
if (first >= last) { |
/* Root entry */ |
if (lflag & L_DIRECTORY) |
if (!(lflag & L_FILE)) |
ipc_answer_5(rid, EOK, devfs_reg.fs_handle, dev_handle, 0, 0, 0); |
else |
ipc_answer_0(rid, ENOENT); |
} else { |
if (lflag & L_FILE) { |
if (!(lflag & L_DIRECTORY)) { |
size_t len; |
if (last >= first) |
len = last - first + 1; |
195,10 → 200,12 |
[DEVICES_KEY_HANDLE] = (unsigned long) handle |
}; |
fibril_mutex_lock(&devices_mutex); |
link_t *lnk = hash_table_find(&devices, key); |
if (lnk == NULL) { |
int phone = devmap_device_connect(handle, 0); |
if (phone < 0) { |
fibril_mutex_unlock(&devices_mutex); |
free(name); |
ipc_answer_0(rid, ENOENT); |
return; |
206,6 → 213,7 |
device_t *dev = (device_t *) malloc(sizeof(device_t)); |
if (dev == NULL) { |
fibril_mutex_unlock(&devices_mutex); |
free(name); |
ipc_answer_0(rid, ENOMEM); |
return; |
220,6 → 228,7 |
device_t *dev = hash_table_get_instance(lnk, device_t, link); |
dev->refcount++; |
} |
fibril_mutex_unlock(&devices_mutex); |
} |
free(name); |
238,10 → 247,12 |
[DEVICES_KEY_HANDLE] = (unsigned long) handle |
}; |
fibril_mutex_lock(&devices_mutex); |
link_t *lnk = hash_table_find(&devices, key); |
if (lnk == NULL) { |
int phone = devmap_device_connect(handle, 0); |
if (phone < 0) { |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_0(rid, ENOENT); |
return; |
} |
248,6 → 259,7 |
device_t *dev = (device_t *) malloc(sizeof(device_t)); |
if (dev == NULL) { |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_0(rid, ENOMEM); |
return; |
} |
261,28 → 273,49 |
device_t *dev = hash_table_get_instance(lnk, device_t, link); |
dev->refcount++; |
} |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_3(rid, EOK, 0, 1, L_FILE); |
} |
void devfs_device(ipc_callid_t rid, ipc_call_t *request) |
void devfs_stat(ipc_callid_t rid, ipc_call_t *request) |
{ |
dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); |
fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); |
ipc_callid_t callid; |
size_t size; |
if (!ipc_data_read_receive(&callid, &size) || |
size != sizeof(struct stat)) { |
ipc_answer_0(callid, EINVAL); |
ipc_answer_0(rid, EINVAL); |
return; |
} |
struct stat stat; |
memset(&stat, 0, sizeof(struct stat)); |
stat.fs_handle = devfs_reg.fs_handle; |
stat.dev_handle = dev_handle; |
stat.index = index; |
stat.lnkcnt = 1; |
stat.is_file = (index != 0); |
stat.size = 0; |
if (index != 0) { |
unsigned long key[] = { |
[DEVICES_KEY_HANDLE] = (unsigned long) index |
}; |
fibril_mutex_lock(&devices_mutex); |
link_t *lnk = hash_table_find(&devices, key); |
if (lnk == NULL) { |
ipc_answer_0(rid, ENOENT); |
return; |
} |
ipc_answer_1(rid, EOK, (ipcarg_t) index); |
} else |
ipc_answer_0(rid, ENOTSUP); |
if (lnk != NULL) |
stat.devfs_stat.device = (dev_handle_t)index; |
fibril_mutex_unlock(&devices_mutex); |
} |
ipc_data_read_finalize(callid, &stat, sizeof(struct stat)); |
ipc_answer_0(rid, EOK); |
} |
void devfs_read(ipc_callid_t rid, ipc_call_t *request) |
295,8 → 328,10 |
[DEVICES_KEY_HANDLE] = (unsigned long) index |
}; |
fibril_mutex_lock(&devices_mutex); |
link_t *lnk = hash_table_find(&devices, key); |
if (lnk == NULL) { |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_0(rid, ENOENT); |
return; |
} |
305,6 → 340,7 |
ipc_callid_t callid; |
if (!ipc_data_read_receive(&callid, NULL)) { |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_0(callid, EINVAL); |
ipc_answer_0(rid, EINVAL); |
return; |
318,6 → 354,7 |
/* Forward the IPC_M_DATA_READ request to the driver */ |
ipc_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); |
fibril_mutex_unlock(&devices_mutex); |
/* Wait for reply from the driver. */ |
ipcarg_t rc; |
369,8 → 406,10 |
[DEVICES_KEY_HANDLE] = (unsigned long) index |
}; |
fibril_mutex_lock(&devices_mutex); |
link_t *lnk = hash_table_find(&devices, key); |
if (lnk == NULL) { |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_0(rid, ENOENT); |
return; |
} |
379,6 → 418,7 |
ipc_callid_t callid; |
if (!ipc_data_write_receive(&callid, NULL)) { |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_0(callid, EINVAL); |
ipc_answer_0(rid, EINVAL); |
return; |
393,6 → 433,8 |
/* Forward the IPC_M_DATA_WRITE request to the driver */ |
ipc_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); |
fibril_mutex_unlock(&devices_mutex); |
/* Wait for reply from the driver. */ |
ipcarg_t rc; |
async_wait_for(msg, &rc); |
420,8 → 462,10 |
[DEVICES_KEY_HANDLE] = (unsigned long) index |
}; |
fibril_mutex_lock(&devices_mutex); |
link_t *lnk = hash_table_find(&devices, key); |
if (lnk == NULL) { |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_0(rid, ENOENT); |
return; |
} |
434,6 → 478,8 |
hash_table_remove(&devices, key, DEVICES_KEYS); |
} |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_0(rid, EOK); |
} else |
ipc_answer_0(rid, ENOTSUP); |
448,8 → 494,10 |
[DEVICES_KEY_HANDLE] = (unsigned long) index |
}; |
fibril_mutex_lock(&devices_mutex); |
link_t *lnk = hash_table_find(&devices, key); |
if (lnk == NULL) { |
fibril_mutex_unlock(&devices_mutex); |
ipc_answer_0(rid, ENOENT); |
return; |
} |
461,6 → 509,8 |
aid_t msg = async_send_2(dev->phone, IPC_GET_METHOD(*request), |
IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), &answer); |
fibril_mutex_unlock(&devices_mutex); |
/* Wait for reply from the driver */ |
ipcarg_t rc; |
async_wait_for(msg, &rc); |
/branches/dd/uspace/srv/fs/devfs/devfs_ops.h |
---|
42,7 → 42,7 |
extern void devfs_mount(ipc_callid_t, ipc_call_t *); |
extern void devfs_lookup(ipc_callid_t, ipc_call_t *); |
extern void devfs_open_node(ipc_callid_t, ipc_call_t *); |
extern void devfs_device(ipc_callid_t, ipc_call_t *); |
extern void devfs_stat(ipc_callid_t, ipc_call_t *); |
extern void devfs_sync(ipc_callid_t, ipc_call_t *); |
extern void devfs_read(ipc_callid_t, ipc_call_t *); |
extern void devfs_write(ipc_callid_t, ipc_call_t *); |
/branches/dd/uspace/srv/fs/tmpfs/tmpfs.h |
---|
86,10 → 86,10 |
extern void tmpfs_read(ipc_callid_t, ipc_call_t *); |
extern void tmpfs_write(ipc_callid_t, ipc_call_t *); |
extern void tmpfs_truncate(ipc_callid_t, ipc_call_t *); |
extern void tmpfs_stat(ipc_callid_t, ipc_call_t *); |
extern void tmpfs_close(ipc_callid_t, ipc_call_t *); |
extern void tmpfs_destroy(ipc_callid_t, ipc_call_t *); |
extern void tmpfs_open_node(ipc_callid_t, ipc_call_t *); |
extern void tmpfs_device(ipc_callid_t, ipc_call_t *); |
extern void tmpfs_sync(ipc_callid_t, ipc_call_t *); |
extern bool tmpfs_restore(dev_handle_t); |
/branches/dd/uspace/srv/fs/tmpfs/tmpfs_dump.c |
---|
67,8 → 67,8 |
tmpfs_node_t *nodep; |
uint32_t size; |
if (block_read(dev, bufpos, buflen, pos, &entry, sizeof(entry), |
TMPFS_BLOCK_SIZE) != EOK) |
if (block_seqread(dev, bufpos, buflen, pos, &entry, |
sizeof(entry), TMPFS_BLOCK_SIZE) != EOK) |
return false; |
entry.len = uint32_t_le2host(entry.len); |
87,7 → 87,7 |
return false; |
} |
if (block_read(dev, bufpos, buflen, pos, fname, |
if (block_seqread(dev, bufpos, buflen, pos, fname, |
entry.len, TMPFS_BLOCK_SIZE) != EOK) { |
ops->destroy(fn); |
free(fname); |
103,7 → 103,7 |
} |
free(fname); |
if (block_read(dev, bufpos, buflen, pos, &size, |
if (block_seqread(dev, bufpos, buflen, pos, &size, |
sizeof(size), TMPFS_BLOCK_SIZE) != EOK) |
return false; |
115,7 → 115,7 |
return false; |
nodep->size = size; |
if (block_read(dev, bufpos, buflen, pos, nodep->data, |
if (block_seqread(dev, bufpos, buflen, pos, nodep->data, |
size, TMPFS_BLOCK_SIZE) != EOK) |
return false; |
131,7 → 131,7 |
return false; |
} |
if (block_read(dev, bufpos, buflen, pos, fname, |
if (block_seqread(dev, bufpos, buflen, pos, fname, |
entry.len, TMPFS_BLOCK_SIZE) != EOK) { |
ops->destroy(fn); |
free(fname); |
174,7 → 174,7 |
off_t pos = 0; |
char tag[6]; |
if (block_read(dev, &bufpos, &buflen, &pos, tag, 5, |
if (block_seqread(dev, &bufpos, &buflen, &pos, tag, 5, |
TMPFS_BLOCK_SIZE) != EOK) |
goto error; |
/branches/dd/uspace/srv/fs/tmpfs/tmpfs.c |
---|
96,37 → 96,39 |
callid = async_get_call(&call); |
switch (IPC_GET_METHOD(call)) { |
case VFS_MOUNTED: |
case IPC_M_PHONE_HUNGUP: |
return; |
case VFS_OUT_MOUNTED: |
tmpfs_mounted(callid, &call); |
break; |
case VFS_MOUNT: |
case VFS_OUT_MOUNT: |
tmpfs_mount(callid, &call); |
break; |
case VFS_LOOKUP: |
case VFS_OUT_LOOKUP: |
tmpfs_lookup(callid, &call); |
break; |
case VFS_READ: |
case VFS_OUT_READ: |
tmpfs_read(callid, &call); |
break; |
case VFS_WRITE: |
case VFS_OUT_WRITE: |
tmpfs_write(callid, &call); |
break; |
case VFS_TRUNCATE: |
case VFS_OUT_TRUNCATE: |
tmpfs_truncate(callid, &call); |
break; |
case VFS_CLOSE: |
case VFS_OUT_CLOSE: |
tmpfs_close(callid, &call); |
break; |
case VFS_DESTROY: |
case VFS_OUT_DESTROY: |
tmpfs_destroy(callid, &call); |
break; |
case VFS_OPEN_NODE: |
case VFS_OUT_OPEN_NODE: |
tmpfs_open_node(callid, &call); |
break; |
case VFS_DEVICE: |
tmpfs_device(callid, &call); |
case VFS_OUT_STAT: |
tmpfs_stat(callid, &call); |
break; |
case VFS_SYNC: |
case VFS_OUT_SYNC: |
tmpfs_sync(callid, &call); |
break; |
default: |
150,7 → 152,7 |
printf(NAME ": Unable to connect to VFS\n"); |
return -1; |
} |
int rc = fs_register(vfs_phone, &tmpfs_reg, &tmpfs_vfs_info, |
tmpfs_connection); |
if (rc != EOK) { |
/branches/dd/uspace/srv/fs/tmpfs/tmpfs_ops.c |
---|
628,9 → 628,9 |
libfs_open_node(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); |
} |
void tmpfs_device(ipc_callid_t rid, ipc_call_t *request) |
void tmpfs_stat(ipc_callid_t rid, ipc_call_t *request) |
{ |
ipc_answer_0(rid, ENOTSUP); |
libfs_stat(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); |
} |
void tmpfs_sync(ipc_callid_t rid, ipc_call_t *request) |
/branches/dd/uspace/srv/fs/fat/fat_idx.c |
---|
42,7 → 42,7 |
#include <adt/hash_table.h> |
#include <adt/list.h> |
#include <assert.h> |
#include <futex.h> |
#include <fibril_sync.h> |
/** Each instance of this type describes one interval of freed VFS indices. */ |
typedef struct { |
68,8 → 68,8 |
link_t freed_head; |
} unused_t; |
/** Futex protecting the list of unused structures. */ |
static futex_t unused_futex = FUTEX_INITIALIZER; |
/** Mutex protecting the list of unused structures. */ |
static FIBRIL_MUTEX_INITIALIZE(unused_lock); |
/** List of unused structures. */ |
static LIST_INITIALIZE(unused_head); |
89,7 → 89,7 |
link_t *l; |
if (lock) |
futex_down(&unused_futex); |
fibril_mutex_lock(&unused_lock); |
for (l = unused_head.next; l != &unused_head; l = l->next) { |
u = list_get_instance(l, unused_t, link); |
if (u->dev_handle == dev_handle) |
96,12 → 96,12 |
return u; |
} |
if (lock) |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
return NULL; |
} |
/** Futex protecting the up_hash and ui_hash. */ |
static futex_t used_futex = FUTEX_INITIALIZER; |
/** Mutex protecting the up_hash and ui_hash. */ |
static FIBRIL_MUTEX_INITIALIZE(used_lock); |
/** |
* Global hash table of all used fat_idx_t structures. |
231,7 → 231,7 |
*/ |
*index = u->next++; |
--u->remaining; |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
return true; |
} |
} else { |
244,7 → 244,7 |
list_remove(&f->link); |
free(f); |
} |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
return true; |
} |
/* |
252,7 → 252,7 |
* theoretically still possible (e.g. too many open unlinked nodes or |
* too many zero-sized nodes). |
*/ |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
return false; |
} |
302,7 → 302,7 |
if (lnk->prev != &u->freed_head) |
try_coalesce_intervals(lnk->prev, lnk, |
lnk); |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
return; |
} |
if (f->last == index - 1) { |
310,7 → 310,7 |
if (lnk->next != &u->freed_head) |
try_coalesce_intervals(lnk, lnk->next, |
lnk); |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
return; |
} |
if (index > f->first) { |
321,7 → 321,7 |
n->first = index; |
n->last = index; |
list_insert_before(&n->link, lnk); |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
return; |
} |
335,7 → 335,7 |
n->last = index; |
list_append(&n->link, &u->freed_head); |
} |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
} |
static fat_idx_t *fat_idx_create(dev_handle_t dev_handle) |
352,7 → 352,7 |
link_initialize(&fidx->uph_link); |
link_initialize(&fidx->uih_link); |
futex_initialize(&fidx->lock, 1); |
fibril_mutex_initialize(&fidx->lock); |
fidx->dev_handle = dev_handle; |
fidx->pfc = FAT_CLST_RES0; /* no parent yet */ |
fidx->pdi = 0; |
365,10 → 365,10 |
{ |
fat_idx_t *fidx; |
futex_down(&used_futex); |
fibril_mutex_lock(&used_lock); |
fidx = fat_idx_create(dev_handle); |
if (!fidx) { |
futex_up(&used_futex); |
fibril_mutex_unlock(&used_lock); |
return NULL; |
} |
378,8 → 378,8 |
}; |
hash_table_insert(&ui_hash, ikey, &fidx->uih_link); |
futex_down(&fidx->lock); |
futex_up(&used_futex); |
fibril_mutex_lock(&fidx->lock); |
fibril_mutex_unlock(&used_lock); |
return fidx; |
} |
395,7 → 395,7 |
[UPH_PDI_KEY] = pdi, |
}; |
futex_down(&used_futex); |
fibril_mutex_lock(&used_lock); |
l = hash_table_find(&up_hash, pkey); |
if (l) { |
fidx = hash_table_get_instance(l, fat_idx_t, uph_link); |
402,7 → 402,7 |
} else { |
fidx = fat_idx_create(dev_handle); |
if (!fidx) { |
futex_up(&used_futex); |
fibril_mutex_unlock(&used_lock); |
return NULL; |
} |
417,8 → 417,8 |
hash_table_insert(&up_hash, pkey, &fidx->uph_link); |
hash_table_insert(&ui_hash, ikey, &fidx->uih_link); |
} |
futex_down(&fidx->lock); |
futex_up(&used_futex); |
fibril_mutex_lock(&fidx->lock); |
fibril_mutex_unlock(&used_lock); |
return fidx; |
} |
431,9 → 431,9 |
[UPH_PDI_KEY] = idx->pdi, |
}; |
futex_down(&used_futex); |
fibril_mutex_lock(&used_lock); |
hash_table_insert(&up_hash, pkey, &idx->uph_link); |
futex_up(&used_futex); |
fibril_mutex_unlock(&used_lock); |
} |
void fat_idx_hashout(fat_idx_t *idx) |
444,9 → 444,9 |
[UPH_PDI_KEY] = idx->pdi, |
}; |
futex_down(&used_futex); |
fibril_mutex_lock(&used_lock); |
hash_table_remove(&up_hash, pkey, 3); |
futex_up(&used_futex); |
fibril_mutex_unlock(&used_lock); |
} |
fat_idx_t * |
459,13 → 459,13 |
[UIH_INDEX_KEY] = index, |
}; |
futex_down(&used_futex); |
fibril_mutex_lock(&used_lock); |
l = hash_table_find(&ui_hash, ikey); |
if (l) { |
fidx = hash_table_get_instance(l, fat_idx_t, uih_link); |
futex_down(&fidx->lock); |
fibril_mutex_lock(&fidx->lock); |
} |
futex_up(&used_futex); |
fibril_mutex_unlock(&used_lock); |
return fidx; |
} |
483,7 → 483,7 |
assert(idx->pfc == FAT_CLST_RES0); |
futex_down(&used_futex); |
fibril_mutex_lock(&used_lock); |
/* |
* Since we can only free unlinked nodes, the index structure is not |
* present in the position hash (uph). We therefore hash it out from |
490,7 → 490,7 |
* the index hash only. |
*/ |
hash_table_remove(&ui_hash, ikey, 2); |
futex_up(&used_futex); |
fibril_mutex_unlock(&used_lock); |
/* Release the VFS index. */ |
fat_index_free(idx->dev_handle, idx->index); |
/* Deallocate the structure. */ |
524,12 → 524,12 |
if (!u) |
return ENOMEM; |
unused_initialize(u, dev_handle); |
futex_down(&unused_futex); |
fibril_mutex_lock(&unused_lock); |
if (!unused_find(dev_handle, false)) |
list_append(&u->link, &unused_head); |
else |
rc = EEXIST; |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
return rc; |
} |
540,7 → 540,7 |
u = unused_find(dev_handle, true); |
assert(u); |
list_remove(&u->link); |
futex_up(&unused_futex); |
fibril_mutex_unlock(&unused_lock); |
while (!list_empty(&u->freed_head)) { |
freed_t *f; |
/branches/dd/uspace/srv/fs/fat/fat.h |
---|
35,6 → 35,7 |
#include "fat_fat.h" |
#include <ipc/ipc.h> |
#include <fibril_sync.h> |
#include <libfs.h> |
#include <atomic.h> |
#include <sys/types.h> |
160,7 → 161,7 |
/** Used indices (index) hash table link. */ |
link_t uih_link; |
futex_t lock; |
fibril_mutex_t lock; |
dev_handle_t dev_handle; |
fs_index_t index; |
/** |
181,7 → 182,7 |
/** Back pointer to the FS node. */ |
fs_node_t *bp; |
futex_t lock; |
fibril_mutex_t lock; |
fat_node_type_t type; |
fat_idx_t *idx; |
/** |
206,10 → 207,11 |
extern void fat_read(ipc_callid_t, ipc_call_t *); |
extern void fat_write(ipc_callid_t, ipc_call_t *); |
extern void fat_truncate(ipc_callid_t, ipc_call_t *); |
extern void fat_stat(ipc_callid_t, ipc_call_t *); |
extern void fat_close(ipc_callid_t, ipc_call_t *); |
extern void fat_destroy(ipc_callid_t, ipc_call_t *); |
extern void fat_open_node(ipc_callid_t, ipc_call_t *); |
extern void fat_device(ipc_callid_t, ipc_call_t *); |
extern void fat_stat(ipc_callid_t, ipc_call_t *); |
extern void fat_sync(ipc_callid_t, ipc_call_t *); |
extern fat_idx_t *fat_idx_get_new(dev_handle_t); |
/branches/dd/uspace/srv/fs/fat/fat_fat.c |
---|
45,15 → 45,15 |
#include <byteorder.h> |
#include <align.h> |
#include <assert.h> |
#include <futex.h> |
#include <fibril_sync.h> |
#include <mem.h> |
/** |
* The fat_alloc_lock futex protects all copies of the File Allocation Table |
* The fat_alloc_lock mutex protects all copies of the File Allocation Table |
* during allocation of clusters. The lock does not have to be held durring |
* deallocation of clusters. |
*/ |
static futex_t fat_alloc_lock = FUTEX_INITIALIZER; |
static FIBRIL_MUTEX_INITIALIZE(fat_alloc_lock); |
/** Walk the cluster chain. |
* |
326,7 → 326,7 |
/* |
* Search FAT1 for unused clusters. |
*/ |
futex_down(&fat_alloc_lock); |
fibril_mutex_lock(&fat_alloc_lock); |
for (b = 0, cl = 0; b < sf; b++) { |
blk = block_get(dev_handle, rscnt + b, BLOCK_FLAGS_NONE); |
for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) { |
350,7 → 350,7 |
*mcl = lifo[found - 1]; |
*lcl = lifo[0]; |
free(lifo); |
futex_up(&fat_alloc_lock); |
fibril_mutex_unlock(&fat_alloc_lock); |
return EOK; |
} |
} |
357,7 → 357,7 |
} |
block_put(blk); |
} |
futex_up(&fat_alloc_lock); |
fibril_mutex_unlock(&fat_alloc_lock); |
/* |
* We could not find enough clusters. Now we need to free the clusters |
/branches/dd/uspace/srv/fs/fat/fat.c |
---|
89,37 → 89,39 |
callid = async_get_call(&call); |
switch (IPC_GET_METHOD(call)) { |
case VFS_MOUNTED: |
case IPC_M_PHONE_HUNGUP: |
return; |
case VFS_OUT_MOUNTED: |
fat_mounted(callid, &call); |
break; |
case VFS_MOUNT: |
case VFS_OUT_MOUNT: |
fat_mount(callid, &call); |
break; |
case VFS_LOOKUP: |
case VFS_OUT_LOOKUP: |
fat_lookup(callid, &call); |
break; |
case VFS_READ: |
case VFS_OUT_READ: |
fat_read(callid, &call); |
break; |
case VFS_WRITE: |
case VFS_OUT_WRITE: |
fat_write(callid, &call); |
break; |
case VFS_TRUNCATE: |
case VFS_OUT_TRUNCATE: |
fat_truncate(callid, &call); |
break; |
case VFS_CLOSE: |
case VFS_OUT_STAT: |
fat_stat(callid, &call); |
break; |
case VFS_OUT_CLOSE: |
fat_close(callid, &call); |
break; |
case VFS_DESTROY: |
case VFS_OUT_DESTROY: |
fat_destroy(callid, &call); |
break; |
case VFS_OPEN_NODE: |
case VFS_OUT_OPEN_NODE: |
fat_open_node(callid, &call); |
break; |
case VFS_DEVICE: |
fat_device(callid, &call); |
break; |
case VFS_SYNC: |
case VFS_OUT_SYNC: |
fat_sync(callid, &call); |
break; |
default: |
/branches/dd/uspace/srv/fs/fat/fat_ops.c |
---|
51,7 → 51,7 |
#include <adt/hash_table.h> |
#include <adt/list.h> |
#include <assert.h> |
#include <futex.h> |
#include <fibril_sync.h> |
#include <sys/mman.h> |
#include <align.h> |
58,8 → 58,8 |
#define FAT_NODE(node) ((node) ? (fat_node_t *) (node)->data : NULL) |
#define FS_NODE(node) ((node) ? (node)->bp : NULL) |
/** Futex protecting the list of cached free FAT nodes. */ |
static futex_t ffn_futex = FUTEX_INITIALIZER; |
/** Mutex protecting the list of cached free FAT nodes. */ |
static FIBRIL_MUTEX_INITIALIZE(ffn_mutex); |
/** List of cached free FAT nodes. */ |
static LIST_INITIALIZE(ffn_head); |
66,7 → 66,7 |
static void fat_node_initialize(fat_node_t *node) |
{ |
futex_initialize(&node->lock, 1); |
fibril_mutex_initialize(&node->lock); |
node->bp = NULL; |
node->idx = NULL; |
node->type = 0; |
115,30 → 115,30 |
fs_node_t *fn; |
fat_node_t *nodep; |
futex_down(&ffn_futex); |
fibril_mutex_lock(&ffn_mutex); |
if (!list_empty(&ffn_head)) { |
/* Try to use a cached free node structure. */ |
fat_idx_t *idxp_tmp; |
nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link); |
if (futex_trydown(&nodep->lock) == ESYNCH_WOULD_BLOCK) |
if (!fibril_mutex_trylock(&nodep->lock)) |
goto skip_cache; |
idxp_tmp = nodep->idx; |
if (futex_trydown(&idxp_tmp->lock) == ESYNCH_WOULD_BLOCK) { |
futex_up(&nodep->lock); |
if (!fibril_mutex_trylock(&idxp_tmp->lock)) { |
fibril_mutex_unlock(&nodep->lock); |
goto skip_cache; |
} |
list_remove(&nodep->ffn_link); |
futex_up(&ffn_futex); |
fibril_mutex_unlock(&ffn_mutex); |
if (nodep->dirty) |
fat_node_sync(nodep); |
idxp_tmp->nodep = NULL; |
futex_up(&nodep->lock); |
futex_up(&idxp_tmp->lock); |
fibril_mutex_unlock(&nodep->lock); |
fibril_mutex_unlock(&idxp_tmp->lock); |
fn = FS_NODE(nodep); |
} else { |
skip_cache: |
/* Try to allocate a new node structure. */ |
futex_up(&ffn_futex); |
fibril_mutex_unlock(&ffn_mutex); |
fn = (fs_node_t *)malloc(sizeof(fs_node_t)); |
if (!fn) |
return NULL; |
175,10 → 175,10 |
* We are lucky. |
* The node is already instantiated in memory. |
*/ |
futex_down(&idxp->nodep->lock); |
fibril_mutex_lock(&idxp->nodep->lock); |
if (!idxp->nodep->refcnt++) |
list_remove(&idxp->nodep->ffn_link); |
futex_up(&idxp->nodep->lock); |
fibril_mutex_unlock(&idxp->nodep->lock); |
return idxp->nodep; |
} |
268,7 → 268,7 |
return NULL; |
/* idxp->lock held */ |
nodep = fat_node_get_core(idxp); |
futex_up(&idxp->lock); |
fibril_mutex_unlock(&idxp->lock); |
return FS_NODE(nodep); |
} |
277,12 → 277,12 |
fat_node_t *nodep = FAT_NODE(fn); |
bool destroy = false; |
futex_down(&nodep->lock); |
fibril_mutex_lock(&nodep->lock); |
if (!--nodep->refcnt) { |
if (nodep->idx) { |
futex_down(&ffn_futex); |
fibril_mutex_lock(&ffn_mutex); |
list_append(&nodep->ffn_link, &ffn_head); |
futex_up(&ffn_futex); |
fibril_mutex_unlock(&ffn_mutex); |
} else { |
/* |
* The node does not have any index structure associated |
293,7 → 293,7 |
destroy = true; |
} |
} |
futex_up(&nodep->lock); |
fibril_mutex_unlock(&nodep->lock); |
if (destroy) { |
free(nodep->bp); |
free(nodep); |
360,7 → 360,7 |
nodep->idx = idxp; |
idxp->nodep = nodep; |
futex_up(&idxp->lock); |
fibril_mutex_unlock(&idxp->lock); |
return FS_NODE(nodep); |
} |
409,16 → 409,16 |
fat_cluster_t mcl, lcl; |
int rc; |
futex_down(&childp->lock); |
fibril_mutex_lock(&childp->lock); |
if (childp->lnkcnt == 1) { |
/* |
* On FAT, we don't support multiple hard links. |
*/ |
futex_up(&childp->lock); |
fibril_mutex_unlock(&childp->lock); |
return EMLINK; |
} |
assert(childp->lnkcnt == 0); |
futex_up(&childp->lock); |
fibril_mutex_unlock(&childp->lock); |
if (!fat_dentry_name_verify(name)) { |
/* |
432,7 → 432,7 |
* a new one. |
*/ |
futex_down(&parentp->idx->lock); |
fibril_mutex_lock(&parentp->idx->lock); |
bs = block_bb_get(parentp->idx->dev_handle); |
bps = uint16_t_le2host(bs->bps); |
dps = bps / sizeof(fat_dentry_t); |
463,12 → 463,12 |
*/ |
if (parentp->idx->pfc == FAT_CLST_ROOT) { |
/* Can't grow the root directory. */ |
futex_up(&parentp->idx->lock); |
fibril_mutex_unlock(&parentp->idx->lock); |
return ENOSPC; |
} |
rc = fat_alloc_clusters(bs, parentp->idx->dev_handle, 1, &mcl, &lcl); |
if (rc != EOK) { |
futex_up(&parentp->idx->lock); |
fibril_mutex_unlock(&parentp->idx->lock); |
return rc; |
} |
fat_append_clusters(bs, parentp, mcl); |
491,9 → 491,9 |
fat_dentry_name_set(d, name); |
b->dirty = true; /* need to sync block */ |
block_put(b); |
futex_up(&parentp->idx->lock); |
fibril_mutex_unlock(&parentp->idx->lock); |
futex_down(&childp->idx->lock); |
fibril_mutex_lock(&childp->idx->lock); |
/* |
* If possible, create the Sub-directory Identifier Entry and the |
529,12 → 529,12 |
childp->idx->pfc = parentp->firstc; |
childp->idx->pdi = i * dps + j; |
futex_up(&childp->idx->lock); |
fibril_mutex_unlock(&childp->idx->lock); |
futex_down(&childp->lock); |
fibril_mutex_lock(&childp->lock); |
childp->lnkcnt = 1; |
childp->dirty = true; /* need to sync node */ |
futex_up(&childp->lock); |
fibril_mutex_unlock(&childp->lock); |
/* |
* Hash in the index structure into the position hash. |
559,10 → 559,10 |
if (fat_has_children(cfn)) |
return ENOTEMPTY; |
futex_down(&parentp->lock); |
futex_down(&childp->lock); |
fibril_mutex_lock(&parentp->lock); |
fibril_mutex_lock(&childp->lock); |
assert(childp->lnkcnt == 1); |
futex_down(&childp->idx->lock); |
fibril_mutex_lock(&childp->idx->lock); |
bs = block_bb_get(childp->idx->dev_handle); |
bps = uint16_t_le2host(bs->bps); |
581,11 → 581,11 |
/* clear position information */ |
childp->idx->pfc = FAT_CLST_RES0; |
childp->idx->pdi = 0; |
futex_up(&childp->idx->lock); |
fibril_mutex_unlock(&childp->idx->lock); |
childp->lnkcnt = 0; |
childp->dirty = true; |
futex_up(&childp->lock); |
futex_up(&parentp->lock); |
fibril_mutex_unlock(&childp->lock); |
fibril_mutex_unlock(&parentp->lock); |
return EOK; |
} |
602,7 → 602,7 |
fat_dentry_t *d; |
block_t *b; |
futex_down(&parentp->idx->lock); |
fibril_mutex_lock(&parentp->idx->lock); |
bs = block_bb_get(parentp->idx->dev_handle); |
bps = uint16_t_le2host(bs->bps); |
dps = bps / sizeof(fat_dentry_t); |
617,7 → 617,7 |
continue; |
case FAT_DENTRY_LAST: |
block_put(b); |
futex_up(&parentp->idx->lock); |
fibril_mutex_unlock(&parentp->idx->lock); |
return NULL; |
default: |
case FAT_DENTRY_VALID: |
636,7 → 636,7 |
fat_idx_t *idx = fat_idx_get_by_pos( |
parentp->idx->dev_handle, parentp->firstc, |
i * dps + j); |
futex_up(&parentp->idx->lock); |
fibril_mutex_unlock(&parentp->idx->lock); |
if (!idx) { |
/* |
* Can happen if memory is low or if we |
646,7 → 646,7 |
return NULL; |
} |
nodep = fat_node_get_core(idx); |
futex_up(&idx->lock); |
fibril_mutex_unlock(&idx->lock); |
block_put(b); |
return FS_NODE(nodep); |
} |
654,7 → 654,7 |
block_put(b); |
} |
futex_up(&parentp->idx->lock); |
fibril_mutex_unlock(&parentp->idx->lock); |
return NULL; |
} |
686,7 → 686,7 |
if (nodep->type != FAT_DIRECTORY) |
return false; |
futex_down(&nodep->idx->lock); |
fibril_mutex_lock(&nodep->idx->lock); |
bs = block_bb_get(nodep->idx->dev_handle); |
bps = uint16_t_le2host(bs->bps); |
dps = bps / sizeof(fat_dentry_t); |
705,22 → 705,22 |
continue; |
case FAT_DENTRY_LAST: |
block_put(b); |
futex_up(&nodep->idx->lock); |
fibril_mutex_unlock(&nodep->idx->lock); |
return false; |
default: |
case FAT_DENTRY_VALID: |
block_put(b); |
futex_up(&nodep->idx->lock); |
fibril_mutex_unlock(&nodep->idx->lock); |
return true; |
} |
block_put(b); |
futex_up(&nodep->idx->lock); |
fibril_mutex_unlock(&nodep->idx->lock); |
return true; |
} |
block_put(b); |
} |
futex_up(&nodep->idx->lock); |
fibril_mutex_unlock(&nodep->idx->lock); |
return false; |
} |
770,6 → 770,7 |
void fat_mounted(ipc_callid_t rid, ipc_call_t *request) |
{ |
dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); |
enum cache_mode cmode; |
fat_bs_t *bs; |
uint16_t bps; |
uint16_t rde; |
797,6 → 798,12 |
} |
opts[size] = '\0'; |
/* Check for option enabling write through. */ |
if (str_cmp(opts, "wtcache") == 0) |
cmode = CACHE_MODE_WT; |
else |
cmode = CACHE_MODE_WB; |
/* initialize libblock */ |
rc = block_init(dev_handle, BS_SIZE); |
if (rc != EOK) { |
826,7 → 833,7 |
} |
/* Initialize the block cache */ |
rc = block_cache_init(dev_handle, bps, 0 /* XXX */); |
rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode); |
if (rc != EOK) { |
block_fini(dev_handle); |
ipc_answer_0(rid, rc); |
881,7 → 888,7 |
rootp->bp = rfn; |
rfn->data = rootp; |
futex_up(&ridxp->lock); |
fibril_mutex_unlock(&ridxp->lock); |
ipc_answer_3(rid, EOK, ridxp->index, rootp->size, rootp->lnkcnt); |
} |
1195,9 → 1202,9 |
libfs_open_node(&fat_libfs_ops, fat_reg.fs_handle, rid, request); |
} |
void fat_device(ipc_callid_t rid, ipc_call_t *request) |
void fat_stat(ipc_callid_t rid, ipc_call_t *request) |
{ |
ipc_answer_0(rid, ENOTSUP); |
libfs_stat(&fat_libfs_ops, fat_reg.fs_handle, rid, request); |
} |
void fat_sync(ipc_callid_t rid, ipc_call_t *request) |