3

Linux block devices in sysfs have a capability file, partly documented here. Well, one is documented.

Looking in genhd.h as it suggests, there are others. Is there any documentation on them, or does anyone know what they mean?

Listed here for convenience:

  • GENHD_FL_REMOVABLE
  • GENHD_FL_CD
  • GENHD_FL_UP
  • GENHD_FL_SUPPRESS_PARTITION_INFO
  • GENHD_FL_EXT_DEVT
  • GENHD_FL_NATIVE_CAPACITY
  • GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE
  • GENHD_FL_NO_PART_SCAN
  • GENHD_FL_HIDDEN

More specifically,

Removable? Like removable USB drives? Relation to /sys/block/*/removable? Redundant?

Whats extended devt?

suppress partitions?

no part scan? Different from suppressing partitions?

UP?

CD? Like "this is a CD drive"? Why? Means something else?

Native capacity?

6
  • There doesn't seem to be any documentation, you'll have to read the source code. For *_CD is clear that it's "cd-like", for *_UP it means alive (just like with a network interface), *_SUPPRESS_PARTITION_INFO means they won't appear in /proc/partitions, etc.
    – user313992
    Commented Feb 29, 2020 at 5:49
  • 1
    *_FL_REMOVABLE is defined in a comment from drivers/mmc/core/block.c: "As discussed on lkml, GENHD_FL_REMOVABLE should: - be set for removable media with permanent block devices - be unset for removable block devices with permanent media".
    – user313992
    Commented Feb 29, 2020 at 5:51
  • I'm asking here because I myself don't have the time nor skill to inspect and understand how they all might be used throughout Linux or what they mean.
    – Linux User
    Commented Feb 29, 2020 at 15:19
  • Do you happen to know what "CD-like" means for block devices? What makes them so different from others they need a special flag?
    – Linux User
    Commented Feb 29, 2020 at 15:19
  • Do you happen to know how/where _SUPPRESS_PARTITION_INFO is set? Is this something userspace can control?
    – Linux User
    Commented Feb 29, 2020 at 15:20

1 Answer 1

5

Starting with kernel 6.3, the capability file is deprecated and always indicates 0.

At the time the question was asked, the only documented flag wasn’t used any more! The others had the following meaning:

  • GENHD_FL_REMOVABLE: the block device provides access to removable media. The block device doesn’t appear or disappear depending on the availability of media. This is appropriate for example for CD-ROM drives (the block device is always present), but not for devices which behave like USB storage (where the block device is only present as long as the drive is connected).
  • GENHD_FL_CD: the block device is a CD-ROM-style device. Affects responses to the CDROM_GET_CAPABILITY ioctl.
  • GENHD_FL_UP: indicates that the block device is “up”, with a similar meaning to network interfaces. This is mostly used for synchronisation with other block device subsystems, to avoid races on removal.
  • GENHD_FL_SUPPRESS_PARTITION_INFO: don’t include partition information in /proc/partitions or in the output of printk_all_partitions() (as shown in the kernel logs). Used for the null block device and some MMC devices.
  • GENHD_FL_EXT_DEVT: the driver supports extended dynamic dev_t, i.e. it wants extended device numbers (BLOCK_EXT_MAJOR, block major 259). This affects the maximum number of partitions.
  • GENHD_FL_NATIVE_CAPACITY: based on information in the partition table, the device’s capacity has been extended to its native capacity; i.e. the device has hidden capacity used by one of the partitions (this is a flag used so that native capacity is only ever unlocked once). This could happen for example if a drive is partitioned, then has a host-protected area created which covers part of a partition.
  • GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE: event polling is blocked whenever a writer holds an exclusive lock.
  • GENHD_FL_NO_PART_SCAN: partition scanning is disabled. Used for loop devices in their default settings and some MMC devices.
  • GENHD_FL_HIDDEN: the block device is hidden; it doesn’t produce events, doesn’t appear in sysfs, and doesn’t have an associated bdev. Implies GENHD_FL_SUPPRESS_PARTITION_INFO and GENHD_FL_NO_PART_SCAN. Used for multipath devices.

Most of these have since been removed, or moved to more appropriate locations; only GENHD_FL_REMOVABLE, GENHD_FL_HIDDEN and GENHD_FL_NO_PART remain (GENHD_FL_NO_PART_SCAN was renamed to GENHD_FL_NO_PART and indicates that the device does not support partitions).

7
  • I can see _REMOVABLE being useful, but then how do you detect whether theres actually anything in it or not? Do you just have to try and fail to read the device file? I hope not, since that would require root.
    – Linux User
    Commented Mar 4, 2020 at 16:12
  • 1
    Yes, you’d try opening it, and handle the resulting ENOMEDIUM. If you don’t have the privileges required to read the device, it makes no difference whether there’s media or not, because you wouldn’t be able to act on it ;-). If the system can act on it on your behalf (e.g. mounting a device through your desktop environment), the part that does so is supposed to act sensibly. Commented Mar 4, 2020 at 16:14
  • Thats.. disappointing. What about the size file in sysfs? Would that report 0 in this case maybe? I'd check myself but don't have a CD drive. It's useful to know even without privileges to get some basic info on connected devices, like size and existence.
    – Linux User
    Commented Mar 4, 2020 at 16:15
  • 1
    Apparently not, my CD drive’s size entry is non-zero even though there’s no CD in the drive. Commented Mar 4, 2020 at 16:16
  • What size does it report? Maybe It's a sentinel or some integers max value?
    – Linux User
    Commented Mar 4, 2020 at 16:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .