This is the weirdest thing that I've ever seen (actually, it has a nice explanation).
I created a C code to list partitions and its own types:
char *get_luks_partition(void) {
blkid_dev dev;
blkid_cache cache;
blkid_dev_iterate iter;
const char *devname = NULL;
char *ret = NULL;
const char *type = NULL;
if (blkid_get_cache(&cache, NULL))
return NULL;
blkid_probe_all(cache);
iter = blkid_dev_iterate_begin(cache);
while (!blkid_dev_next(iter, &dev)) {
devname = blkid_dev_devname(dev);
type = blkid_get_tag_value(cache, "TYPE", devname);
if (type)
printf("dev: %s type: %s\n", devname, type);
if (type && !strcmp(type, "crypto_LUKS")) {
ret = (char *) devname;
break;
}
}
blkid_dev_iterate_end(iter);
return ret;
}
It does not show any device/partition and type when I run as a normal user. So, I try to run as root and I finally see devices, partitions and types. And when I return to user, I can see the same output as root if I run again. See the sequence:
$ ./main
dev: /dev/sr0 type: udf
$ sudo ./main
dev: /dev/vda1 type: vfat
dev: /dev/vda2 type: xfs
dev: /dev/vda3 type: crypto_LUKS
$ ./main
dev: /dev/vda1 type: vfat
dev: /dev/vda2 type: xfs
dev: /dev/vda3 type: crypto_LUKS
Does anyone know what is happening?