mirror of
https://github.com/systemd/systemd
synced 2024-09-06 16:56:43 +00:00
cdrom_id: unroll and simplify data check loop
also removes this warning: src/udev/cdrom_id/cdrom_id.c: In function ‘cd_media_info.isra.13’: src/udev/cdrom_id/cdrom_id.c:612:12: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow] static int cd_media_info(struct udev *udev, int fd) ^
This commit is contained in:
parent
a7f7d1bde4
commit
cb80d06c74
|
@ -650,8 +650,8 @@ static int cd_media_info(struct udev *udev, int fd)
|
|||
* write protected; we need to check the contents if it is blank */
|
||||
if ((cd_media_dvd_rw_ro || cd_media_dvd_plus_rw || cd_media_dvd_plus_rw_dl || cd_media_dvd_ram) && (header[2] & 3) > 1) {
|
||||
unsigned char buffer[32 * 2048];
|
||||
unsigned char result, len;
|
||||
int block, offset;
|
||||
unsigned char len;
|
||||
int offset;
|
||||
|
||||
if (cd_media_dvd_ram) {
|
||||
/* a write protected dvd-ram may report "complete" status */
|
||||
|
@ -732,22 +732,23 @@ static int cd_media_info(struct udev *udev, int fd)
|
|||
/* if any non-zero data is found in sector 16 (iso and udf) or
|
||||
* eventually 0 (fat32 boot sector, ext2 superblock, etc), disc
|
||||
* is assumed non-blank */
|
||||
result = 0;
|
||||
|
||||
for (block = 32768; block >= 0 && !result; block -= 32768) {
|
||||
offset = block;
|
||||
while (offset < (block + 2048) && !result) {
|
||||
result = buffer [offset];
|
||||
offset++;
|
||||
for (offset = 32768; offset < (32768 + 2048); offset++) {
|
||||
if (buffer [offset]) {
|
||||
log_debug("data in block 16, assuming complete");
|
||||
goto determined;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
cd_media_state = media_status[0];
|
||||
log_debug("no data in blocks 0 or 16, assuming blank");
|
||||
} else {
|
||||
log_debug("data in blocks 0 or 16, assuming complete");
|
||||
for (offset = 0; offset < 2048; offset++) {
|
||||
if (buffer [offset]) {
|
||||
log_debug("data in block 0, assuming complete");
|
||||
goto determined;
|
||||
}
|
||||
}
|
||||
|
||||
cd_media_state = media_status[0];
|
||||
log_debug("no data in blocks 0 or 16, assuming blank");
|
||||
}
|
||||
|
||||
determined:
|
||||
|
|
Loading…
Reference in a new issue