aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorWuyang Chung <wy-chung@outlook.com>2025-07-23 09:41:34 +0000
committerWarner Losh <imp@FreeBSD.org>2025-09-05 18:42:21 +0000
commit1167a7d065f8a6265cc8e28025944a2f848e3a7e (patch)
treee263726b6544e05acb8a6a217e1180bea7a4dba2 /sys
parent89ff06870840b99df70afd56058df7ee2b300474 (diff)
Diffstat (limited to 'sys')
-rw-r--r--sys/geom/geom.h5
-rw-r--r--sys/geom/geom_subr.c33
2 files changed, 25 insertions, 13 deletions
diff --git a/sys/geom/geom.h b/sys/geom/geom.h
index 908ce86f03a6..50e6627b0157 100644
--- a/sys/geom/geom.h
+++ b/sys/geom/geom.h
@@ -289,8 +289,9 @@ int g_handleattr_int(struct bio *bp, const char *attribute, int val);
int g_handleattr_off_t(struct bio *bp, const char *attribute, off_t val);
int g_handleattr_uint16_t(struct bio *bp, const char *attribute, uint16_t val);
int g_handleattr_str(struct bio *bp, const char *attribute, const char *str);
-struct g_consumer * g_new_consumer(struct g_geom *gp);
-struct g_geom * g_new_geomf(struct g_class *mp, const char *fmt, ...)
+struct g_consumer *g_new_consumer(struct g_geom *gp);
+struct g_geom *g_new_geom(struct g_class *mp, const char *name);
+struct g_geom *g_new_geomf(struct g_class *mp, const char *fmt, ...)
__printflike(2, 3);
struct g_provider * g_new_providerf(struct g_geom *gp, const char *fmt, ...)
__printflike(2, 3);
diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c
index 1429c84942ed..2a6ce1ab6486 100644
--- a/sys/geom/geom_subr.c
+++ b/sys/geom/geom_subr.c
@@ -368,20 +368,15 @@ g_retaste(struct g_class *mp)
}
struct g_geom *
-g_new_geomf(struct g_class *mp, const char *fmt, ...)
+g_new_geom(struct g_class *mp, const char *name)
{
+ int len;
struct g_geom *gp;
- va_list ap;
- struct sbuf *sb;
g_topology_assert();
G_VALID_CLASS(mp);
- sb = sbuf_new_auto();
- va_start(ap, fmt);
- sbuf_vprintf(sb, fmt, ap);
- va_end(ap);
- sbuf_finish(sb);
- gp = g_malloc(sizeof(*gp) + sbuf_len(sb) + 1, M_WAITOK | M_ZERO);
+ len = strlen(name);
+ gp = g_malloc(sizeof(*gp) + len + 1, M_WAITOK | M_ZERO);
gp->name = (char *)(gp + 1);
gp->class = mp;
gp->rank = 1;
@@ -389,8 +384,7 @@ g_new_geomf(struct g_class *mp, const char *fmt, ...)
LIST_INIT(&gp->provider);
LIST_INSERT_HEAD(&mp->geom, gp, geom);
TAILQ_INSERT_HEAD(&geoms, gp, geoms);
- strcpy(gp->name, sbuf_data(sb));
- sbuf_delete(sb);
+ memcpy(gp->name, name, len);
/* Fill in defaults from class */
gp->start = mp->start;
gp->spoiled = mp->spoiled;
@@ -404,6 +398,23 @@ g_new_geomf(struct g_class *mp, const char *fmt, ...)
return (gp);
}
+struct g_geom *
+g_new_geomf(struct g_class *mp, const char *fmt, ...)
+{
+ struct g_geom *gp;
+ va_list ap;
+ struct sbuf *sb;
+
+ sb = sbuf_new_auto();
+ va_start(ap, fmt);
+ sbuf_vprintf(sb, fmt, ap);
+ va_end(ap);
+ sbuf_finish(sb);
+ gp = g_new_geom(mp, sbuf_data(sb));
+ sbuf_delete(sb);
+ return (gp);
+}
+
void
g_destroy_geom(struct g_geom *gp)
{