blob: abed5c9e0f57a118ee58aef158cf3c455d9821ec [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
Georg Brandl402b2702008-03-20 07:25:55 +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):
Tim Peters495ad3c2001-01-15 01:36:40 +000022 return mode & 07777
Guido van Rossum3bc034b1992-03-31 19:03:19 +000023
Guido van Rossum6b47ed11990-10-21 16:17:08 +000024def S_IFMT(mode):
Tim Peters495ad3c2001-01-15 01:36:40 +000025 return mode & 0170000
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
30S_IFDIR = 0040000
31S_IFCHR = 0020000
32S_IFBLK = 0060000
33S_IFREG = 0100000
34S_IFIFO = 0010000
35S_IFLNK = 0120000
36S_IFSOCK = 0140000
37
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
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
Martin v. Löwis382abef2007-02-19 10:55:19 +000082
83# Names for file flags
84
85UF_NODUMP = 0x00000001
86UF_IMMUTABLE = 0x00000002
87UF_APPEND = 0x00000004
88UF_OPAQUE = 0x00000008
89UF_NOUNLINK = 0x00000010
Ned Deily43e10542011-06-27 23:41:53 -070090UF_COMPRESSED = 0x00000020 # OS X: file is hfs-compressed
91UF_HIDDEN = 0x00008000 # OS X: file should not be displayed
Martin v. Löwis382abef2007-02-19 10:55:19 +000092SF_ARCHIVED = 0x00010000
93SF_IMMUTABLE = 0x00020000
94SF_APPEND = 0x00040000
95SF_NOUNLINK = 0x00100000
96SF_SNAPSHOT = 0x00200000