How to find out in / sys / class the file system type of a non-mounted disk?
- 1. probably meant not a disk, but a disk partition. 2. Probably nothing. Why is this information in this pseudo-file system? - aleksandr barakin
- oneA blkid not help the father of Russian democracy? - don Rumata
- @donRumata I suspect that a friend from his application wants to monitor the state of the file system, and here it’s safer to read sysFS rather than rely on the presence of the utility. - dsnk am
- @dsnk is so accurate, parsing sysfs is more reliable. - elan
- Well, then what is the reason why this blkid doesn’t look? If she knows how to see unmounted FS, then this is somewhere in the code. - don Rumata
|
2 answers
You can get the file system name with blkid.h
Example:
QString type; const char *gettype; blkid_probe pr = blkid_new_probe_from_filename("/dev/sda1"); pr = blkid_new_probe_from_filename("/dev/sda1"); blkid_do_probe(pr); blkid_probe_lookup_value(pr, "TYPE", &gettype, NULL); type = gettype; blkid_free_probe(pr); return type;
|
The linux program, as far as I know, is not engaged in identifying file systems "for emergency," that is, on non-mounted block devices. therefore, it does not provide this information from the sysfs pseudo-file system.
A confirmation can be a call to the blkid program, which (in particular) identifies file systems on non-mounted block devices.
judging by the output of the command (only the essential lines are left):
$ sudo strace -e open blkid open("/dev/sr0", O_RDONLY) = -1 ENOMEDIUM (No medium found) open("/dev/sda1", O_RDONLY) = 4 open("/dev/sda5", O_RDONLY) = 4 open("/dev/sdb1", O_RDONLY) = 4
each time the program starts, it reads information directly from partitions, probably identifying (possibly) the file systems located on the partitions.
|