diff --git a/pkg/p9/p9.go b/pkg/p9/p9.go index d06949fabf..6dc76a8a5f 100644 --- a/pkg/p9/p9.go +++ b/pkg/p9/p9.go @@ -130,9 +130,6 @@ func (o OpenFlags) String() string { return buf.String() } -// Tag is a message tag. -type Tag uint16 - // FileMode are flags corresponding to file modes. // // These correspond to bits sent over the wire. @@ -569,137 +566,6 @@ func StatToAttr(s *syscall.Stat_t, req AttrMask) (Attr, AttrMask) { return attr, req } -// SetAttrMask specifies a valid mask for setattr. -type SetAttrMask struct { - Permissions bool - UID bool - GID bool - Size bool - ATime bool - MTime bool - CTime bool - ATimeNotSystemTime bool - MTimeNotSystemTime bool -} - -// IsSubsetOf returns whether s is a subset of m. -func (s SetAttrMask) IsSubsetOf(m SetAttrMask) bool { - sb := s.bitmask() - sm := m.bitmask() - return sm|sb == sm -} - -// String implements fmt.Stringer. -func (s SetAttrMask) String() string { - var masks []string - if s.Permissions { - masks = append(masks, "Permissions") - } - if s.UID { - masks = append(masks, "UID") - } - if s.GID { - masks = append(masks, "GID") - } - if s.Size { - masks = append(masks, "Size") - } - if s.ATime { - masks = append(masks, "ATime") - } - if s.MTime { - masks = append(masks, "MTime") - } - if s.CTime { - masks = append(masks, "CTime") - } - if s.ATimeNotSystemTime { - masks = append(masks, "ATimeNotSystemTime") - } - if s.MTimeNotSystemTime { - masks = append(masks, "MTimeNotSystemTime") - } - return fmt.Sprintf("SetAttrMask{with: %s}", strings.Join(masks, " ")) -} - -// Empty returns true if no fields are masked. -func (s SetAttrMask) Empty() bool { - return !s.Permissions && !s.UID && !s.GID && !s.Size && !s.ATime && !s.MTime && !s.CTime && !s.ATimeNotSystemTime && !s.MTimeNotSystemTime -} - -func (s SetAttrMask) bitmask() uint32 { - var mask uint32 - if s.Permissions { - mask |= 0x00000001 - } - if s.UID { - mask |= 0x00000002 - } - if s.GID { - mask |= 0x00000004 - } - if s.Size { - mask |= 0x00000008 - } - if s.ATime { - mask |= 0x00000010 - } - if s.MTime { - mask |= 0x00000020 - } - if s.CTime { - mask |= 0x00000040 - } - if s.ATimeNotSystemTime { - mask |= 0x00000080 - } - if s.MTimeNotSystemTime { - mask |= 0x00000100 - } - return mask -} - -// SetAttr specifies a set of attributes for a setattr. -type SetAttr struct { - Permissions FileMode - UID UID - GID GID - Size uint64 - ATimeSeconds uint64 - ATimeNanoSeconds uint64 - MTimeSeconds uint64 - MTimeNanoSeconds uint64 -} - -// String implements fmt.Stringer. -func (s SetAttr) String() string { - return fmt.Sprintf("SetAttr{Permissions: 0o%o, UID: %d, GID: %d, Size: %d, ATime: {Sec: %d, NanoSec: %d}, MTime: {Sec: %d, NanoSec: %d}}", s.Permissions, s.UID, s.GID, s.Size, s.ATimeSeconds, s.ATimeNanoSeconds, s.MTimeSeconds, s.MTimeNanoSeconds) -} - -// Apply applies this to the given Attr. -func (a *Attr) Apply(mask SetAttrMask, attr SetAttr) { - if mask.Permissions { - a.Mode = a.Mode&^permissionsMask | (attr.Permissions & permissionsMask) - } - if mask.UID { - a.UID = attr.UID - } - if mask.GID { - a.GID = attr.GID - } - if mask.Size { - a.Size = attr.Size - } - if mask.ATime { - a.ATimeSeconds = attr.ATimeSeconds - a.ATimeNanoSeconds = attr.ATimeNanoSeconds - } - if mask.MTime { - a.MTimeSeconds = attr.MTimeSeconds - a.MTimeNanoSeconds = attr.MTimeNanoSeconds - } -} - // AllocateMode are possible modes to p9.File.Allocate(). type AllocateMode struct { KeepSize bool