tags:

views:

112

answers:

3

Is there a way to determine programatically if a particular directory is actually remotely mounted? Can this be done with Java, and if not can it be done with native C code over JNI?

Since this is Java it could be running under Linux or Windows or Mac, so a proper solution needs to address all these platforms. (Again if its multiple separate solutions with C over JNI thats ok). And there may be different cases like with NFS or samba or anything else.

Thanks.

+1  A: 

for Linux, and possibly Macintosh, you can use system library through JNI. The relevant system call is getmntent, described here.

There is a field in mntent you can use to check to see if mount point is from device or a server, mnt_fsname, in a similar field you can get filesystem type, `mnt_type"

aaa
A: 

For Linux, you can parse /etc/mtab to find the filesystem type (nfs, smb, etc.) and match it against known network filesystem types in your program.

EDIT: column 2 is what you want in /etc/mtab

Chinmay Kanchi
A: 

I need that as well and might end up implementing it using this command:

df -k

That works under Linux, Mac OS and Solaris.

Maybe this is something else that will be added to JDK 7 since they're also going to support symlinks.

Eliseo Soto