- 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:
parent
63afe606f8
commit
d19dbf4a23
@ -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, ...);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user