Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/md/md.c
Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | struct md_ioctl32 { | ||||
uint32_t md_label; | uint32_t md_label; | ||||
int md_pad[MDNPAD]; | int md_pad[MDNPAD]; | ||||
} __attribute__((__packed__)); | } __attribute__((__packed__)); | ||||
CTASSERT((sizeof(struct md_ioctl32)) == 436); | CTASSERT((sizeof(struct md_ioctl32)) == 436); | ||||
#define MDIOCATTACH_32 _IOC_NEWTYPE(MDIOCATTACH, struct md_ioctl32) | #define MDIOCATTACH_32 _IOC_NEWTYPE(MDIOCATTACH, struct md_ioctl32) | ||||
#define MDIOCDETACH_32 _IOC_NEWTYPE(MDIOCDETACH, struct md_ioctl32) | #define MDIOCDETACH_32 _IOC_NEWTYPE(MDIOCDETACH, struct md_ioctl32) | ||||
#define MDIOCQUERY_32 _IOC_NEWTYPE(MDIOCQUERY, struct md_ioctl32) | #define MDIOCQUERY_32 _IOC_NEWTYPE(MDIOCQUERY, struct md_ioctl32) | ||||
#define MDIOCLIST_32 _IOC_NEWTYPE(MDIOCLIST, struct md_ioctl32) | |||||
#define MDIOCRESIZE_32 _IOC_NEWTYPE(MDIOCRESIZE, struct md_ioctl32) | #define MDIOCRESIZE_32 _IOC_NEWTYPE(MDIOCRESIZE, struct md_ioctl32) | ||||
#endif /* COMPAT_FREEBSD32 */ | #endif /* COMPAT_FREEBSD32 */ | ||||
static MALLOC_DEFINE(M_MD, "md_disk", "Memory Disk"); | static MALLOC_DEFINE(M_MD, "md_disk", "Memory Disk"); | ||||
static MALLOC_DEFINE(M_MDSECT, "md_sectors", "Memory Disk Sectors"); | static MALLOC_DEFINE(M_MDSECT, "md_sectors", "Memory Disk Sectors"); | ||||
static int md_debug; | static int md_debug; | ||||
SYSCTL_INT(_debug, OID_AUTO, mddebug, CTLFLAG_RW, &md_debug, 0, | SYSCTL_INT(_debug, OID_AUTO, mddebug, CTLFLAG_RW, &md_debug, 0, | ||||
▲ Show 20 Lines • Show All 1,693 Lines • ▼ Show 20 Lines | kern_mdquery(struct md_req *mdr) | ||||
int error; | int error; | ||||
sx_xlock(&md_sx); | sx_xlock(&md_sx); | ||||
error = kern_mdquery_locked(mdr); | error = kern_mdquery_locked(mdr); | ||||
sx_xunlock(&md_sx); | sx_xunlock(&md_sx); | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | |||||
kern_mdlist_locked(struct md_req *mdr) | |||||
{ | |||||
struct md_s *sc; | |||||
int i; | |||||
sx_assert(&md_sx, SA_XLOCKED); | |||||
/* | |||||
* Write the number of md devices to mdr->md_units[0]. | |||||
* Write the unit number of the first (mdr->md_units_nitems - 2) | |||||
* units to mdr->md_units[1::(mdr->md_units - 2)] and terminate the | |||||
* list with -1. | |||||
* | |||||
* XXX: There is currently no mechanism to retrieve unit | |||||
* numbers for more than (MDNPAD - 2) units. | |||||
* | |||||
* XXX: Due to the use of LIST_INSERT_HEAD in mdnew(), the | |||||
* list of visible unit numbers not stable. | |||||
*/ | |||||
i = 1; | |||||
LIST_FOREACH(sc, &md_softc_list, list) { | |||||
if (i < mdr->md_units_nitems - 1) | |||||
mdr->md_units[i] = sc->unit; | |||||
i++; | |||||
} | |||||
mdr->md_units[MIN(i, mdr->md_units_nitems - 1)] = -1; | |||||
mdr->md_units[0] = i - 1; | |||||
return (0); | |||||
} | |||||
static int | |||||
kern_mdlist(struct md_req *mdr) | |||||
{ | |||||
int error; | |||||
sx_xlock(&md_sx); | |||||
error = kern_mdlist_locked(mdr); | |||||
sx_xunlock(&md_sx); | |||||
return (error); | |||||
} | |||||
/* Copy members that are not userspace pointers. */ | /* Copy members that are not userspace pointers. */ | ||||
#define MD_IOCTL2REQ(mdio, mdr) do { \ | #define MD_IOCTL2REQ(mdio, mdr) do { \ | ||||
(mdr)->md_unit = (mdio)->md_unit; \ | (mdr)->md_unit = (mdio)->md_unit; \ | ||||
(mdr)->md_type = (mdio)->md_type; \ | (mdr)->md_type = (mdio)->md_type; \ | ||||
(mdr)->md_mediasize = (mdio)->md_mediasize; \ | (mdr)->md_mediasize = (mdio)->md_mediasize; \ | ||||
(mdr)->md_sectorsize = (mdio)->md_sectorsize; \ | (mdr)->md_sectorsize = (mdio)->md_sectorsize; \ | ||||
(mdr)->md_options = (mdio)->md_options; \ | (mdr)->md_options = (mdio)->md_options; \ | ||||
(mdr)->md_fwheads = (mdio)->md_fwheads; \ | (mdr)->md_fwheads = (mdio)->md_fwheads; \ | ||||
Show All 24 Lines | if (md_debug) | ||||
printf("mdctlioctl(%s %lx %p %x %p)\n", | printf("mdctlioctl(%s %lx %p %x %p)\n", | ||||
devtoname(dev), cmd, addr, flags, td); | devtoname(dev), cmd, addr, flags, td); | ||||
bzero(&mdr, sizeof(mdr)); | bzero(&mdr, sizeof(mdr)); | ||||
switch (cmd) { | switch (cmd) { | ||||
case MDIOCATTACH: | case MDIOCATTACH: | ||||
case MDIOCDETACH: | case MDIOCDETACH: | ||||
case MDIOCRESIZE: | case MDIOCRESIZE: | ||||
case MDIOCQUERY: | case MDIOCQUERY: { | ||||
case MDIOCLIST: { | |||||
struct md_ioctl *mdio = (struct md_ioctl *)addr; | struct md_ioctl *mdio = (struct md_ioctl *)addr; | ||||
if (mdio->md_version != MDIOVERSION) | if (mdio->md_version != MDIOVERSION) | ||||
return (EINVAL); | return (EINVAL); | ||||
MD_IOCTL2REQ(mdio, &mdr); | MD_IOCTL2REQ(mdio, &mdr); | ||||
mdr.md_file = mdio->md_file; | mdr.md_file = mdio->md_file; | ||||
mdr.md_file_seg = UIO_USERSPACE; | mdr.md_file_seg = UIO_USERSPACE; | ||||
/* If the file is adjacent to the md_ioctl it's in kernel. */ | /* If the file is adjacent to the md_ioctl it's in kernel. */ | ||||
if ((void *)mdio->md_file == (void *)(mdio + 1)) | if ((void *)mdio->md_file == (void *)(mdio + 1)) | ||||
mdr.md_file_seg = UIO_SYSSPACE; | mdr.md_file_seg = UIO_SYSSPACE; | ||||
mdr.md_label = mdio->md_label; | mdr.md_label = mdio->md_label; | ||||
break; | break; | ||||
} | } | ||||
#ifdef COMPAT_FREEBSD32 | #ifdef COMPAT_FREEBSD32 | ||||
case MDIOCATTACH_32: | case MDIOCATTACH_32: | ||||
case MDIOCDETACH_32: | case MDIOCDETACH_32: | ||||
case MDIOCRESIZE_32: | case MDIOCRESIZE_32: | ||||
case MDIOCQUERY_32: | case MDIOCQUERY_32: { | ||||
case MDIOCLIST_32: { | |||||
struct md_ioctl32 *mdio = (struct md_ioctl32 *)addr; | struct md_ioctl32 *mdio = (struct md_ioctl32 *)addr; | ||||
if (mdio->md_version != MDIOVERSION) | if (mdio->md_version != MDIOVERSION) | ||||
return (EINVAL); | return (EINVAL); | ||||
MD_IOCTL2REQ(mdio, &mdr); | MD_IOCTL2REQ(mdio, &mdr); | ||||
mdr.md_file = (void *)(uintptr_t)mdio->md_file; | mdr.md_file = (void *)(uintptr_t)mdio->md_file; | ||||
mdr.md_file_seg = UIO_USERSPACE; | mdr.md_file_seg = UIO_USERSPACE; | ||||
mdr.md_label = (void *)(uintptr_t)mdio->md_label; | mdr.md_label = (void *)(uintptr_t)mdio->md_label; | ||||
break; | break; | ||||
Show All 24 Lines | |||||
#endif | #endif | ||||
error = kern_mdresize(&mdr); | error = kern_mdresize(&mdr); | ||||
break; | break; | ||||
case MDIOCQUERY: | case MDIOCQUERY: | ||||
#ifdef COMPAT_FREEBSD32 | #ifdef COMPAT_FREEBSD32 | ||||
case MDIOCQUERY_32: | case MDIOCQUERY_32: | ||||
#endif | #endif | ||||
error = kern_mdquery(&mdr); | error = kern_mdquery(&mdr); | ||||
break; | |||||
case MDIOCLIST: | |||||
#ifdef COMPAT_FREEBSD32 | |||||
case MDIOCLIST_32: | |||||
#endif | |||||
error = kern_mdlist(&mdr); | |||||
break; | break; | ||||
default: | default: | ||||
error = ENOIOCTL; | error = ENOIOCTL; | ||||
} | } | ||||
switch (cmd) { | switch (cmd) { | ||||
case MDIOCATTACH: | case MDIOCATTACH: | ||||
case MDIOCQUERY: { | case MDIOCQUERY: { | ||||
▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines |