So I'm working on a fairly stripped down custom linux build at my job. I'm trying to discover a way to get the UUID's of the harddrive and zram partitions using C.
First of all, are you aware that there are UUIDs for both partitions and for filesystems? Neither is always present. Linux itself does not know about UUIDs, the entire concept is handled in user-space by programs installed on your system, and these programs all use libblkid, as far as I know.
You say that you want partition UUIDs, but you probably actually want filesystem UUIDs.
Sorry, but when you say that "libblkid isn't available", what does that even mean? I am a bit skeptical. Libblkid is open source and free software, after all, so if you don't have a copy of libblkid it is trivial to get one. Libblkid is also written in C, and you're already writing code in C, so you must have a C compiler around to compile libblkid. You can make a static version of it if necessary.
The main way libblkid works is by reading data directly from block devices. For disks, this means reading the partition table. For filesystems, this means reading from the filesystem superblock. Theoretically, if you can't use libblkid (which is highly unusual, even for stripped-down systems) you can parse the partition table or superblock yourself.
Libblkid does use a cache file at
/etc/blkid.tab but this is just a cache and it is not necessary.
Other interfaces to UUIDs, like
/dev/disk/by-uuid, are created in user-space by programs which use libblkid.
Normally, if you are talking about the UUIDs you see in
/dev/disk/by-uuid, which are the same UUIDs you use in
/etc/fstab, you are talking about the filesystem UUID. The libblkid library does the hard work of decoding the superblocks for a wide array of filesystems. You can see, for example, the UUID for Ext2 filesystems appear in libblkid src/superblocks/ext.c line 48. Libblkid supports many filesystem types and you can see them in the
Not all filesystem types have UUIDs. Ext2 has a UUID, FAT32 does not, but it has a different ID which serves the same purpose.
If you really need the unique partition UUID, you can also get that. Libblkid reads this out of the partition table. Only certain types of partition tables have UUIDs for partitions at all. GPT does, but DOS partition tables do not.