blob: db25b11b68fecf4b2dd5102efea9d4c179382d21 (
plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
// Copyright 2019 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package disklayout
import (
"gvisor.dev/gvisor/pkg/abi/linux"
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
"gvisor.dev/gvisor/pkg/sentry/kernel/time"
)
const (
// OldInodeSize is the inode size in ext2/ext3.
OldInodeSize = 128
)
// InodeOld implements Inode interface. It emulates ext2/ext3 inode struct.
// Inode struct size and record size are both 128 bytes for this.
//
// All fields representing time are in seconds since the epoch. Which means that
// they will overflow in January 2038.
type InodeOld struct {
ModeRaw uint16
UIDLo uint16
SizeLo uint32
// The time fields are signed integers because they could be negative to
// represent time before the epoch.
AccessTimeRaw int32
ChangeTimeRaw int32
ModificationTimeRaw int32
DeletionTimeRaw int32
GIDLo uint16
LinksCountRaw uint16
BlocksCountLo uint32
FlagsRaw uint32
VersionLo uint32 // This is OS dependent.
DataRaw [60]byte
Generation uint32
FileACLLo uint32
SizeHi uint32
ObsoFaddr uint32
// OS dependent fields have been inlined here.
BlocksCountHi uint16
FileACLHi uint16
UIDHi uint16
GIDHi uint16
ChecksumLo uint16
_ uint16
}
// Compiles only if InodeOld implements Inode.
var _ Inode = (*InodeOld)(nil)
// Mode implements Inode.Mode.
func (in *InodeOld) Mode() linux.FileMode { return linux.FileMode(in.ModeRaw) }
// UID implements Inode.UID.
func (in *InodeOld) UID() auth.KUID {
return auth.KUID((uint32(in.UIDHi) << 16) | uint32(in.UIDLo))
}
// GID implements Inode.GID.
func (in *InodeOld) GID() auth.KGID {
return auth.KGID((uint32(in.GIDHi) << 16) | uint32(in.GIDLo))
}
// Size implements Inode.Size.
func (in *InodeOld) Size() uint64 {
// In ext2/ext3, in.SizeHi did not exist, it was instead named in.DirACL.
return uint64(in.SizeLo)
}
// InodeSize implements Inode.InodeSize.
func (in *InodeOld) InodeSize() uint16 { return OldInodeSize }
// AccessTime implements Inode.AccessTime.
func (in *InodeOld) AccessTime() time.Time {
return time.FromUnix(int64(in.AccessTimeRaw), 0)
}
// ChangeTime implements Inode.ChangeTime.
func (in *InodeOld) ChangeTime() time.Time {
return time.FromUnix(int64(in.ChangeTimeRaw), 0)
}
// ModificationTime implements Inode.ModificationTime.
func (in *InodeOld) ModificationTime() time.Time {
return time.FromUnix(int64(in.ModificationTimeRaw), 0)
}
// DeletionTime implements Inode.DeletionTime.
func (in *InodeOld) DeletionTime() time.Time {
return time.FromUnix(int64(in.DeletionTimeRaw), 0)
}
// LinksCount implements Inode.LinksCount.
func (in *InodeOld) LinksCount() uint16 { return in.LinksCountRaw }
// Flags implements Inode.Flags.
func (in *InodeOld) Flags() InodeFlags { return InodeFlagsFromInt(in.FlagsRaw) }
// Data implements Inode.Data.
func (in *InodeOld) Data() []byte { return in.DataRaw[:] }
|