Il 02/01/2014 19:23, Nathan Whitehorn ha scritto: >>> Let me try to grasp what you're doing here. You're trying to >>> figure out how many devices there are attached to the bus. For >>> every device you reserve a buffer block. Lun0 is mandatory, all >>> others are optional. >>> >>> First off, I think the code would be easier to grasp if you'd >>> count "number of entries" rather than "number of bytes". That way >>> we don't have to mentally deal with the 8 byte block >>> granularity. >>> >>> Then IIUC you're jumping through a lot of hoops to count lun0 if >>> it's there, but keep it reserved when it's not there. Why don't >>> you just always reserve entry 0 for lun0? In the loop where >>> you're actually filling in data you just skip lun0. Or is lun0 a >>> terminator and always has to come last?
This is simply because you should not report lun 0 twice; even if it is not defined, LUN 0 is there as a dummy device that only answers a handful of commands (including INQUIRY and REPORT LUNS). There are many ways to write it, but unless you use GArray or something like that, it will look very much like Nathan and hw/scsi/scsi-bus.c's code. Paolo