forked from Foxboron/sbctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chattr.go
50 lines (44 loc) · 2.03 KB
/
chattr.go
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
package sbctl
import (
"os"
"golang.org/x/sys/unix"
)
const (
// from /usr/include/linux/fs.h
FS_SECRM_FL = 0x00000001 /* Secure deletion */
FS_UNRM_FL = 0x00000002 /* Undelete */
FS_COMPR_FL = 0x00000004 /* Compress file */
FS_SYNC_FL = 0x00000008 /* Synchronous updates */
FS_IMMUTABLE_FL = 0x00000010 /* Immutable file */
FS_APPEND_FL = 0x00000020 /* writes to file may only append */
FS_NODUMP_FL = 0x00000040 /* do not dump file */
FS_NOATIME_FL = 0x00000080 /* do not update atime */
FS_DIRTY_FL = 0x00000100
FS_COMPRBLK_FL = 0x00000200 /* One or more compressed clusters */
FS_NOCOMP_FL = 0x00000400 /* Don't compress */
FS_ECOMPR_FL = 0x00000800 /* Compression error */
FS_BTREE_FL = 0x00001000 /* btree format dir */
FS_INDEX_FL = 0x00001000 /* hash-indexed directory */
FS_IMAGIC_FL = 0x00002000 /* AFS directory */
FS_JOURNAL_DATA_FL = 0x00004000 /* Reserved for ext3 */
FS_NOTAIL_FL = 0x00008000 /* file tail should not be merged */
FS_DIRSYNC_FL = 0x00010000 /* dirsync behaviour (directories only) */
FS_TOPDIR_FL = 0x00020000 /* Top of directory hierarchies*/
FS_EXTENT_FL = 0x00080000 /* Extents */
FS_DIRECTIO_FL = 0x00100000 /* Use direct i/o */
FS_NOCOW_FL = 0x00800000 /* Do not cow file */
FS_PROJINHERIT_FL = 0x20000000 /* Create with parents projid */
FS_RESERVED_FL = 0x80000000 /* reserved for ext2 lib */
)
/* The code below won't work correctly if this tool is built
* for a 64-bit big endian platform.
* See https://github.com/golang/go/issues/45585 for context. */
// GetAttr retrieves the attributes of a file on a linux filesystem
func GetAttr(f *os.File) (int32, error) {
attr_int, err := unix.IoctlGetInt(int(f.Fd()), unix.FS_IOC_GETFLAGS)
return int32(attr_int), err
}
// SetAttr sets the attributes of a file on a linux filesystem to the given value
func SetAttr(f *os.File, attr int32) error {
return unix.IoctlSetPointerInt(int(f.Fd()), unix.FS_IOC_SETFLAGS, int(attr))
}