Overview
ThePartitionStat struct contains information about a disk partition, including its device path, mount point, filesystem type, and mount options. This information is useful for discovering available filesystems and their configurations.
Struct Definition
Fields
Device
- Type:
string - Description: Device path or device name
- Examples:
- Linux:
/dev/sda1,/dev/nvme0n1p1,/dev/mapper/vg0-root - Windows:
C:\,D:\,\\?\Volume{guid} - macOS:
/dev/disk1s1 - Network:
server:/export/home(NFS),//server/share(SMB)
- Linux:
- Note: This is typically a physical device path, but can be a virtual device, network path, or special identifier
Mountpoint
- Type:
string - Description: Directory where the filesystem is mounted (accessible path)
- Examples:
- Linux/macOS:
/,/home,/mnt/data,/media/usb - Windows:
C:\,D:\,E:\
- Linux/macOS:
- Important: Use this field (not
Device) when callingdisk.Usage()
Fstype
- Type:
string - Description: Filesystem type
- Common values:
- Linux:
ext4,xfs,btrfs,ext3,ext2,vfat,ntfs,tmpfs,nfs,cifs - Windows:
NTFS,FAT32,exFAT,ReFS - macOS:
apfs,hfs,msdos,exfat - BSD:
ufs,zfs,ffs - Special:
tmpfs,devtmpfs,sysfs,proc,devfs
- Linux:
Opts
- Type:
[]string - Description: Mount options as a slice of strings
- Common options:
- Linux/Unix:
rw/ro- Read-write / Read-onlynodev- Do not interpret device filesnosuid- Do not allow set-user-ID or set-group-ID bitsnoexec- Do not allow direct execution of binariesrelatime- Update access times relative to modify timedefaults- Use default mount options
- Windows:
rw/rocompressed- NTFS compression enabledencrypted- NTFS encryption enabled
- Linux/Unix:
- Example:
["rw", "nosuid", "nodev", "relatime"]
Methods
String
Partitions Function
all- Controls which filesystems are returned:false- Returns only physical devices (hard disks, SSDs, USB drives, CD-ROM)true- Returns all filesystems including virtual/pseudo filesystems (tmpfs, sysfs, proc, devfs, etc.)
all parameter is ignored due to platform limitations. See psutil issue #906.
Returns:
[]PartitionStat- Slice of partition informationerror- Error if partitions cannot be enumerated
Usage Examples
List All Physical Partitions
List All Filesystems (Including Virtual)
Get Usage for Each Partition
Filter Partitions by Filesystem Type
Check Mount Options
Find Specific Mount Point
Platform-Specific Behavior
Linux
- Reads from
/proc/mountsor/etc/mtab - Both physical and virtual filesystems available
all=falsefilters out pseudo filesystems like proc, sysfs, tmpfs, devtmpfs, etc.- Network filesystems (NFS, CIFS) included when mounted
Windows
- Uses
GetLogicalDrivesandGetVolumeInformationAPIs - Returns drive letters as both device and mountpoint (e.g.,
C:\) allparameter typically has less effect since Windows has fewer virtual filesystems- Network drives included when mapped
macOS
- Uses
getmntinfosystem call - Returns both physical and virtual filesystems
- APFS container structure may result in multiple entries for a single physical device
- Network mounts (AFP, SMB, NFS) included
BSD (FreeBSD, OpenBSD)
- Uses
getmntinfosystem call - Important: The
allparameter is ignored on BSD systems - All mounted filesystems are returned regardless of the
allvalue - Application must filter pseudo filesystems if needed
Common Filesystem Types
Linux
- Physical:
ext4,ext3,ext2,xfs,btrfs,f2fs,ntfs,vfat - Virtual:
tmpfs,sysfs,proc,devtmpfs,cgroup,cgroup2 - Network:
nfs,nfs4,cifs,smbfs - Special:
fuse,overlay,aufs
Windows
- Local:
NTFS,FAT32,exFAT,ReFS - Network:
CIFS,SMB
macOS
- Local:
apfs,hfs,jhfs+(journaled HFS+),msdos,exfat - Network:
nfs,smbfs,afpfs - Virtual:
devfs,autofs
BSD
- Local:
ufs,zfs,ffs,ext2fs - Network:
nfs - Virtual:
devfs,procfs,tmpfs
Common Mount Options
Read/Write Permissions
rw- Read-write (default)ro- Read-only
Security Options
nosuid- Ignore set-user-ID and set-group-ID bitsnodev- Do not interpret character or block special devicesnoexec- Do not allow direct execution of binaries
Access Time Options
relatime- Update access times relative to modify/change timenoatime- Do not update access timesstrictatime- Always update access times
Linux-Specific
errors=remount-ro- Remount read-only on errors (ext filesystems)errors=continue- Continue on errorsdata=ordered- Write data before metadata (ext filesystems)discard- Enable TRIM for SSDs
Windows-Specific
compressed- NTFS compression enabledencrypted- NTFS encryption enabled
Important Notes
On BSD systems, the
all parameter to Partitions() is ignored. You’ll always get all mounted filesystems. Filter the results in your application if you only want physical devices.Network filesystems (NFS, CIFS, SMB) will appear in the partition list when mounted. Accessing them may be slower, especially if the network connection is poor or the server is unresponsive.
See Also
- Usage Statistics - Get filesystem usage for a partition
- I/O Counters - Disk I/O statistics
- Disk Package Overview - Package introduction