Beispiel #1
0
struct block_dev *block_dev_create(char *path, void *driver, void *privdata) {
	block_dev_t *bdev;
	struct path node, root;
	struct nas *nas;
	struct node_fi *node_fi;

	bdev = block_dev_create_common(path, driver, privdata);
	if (NULL == bdev) {
		return NULL;
	}

	vfs_get_root_path(&root);

	if (0 != vfs_create(&root, path, S_IFBLK | S_IRALL | S_IWALL, &node)) {
		block_dev_free(bdev);
		return NULL;
	}

	bdev->dev_vfs_info = node.node;
	nas = node.node->nas;
	nas->fs = blockdev_fs;
	node_fi = nas->fi;
	node_fi->privdata = bdev;
	node_fi->ni.size = 0;/*TODO*/
	node_fi->ni.mtime = 0;/*TODO*/

	return bdev;
}
/**
 * @brief Create node in devfs
 *
 * @param path Name of bdev
 * @param driver
 * @param privdata
 *
 * @return Pointer to created device or NULL if failed
 */
struct block_dev *block_dev_create(char *path, void *driver, void *privdata) {
	struct block_dev *bdev;
	char full_path[256];
	struct lookup lu;
	struct dev_module *devmod;

	if (NULL == (bdev = block_dev_create_common(path, driver, privdata)))
		return NULL;

	bdev->dev_ops = &bdev_dev_ops;

	/* Get root of devfs in smarter way? */

	strcpy(full_path, "/dev/");
	strcat(full_path, path);

	dvfs_lookup("/dev", &lu);
	lu.parent = lu.item;
	lu.item = NULL;

	if (!lu.parent) {
		block_dev_free(bdev);
		return NULL;
	}

	devmod = dev_module_create(&block_device, dvfs_last_link(path), bdev);
	bdev->dev_module = devmod;

	return bdev;
}
Beispiel #3
0
int block_dev_destroy(void *dev) {
	struct block_dev *bdev;

	bdev = block_dev(dev);
	vfs_del_leaf(bdev->dev_vfs_info);
	block_dev_free(bdev);

	return 0;
}