|
19 | 19 | # Extract bits from the mode |
20 | 20 |
|
21 | 21 | def S_IMODE(mode): |
| 22 | + """Return the portion of the file's mode that can be set by |
| 23 | + os.chmod(). |
| 24 | + """ |
22 | 25 | return mode & 0o7777 |
23 | 26 |
|
24 | 27 | def S_IFMT(mode): |
| 28 | + """Return the portion of the file's mode that describes the |
| 29 | + file type. |
| 30 | + """ |
25 | 31 | return mode & 0o170000 |
26 | 32 |
|
27 | 33 | # Constants used as S_IFMT() for various file types |
28 | 34 | # (not all are implemented on all systems) |
29 | 35 |
|
30 | | -S_IFDIR = 0o040000 |
31 | | -S_IFCHR = 0o020000 |
32 | | -S_IFBLK = 0o060000 |
33 | | -S_IFREG = 0o100000 |
34 | | -S_IFIFO = 0o010000 |
35 | | -S_IFLNK = 0o120000 |
36 | | -S_IFSOCK = 0o140000 |
| 36 | +S_IFDIR = 0o040000 # directory |
| 37 | +S_IFCHR = 0o020000 # character device |
| 38 | +S_IFBLK = 0o060000 # block device |
| 39 | +S_IFREG = 0o100000 # regular file |
| 40 | +S_IFIFO = 0o010000 # fifo (named pipe) |
| 41 | +S_IFLNK = 0o120000 # symbolic link |
| 42 | +S_IFSOCK = 0o140000 # socket file |
37 | 43 |
|
38 | 44 | # Functions to test for each file type |
39 | 45 |
|
40 | 46 | def S_ISDIR(mode): |
| 47 | + """Return True if mode is from a directory.""" |
41 | 48 | return S_IFMT(mode) == S_IFDIR |
42 | 49 |
|
43 | 50 | def S_ISCHR(mode): |
| 51 | + """Return True if mode is from a character special device file.""" |
44 | 52 | return S_IFMT(mode) == S_IFCHR |
45 | 53 |
|
46 | 54 | def S_ISBLK(mode): |
| 55 | + """Return True if mode is from a block special device file.""" |
47 | 56 | return S_IFMT(mode) == S_IFBLK |
48 | 57 |
|
49 | 58 | def S_ISREG(mode): |
| 59 | + """Return True if mode is from a regular file.""" |
50 | 60 | return S_IFMT(mode) == S_IFREG |
51 | 61 |
|
52 | 62 | def S_ISFIFO(mode): |
| 63 | + """Return True if mode is from a FIFO (named pipe).""" |
53 | 64 | return S_IFMT(mode) == S_IFIFO |
54 | 65 |
|
55 | 66 | def S_ISLNK(mode): |
| 67 | + """Return True if mode is from a symbolic link.""" |
56 | 68 | return S_IFMT(mode) == S_IFLNK |
57 | 69 |
|
58 | 70 | def S_ISSOCK(mode): |
| 71 | + """Return True if mode is from a socket.""" |
59 | 72 | return S_IFMT(mode) == S_IFSOCK |
60 | 73 |
|
61 | 74 | # Names for permission bits |
62 | 75 |
|
63 | | -S_ISUID = 0o4000 |
64 | | -S_ISGID = 0o2000 |
65 | | -S_ENFMT = S_ISGID |
66 | | -S_ISVTX = 0o1000 |
67 | | -S_IREAD = 0o0400 |
68 | | -S_IWRITE = 0o0200 |
69 | | -S_IEXEC = 0o0100 |
70 | | -S_IRWXU = 0o0700 |
71 | | -S_IRUSR = 0o0400 |
72 | | -S_IWUSR = 0o0200 |
73 | | -S_IXUSR = 0o0100 |
74 | | -S_IRWXG = 0o0070 |
75 | | -S_IRGRP = 0o0040 |
76 | | -S_IWGRP = 0o0020 |
77 | | -S_IXGRP = 0o0010 |
78 | | -S_IRWXO = 0o0007 |
79 | | -S_IROTH = 0o0004 |
80 | | -S_IWOTH = 0o0002 |
81 | | -S_IXOTH = 0o0001 |
| 76 | +S_ISUID = 0o4000 # set UID bit |
| 77 | +S_ISGID = 0o2000 # set GID bit |
| 78 | +S_ENFMT = S_ISGID # file locking enforcement |
| 79 | +S_ISVTX = 0o1000 # sticky bit |
| 80 | +S_IREAD = 0o0400 # Unix V7 synonym for S_IRUSR |
| 81 | +S_IWRITE = 0o0200 # Unix V7 synonym for S_IWUSR |
| 82 | +S_IEXEC = 0o0100 # Unix V7 synonym for S_IXUSR |
| 83 | +S_IRWXU = 0o0700 # mask for owner permissions |
| 84 | +S_IRUSR = 0o0400 # read by owner |
| 85 | +S_IWUSR = 0o0200 # write by owner |
| 86 | +S_IXUSR = 0o0100 # execute by owner |
| 87 | +S_IRWXG = 0o0070 # mask for group permissions |
| 88 | +S_IRGRP = 0o0040 # read by group |
| 89 | +S_IWGRP = 0o0020 # write by group |
| 90 | +S_IXGRP = 0o0010 # execute by group |
| 91 | +S_IRWXO = 0o0007 # mask for others (not in group) permissions |
| 92 | +S_IROTH = 0o0004 # read by others |
| 93 | +S_IWOTH = 0o0002 # write by others |
| 94 | +S_IXOTH = 0o0001 # execute by others |
82 | 95 |
|
83 | 96 | # Names for file flags |
84 | 97 |
|
85 | | -UF_NODUMP = 0x00000001 |
86 | | -UF_IMMUTABLE = 0x00000002 |
87 | | -UF_APPEND = 0x00000004 |
88 | | -UF_OPAQUE = 0x00000008 |
89 | | -UF_NOUNLINK = 0x00000010 |
90 | | -UF_COMPRESSED = 0x00000020 # OS X: file is hfs-compressed |
91 | | -UF_HIDDEN = 0x00008000 # OS X: file should not be displayed |
92 | | -SF_ARCHIVED = 0x00010000 |
93 | | -SF_IMMUTABLE = 0x00020000 |
94 | | -SF_APPEND = 0x00040000 |
95 | | -SF_NOUNLINK = 0x00100000 |
96 | | -SF_SNAPSHOT = 0x00200000 |
| 98 | +UF_NODUMP = 0x00000001 # do not dump file |
| 99 | +UF_IMMUTABLE = 0x00000002 # file may not be changed |
| 100 | +UF_APPEND = 0x00000004 # file may only be appended to |
| 101 | +UF_OPAQUE = 0x00000008 # directory is opaque when viewed through a union stack |
| 102 | +UF_NOUNLINK = 0x00000010 # file may not be renamed or deleted |
| 103 | +UF_COMPRESSED = 0x00000020 # OS X: file is hfs-compressed |
| 104 | +UF_HIDDEN = 0x00008000 # OS X: file should not be displayed |
| 105 | +SF_ARCHIVED = 0x00010000 # file may be archived |
| 106 | +SF_IMMUTABLE = 0x00020000 # file may not be changed |
| 107 | +SF_APPEND = 0x00040000 # file may only be appended to |
| 108 | +SF_NOUNLINK = 0x00100000 # file may not be renamed or deleted |
| 109 | +SF_SNAPSHOT = 0x00200000 # file is a snapshot file |
0 commit comments