On Mon, 2006-08-14 at 19:45 +0200, Jan Trippler wrote:
Am Montag, 14. August 2006 08:27 schrieb Roger Oberholtzer: [...]
This assumes that the mount point will not exist until the media is inserted. This is not always the case. I am interested in the case where the mount point exists even when the media is not mounted. Like in the old days of fstab. BTW, I am hoping to do this from a C program. Preferably without calling a script. Unless the script is better than sliced bread. [...]
Try the statvfs() call (demo program without any checks or validations):
#include <stdio.h> #include <sys/statvfs.h> #include <string.h>
int main(int argc, char **argv) { char *p = NULL; struct statvfs st; if (argc == 2) p = strdup(argv[1]); else p = strdup("."); statvfs(p, &st); printf("%ld\n", st.f_fsid); free(p); exit(0); }
You can check the f_fsid field of the mount point against his parent. If the path is a simple directory, you will get equal f_fsid for both of them, otherwise the mount point will have its own f_fsid.
I was already using statvfs to track disk usage as data is streamed. In fact, I was originally going to use statfs for this as statfs has a f_type field that could help. But the statfs man page said it was better to use statvfs as statfs is depreciated in LSB, so I did. Where is there a description of f_fsid that describes this behavior? I will of course google. But maybe you have already found a good description. The info in the statfs man page for f_fsid is rather sketchy on the values themselves. -- Roger Oberholtzer OPQ Systems AB Ramböll Sverige AB Kapellgränd 7 P.O. Box 4205 SE-102 65 Stockholm, Sweden Tel: Int +46 8-615 60 20 Fax: Int +46 8-31 42 23