Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3107 → Rev 3150

/branches/dynload/uspace/srv/kbd/generic/kbd.c
50,7 → 50,7
#include <async.h>
#include <keys.h>
 
#define NAME "KBD"
#define NAME "kbd"
 
int cons_connected = 0;
int phone2cons = -1;
121,6 → 121,8
 
int main(int argc, char **argv)
{
printf(NAME ": HelenOS Keyboard service\n");
ipcarg_t phonead;
/* Initialize arch dependent parts */
135,7 → 137,8
/* Register service at nameserver */
if (ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, 0, &phonead) != 0)
return -1;
 
printf(NAME ": Accepting connections\n");
async_manager();
 
/* Never reached */
145,4 → 148,3
/**
* @}
*/
 
/branches/dynload/uspace/srv/kbd/Makefile
72,11 → 72,9
genarch/src/kbd.c
endif
ifeq ($(ARCH), arm32)
ifeq ($(MACHINE), gxemul_testarm)
ARCH_SOURCES += \
arch/$(ARCH)/src/kbd_gxemul.c
endif
endif
 
 
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
100,7 → 98,7
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
 
$(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(GENARCH_OBJECTS) $(LIBS)
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
 
disasm:
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
/branches/dynload/uspace/srv/ns/ns.c
50,7 → 50,7
#include <ddi.h>
#include <as.h>
 
#define NAME "NS"
#define NAME "ns"
 
#define NS_HASH_TABLE_CHAINS 20
 
104,6 → 104,8
 
int main(int argc, char **argv)
{
printf(NAME ": HelenOS IPC Naming Service\n");
ipc_call_t call;
ipc_callid_t callid;
111,9 → 113,11
 
if (!hash_table_create(&ns_hash_table, NS_HASH_TABLE_CHAINS, 3,
&ns_hash_table_ops)) {
printf(NAME ": No memory available\n");
return ENOMEM;
}
printf(NAME ": Accepting connections\n");
while (1) {
callid = ipc_wait_for_call(&call);
switch (IPC_GET_METHOD(call)) {
156,6 → 160,9
ipc_answer_0(callid, retval);
}
}
/* Not reached */
return 0;
}
 
/** Register service.
/branches/dynload/uspace/srv/ns/Makefile
57,7 → 57,7
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
 
$(OUTPUT): $(OBJECTS) $(LIBS)
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
 
disasm:
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
/branches/dynload/uspace/srv/console/console.c
46,12 → 46,13
#include <libadt/fifo.h>
#include <screenbuffer.h>
#include <sys/mman.h>
#include <stdio.h>
 
#include "gcons.h"
 
#define MAX_KEYREQUESTS_BUFFERED 32
 
#define NAME "CONSOLE"
#define NAME "console"
 
/** Index of currently used virtual console.
*/
474,6 → 475,8
 
int main(int argc, char *argv[])
{
printf(NAME ": HelenOS Console service\n");
ipcarg_t phonehash;
int kbd_phone;
int i;
550,10 → 553,11
connections[active_console].screenbuffer.is_cursor_visible);
 
/* Register at NS */
if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0)
return -1;
}
// FIXME: avoid connectiong to itself, keep using klog
// printf(NAME ": Accepting connections\n");
async_manager();
 
return 0;
/branches/dynload/uspace/srv/console/Makefile
70,7 → 70,7
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
 
$(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS)
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
 
disasm:
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
/branches/dynload/uspace/srv/rd/rd.c
51,8 → 51,12
#include <align.h>
#include <async.h>
#include <futex.h>
#include <stdio.h>
#include <ipc/devmap.h>
#include "rd.h"
 
#define NAME "rd"
 
