Domanda

I want to mount a block device, especially, optical drives, for instance, /dev/sr0 (or /dev/cdrom) in my application (wrtten in C++) in Linux in order to read each file from the device. I found a mount() function and wrote next code:

mount("/dev/sr0", "/path/to/mount/point", "udf", MS_RDONLY, "");

It works very well ONLY IF I have root permission, which is not usual case.

Since desktop environments(e.g., KDE) can mount USB/CD/DVDs without permission, I thought maybe there's an interface to allow this such as D-Bus protocol, but I couldn't find.

Is it impossible to mount a device without root-permission programmatically? Or, am I missing something?

È stato utile?

Soluzione

Is it impossible to mount a device without root-permission programmatically?

Yes, it is not possible.

From man 2 mount:

Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required to mount file systems.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top