- 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
This commit is contained in:
Pawel Jakub Dawidek 2007-05-05 16:33:44 +00:00
parent 63afe606f8
commit d19dbf4a23
2 changed files with 23 additions and 7 deletions

View File

@ -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, ...);

View File

@ -789,21 +789,36 @@ g_handleattr_off_t(struct bio *bp, const char *attribute, off_t val)
return (g_handleattr(bp, attribute, &val, sizeof 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);