Beispiel #1
0
/* Initialize the vnode structures and initialize each file system type. */
void
vfsinit(void)
{
	int i;
	struct vfsconf *vfsconflist;
	int vfsconflistlen;

	pool_init(&namei_pool, MAXPATHLEN, 0, 0, 0, "namei",
	    &pool_allocator_nointr);

	/* Initialize the vnode table. */
	vntblinit();

	/* Initialize the vnode name cache. */
	nchinit();

#ifdef WAPBL
	wapbl_init();
#endif

	/*
	 * Stop using vfsconf and maxvfsconf as a temporary storage,
	 * set them to their correct values now.
	 */
	vfsconflist = vfsconf;
	vfsconflistlen = maxvfsconf;
	vfsconf = NULL;
	maxvfsconf = 0;

	for (i = 0; i < vfsconflistlen; i++)
		vfs_register(&vfsconflist[i]);
}
Beispiel #2
0
int
afs_module_handler(module_t mod, int what, void *arg)
{
    static int inited = 0;
    int error = 0;

    switch (what) {
    case MOD_LOAD:
	if (inited) {
	    printf("afs cannot be MOD_LOAD'd more than once\n");
	    error = EBUSY;
	    break;
	}
	memset(&afs_vfsconf, 0, sizeof(struct vfsconf));
#ifdef AFS_FBSD53_ENV
	afs_vfsconf.vfc_version = VFS_VERSION;
#endif
	strcpy(afs_vfsconf.vfc_name, "AFS");
	afs_vfsconf.vfc_vfsops = &afs_vfsops;
	afs_vfsconf.vfc_typenum = -1;	/* set by vfs_register */
	afs_vfsconf.vfc_flags = VFCF_NETWORK;
	if ((error = vfs_register(&afs_vfsconf)) != 0)
	    break;
	vfs_add_vnodeops(&afs_vnodeop_opv_desc);
	inited = 1;
	break;
    case MOD_UNLOAD:
#ifndef RXK_LISTENER_ENV
	/* shutdown is incomplete unless RXK_LISTENER_ENV */
	printf("afs: I can't be unloaded yet\n");
	return -1;
#endif
	if (!inited) {
	    error = 0;
	    break;
	}
	if ((error = vfs_unregister(&afs_vfsconf)) != 0) {
	    break;
	}
	vfs_rm_vnodeops(&afs_vnodeop_opv_desc);
	break;
    }

    return (error);
}
Beispiel #3
0
//powiadomienie vfs o istnieniu tego fs
void
devfs_init()
{
    vfs_register("devfs", &devfs_ops);

    devfs_node_t *n = kmem_zalloc(sizeof(devfs_node_t), KM_SLEEP);
    str_cpy(n->i_name, "<devfs root>"); // ciekawe, czy da radę jakoś to zobaczyć...
    n->i_type = _INODE_TYPE_DIR;
    n->i_attr = 0;
    n->i_uid = 0;
    n->i_gid = 0;
    n->i_attr = 0755;
    n->i_dirvnode = NULL;
    n->i_dev = NULL;
    n->i_parent = NULL;
    n->i_child = NULL;
    n->i_next = NULL;
    devfs_rootinode = n;
}
Beispiel #4
0
void init_initrd(void)
{
    if (multiboot_info.mods_count < 1) {
        panic("No initrd.");
    }

    void *disk;
    char *params;

    int size = mod_load(0, &disk, &params);

    dbg_printf(DBG_FS, "Loading initrd '%s' at %p with %d bytes length.\n", params, disk, size);

    if (!check_img(disk)) {
        panic("Module 1 is not a kOS initrd (%s)\n", params);
    }

    root = parse_dir(disk + sizeof(struct id_header), disk);

    vfs_register(&initrd);
}
/*
 * Standard kernel module handling code for filesystem modules.
 * Referenced from VFS_SET().
 */
