1"""Constants/functions for interpreting results of os.stat() and os.lstat(). 2 3Suggested usage: from stat import * 4""" 5 6# Indices for stat struct members in the tuple returned by os.stat() 7 8ST_MODE = 0 9ST_INO = 1 10ST_DEV = 2 11ST_NLINK = 3 12ST_UID = 4 13ST_GID = 5 14ST_SIZE = 6 15ST_ATIME = 7 16ST_MTIME = 8 17ST_CTIME = 9 18 19# Extract bits from the mode 20 21def S_IMODE(mode): 22 return mode & 07777 23 24def S_IFMT(mode): 25 return mode & 0170000 26 27# Constants used as S_IFMT() for various file types 28# (not all are implemented on all systems) 29 30S_IFDIR = 0040000 31S_IFCHR = 0020000 32S_IFBLK = 0060000 33S_IFREG = 0100000 34S_IFIFO = 0010000 35S_IFLNK = 0120000 36S_IFSOCK = 0140000 37 38# Functions to test for each file type 39 40def S_ISDIR(mode): 41 return S_IFMT(mode) == S_IFDIR 42 43def S_ISCHR(mode): 44 return S_IFMT(mode) == S_IFCHR 45 46def S_ISBLK(mode): 47 return S_IFMT(mode) == S_IFBLK 48 49def S_ISREG(mode): 50 return S_IFMT(mode) == S_IFREG 51 52def S_ISFIFO(mode): 53 return S_IFMT(mode) == S_IFIFO 54 55def S_ISLNK(mode): 56 return S_IFMT(mode) == S_IFLNK 57 58def S_ISSOCK(mode): 59 return S_IFMT(mode) == S_IFSOCK 60 61# Names for permission bits 62 63S_ISUID = 04000 64S_ISGID = 02000 65S_ENFMT = S_ISGID 66S_ISVTX = 01000 67S_IREAD = 00400 68S_IWRITE = 00200 69S_IEXEC = 00100 70S_IRWXU = 00700 71S_IRUSR = 00400 72S_IWUSR = 00200 73S_IXUSR = 00100 74S_IRWXG = 00070 75S_IRGRP = 00040 76S_IWGRP = 00020 77S_IXGRP = 00010 78S_IRWXO = 00007 79S_IROTH = 00004 80S_IWOTH = 00002 81S_IXOTH = 00001 82 83# Names for file flags 84 85UF_NODUMP = 0x00000001 86UF_IMMUTABLE = 0x00000002 87UF_APPEND = 0x00000004 88UF_OPAQUE = 0x00000008 89UF_NOUNLINK = 0x00000010 90SF_ARCHIVED = 0x00010000 91SF_IMMUTABLE = 0x00020000 92SF_APPEND = 0x00040000 93SF_NOUNLINK = 0x00100000 94SF_SNAPSHOT = 0x00200000 95