* 'fssize' of https://github.com/t-8ch/util-linux:
  libblkid: iso9660: read block size from superblock
  iso9660.h: avoid undefined signed integer shift
  iso9660.h: use more correct function types
  libblkid: ntfs: report fssize
  libblkid: ubifs: report fssize
  libblkid: f2fs: report fssize
  libblkid: erofs: report fssize
  libblkid: vfat: report fssize
This commit is contained in:
Karel Zak 2022-12-21 10:15:07 +01:00
commit adcfe57a7e
42 changed files with 82 additions and 27 deletions

View file

@ -2,25 +2,26 @@
#define UTIL_LINUX_ISO_H
#include <stdbool.h>
#include <stdint.h>
#include "c.h"
static inline int isonum_721(unsigned char *p)
static inline uint16_t isonum_721(const unsigned char *p)
{
return ((p[0] & 0xff)
| ((p[1] & 0xff) << 8));
}
static inline int isonum_722(unsigned char *p)
static inline uint16_t isonum_722(const unsigned char *p)
{
return ((p[1] & 0xff)
| ((p[0] & 0xff) << 8));
}
static inline int isonum_723(unsigned char *p, bool check_match)
static inline uint16_t isonum_723(const unsigned char *p, bool check_match)
{
int le = isonum_721(p);
int be = isonum_722(p + 2);
uint16_t le = isonum_721(p);
uint16_t be = isonum_722(p + 2);
if (check_match && le != be)
/* translation is useless */
@ -28,26 +29,26 @@ static inline int isonum_723(unsigned char *p, bool check_match)
return (le);
}
static inline int isonum_731(unsigned char *p)
static inline uint32_t isonum_731(const unsigned char *p)
{
return ((p[0] & 0xff)
| ((p[1] & 0xff) << 8)
| ((p[2] & 0xff) << 16)
| ((p[3] & 0xff) << 24));
| (((uint32_t) p[3] & 0xff) << 24));
}
static inline int isonum_732(unsigned char *p)
static inline uint32_t isonum_732(const unsigned char *p)
{
return ((p[3] & 0xff)
| ((p[2] & 0xff) << 8)
| ((p[1] & 0xff) << 16)
| ((p[0] & 0xff) << 24));
| (((uint32_t) p[0] & 0xff) << 24));
}
static inline int isonum_733(unsigned char *p, bool check_match)
static inline uint32_t isonum_733(const unsigned char *p, bool check_match)
{
int le = isonum_731(p);
int be = isonum_732(p + 4);
uint32_t le = isonum_731(p);
uint32_t be = isonum_732(p + 4);
if (check_match && le != be)
/* translation is useless */

View file

@ -86,6 +86,7 @@ static int probe_erofs(blkid_probe pr, const struct blkid_idmag *mag)
blkid_probe_set_uuid(pr, sb->uuid);
blkid_probe_set_fsblocksize(pr, 1U << sb->blkszbits);
blkid_probe_set_block_size(pr, 1U << sb->blkszbits);
blkid_probe_set_fssize(pr, (uint64_t) (1U << sb->blkszbits) * le32_to_cpu(sb->blocks));
return BLKID_PROBE_OK;
}

View file

@ -110,8 +110,10 @@ static int probe_f2fs(blkid_probe pr, const struct blkid_idmag *mag)
blkid_probe_set_uuid(pr, sb->uuid);
blkid_probe_sprintf_version(pr, "%u.%u", vermaj, vermin);
if (le32_to_cpu(sb->log_blocksize) < 32){
blkid_probe_set_fsblocksize(pr, 1U << le32_to_cpu(sb->log_blocksize));
blkid_probe_set_block_size(pr, 1U << le32_to_cpu(sb->log_blocksize));
uint32_t blocksize = 1U << le32_to_cpu(sb->log_blocksize);
blkid_probe_set_fsblocksize(pr, blocksize);
blkid_probe_set_block_size(pr, blocksize);
blkid_probe_set_fssize(pr, le64_to_cpu(sb->block_count) * blocksize);
}
return 0;
}

View file

@ -20,6 +20,7 @@
#include "superblocks.h"
#include "cctype.h"
#include "iso9660.h"
struct iso9660_date {
unsigned char year[4];
@ -43,12 +44,14 @@ struct iso_volume_descriptor {
unsigned char unused[8];
unsigned char space_size[8];
unsigned char escape_sequences[8];
unsigned char unused2[94];
unsigned char unused2[32];
unsigned char logical_block_size[4];
unsigned char unused3[58];
unsigned char volume_set_id[128];
unsigned char publisher_id[128];
unsigned char data_preparer_id[128];
unsigned char application_id[128];
unsigned char unused3[111];
unsigned char unused4[111];
struct iso9660_date created;
struct iso9660_date modified;
} __attribute__((packed));
@ -253,8 +256,12 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag)
if (!pvd)
return errno ? -errno : 1;
blkid_probe_set_fsblocksize(pr, ISO_SECTOR_SIZE);
blkid_probe_set_block_size(pr, ISO_SECTOR_SIZE);
uint16_t logical_block_size = isonum_723(pvd->logical_block_size, true);
uint32_t space_size = isonum_733(pvd->space_size, true);
blkid_probe_set_fsblocksize(pr, logical_block_size);
blkid_probe_set_block_size(pr, logical_block_size);
blkid_probe_set_fssize(pr, (uint64_t) space_size * logical_block_size);
if (joliet && (len = merge_utf16be_ascii(buf, sizeof(buf), joliet->system_id, pvd->system_id, sizeof(pvd->system_id))) != 0)
blkid_probe_set_utf8_id_label(pr, "SYSTEM_ID", buf, len, UL_ENCODE_UTF16BE);

View file

@ -218,6 +218,7 @@ static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_
blkid_probe_set_fsblocksize(pr, sector_size * sectors_per_cluster);
blkid_probe_set_block_size(pr, sector_size);
blkid_probe_set_fssize(pr, le64_to_cpu(ns->number_of_sectors) * sector_size);
blkid_probe_sprintf_uuid(pr,
(unsigned char *) &ns->volume_serial,

View file

@ -118,6 +118,9 @@ static int probe_ubifs(blkid_probe pr, const struct blkid_idmag *mag)
blkid_probe_sprintf_version(pr, "w%dr%d",
le32_to_cpu(sb->fmt_version),
le32_to_cpu(sb->ro_compat_version));
blkid_probe_set_fssize(pr,
(uint64_t) le32_to_cpu(sb->leb_size)
* le32_to_cpu(sb->leb_cnt));
return 0;
}

View file

