libblkid: detect session_offset hint for optical discs

When offset and session_offset hint are not specified then sets
session_offset hint from CDROMMULTISESSION ioctl which returns start
position of the last session of multisession optical disc.

It is expected that session_offset hint contains position offset in bytes
where starts session of multisession optical disc which should be read.

Filesystems designed for optical discs are expected to use this value when
dealing with multisession optical disc to know where they should start
reading optical disc or image of optical disc.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
This commit is contained in:
Pali Rohár 2020-11-05 19:21:15 +01:00
parent bfd4da5628
commit 427ea35512
1 changed files with 8 additions and 0 deletions

View File

@ -983,6 +983,14 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
if (pr->flags & BLKID_FL_CDROM_DEV) {
cdrom_size_correction(pr, last_written);
# ifdef CDROMMULTISESSION
if (!pr->off && blkid_probe_get_hint(pr, "session_offset", NULL) < 0) {
struct cdrom_multisession multisession = { .addr_format = CDROM_LBA };
if (ioctl(fd, CDROMMULTISESSION, &multisession) == 0 && multisession.xa_flag)
blkid_probe_set_hint(pr, "session_offset", (multisession.addr.lba << 11));
}
# endif
}
}
#endif