Rusty Russell wrote: > On Tue, 22 Jun 2010 02:13:21 am Ryan Harper wrote: >> * john cooper <john.cooper@xxxxxxxxxx> [2010-06-21 01:11]: >>> Rusty Russell wrote: >>>> /* id_str is not necessarily nul-terminated! */ >>>> buf[VIRTIO_BLK_ID_BYTES] = '\0'; >>>> return virtblk_get_id(disk, buf); >>> The /sys file is rendered according to the length >>> returned from this function and the trailing nul >>> is not interpreted in this context. In fact if a >>> nul is added and included in the byte count of the >>> string it will appear in the /sys file. >> Yeah; I like the simplicity; but we do need to know how long the string >> is so we can return that value. > > So we're looking at something like: > > /* id_str is not necessarily nul-terminated! */ > buf[VIRTIO_BLK_ID_BYTES] = '\0'; > err = virtblk_get_id(disk, buf); > if (!err) > return strlen(buf); > if (err == -EIO) /* Unsupported? Make it empty. */ > return 0; > return err; In my haste reading your prior mail, I'd glossed over the fact you were copying direct to the sysfs buf. So in retrospect that (and the above) do make sense. Thanks, -john -- john.cooper@xxxxxxxxxx -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html