[solved] opening file /proc/mounts works, file length 0



  • I'm trying to set up monitoring of usb flash drive insertions and removals. I've got udev monitoring working, but when I try to open /proc/mounts to map the /dev device to a file system mount point, i.e. /media/... the file open for /proc/mounts works, but the file length is zero. If I cat the file I get all of the mount data. The permissions are read for everybody. /proc/mounts is symlinked to /proc/self/mounts and that is symlinked to /proc/processID/mounts. I'm wondering if there is some kind of a problem with thying to open a symlinked file, or just because it is symlinked through the processID. If I trace the symlinks through QFile, /proc/mounts points to /proc/self/mounts which then shows points to "". This would imply that /proc/self/mounts is the end of the chain, but if the links are examined in a shell, then /proc/self/mounts points the processID link.

    Any insight into what might be happening would be greatly appreciated.
    Regards,



  • The file /proc/self/mounts is not a real file. Take a look on man proc. The size of a file is 0 because it does not take any space on a harddrive. It is a reference to a structure in a kernel memory. You can read with it with QFile using readAll() or other read... functions.



  • Thanks for the clue bat, I know it's not a real file, but I wasn't thinking of the implications of that. I started out using a while loop with file.atEnd() as the terminal condition, but that won't work as you pointed out. I'll just have to read til I get a no more data return from readline() .

    Again, Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.