On Wed, 05 May 2010 13:23:03 +0100, Baz Walter wrote: >>> so >>> if several filesystems are mounted in the same parent directory, there is >>> no way to tell which of them is the "right" one. >> >> The only case which would cause a problem here is if you mount the same >> device on two different subdirectories of a common directory. But in that >> case, it doesn't really matter which answer you get, as they're both >> equivalent in any sense that matters. > > nope! just to be clear: > > here's what i get on my system, where '/dev/sda1' and '/dev/sda6' are > mounted at '/boot' and '/home' respectively: > > >>> os.stat('/').st_ino > 2L > >>> os.stat('/usr').st_ino > 212993L > >>> os.stat('/boot').st_ino > 2L > >>> os.stat('/home').st_ino > 2L > >>>
Right. /, /boot and /home are separate filesystems; ext2/ext3 filesystems normally use inode #2 as the root directory. If you look at the st_dev field, all three will be different (for /boot and /home, they'll correspond to sda1 and sda6 respectively). > if the algorithm is climbing up from '/home/baz/tmp/xxx', what does it > do when it searches os.listdir('../../../..')? how can it tell whether > 'boot' or 'home' is the correct next parent if it only checks the inode > number? It doesn't. Inode numbers are only unique within a single device; you need to use both st_dev and st_ino to uniquely identify an inode within a complete filesystem. > i think the algorithm would at least need to take account of > changes in the current device id. not sure whether that would be enough > to cover all cases, though. st_dev+st_ino is sufficient. -- http://mail.python.org/mailman/listinfo/python-list