diff options
author | pjd <pjd@FreeBSD.org> | 2007-05-05 16:33:44 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2007-05-05 16:33:44 +0000 |
commit | ddfa2416f5fd67d07e1e660be1dbdc2e15598197 (patch) | |
tree | 69cba8c95e8d486ed7c759b9c314766689054403 | |
parent | 85b1cff269c7329345338a7c9bbed1d6d4b18bce (diff) | |
download | FreeBSD-src-ddfa2416f5fd67d07e1e660be1dbdc2e15598197.zip FreeBSD-src-ddfa2416f5fd67d07e1e660be1dbdc2e15598197.tar.gz |
- Implement helper g_handleattr_str() function for string attributes
handling.
- Extend g_handleattr() to treat attribute as string when len=0.
OK'ed by: phk
-rw-r--r-- | sys/geom/geom.h | 1 | ||||
-rw-r--r-- | sys/geom/geom_subr.c | 29 |
2 files changed, 23 insertions, 7 deletions
diff --git a/sys/geom/geom.h b/sys/geom/geom.h index 4d7c5b8..eb9b595 100644 --- a/sys/geom/geom.h +++ b/sys/geom/geom.h @@ -230,6 +230,7 @@ int g_getattr__(const char *attr, struct g_consumer *cp, void *var, int len); int g_handleattr(struct bio *bp, const char *attribute, void *val, int len); 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_str(struct bio *bp, const char *attribute, 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_provider * g_new_providerf(struct g_geom *gp, const char *fmt, ...); diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c index eec44c3..1c0b3a4 100644 --- a/sys/geom/geom_subr.c +++ b/sys/geom/geom_subr.c @@ -790,20 +790,35 @@ g_handleattr_off_t(struct bio *bp, const char *attribute, off_t val) } int +g_handleattr_str(struct bio *bp, const char *attribute, char *str) +{ + + return (g_handleattr(bp, attribute, str, 0)); +} + +int g_handleattr(struct bio *bp, const char *attribute, void *val, int len) { - int error; + int error = 0; if (strcmp(bp->bio_attribute, attribute)) return (0); - if (bp->bio_length != len) { - printf("bio_length %jd len %d -> EFAULT\n", - (intmax_t)bp->bio_length, len); - error = EFAULT; - } else { - error = 0; + if (len == 0) { + bzero(bp->bio_data, bp->bio_length); + if (strlcpy(bp->bio_data, val, bp->bio_length) >= + bp->bio_length) { + printf("%s: %s bio_length %jd len %zu -> EFAULT\n", + __func__, bp->bio_to->name, + (intmax_t)bp->bio_length, strlen(val)); + error = EFAULT; + } + } else if (bp->bio_length == len) { bcopy(val, bp->bio_data, len); bp->bio_completed = len; + } else { + printf("%s: %s bio_length %jd len %d -> EFAULT\n", __func__, + bp->bio_to->name, (intmax_t)bp->bio_length, len); + error = EFAULT; } g_io_deliver(bp, error); return (1); |