@ -185,10 +185,11 @@ static int fat_valid_superblock(blkid_probe pr,
const struct blkid_idmag *mag,
struct msdos_super_block *ms,
struct vfat_super_block *vs,
uint32_t *cluster_count, uint32_t *fat_size)
uint32_t *cluster_count, uint32_t *fat_size,
uint32_t *sect_count)
{
uint16_t sector_size, dir_entries, reserved;
uint32_t sect_count, __fat_size, dir_size, __cluster_count, fat_length;
uint32_t __sect_count, __fat_size, dir_size, __cluster_count, fat_length;
uint32_t max_count;
/* extra check for FATs without magic strings */
@ -230,10 +231,10 @@ static int fat_valid_superblock(blkid_probe pr,
dir_entries = unaligned_le16(&ms->ms_dir_entries);
reserved = le16_to_cpu(ms->ms_reserved);
sect_count = unaligned_le16(&ms->ms_sectors);
__sect_count = unaligned_le16(&ms->ms_sectors);
if (sect_count == 0)
sect_count = le32_to_cpu(ms->ms_total_sect);
if (__sect_count == 0)
__sect_count = le32_to_cpu(ms->ms_total_sect);
fat_length = le16_to_cpu(ms->ms_fat_length);
if (fat_length == 0)
@ -243,7 +244,7 @@ static int fat_valid_superblock(blkid_probe pr,
dir_size = ((dir_entries * sizeof(struct vfat_dir_entry)) +
(sector_size-1)) / sector_size;
__cluster_count = (sect_count - (reserved + __fat_size + dir_size)) /
__cluster_count = (__sect_count - (reserved + __fat_size + dir_size)) /
ms->ms_cluster_size;
if (!ms->ms_fat_length && vs->vs_fat32_length)
max_count = FAT32_MAX;
@ -257,6 +258,8 @@ static int fat_valid_superblock(blkid_probe pr,
*fat_size = __fat_size;
if (cluster_count)
*cluster_count = __cluster_count;
if (sect_count)
*sect_count = __sect_count;
if (blkid_probe_is_bitlocker(pr))
return 0;
@ -291,7 +294,7 @@ int blkid_probe_is_vfat(blkid_probe pr)
if (!vs)
return errno ? -errno : 0;
return fat_valid_superblock(pr, mag, ms, vs, NULL, NULL);
return fat_valid_superblock(pr, mag, ms, vs, NULL, NULL, NULL);
}
/* FAT label extraction from the root directory taken from Kay
@ -304,7 +307,7 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
const unsigned char *boot_label = NULL;
unsigned char *vol_serno = NULL, vol_label_buf[11];
uint16_t sector_size = 0, reserved;
uint32_t cluster_count, fat_size;
uint32_t cluster_count, fat_size, sect_count;
const char *version = NULL;
ms = blkid_probe_get_sb(pr, mag, struct msdos_super_block);
@ -315,7 +318,8 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
if (!vs)
return errno ? -errno : 1;
if (!fat_valid_superblock(pr, mag, ms, vs, &cluster_count, &fat_size))
if (!fat_valid_superblock(pr, mag, ms, vs, &cluster_count, &fat_size,
&sect_count))
return 1;
sector_size = unaligned_le16(&ms->ms_sector_size);
@ -435,6 +439,7 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
blkid_probe_set_fsblocksize(pr, vs->vs_cluster_size * sector_size);
blkid_probe_set_block_size(pr, sector_size);
blkid_probe_set_fssize(pr, (uint64_t) sector_size * sect_count);
return 0;
}

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=4096
ID_FS_FSBLOCKSIZE=4096
ID_FS_FSSIZE=4096
ID_FS_TYPE=erofs
ID_FS_USAGE=filesystem
ID_FS_UUID=2375febf-f260-479d-ade7-952494047cb4

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=4096
ID_FS_FSBLOCKSIZE=4096
ID_FS_FSSIZE=148897792
ID_FS_LABEL=test-f2fs
ID_FS_LABEL_ENC=test-f2fs
ID_FS_TYPE=f2fs

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=1474560
ID_FS_LABEL=TEST-FAT
ID_FS_LABEL_ENC=TEST-FAT
ID_FS_LABEL_FATBOOT=TEST-FAT

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=4096
ID_FS_FSSIZE=219898368
ID_FS_LABEL=VTech_1070
ID_FS_LABEL_ENC=VTech\x201070
ID_FS_SEC_TYPE=msdos

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=___
ID_FS_LABEL_ENC=\xe5\xe5\xe5
ID_FS_LABEL_FATBOOT=___

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=65454080
ID_FS_LABEL=BINGO
ID_FS_LABEL_ENC=BINGO
ID_FS_TYPE=vfat

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=label1
ID_FS_LABEL_ENC=label1
ID_FS_LABEL_FATBOOT=label1

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=NO_NAME
ID_FS_LABEL_ENC=NO\x20NAME
ID_FS_TYPE=vfat

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_FS_UUID=92B4-BA66

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=label2
ID_FS_LABEL_ENC=label2
ID_FS_LABEL_FATBOOT=label2

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=NO_NAME
ID_FS_LABEL_ENC=NO\x20NAME
ID_FS_TYPE=vfat

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_FS_UUID=92B4-BA66

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL_FATBOOT=label1
ID_FS_LABEL_FATBOOT_ENC=label1
ID_FS_TYPE=vfat

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=LABEL2
ID_FS_LABEL_ENC=LABEL2
ID_FS_LABEL_FATBOOT=label1

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_FS_UUID=E6B8-AF8C

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_FS_UUID=E6B8-AF8C

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL_FATBOOT=label1
ID_FS_LABEL_FATBOOT_ENC=label1
ID_FS_TYPE=vfat

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=LABEL2
ID_FS_LABEL_ENC=LABEL2
ID_FS_LABEL_FATBOOT=label1

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=LABEL1
ID_FS_LABEL_ENC=LABEL1
ID_FS_TYPE=vfat

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=label2
ID_FS_LABEL_ENC=label2
ID_FS_LABEL_FATBOOT=label2

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=LABEL1
ID_FS_LABEL_ENC=LABEL1
ID_FS_TYPE=vfat

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_FS_UUID=54B6-DC94

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL_FATBOOT=label1
ID_FS_LABEL_FATBOOT_ENC=label1
ID_FS_TYPE=vfat

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=34603008
ID_FS_LABEL=LABEL1
ID_FS_LABEL_ENC=LABEL1
ID_FS_LABEL_FATBOOT=LABEL1

View file

@ -1,6 +1,7 @@
ID_FS_APPLICATION_ID=GENISOIMAGE\x20ISO\x209660\x2fHFS\x20FILESYSTEM\x20CREATOR\x20\x28C\x29\x201993\x20E.YOUNGDALE\x20\x28C\x29\x201997-2006\x20J.PEARSON\x2fJ.SCHILLING\x20\x28C\x29\x202006-2007\x20CDRKIT\x20TEAM
ID_FS_BLOCK_SIZE=2048
ID_FS_FSBLOCKSIZE=2048
ID_FS_FSSIZE=438272
ID_FS_LABEL=IsoVolumeName
ID_FS_LABEL_ENC=IsoVolumeName
ID_FS_SYSTEM_ID=LINUX

View file

@ -2,6 +2,7 @@ ID_FS_APPLICATION_ID=Joliet\x20Application
ID_FS_BLOCK_SIZE=2048
ID_FS_DATA_PREPARER_ID=Joliet\x20Preparer
ID_FS_FSBLOCKSIZE=2048
ID_FS_FSSIZE=1228800
ID_FS_LABEL=Joliet_Label
ID_FS_LABEL_ENC=Joliet\x20Label
ID_FS_PUBLISHER_ID=Joliet\x20Publisher

View file

@ -1,6 +1,7 @@
ID_FS_APPLICATION_ID=GENISOIMAGE\x20ISO\x209660\x2fHFS\x20FILESYSTEM\x20CREATOR\x20\x28C\x29\x201993\x20E.YOUNGDALE\x20\x28C\x29\x201997-2006\x20J.PEARSON\x2fJ.SCHILLING\x20\x28C\x29\x202006-2007\x20CDRKIT\x20TEAM
ID_FS_BLOCK_SIZE=2048
ID_FS_FSBLOCKSIZE=2048
ID_FS_FSSIZE=450560
ID_FS_LABEL=ThisWonderfulLabelIsVeryVeryLong
ID_FS_LABEL_ENC=ThisWonderfulLabelIsVeryVeryLong
ID_FS_SYSTEM_ID=LINUX

View file

@ -1,6 +1,7 @@
ID_FS_APPLICATION_ID=GENISOIMAGE\x20ISO\x209660\x2fHFS\x20FILESYSTEM\x20CREATOR\x20\x28C\x29\x201993\x20E.YOUNGDALE\x20\x28C\x29\x201997-2006\x20J.PEARSON\x2fJ.SCHILLING\x20\x28C\x29\x202006-2007\x20CDRKIT\x20TEAM
ID_FS_BLOCK_SIZE=2048
ID_FS_FSBLOCKSIZE=2048
ID_FS_FSSIZE=356352
ID_FS_LABEL=first_session
ID_FS_LABEL_ENC=first\x20session
ID_FS_SYSTEM_ID=LINUX

View file

@ -1,6 +1,7 @@
ID_FS_APPLICATION_ID=GENISOIMAGE\x20ISO\x209660\x2fHFS\x20FILESYSTEM\x20CREATOR\x20\x28C\x29\x201993\x20E.YOUNGDALE\x20\x28C\x29\x201997-2006\x20J.PEARSON\x2fJ.SCHILLING\x20\x28C\x29\x202006-2007\x20CDRKIT\x20TEAM
ID_FS_BLOCK_SIZE=2048
ID_FS_FSBLOCKSIZE=2048
ID_FS_FSSIZE=356352
ID_FS_LABEL=second_session
ID_FS_LABEL_ENC=second\x20session
ID_FS_SYSTEM_ID=LINUX

View file

@ -1,6 +1,7 @@
ID_FS_APPLICATION_ID=GENISOIMAGE\x20ISO\x209660\x2fHFS\x20FILESYSTEM\x20CREATOR\x20\x28C\x29\x201993\x20E.YOUNGDALE\x20\x28C\x29\x201997-2006\x20J.PEARSON\x2fJ.SCHILLING\x20\x28C\x29\x202006-2007\x20CDRKIT\x20TEAM
ID_FS_BLOCK_SIZE=2048
ID_FS_FSBLOCKSIZE=2048
ID_FS_FSSIZE=356352
ID_FS_LABEL=third_session
ID_FS_LABEL_ENC=third\x20session
ID_FS_SYSTEM_ID=LINUX

View file

@ -1,6 +1,7 @@
ID_FS_APPLICATION_ID=GENISOIMAGE\x20ISO\x209660\x2fHFS\x20FILESYSTEM\x20CREATOR\x20\x28C\x29\x201993\x20E.YOUNGDALE\x20\x28C\x29\x201997-2006\x20J.PEARSON\x2fJ.SCHILLING\x20\x28C\x29\x202006-2007\x20CDRKIT\x20TEAM
ID_FS_BLOCK_SIZE=2048
ID_FS_FSBLOCKSIZE=2048
ID_FS_FSSIZE=452608
ID_FS_LABEL=ThisIsVolumeName
ID_FS_LABEL_ENC=ThisIsVolumeName
ID_FS_SYSTEM_ID=LINUX

View file

@ -2,6 +2,7 @@ ID_FS_APPLICATION_ID=Nero\x20Linux
ID_FS_BLOCK_SIZE=2048
ID_FS_DATA_PREPARER_ID=Naïve\x20and\x20very\x20looooooooooooooooooooooooooooooooooooooooooooooooOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG\x20DATA\x20PREPARER
ID_FS_FSBLOCKSIZE=2048
ID_FS_FSSIZE=1228800
ID_FS_LABEL=Naïve_and_very_lOOOOOOOONG_LABEL
ID_FS_LABEL_ENC=Naïve\x20and\x20very\x20lOOOOOOOONG_LABEL
ID_FS_PUBLISHER_ID=Naïve\x20and\x20very\x20looooooooooooooooooooooooooooooooooooooooooooooooOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG\x20PUBLISHER

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=4096
ID_FS_FSSIZE=10485248
ID_FS_LABEL=Новый_том
ID_FS_LABEL_ENC=Новый\x20том
ID_FS_TYPE=ntfs

View file

@ -1,5 +1,6 @@
ID_FS_BLOCK_SIZE=512
ID_FS_FSBLOCKSIZE=512
ID_FS_FSSIZE=1474560
ID_FS_LABEL=TESTVFAT
ID_FS_LABEL_ENC=TESTVFAT
ID_FS_LABEL_FATBOOT=TESTVFAT

View file

@ -1,3 +1,4 @@
ID_FS_FSSIZE=1703936
ID_FS_TYPE=ubifs
ID_FS_USAGE=filesystem
ID_FS_UUID=bafe46c2-5ed9-4405-8e81-7fc317fab8f0