Find the device and point the cookie to it on open().
Comment. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20964 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,6 +8,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
|
|||||||
# UsePublicHeaders drivers ;
|
# UsePublicHeaders drivers ;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
# not Haiku-specific, ksocket.h also works in BONE.
|
||||||
UsePrivateHeaders drivers ;
|
UsePrivateHeaders drivers ;
|
||||||
|
|
||||||
KernelAddon nbd :
|
KernelAddon nbd :
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/*
|
/*
|
||||||
nbd driver for Haiku
|
nbd driver for Haiku
|
||||||
|
|
||||||
Maps BEOS/IMAGE.BE files as virtual partitions.
|
Maps a Network Block Device as virtual partitions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
@@ -51,6 +51,8 @@ status_t nbd_post_request(struct nbd_device, uint64 handle, struct nbd_request_e
|
|||||||
status_t nbd_dequeue_request(struct nbd_device, uint64 handle, struct nbd_request_entry **req);
|
status_t nbd_dequeue_request(struct nbd_device, uint64 handle, struct nbd_request_entry **req);
|
||||||
status_t nbd_free_request(struct nbd_device, struct nbd_request_entry *req);
|
status_t nbd_free_request(struct nbd_device, struct nbd_request_entry *req);
|
||||||
|
|
||||||
|
struct nbd_device *nbd_find_device(const char* name);
|
||||||
|
|
||||||
#pragma mark ==== request manager ====
|
#pragma mark ==== request manager ====
|
||||||
|
|
||||||
|
|
||||||
@@ -68,14 +70,21 @@ int32 postoffice(void *arg)
|
|||||||
|
|
||||||
#pragma mark ==== device hooks ====
|
#pragma mark ==== device hooks ====
|
||||||
|
|
||||||
|
static struct nbd_device nbd_devices[MAX_NBDS];
|
||||||
|
|
||||||
status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) {
|
status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) {
|
||||||
|
struct nbd_device *dev = NULL;
|
||||||
(void)name; (void)flags;
|
(void)name; (void)flags;
|
||||||
|
dev = nbd_find_device(name);
|
||||||
|
if (!dev)
|
||||||
|
return ENOENT;
|
||||||
*cookie = (void*)malloc(sizeof(cookie_t));
|
*cookie = (void*)malloc(sizeof(cookie_t));
|
||||||
if (*cookie == NULL) {
|
if (*cookie == NULL) {
|
||||||
dprintf("nbd_open : error allocating cookie\n");
|
dprintf("nbd_open : error allocating cookie\n");
|
||||||
goto err0;
|
goto err0;
|
||||||
}
|
}
|
||||||
memset(*cookie, 0, sizeof(cookie_t));
|
memset(*cookie, 0, sizeof(cookie_t));
|
||||||
|
(*cookie)->dev = dev;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
err0:
|
err0:
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -191,6 +200,7 @@ init_driver (void)
|
|||||||
if (nbd_name[i] == NULL)
|
if (nbd_name[i] == NULL)
|
||||||
break;
|
break;
|
||||||
sprintf(nbd_name[i], DEVICE_FMT, i);
|
sprintf(nbd_name[i], DEVICE_FMT, i);
|
||||||
|
// XXX: init nbd_devices[i]
|
||||||
}
|
}
|
||||||
nbd_name[i] = NULL;
|
nbd_name[i] = NULL;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -216,3 +226,14 @@ find_device(const char* name)
|
|||||||
{
|
{
|
||||||
return &nbd_hooks;
|
return &nbd_hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct nbd_device*
|
||||||
|
nbd_find_device(const char* name)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < MAX_NBDS; i++) {
|
||||||
|
if (!strcmp(nbd_name[i], name))
|
||||||
|
return &nbd_devices[i];
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user