- off_t ext_start = lseek (fd, 0, SEEK_DATA);
- if (0 <= ext_start || errno == ENXIO)
+ scan_inference->ext_start = lseek (fd, 0, SEEK_DATA);
+ if (scan_inference->ext_start == 0)
+ {
+ scan_inference->hole_start = lseek (fd, 0, SEEK_HOLE);
+ if (0 <= scan_inference->hole_start)
+ {
+ if (scan_inference->hole_start < sb->st_size)
+ return LSEEK_SCANTYPE;
+
+ /* Though the file likely has holes, SEEK_DATA and SEEK_HOLE
+ didn't find any. This can happen with file systems like
+ circa-2025 squashfs that support SEEK_HOLE only trivially.
+ Fall back on ZERO_SCANTYPE. */
+ if (lseek (fd, 0, SEEK_SET) < 0)
+ return ERROR_SCANTYPE;
+ }
+ }
+ else if (0 < scan_inference->ext_start || errno == ENXIO)