First, sorry for my bad English.
I’m writing a python script, which compares the files in two different directories. But for performance, I want to know that: “Are the directories on the same physical disk or not?”, so I can read them simultaneously for performance gain.
My current idea is getting “mount” commands output, and getting the /dev/sd* directories path and use them for identify the disks. But sometimes you can mount an already mounted directory on somewhere else(or something like that, i’m not so sure), so things get complicated.
Is there a better way to do that, like a library?
(If there is a cross-platform way, I will be more appreciated, but it seems it’s hard to find a cross-platform library like this.)
You are looking for the stat function from linux, which is also provided to you by python (see http://docs.python.org/library/os.html#os.stat).
You will have to compare the st_dev from the resulting structure and both files will be on the same filesystem if they match.
Using this function is as portable as you can get (better than mount or df).
Bonus: you do not have to run expensive exec calls and do error prone text parsing.