The question
I have a Linux program that can be run from different directories. It needs to detect the device from where it is started.
The program need to detect where some block device is mounted.
How these tasks can be done?
The language is not important, only the algorithm. It is better external libraries not to be used.
Linux system tools like "df" are not acceptable as the work must to be done in compilable language and the program must to be self-sufficient.
The whole story
It is a part of portable application that need to work on every Linux distribution. The program has to be started from a USB pendrive with two partitions, for example /dev/sdb1 and /dev/sdb2. Linux will automatically mount these partitions on an arbitrary place depending on the Linux distribution.
The user runs the program from the /dev/sdb1 mounting point and the program need to have access to some files on /dev/sdb2. (notice, that the device name varies - sdb, sdc, etc.) In order to read these files, the program must detect what is the device where it is located and then to increase the number by 1 and to find where this device is mounted. Of course, if there is no such device, or the program is located not on removable drive, it will end with error message.