blob: d29c63c1f7c6988d9337e5d95514864ec7e6c0d8 [file] [log] [blame]
Guido van Rossume7b146f2000-02-04 15:28:42 +00001"""Constants/functions for interpreting results of os.stat() and os.lstat().
2
3Suggested usage: from stat import *
4"""
5
Christian Heimese25f35e2008-03-20 10:49:03 +00006# Indices for stat struct members in the tuple returned by os.stat()
Guido van Rossum6b47ed11990-10-21 16:17:08 +00007
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
Guido van Rossum3bc034b1992-03-31 19:03:19 +000019# Extract bits from the mode
20
Guido van Rossum468c4481990-10-31 11:25:23 +000021def S_IMODE(mode):
Guido van Rossumcd16bf62007-06-13 18:07:49 +000022 return mode & 0o7777
Guido van Rossum3bc034b1992-03-31 19:03:19 +000023
Guido van Rossum6b47ed11990-10-21 16:17:08 +000024def S_IFMT(mode):
Guido van Rossumcd16bf62007-06-13 18:07:49 +000025 return mode & 0o170000
Guido van Rossum3bc034b1992-03-31 19:03:19 +000026
27# Constants used as S_IFMT() for various file types
28# (not all are implemented on all systems)
Guido van Rossum6b47ed11990-10-21 16:17:08 +000029
Guido van Rossumcd16bf62007-06-13 18:07:49 +000030S_IFDIR = 0o040000
31S_IFCHR = 0o020000
32S_IFBLK = 0o060000
33S_IFREG = 0o100000
34S_IFIFO = 0o010000
35S_IFLNK = 0o120000
36S_IFSOCK = 0o140000
Guido van Rossum6b47ed11990-10-21 16:17:08 +000037
Guido van Rossum3bc034b1992-03-31 19:03:19 +000038# Functions to test for each file type
39
Guido van Rossum6b47ed11990-10-21 16:17:08 +000040def S_ISDIR(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000041 return S_IFMT(mode) == S_IFDIR
Guido van Rossum6b47ed11990-10-21 16:17:08 +000042
43def S_ISCHR(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000044 return S_IFMT(mode) == S_IFCHR
Guido van Rossum6b47ed11990-10-21 16:17:08 +000045
46def S_ISBLK(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000047 return S_IFMT(mode) == S_IFBLK
Guido van Rossum6b47ed11990-10-21 16:17:08 +000048
49def S_ISREG(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000050 return S_IFMT(mode) == S_IFREG
Guido van Rossum6b47ed11990-10-21 16:17:08 +000051
52def S_ISFIFO(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000053 return S_IFMT(mode) == S_IFIFO
Guido van Rossum6b47ed11990-10-21 16:17:08 +000054
55def S_ISLNK(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000056 return S_IFMT(mode) == S_IFLNK
Guido van Rossum6b47ed11990-10-21 16:17:08 +000057
58def S_ISSOCK(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000059 return S_IFMT(mode) == S_IFSOCK
Guido van Rossum8899a9c1992-05-06 11:38:27 +000060
61# Names for permission bits
62
Guido van Rossumcd16bf62007-06-13 18:07:49 +000063S_ISUID = 0o4000
64S_ISGID = 0o2000
Guido van Rossum8899a9c1992-05-06 11:38:27 +000065S_ENFMT = S_ISGID
Guido van Rossumcd16bf62007-06-13 18:07:49 +000066S_ISVTX = 0o1000
67S_IREAD = 0o0400
68S_IWRITE = 0o0200
69S_IEXEC = 0o0100
70S_IRWXU = 0o0700
71S_IRUSR = 0o0400
72S_IWUSR = 0o0200
73S_IXUSR = 0o0100
74S_IRWXG = 0o0070
75S_IRGRP = 0o0040
76S_IWGRP = 0o0020
77S_IXGRP = 0o0010
78S_IRWXO = 0o0007
79S_IROTH = 0o0004
80S_IWOTH = 0o0002
81S_IXOTH = 0o0001
Thomas Wouterscf297e42007-02-23 15:07:44 +000082
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