os.stat() and os.lstat() returnst_dev = 5 for all devices

Bug #1029621 reported by Austin S. Hemmelgarn on 2012-07-26
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python3.2 (Ubuntu)
Undecided
Unassigned

Bug Description

Using Python 3.2 on Xubuntu 12.04 on AMD64
When calling os.stat() or os.lstat() on with a path to a device file, stat.st_dev is always 5. This in turn casues os.major() and os.minor() to return incorrect values for the particular device file.

Example:
Python 3.2.3 (default, May 3 2012, 15:51:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.stat('/dev/sda')
posix.stat_result(st_mode=25008, st_ino=6887, st_dev=5, st_nlink=1, st_uid=0, st_gid=6, st_size=0, st_atime=1343317745, st_mtime=1343317744, st_ctime=1343317744)
>>> os.stat('/dev/nvram')
posix.stat_result(st_mode=8608, st_ino=7816, st_dev=5, st_nlink=1, st_uid=0, st_gid=15, st_size=0, st_atime=1343317740, st_mtime=1343317740, st_ctime=1343317740)
>>> os.stat('/dev/tty1')
posix.stat_result(st_mode=8624, st_ino=1044, st_dev=5, st_nlink=1, st_uid=0, st_gid=5, st_size=0, st_atime=1343317740, st_mtime=1343317805, st_ctime=1343317805)

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: python3.2 3.2.3-0ubuntu3
ProcVersionSignature: Ubuntu 3.2.0-27.43-generic 3.2.21
Uname: Linux 3.2.0-27-generic x86_64
ApportVersion: 2.0.1-0ubuntu11
Architecture: amd64
Date: Thu Jul 26 15:11:35 2012
InstallationMedia: Xubuntu 12.04 LTS "Precise Pangolin" - Release amd64 (20120425)
SourcePackage: python3.2
UpgradeStatus: No upgrade log present (probably fresh install)

Matthias Klose (doko) wrote :

look at the st_mode attribute, not st_dev

Changed in python3.2 (Ubuntu):
status: New → Invalid

Then the documentation is inconsistent with the implementation.
I know that on both BSD and OS X the returned dict follows what the documentation says and contains a composed device id in st_dev, so this should be noted in the documentation as being different on linux, or at least different on ubuntu, as it would break some scripts that depend on this.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers