Changeset View
Changeset View
Standalone View
Standalone View
sys/fs/cuse/cuse.c
Show First 20 Lines • Show All 419 Lines • ▼ Show 20 Lines | cuse_server_alloc_memory(struct cuse_server *pcs, uint32_t alloc_nr, | ||||
uint32_t page_count) | uint32_t page_count) | ||||
{ | { | ||||
struct cuse_memory *temp; | struct cuse_memory *temp; | ||||
struct cuse_memory *mem; | struct cuse_memory *mem; | ||||
vm_object_t object; | vm_object_t object; | ||||
int error; | int error; | ||||
mem = malloc(sizeof(*mem), M_CUSE, M_WAITOK | M_ZERO); | mem = malloc(sizeof(*mem), M_CUSE, M_WAITOK | M_ZERO); | ||||
if (mem == NULL) | |||||
return (ENOMEM); | |||||
object = vm_pager_allocate(OBJT_SWAP, NULL, PAGE_SIZE * page_count, | object = vm_pager_allocate(OBJT_SWAP, NULL, PAGE_SIZE * page_count, | ||||
VM_PROT_DEFAULT, 0, curthread->td_ucred); | VM_PROT_DEFAULT, 0, curthread->td_ucred); | ||||
if (object == NULL) { | if (object == NULL) { | ||||
error = ENOMEM; | error = ENOMEM; | ||||
goto error_0; | goto error_0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static int | static int | ||||
cuse_server_open(struct cdev *dev, int fflags, int devtype, struct thread *td) | cuse_server_open(struct cdev *dev, int fflags, int devtype, struct thread *td) | ||||
{ | { | ||||
struct cuse_server *pcs; | struct cuse_server *pcs; | ||||
pcs = malloc(sizeof(*pcs), M_CUSE, M_WAITOK | M_ZERO); | pcs = malloc(sizeof(*pcs), M_CUSE, M_WAITOK | M_ZERO); | ||||
if (pcs == NULL) | |||||
return (ENOMEM); | |||||
if (devfs_set_cdevpriv(pcs, &cuse_server_free)) { | if (devfs_set_cdevpriv(pcs, &cuse_server_free)) { | ||||
printf("Cuse: Cannot set cdevpriv.\n"); | printf("Cuse: Cannot set cdevpriv.\n"); | ||||
free(pcs, M_CUSE); | free(pcs, M_CUSE); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
/* store current process ID */ | /* store current process ID */ | ||||
pcs->pid = curproc->p_pid; | pcs->pid = curproc->p_pid; | ||||
▲ Show 20 Lines • Show All 451 Lines • ▼ Show 20 Lines | case CUSE_IOCTL_CREATE_DEV: | ||||
cuse_str_filter(pcd->devname); | cuse_str_filter(pcd->devname); | ||||
pcd->permissions &= 0777; | pcd->permissions &= 0777; | ||||
/* try to allocate a character device */ | /* try to allocate a character device */ | ||||
pcsd = malloc(sizeof(*pcsd), M_CUSE, M_WAITOK | M_ZERO); | pcsd = malloc(sizeof(*pcsd), M_CUSE, M_WAITOK | M_ZERO); | ||||
if (pcsd == NULL) { | |||||
error = ENOMEM; | |||||
break; | |||||
} | |||||
pcsd->server = pcs; | pcsd->server = pcs; | ||||
pcsd->user_dev = pcd->dev; | pcsd->user_dev = pcd->dev; | ||||
pcsd->kern_dev = make_dev_credf(MAKEDEV_CHECKNAME, | pcsd->kern_dev = make_dev_credf(MAKEDEV_CHECKNAME, | ||||
&cuse_client_devsw, 0, NULL, pcd->user_id, pcd->group_id, | &cuse_client_devsw, 0, NULL, pcd->user_id, pcd->group_id, | ||||
pcd->permissions, "%s", pcd->devname); | pcd->permissions, "%s", pcd->devname); | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | if (pcs->refs < 0 || pcs->pid == curproc->p_pid) { | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
cuse_server_unlock(pcs); | cuse_server_unlock(pcs); | ||||
} else { | } else { | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
pcc = malloc(sizeof(*pcc), M_CUSE, M_WAITOK | M_ZERO); | pcc = malloc(sizeof(*pcc), M_CUSE, M_WAITOK | M_ZERO); | ||||
if (pcc == NULL) { | |||||
/* drop reference on server */ | |||||
cuse_server_unref(pcs); | |||||
return (ENOMEM); | |||||
} | |||||
if (devfs_set_cdevpriv(pcc, &cuse_client_free)) { | if (devfs_set_cdevpriv(pcc, &cuse_client_free)) { | ||||
printf("Cuse: Cannot set cdevpriv.\n"); | printf("Cuse: Cannot set cdevpriv.\n"); | ||||
/* drop reference on server */ | /* drop reference on server */ | ||||
cuse_server_unref(pcs); | cuse_server_unref(pcs); | ||||
free(pcc, M_CUSE); | free(pcc, M_CUSE); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
pcc->fflags = fflags; | pcc->fflags = fflags; | ||||
▲ Show 20 Lines • Show All 499 Lines • Show Last 20 Lines |