-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.go
More file actions
64 lines (57 loc) · 1.82 KB
/
type.go
File metadata and controls
64 lines (57 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package squashfs
import "io/fs"
// Type represents the type of a file or directory in a SquashFS filesystem.
// SquashFS has both basic and extended types, where extended types provide additional
// information or capabilities.
type Type uint16
const (
DirType Type = iota + 1 // Basic directory
FileType // Basic regular file
SymlinkType // Symbolic link
BlockDevType // Block device
CharDevType // Character device
FifoType // Named pipe (FIFO)
SocketType // UNIX domain socket
XDirType // Extended directory with optional index information
XFileType // Extended file with additional metadata
XSymlinkType // Extended symbolic link
XBlockDevType // Extended block device
XCharDevType // Extended character device
XFifoType // Extended named pipe
XSocketType // Extended UNIX domain socket
)
// Basic returns the type as a basic type (ie. XDirType.Basic() == DirType)
func (t Type) Basic() Type {
if t >= 8 {
return t - 7
}
return t
}
func (t Type) IsDir() bool {
return t.Basic() == DirType
}
func (t Type) IsSymlink() bool {
return t.Basic() == SymlinkType
}
// Mode returns a fs.FileMode for this type that contains no permissions, only the file's type
func (t Type) Mode() fs.FileMode {
switch t.Basic() {
case DirType:
return fs.ModeDir
case FileType:
return 0
case SymlinkType:
return fs.ModeSymlink
case BlockDevType:
return fs.ModeDevice // block device
case CharDevType:
return fs.ModeDevice | fs.ModeCharDevice // char device
case FifoType:
return fs.ModeNamedPipe
case SocketType:
return fs.ModeSocket
default:
// ??
return fs.ModeIrregular
}
}