I need to write function in C language on Linux which accesses all mounted CDROMs and performs some action.
I can do it on BSD using
count = getmntinfo(&buf, 0);
And looping on all devices and checking
buf[i].f_type == 17
Is any way to do the same on Linux?
The best way is probably to parse /proc/mounts. It looks identical to /etc/mtab, but this is not actually an on disk file, it’s a kernel interface, and you should use low level file descriptor functions with it — ie, read(), not fread(), fscanf(), etc. Virtually all linux systems that mount a cdrom will also have a proc available, and much of it (inluding mounts) does not require privileges to read.
There is also libudev, but I think that solution will be a lot more convoluted:
http://www.freedesktop.org/software/systemd/libudev/
Again, virtually all linux systems that mount a cd will also use udev, although I think this is a little less true that it would be for proc.
/sys/dev contains more in-depth information about each mounted device that might enable you to make a determination. libudev uses those paths.
Really, to respect the user, I think you should try and stick with conventional symlinks like /dev/dvdrw, etc, and not try so much to find things in unconventional places. That’s what those links are for. It also makes your job much much easier.