int
vfs_modevent(module_t mod, int type, void *data)
{
	struct vfsconf *vfc;
	int error = 0;

	vfc = (struct vfsconf *)data;

	switch (type) {
	case MOD_LOAD:
		if (vfc)
			error = vfs_register(vfc);
		break;

	case MOD_UNLOAD:
		if (vfc)
			error = vfs_unregister(vfc);
		break;
	default:
		error = EOPNOTSUPP;
		break;
	}
	return (error);
}
Beispiel #6
0
static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
{
	bool cont = true;
	
	/*
	 * The connection was opened via the IPC_CONNECT_ME_TO call.
	 * This call needs to be answered.
	 */
	async_answer_0(iid, EOK);
	
	while (cont) {
		ipc_call_t call;
		ipc_callid_t callid = async_get_call(&call);
		
		if (!IPC_GET_IMETHOD(call))
			break;
		
		switch (IPC_GET_IMETHOD(call)) {
		case VFS_IN_REGISTER:
			vfs_register(callid, &call);
			cont = false;
			break;
		case VFS_IN_MOUNT:
			vfs_mount(callid, &call);
			break;
		case VFS_IN_UNMOUNT:
			vfs_unmount(callid, &call);
			break;
		case VFS_IN_OPEN:
			vfs_open(callid, &call);
			break;
		case VFS_IN_CLOSE:
			vfs_close(callid, &call);
			break;
		case VFS_IN_READ:
			vfs_read(callid, &call);
			break;
		case VFS_IN_WRITE:
			vfs_write(callid, &call);
			break;
		case VFS_IN_SEEK:
			vfs_seek(callid, &call);
			break;
		case VFS_IN_TRUNCATE:
			vfs_truncate(callid, &call);
			break;
		case VFS_IN_FSTAT:
			vfs_fstat(callid, &call);
			break;
		case VFS_IN_STAT:
			vfs_stat(callid, &call);
			break;
		case VFS_IN_MKDIR:
			vfs_mkdir(callid, &call);
			break;
		case VFS_IN_UNLINK:
			vfs_unlink(callid, &call);
			break;
		case VFS_IN_RENAME:
			vfs_rename(callid, &call);
			break;
		case VFS_IN_SYNC:
			vfs_sync(callid, &call);
			break;
		case VFS_IN_DUP:
			vfs_dup(callid, &call);
			break;
		case VFS_IN_WAIT_HANDLE:
			vfs_wait_handle(callid, &call);
			break;
		case VFS_IN_MTAB_GET:
			vfs_get_mtab(callid, &call);
			break;
		default:
			async_answer_0(callid, ENOTSUP);
			break;
		}
	}
	
	/*
	 * Open files for this client will be cleaned up when its last
	 * connection fibril terminates.
	 */
}
Beispiel #7
0
ELK_PRECONSTRUCTOR()
{
  vfs_register("ramfs", ramfs_init, &ramfs_vfsops);
}
Beispiel #8
0
int read_mbr(struct block_device *parent, struct block_device ***partitions, int *part_count)
{
	(void)partitions;
	(void)part_count;
	(void)driver_name;
	/* Check the validity of the parent device */
	if(parent == (void*)0)
	{
		printf("MBR: invalid parent device\n");
		return -1;
	}

	/* Read the first 512 bytes */
	uint8_t *block_0 = (uint8_t *)malloc(512);
#ifdef MBR_DEBUG
	printf("MBR: reading block 0 from device %s\n", parent->device_name);
#endif
	
	int ret = block_read(parent, block_0, 512, 0);
	if(ret < 0)
	{
		printf("MBR: block_read failed (%i)\n", ret);
		return ret;
	}
	if(ret != 512)
	{
		printf("MBR: unable to read first 512 bytes of device %s, only %d bytes read\n",
				parent->device_name, ret);
		return -1;
	}

	/* Check the MBR signature */
	if((block_0[0x1fe] != 0x55) || (block_0[0x1ff] != 0xaa))
	{
		printf("MBR: no valid mbr signature on device %s (bytes are %x %x)\n",
				parent->device_name, block_0[0x1fe], block_0[0x1ff]);
		return -1;
	}
	printf("MBR: found valid MBR on device %s\n", parent->device_name);

#ifdef MBR_DEBUG
	/* Dump the first sector */
	printf("MBR: first sector:");
	for(int dump_idx = 0; dump_idx < 512; dump_idx++)
	{
		if((dump_idx & 0xf) == 0)
			printf("\n%03x: ", dump_idx);
		printf("%02x ", block_0[dump_idx]);
	}
	printf("\n");
#endif

	/* Load the partitions */
	struct block_device **parts =
		(struct block_device **)malloc(4 * sizeof(struct block_device *));
	int cur_p = 0;
	for(int i = 0; i < 4; i++)
	{
		int p_offset = 0x1be + (i * 0x10);
		if(block_0[p_offset + 4] != 0x00)
		{
			// Valid partition
			struct mbr_block_dev *d =
				(struct mbr_block_dev *)malloc(sizeof(struct mbr_block_dev));
			memset(d, 0, sizeof(struct mbr_block_dev));
			d->bd.driver_name = driver_name;
			char *dev_name = (char *)malloc(strlen(parent->device_name + 2));
			strcpy(dev_name, parent->device_name);
			dev_name[strlen(parent->device_name)] = '_';
			dev_name[strlen(parent->device_name) + 1] = '0' + i;
			dev_name[strlen(parent->device_name) + 2] = 0;
			d->bd.device_name = dev_name;
			d->bd.device_id = (uint8_t *)malloc(1);
			d->bd.device_id[0] = i;
			d->bd.dev_id_len = 1;
			d->bd.read = mbr_read;
			d->bd.block_size = 512;
			d->part_no = i;
			d->part_id = block_0[p_offset + 4];
			d->start_block = read_word(block_0, p_offset + 8);
			d->blocks = read_word(block_0, p_offset + 12);
			d->parent = parent;
			
			parts[cur_p++] = (struct block_device *)d;
#ifdef MBR_DEBUG
			printf("MBR: partition number %i (%s) of type %x, start sector %u, "
					"sector count %u, p_offset %03x\n", 
					d->part_no, d->bd.device_name, d->part_id,
					d->start_block, d->blocks, p_offset);
#endif

			switch(d->part_id)
			{
				case 1:
				case 4:
				case 6:
				case 0xb:
				case 0xc:
				case 0xe:
				case 0x11:
				case 0x14:
				case 0x1b:
				case 0x1c:
				case 0x1e:
					fat_init((struct block_device *)d, &d->bd.fs);
					break;

				case 0x83:
					ext2_init((struct block_device *)d, &d->bd.fs);
					break;
			}

			if(d->bd.fs)
				vfs_register(d->bd.fs);
		}
	}

	*partitions = parts;
	*part_count = cur_p;
	printf("MBR: found total of %i partition(s)\n", cur_p);

	return 0;
}
Beispiel #9
0
static int init(void) {
	vfs_register("tar", tar_mount);
	return 0;
}