Mailinglist Archive: opensuse-programming (96 mails)

< Previous Next >
Re: [suse-programming-e] Detecting File System type
  • From: James Oakley <joakley@xxxxxxxxxxxxxxx>
  • Date: Thu, 13 Mar 2003 15:25:31 -0400
  • Message-id: <200303131525.33917.joakley@xxxxxxxxxxxxxxx>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 13 March 2003 01:34 pm, Greg Freemyer wrote:
> All,
>
> I'm going to do some work on rdiff-backup. It's written in Python. (I'm a
> python newbie)
>
> I want to be able to detect the filesystem type of the target directory.
> (i.e. ext2/xfs/reiser/NTFS/FAT etc.).
>
> Is there a good way to get that info? It would be really nice if the
> method worked in Linux and Win32, but that maybe too much to hope for.

This only works in Linux. I know little of Windows, unfortunately:

- --------cut----------
import os, stat

def getFSType(filename):
"""
Returns the fstype of the volume containg 'filename', which should be the
full path to the file
"""
# Build dict of filesystems and use the device number as the key
devices = {}
f = open('/proc/mounts')
for line in f.readlines():
info = line.split()
devnum = os.stat(info[1])[stat.ST_DEV]
devices[devnum] = info[2]
f.close()

# Find out which one contains 'filename' and return the fstype
return devices[os.stat(filename)[stat.ST_DEV]]
- ------------cut---------

If you want to know more about how that works, check out the documentation for
the 'stat' module.

- --
James Oakley
Engineering - SolutionInc Ltd.
joakley@xxxxxxxxxxxxxxx
http://www.solutioninc.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+cNss+FOexA3koIgRAsC+AJ9NNUm54b0Mt8jmXXGo9kUSdUcCDQCgt7Lm
1d+V3Qagr3fYS2yGp5yCeR8=
=1PmL
-----END PGP SIGNATURE-----


< Previous Next >
References