File: print_linux.go

package info (click to toggle)
golang-github-hanwen-go-fuse 2.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,584 kB
  • sloc: cpp: 78; sh: 47; makefile: 16
file content (91 lines) | stat: -rw-r--r-- 2,771 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fuse

import (
	"fmt"
	"runtime"
	"strings"
	"syscall"

	"golang.org/x/sys/unix"
)

var statxFieldFlags = newFlagNames([]flagNameEntry{
	{unix.STATX_ATIME, "Atime"},
	{unix.STATX_BLOCKS, "blocks"},
	{unix.STATX_BTIME, "Btime"},
	{unix.STATX_CTIME, "Ctime"},
	{unix.STATX_GID, "Gid"},
	{unix.STATX_INO, "Ino"},
	{unix.STATX_MNT_ID, "Mntid"},
	{unix.STATX_MODE, "Mode"},
	{unix.STATX_MTIME, "Mtime"},
	{unix.STATX_NLINK, "Nlink"},
	{unix.STATX_SIZE, "Size"},
	{unix.STATX_TYPE, "Type"},
	{unix.STATX_UID, "Uid"},
})

func init() {
	// syscall.O_LARGEFILE is 0x0 on x86_64, but the kernel
	// supplies 0x8000 anyway, except on mips64el, where 0x8000 is
	// used for O_DIRECT.
	if !strings.Contains(runtime.GOARCH, "mips64") {
		openFlagNames.set(0x8000, "LARGEFILE")
	}

	openFlagNames.set(syscall.O_DIRECT, "DIRECT")
	openFlagNames.set(syscall_O_NOATIME, "NOATIME")
	initFlagNames.set(CAP_NO_OPENDIR_SUPPORT, "NO_OPENDIR_SUPPORT")
	initFlagNames.set(CAP_EXPLICIT_INVAL_DATA, "EXPLICIT_INVAL_DATA")
	initFlagNames.set(CAP_MAP_ALIGNMENT, "MAP_ALIGNMENT")
	initFlagNames.set(CAP_SUBMOUNTS, "SUBMOUNTS")
	initFlagNames.set(CAP_HANDLE_KILLPRIV_V2, "HANDLE_KILLPRIV_V2")
	initFlagNames.set(CAP_SETXATTR_EXT, "SETXATTR_EXT")
	initFlagNames.set(CAP_INIT_EXT, "INIT_EXT")
	initFlagNames.set(CAP_INIT_RESERVED, "INIT_RESERVED")
}

func (a *Statx) string() string {
	var ss []string
	if a.Mask&unix.STATX_MODE != 0 || a.Mask&unix.STATX_TYPE != 0 {
		ss = append(ss, fmt.Sprintf("M0%o", a.Mode))
	}
	if a.Mask&unix.STATX_SIZE != 0 {
		ss = append(ss, fmt.Sprintf("SZ=%d", a.Size))
	}
	if a.Mask&unix.STATX_NLINK != 0 {
		ss = append(ss, fmt.Sprintf("L=%d", a.Nlink))
	}
	if a.Mask&unix.STATX_UID != 0 || a.Mask&unix.STATX_GID != 0 {
		ss = append(ss, fmt.Sprintf("%d:%d", a.Uid, a.Gid))
	}
	if a.Mask&unix.STATX_INO != 0 {
		ss = append(ss, fmt.Sprintf("i%d", a.Ino))
	}
	if a.Mask&unix.STATX_ATIME != 0 {
		ss = append(ss, fmt.Sprintf("A %f", a.Atime.Seconds()))
	}
	if a.Mask&unix.STATX_BTIME != 0 {
		ss = append(ss, fmt.Sprintf("B %f", a.Btime.Seconds()))
	}
	if a.Mask&unix.STATX_CTIME != 0 {
		ss = append(ss, fmt.Sprintf("C %f", a.Ctime.Seconds()))
	}
	if a.Mask&unix.STATX_MTIME != 0 {
		ss = append(ss, fmt.Sprintf("M %f", a.Mtime.Seconds()))
	}
	if a.Mask&unix.STATX_BLOCKS != 0 {
		ss = append(ss, fmt.Sprintf("%d*%d", a.Blocks, a.Blksize))
	}

	return "{" + strings.Join(ss, " ") + "}"
}

func (in *StatxIn) string() string {
	return fmt.Sprintf("{Fh %d %s 0x%x %s}", in.Fh, flagString(getAttrFlagNames, int64(in.GetattrFlags), ""),
		in.SxFlags, flagString(statxFieldFlags, int64(in.SxMask), ""))
}