/** Pointer to the ramdisk's image. */
static void *rd_addr;
/** Size of the ramdisk. */
104,7 → 108,8
* Now we wait for the client to send us its communication as_area.
*/
size_t size;
if (ipc_share_out_receive(&callid, &size, NULL)) {
int flags;
if (ipc_share_out_receive(&callid, &size, &flags)) {
if (size >= BLOCK_SIZE) {
/*
* The client sends an as_area that can absorb the whole
149,7 → 154,7
break;
}
futex_down(&rd_futex);
memcpy(fs_va, rd_addr + offset, BLOCK_SIZE);
memcpy(fs_va, rd_addr + offset * BLOCK_SIZE, BLOCK_SIZE);
futex_up(&rd_futex);
retval = EOK;
break;
163,7 → 168,7
break;
}
futex_up(&rd_futex);
memcpy(rd_addr + offset, fs_va, BLOCK_SIZE);
memcpy(rd_addr + offset * BLOCK_SIZE, fs_va, BLOCK_SIZE);
futex_down(&rd_futex);
retval = EOK;
break;
181,46 → 186,119
}
}
 
static int driver_register(char *name)
{
ipcarg_t retval;
aid_t req;
ipc_call_t answer;
int phone;
ipcarg_t callback_phonehash;
 
phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER, 0);
 
while (phone < 0) {
usleep(10000);
phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP,
DEVMAP_DRIVER, 0);
}
req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
 
retval = ipc_data_write_start(phone, (char *) name, strlen(name) + 1);
 
if (retval != EOK) {
async_wait_for(req, NULL);
return -1;
}
 
async_set_client_connection(rd_connection);
 
ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
async_wait_for(req, &retval);
 
return phone;
}
 
static int device_register(int driver_phone, char *name, int *handle)
{
ipcarg_t retval;
aid_t req;
ipc_call_t answer;
 
req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer);
 
retval = ipc_data_write_start(driver_phone, (char *) name, strlen(name) + 1);
 
if (retval != EOK) {
async_wait_for(req, NULL);
return retval;
}
 
async_wait_for(req, &retval);
 
if (handle != NULL)
*handle = -1;
if (EOK == retval) {
if (NULL != handle)
*handle = (int) IPC_GET_ARG1(answer);
}
return retval;
}
 
/** Prepare the ramdisk image for operation. */
static bool rd_init(void)
{
int retval, flags;
 
rd_size = sysinfo_value("rd.size");
void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical");
if (rd_size == 0)
if (rd_size == 0) {
printf(NAME ": No RAM disk found\n");
return false;
}
rd_addr = as_get_mappable_page(rd_size);
flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
retval = physmem_map(rd_ph_addr, rd_addr,
int flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
int retval = physmem_map(rd_ph_addr, rd_addr,
ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
 
if (retval < 0)
if (retval < 0) {
printf(NAME ": Error mapping RAM disk\n");
return false;
}
printf(NAME ": Found RAM disk at %p, %d bytes\n", rd_ph_addr, rd_size);
int driver_phone = driver_register(NAME);
if (driver_phone < 0) {
printf(NAME ": Unable to register driver\n");
return false;
}
int dev_handle;
if (EOK != device_register(driver_phone, "initrd", &dev_handle)) {
ipc_hangup(driver_phone);
printf(NAME ": Unable to register device\n");
return false;
}
return true;
}
 
int main(int argc, char **argv)
{
if (rd_init()) {
ipcarg_t phonead;
async_set_client_connection(rd_connection);
/* Register service at nameserver */
if (ipc_connect_to_me(PHONE_NS, SERVICE_RD, 0, 0, &phonead) != 0)
return -1;
async_manager();
/* Never reached */
return 0;
}
printf(NAME ": HelenOS RAM disk server\n");
return -1;
if (!rd_init())
return -1;
printf(NAME ": Accepting connections\n");
async_manager();
 
/* Never reached */
return 0;
}
 
/**
/branches/dynload/uspace/srv/rd/Makefile
57,7 → 57,7
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
 
$(OUTPUT): $(OBJECTS) $(LIBS)
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
 
disasm:
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
/branches/dynload/uspace/srv/fb/sysio.h
File deleted
/branches/dynload/uspace/srv/fb/sysio.c
File deleted
/branches/dynload/uspace/srv/fb/main.c
33,12 → 33,14
#include <as.h>
#include <align.h>
#include <errno.h>
#include <stdio.h>
 
#include "fb.h"
#include "sysio.h"
#include "ega.h"
#include "main.h"
 
#define NAME "fb"
 
void receive_comm_area(ipc_callid_t callid, ipc_call_t *call, void **area)
{
void *dest;
53,6 → 55,8
 
int main(int argc, char *argv[])
{
printf(NAME ": HelenOS Framebuffer service\n");
ipcarg_t phonead;
int initialized = 0;
 
70,11 → 74,12
#endif
 
if (!initialized)
sysio_init();
return -1;
 
if (ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, 0, &phonead) != 0)
return -1;
printf(NAME ": Accepting connections\n");
async_manager();
/* Never reached */
return 0;
/branches/dynload/uspace/srv/fb/Makefile
43,7 → 43,6
OUTPUT = fb
SOURCES = \
main.c \
sysio.c \
ppm.c
 
ifneq ($(ARCH), ia64)
82,7 → 81,7
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
 
$(OUTPUT): $(OBJECTS) $(LIBS)
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
 
disasm:
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
/branches/dynload/uspace/srv/fs/tmpfs/tmpfs.c
50,7 → 50,9
#include <libfs.h>
#include "../../vfs/vfs.h"
 
#define NAME "tmpfs"
 
 
vfs_info_t tmpfs_vfs_info = {
.name = "tmpfs",
.ops = {
132,7 → 134,7
{
int vfs_phone;
 
printf("TMPFS: HelenOS TMPFS file system server.\n");
printf(NAME ": HelenOS TMPFS file system server\n");
 
vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0, 0);
while (vfs_phone < EOK) {
144,13 → 146,11
rc = fs_register(vfs_phone, &tmpfs_reg, &tmpfs_vfs_info,
tmpfs_connection);
if (rc != EOK) {
printf("Failed to register the TMPFS file system (%d)\n", rc);
printf(NAME ": Failed to register file system (%d)\n", rc);
return rc;
}
dprintf("TMPFS filesystem registered, fs_handle=%d.\n",
tmpfs_reg.fs_handle);
 
printf(NAME ": Accepting connections\n");
async_manager();
/* not reached */
return 0;
/branches/dynload/uspace/srv/fs/tmpfs/tmpfs_ops.c
50,6 → 50,10
#include <libadt/hash_table.h>
#include <as.h>
#include <libfs.h>
#include <ipc/services.h>
#include <ipc/devmap.h>
#include <sys/mman.h>
#include <byteorder.h>
 
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
58,6 → 62,10
 
#define NAMES_BUCKETS 4
 
#define BLOCK_SIZE 1024 // FIXME
#define RD_BASE 1024 // FIXME
#define RD_READ_BLOCK (RD_BASE + 1)
 
/*
* For now, we don't distinguish between different dev_handles/instances. All
* requests resolve to the only instance, rooted in the following variable.
140,6 → 148,11
/** Hash table of all directory entries. */
hash_table_t dentries;
 
struct rdentry {
uint8_t type;
uint32_t len;
} __attribute__((packed));
 
/* Implementation of hash table interface for the dentries hash table. */
static hash_index_t dentries_hash(unsigned long *key)
{
237,6 → 250,177
return true;
}
 
static bool tmpfs_blockread(int phone, void *buffer, size_t *bufpos, size_t *buflen, size_t *pos, void *dst, size_t size)
{
size_t offset = 0;
size_t left = size;
while (left > 0) {
size_t rd;
if (*bufpos + left < *buflen)
rd = left;
else
rd = *buflen - *bufpos;
if (rd > 0) {
memcpy(dst + offset, buffer + *bufpos, rd);
offset += rd;
*bufpos += rd;
*pos += rd;
left -= rd;
}
if (*bufpos == *buflen) {
int retval;
int rc = ipc_call_sync_2_1(phone, RD_READ_BLOCK, *pos / BLOCK_SIZE, BLOCK_SIZE, (sysarg_t *) &retval);
if ((rc != EOK) || (retval != EOK))
return false;
*bufpos = 0;
*buflen = BLOCK_SIZE;
}
}
return true;
}
 
static bool tmpfs_restore_recursion(int phone, void *block, size_t *bufpos, size_t *buflen, size_t *pos, tmpfs_dentry_t *parent)
{
struct rdentry entry;
do {
char *fname;
tmpfs_dentry_t *node;
uint32_t size;
if (!tmpfs_blockread(phone, block, bufpos, buflen, pos, &entry, sizeof(entry)))
return false;
entry.len = uint32_t_le2host(entry.len);
switch (entry.type) {
case 0:
break;
case 1:
fname = malloc(entry.len + 1);
if (fname == NULL)
return false;
node = (tmpfs_dentry_t *) tmpfs_create_node(L_FILE);
if (node == NULL) {
free(fname);
return false;
}
if (!tmpfs_blockread(phone, block, bufpos, buflen, pos, fname, entry.len)) {
tmpfs_destroy_node((void *) node);
free(fname);
return false;
}
fname[entry.len] = 0;
if (!tmpfs_link_node((void *) parent, (void *) node, fname)) {
tmpfs_destroy_node((void *) node);
free(fname);
return false;
}
free(fname);
if (!tmpfs_blockread(phone, block, bufpos, buflen, pos, &size, sizeof(size)))
return false;
size = uint32_t_le2host(size);
node->data = malloc(size);
if (node->data == NULL)
return false;
node->size = size;
if (!tmpfs_blockread(phone, block, bufpos, buflen, pos, node->data, size))
return false;
break;
case 2:
fname = malloc(entry.len + 1);
if (fname == NULL)
return false;
node = (tmpfs_dentry_t *) tmpfs_create_node(L_DIRECTORY);
if (node == NULL) {
free(fname);
return false;
}
if (!tmpfs_blockread(phone, block, bufpos, buflen, pos, fname, entry.len)) {
tmpfs_destroy_node((void *) node);
free(fname);
return false;
}
fname[entry.len] = 0;
if (!tmpfs_link_node((void *) parent, (void *) node, fname)) {
tmpfs_destroy_node((void *) node);
free(fname);
return false;
}
free(fname);
if (!tmpfs_restore_recursion(phone, block, bufpos, buflen, pos, node))
return false;
break;
default:
return false;
}
} while (entry.type != 0);
return true;
}
 
static bool tmpfs_restore(dev_handle_t dev)
{
void *block = mmap(NULL, BLOCK_SIZE,
PROTO_READ | PROTO_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
if (block == NULL)
return false;
int phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CONNECT_TO_DEVICE, dev);
 
if (phone < 0) {
munmap(block, BLOCK_SIZE);
return false;
}
if (ipc_share_out_start(phone, block, AS_AREA_READ | AS_AREA_WRITE) != EOK)
goto error;
size_t bufpos = 0;
size_t buflen = 0;
size_t pos = 0;
char tag[6];
if (!tmpfs_blockread(phone, block, &bufpos, &buflen, &pos, tag, 5))
goto error;
tag[5] = 0;
if (strcmp(tag, "TMPFS") != 0)
goto error;
if (!tmpfs_restore_recursion(phone, block, &bufpos, &buflen, &pos, root))
goto error;
ipc_hangup(phone);
munmap(block, BLOCK_SIZE);
return true;
error:
ipc_hangup(phone);
munmap(block, BLOCK_SIZE);
return false;
}
 
/** Compare one component of path to a directory entry.
*
* @param parentp Pointer to node from which we descended.
395,16 → 579,24
 
void tmpfs_mount(ipc_callid_t rid, ipc_call_t *request)
{
dev_handle_t mr_dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
fs_index_t mr_index = (fs_index_t)IPC_GET_ARG2(*request);
fs_handle_t mp_fs_handle = (fs_handle_t)IPC_GET_ARG3(*request);
dev_handle_t mp_dev_handle = (dev_handle_t)IPC_GET_ARG4(*request);
fs_index_t mp_index = (fs_index_t)IPC_GET_ARG5(*request);
dev_handle_t mr_dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
fs_index_t mr_index = (fs_index_t) IPC_GET_ARG2(*request);
fs_handle_t mp_fs_handle = (fs_handle_t) IPC_GET_ARG3(*request);
dev_handle_t mp_dev_handle = (dev_handle_t) IPC_GET_ARG4(*request);
fs_index_t mp_index = (fs_index_t) IPC_GET_ARG5(*request);
if ((mr_index == root->index) &&
(mp_fs_handle == tmpfs_reg.fs_handle) &&
(mp_index == mr_index))
ipc_answer_0(rid, EOK);
else
(mp_fs_handle == tmpfs_reg.fs_handle) &&
(mp_index == mr_index)) {
if (mr_dev_handle >= 0) {
if (tmpfs_restore(mr_dev_handle))
ipc_answer_0(rid, EOK);
else
ipc_answer_0(rid, ELIMIT);
} else
ipc_answer_0(rid, EOK);
} else
ipc_answer_0(rid, ENOTSUP);
}
 
/branches/dynload/uspace/srv/devmap/devmap.h
File deleted
/branches/dynload/uspace/srv/devmap/devmap.c
44,8 → 44,9
#include <futex.h>
#include <stdlib.h>
#include <string.h>
#include <ipc/devmap.h>
 
#include "devmap.h"
#define NAME "devmap"
 
 
LIST_INITIALIZE(devices_list);
112,10 → 113,8
item = item->next;
}
 
if (item == &devices_list) {
printf("DEVMAP: no device named %s.\n", name);
if (item == &devices_list)
return NULL;
}
 
device = list_get_instance(item, devmap_device_t, devices);
return device;
203,7 → 202,6
* Get driver name
*/
if (!ipc_data_write_receive(&callid, &name_size)) {
printf("Unexpected request.\n");
free(driver);
ipc_answer_0(callid, EREFUSED);
ipc_answer_0(iid, EREFUSED);
211,8 → 209,6
}
 
if (name_size > DEVMAP_NAME_MAXLEN) {
printf("Too logn name: %u: maximum is %u.\n", name_size,
DEVMAP_NAME_MAXLEN);
free(driver);
ipc_answer_0(callid, EINVAL);
ipc_answer_0(iid, EREFUSED);
223,7 → 219,6
* Allocate buffer for device name.
*/
if (NULL == (driver->name = (char *)malloc(name_size + 1))) {
printf("Cannot allocate space for driver name.\n");
free(driver);
ipc_answer_0(callid, ENOMEM);
ipc_answer_0(iid, EREFUSED);
234,7 → 229,6
* Send confirmation to sender and get data into buffer.
*/
if (EOK != ipc_data_write_finalize(callid, driver->name, name_size)) {
printf("Cannot read driver name.\n");
free(driver->name);
free(driver);
ipc_answer_0(iid, EREFUSED);
243,8 → 237,6
 
driver->name[name_size] = 0;
 
printf("Read driver name: '%s'.\n", driver->name);
 
/* Initialize futex for list of devices owned by this driver */
futex_initialize(&(driver->devices_futex), 1);
 
259,8 → 251,6
callid = async_get_call(&call);
 
if (IPC_M_CONNECT_TO_ME != IPC_GET_METHOD(call)) {
printf("DEVMAP: Unexpected method: %u.\n",
IPC_GET_METHOD(call));
ipc_answer_0(callid, ENOTSUP);
free(driver->name);
288,10 → 278,8
futex_up(&drivers_list_futex);
ipc_answer_0(iid, EOK);
printf("Driver registered.\n");
 
*odriver = driver;
return;
}
 
/** Unregister device driver, unregister all its devices and free driver
301,12 → 289,9
{
devmap_device_t *device;
 
if (NULL == driver) {
printf("Error: driver == NULL.\n");
if (NULL == driver)
return EEXISTS;
}
 
printf("Unregister driver '%s'.\n", driver->name);
futex_down(&drivers_list_futex);
 
ipc_hangup(driver->phone);
322,7 → 307,6
while (!list_empty(&(driver->devices))) {
device = list_get_instance(driver->devices.next,
devmap_device_t, driver_devices);
printf("Unregister device '%s'.\n", device->name);
devmap_device_unregister_core(device);
}
337,8 → 321,6
 
free(driver);
 
printf("Driver unregistered.\n");
 
return EOK;
}
 
354,7 → 336,6
devmap_device_t *device;
 
if (NULL == driver) {
printf("Invalid driver registration.\n");
ipc_answer_0(iid, EREFUSED);
return;
}
361,8 → 342,7
/* Create new device entry */
if (NULL ==
(device = (devmap_device_t *)malloc(sizeof(devmap_device_t)))) {
printf("Cannot allocate new device.\n");
(device = (devmap_device_t *) malloc(sizeof(devmap_device_t)))) {
ipc_answer_0(iid, ENOMEM);
return;
}
370,24 → 350,21
/* Get device name */
if (!ipc_data_write_receive(&callid, &size)) {
free(device);
printf("Cannot read device name.\n");
ipc_answer_0(iid, EREFUSED);
return;
}
 
if (size > DEVMAP_NAME_MAXLEN) {
printf("Too long device name: %u.\n", size);
free(device);
ipc_answer_0(callid, EINVAL);
ipc_answer_0(iid, EREFUSED);
return;
}
/* +1 for terminating \0 */
device->name = (char *) malloc(size + 1);
 
/* +1 for terminating \0 */
device->name = (char *)malloc(size + 1);
 
if (NULL == device->name) {
printf("Cannot read device name.\n");
free(device);
ipc_answer_0(callid, ENOMEM);
ipc_answer_0(iid, EREFUSED);
404,7 → 381,7
 
/* Check that device with such name is not already registered */
if (NULL != devmap_device_find_name(device->name)) {
printf("Device '%s' already registered.\n", device->name);
printf(NAME ": Device '%s' already registered\n", device->name);
futex_up(&devices_list_futex);
free(device->name);
free(device);
428,10 → 405,7
futex_up(&device->driver->devices_futex);
futex_up(&devices_list_futex);
 
printf("Device '%s' registered.\n", device->name);
ipc_answer_1(iid, EOK, device->handle);
 
return;
}
 
/**
461,8 → 435,6
dev = devmap_device_find_handle(handle);
 
if (NULL == dev) {
printf("DEVMAP: No registered device with handle %d.\n",
handle);
ipc_answer_0(callid, ENOENT);
return;
}
469,7 → 441,6
 
ipc_forward_fast(callid, dev->driver->phone, (ipcarg_t)(dev->handle),
IPC_GET_ARG3(*call), 0, IPC_FF_NONE);
return;
}
 
/** Find handle for device instance identified by name.
484,7 → 455,6
ipc_callid_t callid;
ipcarg_t retval;
/*
* Wait for incoming message with device name (but do not
* read the name itself until the buffer is allocated).
528,16 → 498,11
* Device was not found.
*/
if (NULL == dev) {
printf("DEVMAP: device %s has not been registered.\n", name);
ipc_answer_0(iid, ENOENT);
return;
}
 
printf("DEVMAP: device %s has handler %d.\n", name, dev->handle);
ipc_answer_1(iid, EOK, dev->handle);
 
return;
}
 
/** Find name of device identified by id and send it to caller.
574,15 → 539,12
}
*/
/* TODO: send name in response */
 
return;
}
 
/** Handle connection with device driver.
*
*/
static void
devmap_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
static void devmap_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
{
ipc_callid_t callid;
ipc_call_t call;
593,10 → 555,8
 
devmap_driver_register(&driver);
 
if (NULL == driver) {
printf("DEVMAP: driver registration failed.\n");
if (NULL == driver)
return;
}
while (cont) {
callid = async_get_call(&call);
603,13 → 563,10
 
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
printf("DEVMAP: connection hung up.\n");
cont = false;
continue; /* Exit thread */
case DEVMAP_DRIVER_UNREGISTER:
printf("DEVMAP: unregister driver.\n");
if (NULL == driver) {
printf("DEVMAP: driver was not registered!\n");
ipc_answer_0(callid, ENOENT);
} else {
ipc_answer_0(callid, EOK);
649,8 → 606,7
/** Handle connection with device client.
*
*/
static void
devmap_connection_client(ipc_callid_t iid, ipc_call_t *icall)
static void devmap_connection_client(ipc_callid_t iid, ipc_call_t *icall)
{
ipc_callid_t callid;
ipc_call_t call;
663,7 → 619,6
 
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
printf("DEVMAP: connection hung up.\n");
cont = false;
continue; /* Exit thread */
 
686,14 → 641,10
/** Function for handling connections to devmap
*
*/
static void
devmap_connection(ipc_callid_t iid, ipc_call_t *icall)
static void devmap_connection(ipc_callid_t iid, ipc_call_t *icall)
{
 
printf("DEVMAP: new connection.\n");
 
/* Select interface */
switch ((ipcarg_t)(IPC_GET_ARG1(*icall))) {
/* Select interface */
switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
case DEVMAP_DRIVER:
devmap_connection_driver(iid, icall);
break;
701,21 → 652,14
devmap_connection_client(iid, icall);
break;
case DEVMAP_CONNECT_TO_DEVICE:
/* Connect client to selected device */
printf("DEVMAP: connect to device %d.\n",
IPC_GET_ARG2(*icall));
/* Connect client to selected device */
devmap_forward(iid, icall);
break;
default:
ipc_answer_0(iid, ENOENT); /* No such interface */
printf("DEVMAP: Unknown interface %u.\n",
(ipcarg_t)(IPC_GET_ARG1(*icall)));
}
 
/* Cleanup */
printf("DEVMAP: connection closed.\n");
return;
}
 
/**
723,16 → 667,16
*/
int main(int argc, char *argv[])
{
printf(NAME ": HelenOS Device Mapper\n");
ipcarg_t phonead;
 
printf("DEVMAP: HelenOS device mapper.\n");
 
if (devmap_init() != 0) {
printf("Error while initializing DEVMAP service.\n");
printf(NAME ": Error while initializing service\n");
return -1;
}
 
/* Set a handler of incomming connections */
/* Set a handler of incomming connections */
async_set_client_connection(devmap_connection);
 
/* Register device mapper at naming service */
739,6 → 683,7
if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, &phonead) != 0)
return -1;
printf(NAME ": Accepting connections\n");
async_manager();
/* Never reached */
return 0;
747,4 → 692,3
/**
* @}
*/
 
/branches/dynload/uspace/srv/vfs/vfs.c
47,6 → 47,8
#include <atomic.h>
#include "vfs.h"
 
#define NAME "vfs"
 
#define dprintf(...) printf(__VA_ARGS__)
 
static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall)
53,8 → 55,6
{
bool keep_on_going = 1;
 
printf("Connection opened from %p\n", icall->in_phone_hash);
 
/*
* The connection was opened via the IPC_CONNECT_ME_TO call.
* This call needs to be answered.
77,8 → 77,6
 
callid = async_get_call(&call);
 
printf("Received call, method=%d\n", IPC_GET_METHOD(call));
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
keep_on_going = false;
131,7 → 129,7
{
ipcarg_t phonead;
 
printf("VFS: HelenOS VFS server\n");
printf(NAME ": HelenOS VFS server\n");
 
/*
* Initialize the list of registered file systems.
142,7 → 140,7
* Initialize VFS node hash table.
*/
if (!vfs_nodes_init()) {
printf("Failed to initialize the VFS node hash table.\n");
printf(NAME ": Failed to initialize VFS node hash table\n");
return ENOMEM;
}
 
152,12 → 150,12
list_initialize(&plb_head);
plb = as_get_mappable_page(PLB_SIZE);
if (!plb) {
printf("Cannot allocate a mappable piece of address space\n");
printf(NAME ": Cannot allocate a mappable piece of address space\n");
return ENOMEM;
}
if (as_area_create(plb, PLB_SIZE, AS_AREA_READ | AS_AREA_WRITE |
AS_AREA_CACHEABLE) != plb) {
printf("Cannot create address space area.\n");
printf(NAME ": Cannot create address space area\n");
return ENOMEM;
}
memset(plb, 0, PLB_SIZE);
175,6 → 173,7
/*
* Start accepting connections.
*/
printf(NAME ": Accepting connections\n");
async_manager();
return 0;
}
/branches/dynload/uspace/srv/vfs/vfs_ops.c
444,7 → 444,7
*/
 
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) {
451,7 → 451,7
ipc_answer_0(rid, ENOENT);
return;
}
 
/*
* Now we need to receive a call with client's
* IPC_M_DATA_READ/IPC_M_DATA_WRITE request.
467,13 → 467,13
ipc_answer_0(rid, EINVAL);
return;
}
 
/*
* Lock the open file structure so that no other thread can manipulate
* the same open file at a time.
*/
futex_down(&file->lock);
 
/*
* Lock the file's node so that no other client can read/write to it at
* the same time.
482,7 → 482,7
rwlock_read_lock(&file->node->contents_rwlock);
else
rwlock_write_lock(&file->node->contents_rwlock);
 
int fs_phone = vfs_grab_phone(file->node->fs_handle);
/* Make a VFS_READ/VFS_WRITE request at the destination FS server. */
500,14 → 500,14
* don't have to bother.
*/
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);
size_t bytes = IPC_GET_ARG1(answer);
 
/* Unlock the VFS node. */
if (read)
rwlock_read_unlock(&file->node->contents_rwlock);
517,12 → 517,12
file->node->size = IPC_GET_ARG2(answer);
rwlock_write_unlock(&file->node->contents_rwlock);
}
 
/* Update the position pointer and unlock the open file. */
if (rc == EOK)
file->pos += bytes;
futex_up(&file->lock);
 
/*
* FS server's reply is the final result of the whole operation we
* return to the client.
/branches/dynload/uspace/srv/vfs/vfs.h
40,8 → 40,11
#include <sys/types.h>
#include <bool.h>
 
#define dprintf(...) printf(__VA_ARGS__)
// FIXME: according to CONFIG_DEBUG
// #define dprintf(...) printf(__VA_ARGS__)
 
#define dprintf(...)
 
#define VFS_FIRST IPC_FIRST_USER_METHOD
 
#define IPC_METHOD_TO_VFS_OP(m) ((m) - VFS_FIRST)