Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/md/md.c
Show First 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | struct md_s { | ||||
/* MD_PRELOAD related fields */ | /* MD_PRELOAD related fields */ | ||||
u_char *pl_ptr; | u_char *pl_ptr; | ||||
size_t pl_len; | size_t pl_len; | ||||
/* MD_VNODE related fields */ | /* MD_VNODE related fields */ | ||||
struct vnode *vnode; | struct vnode *vnode; | ||||
char file[PATH_MAX]; | char file[PATH_MAX]; | ||||
char label[PATH_MAX]; | |||||
struct ucred *cred; | struct ucred *cred; | ||||
/* MD_SWAP related fields */ | /* MD_SWAP related fields */ | ||||
vm_object_t object; | vm_object_t object; | ||||
}; | }; | ||||
static struct indir * | static struct indir * | ||||
new_indir(u_int shift) | new_indir(u_int shift) | ||||
▲ Show 20 Lines • Show All 1,372 Lines • ▼ Show 20 Lines | if (mdio->md_options & MD_AUTOUNIT) | ||||
sc = mdnew(-1, &error, mdio->md_type); | sc = mdnew(-1, &error, mdio->md_type); | ||||
else { | else { | ||||
if (mdio->md_unit > INT_MAX) | if (mdio->md_unit > INT_MAX) | ||||
return (EINVAL); | return (EINVAL); | ||||
sc = mdnew(mdio->md_unit, &error, mdio->md_type); | sc = mdnew(mdio->md_unit, &error, mdio->md_type); | ||||
} | } | ||||
if (sc == NULL) | if (sc == NULL) | ||||
return (error); | return (error); | ||||
if (mdio->md_label != NULL) | |||||
error = copyinstr(mdio->md_label, sc->label, | |||||
sizeof(sc->label), NULL); | |||||
if (error != 0) | |||||
goto err_after_new; | |||||
if (mdio->md_options & MD_AUTOUNIT) | if (mdio->md_options & MD_AUTOUNIT) | ||||
mdio->md_unit = sc->unit; | mdio->md_unit = sc->unit; | ||||
sc->mediasize = mdio->md_mediasize; | sc->mediasize = mdio->md_mediasize; | ||||
sc->sectorsize = sectsize; | sc->sectorsize = sectsize; | ||||
error = EDOOFUS; | error = EDOOFUS; | ||||
switch (sc->type) { | switch (sc->type) { | ||||
case MD_MALLOC: | case MD_MALLOC: | ||||
sc->start = mdstart_malloc; | sc->start = mdstart_malloc; | ||||
Show All 15 Lines | case MD_SWAP: | ||||
sc->start = mdstart_swap; | sc->start = mdstart_swap; | ||||
error = mdcreate_swap(sc, mdio, td); | error = mdcreate_swap(sc, mdio, td); | ||||
break; | break; | ||||
case MD_NULL: | case MD_NULL: | ||||
sc->start = mdstart_null; | sc->start = mdstart_null; | ||||
error = mdcreate_null(sc, mdio, td); | error = mdcreate_null(sc, mdio, td); | ||||
break; | break; | ||||
} | } | ||||
err_after_new: | |||||
if (error != 0) { | if (error != 0) { | ||||
mddestroy(sc, td); | mddestroy(sc, td); | ||||
return (error); | return (error); | ||||
} | } | ||||
/* Prune off any residual fractional sector */ | /* Prune off any residual fractional sector */ | ||||
i = sc->mediasize % sc->sectorsize; | i = sc->mediasize % sc->sectorsize; | ||||
sc->mediasize -= i; | sc->mediasize -= i; | ||||
Show All 29 Lines | err_after_new: | ||||
case MDIOCQUERY: | case MDIOCQUERY: | ||||
sc = mdfind(mdio->md_unit); | sc = mdfind(mdio->md_unit); | ||||
if (sc == NULL) | if (sc == NULL) | ||||
return (ENOENT); | return (ENOENT); | ||||
mdio->md_type = sc->type; | mdio->md_type = sc->type; | ||||
mdio->md_options = sc->flags; | mdio->md_options = sc->flags; | ||||
mdio->md_mediasize = sc->mediasize; | mdio->md_mediasize = sc->mediasize; | ||||
mdio->md_sectorsize = sc->sectorsize; | mdio->md_sectorsize = sc->sectorsize; | ||||
error = 0; | |||||
if (mdio->md_label != NULL) { | |||||
error = copyout(sc->label, mdio->md_label, | |||||
strlen(sc->label) + 1); | |||||
} | |||||
rpokala: I think you want `copystr()`. | |||||
sobomaxAuthorUnsubmitted Not Done Inline ActionsAre you sure? Reading copystr(8): DESCRIPTION The copy functions are designed to copy contiguous data from one address to another. All but copystr() copy data from user-space to kernel-space or vice-versa. ... The copystr() function copies a NUL-terminated string, at most len bytes long, from kernel-space address kfaddr to kernel-space address kdaddr. The number of bytes actually copied, including the terminating NUL, is returned in *done (if done is non-NULL). sobomax: Are you sure? Reading copystr(8):
```
DESCRIPTION
The copy functions are designed to copy… | |||||
rpokalaUnsubmitted Not Done Inline ActionsYou're right. I need new glasses. :-p rpokala: You're right. I need new glasses. :-p | |||||
if (sc->type == MD_VNODE || | if (sc->type == MD_VNODE || | ||||
(sc->type == MD_PRELOAD && mdio->md_file != NULL)) | (sc->type == MD_PRELOAD && mdio->md_file != NULL)) | ||||
error = copyout(sc->file, mdio->md_file, | error = copyout(sc->file, mdio->md_file, | ||||
strlen(sc->file) + 1); | strlen(sc->file) + 1); | ||||
return (error); | return (error); | ||||
case MDIOCLIST: | case MDIOCLIST: | ||||
i = 1; | i = 1; | ||||
LIST_FOREACH(sc, &md_softc_list, list) { | LIST_FOREACH(sc, &md_softc_list, list) { | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | if (indent == NULL) { | ||||
sbuf_printf(sb, " s %ju", (uintmax_t) mp->sectorsize); | sbuf_printf(sb, " s %ju", (uintmax_t) mp->sectorsize); | ||||
sbuf_printf(sb, " f %ju", (uintmax_t) mp->fwheads); | sbuf_printf(sb, " f %ju", (uintmax_t) mp->fwheads); | ||||
sbuf_printf(sb, " fs %ju", (uintmax_t) mp->fwsectors); | sbuf_printf(sb, " fs %ju", (uintmax_t) mp->fwsectors); | ||||
sbuf_printf(sb, " l %ju", (uintmax_t) mp->mediasize); | sbuf_printf(sb, " l %ju", (uintmax_t) mp->mediasize); | ||||
sbuf_printf(sb, " t %s", type); | sbuf_printf(sb, " t %s", type); | ||||
if ((mp->type == MD_VNODE && mp->vnode != NULL) || | if ((mp->type == MD_VNODE && mp->vnode != NULL) || | ||||
(mp->type == MD_PRELOAD && mp->file[0] != '\0')) | (mp->type == MD_PRELOAD && mp->file[0] != '\0')) | ||||
sbuf_printf(sb, " file %s", mp->file); | sbuf_printf(sb, " file %s", mp->file); | ||||
sbuf_printf(sb, " label %s", mp->label); | |||||
} else { | } else { | ||||
sbuf_printf(sb, "%s<unit>%d</unit>\n", indent, | sbuf_printf(sb, "%s<unit>%d</unit>\n", indent, | ||||
mp->unit); | mp->unit); | ||||
sbuf_printf(sb, "%s<sectorsize>%ju</sectorsize>\n", | sbuf_printf(sb, "%s<sectorsize>%ju</sectorsize>\n", | ||||
indent, (uintmax_t) mp->sectorsize); | indent, (uintmax_t) mp->sectorsize); | ||||
sbuf_printf(sb, "%s<fwheads>%ju</fwheads>\n", | sbuf_printf(sb, "%s<fwheads>%ju</fwheads>\n", | ||||
indent, (uintmax_t) mp->fwheads); | indent, (uintmax_t) mp->fwheads); | ||||
sbuf_printf(sb, "%s<fwsectors>%ju</fwsectors>\n", | sbuf_printf(sb, "%s<fwsectors>%ju</fwsectors>\n", | ||||
indent, (uintmax_t) mp->fwsectors); | indent, (uintmax_t) mp->fwsectors); | ||||
sbuf_printf(sb, "%s<length>%ju</length>\n", | sbuf_printf(sb, "%s<length>%ju</length>\n", | ||||
indent, (uintmax_t) mp->mediasize); | indent, (uintmax_t) mp->mediasize); | ||||
sbuf_printf(sb, "%s<compression>%s</compression>\n", indent, | sbuf_printf(sb, "%s<compression>%s</compression>\n", indent, | ||||
(mp->flags & MD_COMPRESS) == 0 ? "off": "on"); | (mp->flags & MD_COMPRESS) == 0 ? "off": "on"); | ||||
sbuf_printf(sb, "%s<access>%s</access>\n", indent, | sbuf_printf(sb, "%s<access>%s</access>\n", indent, | ||||
(mp->flags & MD_READONLY) == 0 ? "read-write": | (mp->flags & MD_READONLY) == 0 ? "read-write": | ||||
"read-only"); | "read-only"); | ||||
sbuf_printf(sb, "%s<type>%s</type>\n", indent, | sbuf_printf(sb, "%s<type>%s</type>\n", indent, | ||||
type); | type); | ||||
if ((mp->type == MD_VNODE && mp->vnode != NULL) || | if ((mp->type == MD_VNODE && mp->vnode != NULL) || | ||||
(mp->type == MD_PRELOAD && mp->file[0] != '\0')) { | (mp->type == MD_PRELOAD && mp->file[0] != '\0')) { | ||||
sbuf_printf(sb, "%s<file>", indent); | sbuf_printf(sb, "%s<file>", indent); | ||||
g_conf_printf_escaped(sb, "%s", mp->file); | g_conf_printf_escaped(sb, "%s", mp->file); | ||||
sbuf_printf(sb, "</file>\n"); | sbuf_printf(sb, "</file>\n"); | ||||
} | } | ||||
sbuf_printf(sb, "%s<label>", indent); | |||||
g_conf_printf_escaped(sb, "%s", mp->label); | |||||
sbuf_printf(sb, "</label>\n"); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
g_md_fini(struct g_class *mp __unused) | g_md_fini(struct g_class *mp __unused) | ||||
{ | { | ||||
sx_destroy(&md_sx); | sx_destroy(&md_sx); | ||||
if (status_dev != NULL) | if (status_dev != NULL) | ||||
destroy_dev(status_dev); | destroy_dev(status_dev); | ||||
delete_unrhdr(md_uh); | delete_unrhdr(md_uh); | ||||
} | } |
I think you want copystr().