github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/fsimpl/ext/disklayout/block_group_64.go (about)

     1  // Copyright 2019 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package disklayout
    16  
    17  // BlockGroup64Bit emulates struct ext4_group_desc in fs/ext4/ext4.h.
    18  // It is the block group descriptor struct for 64-bit ext4 filesystems.
    19  // It implements BlockGroup interface. It is an extension of the 32-bit
    20  // version of BlockGroup.
    21  //
    22  // +marshal
    23  type BlockGroup64Bit struct {
    24  	// We embed the 32-bit struct here because 64-bit version is just an extension
    25  	// of the 32-bit version.
    26  	BlockGroup32Bit
    27  
    28  	// 64-bit specific fields.
    29  	BlockBitmapHi         uint32
    30  	InodeBitmapHi         uint32
    31  	InodeTableHi          uint32
    32  	FreeBlocksCountHi     uint16
    33  	FreeInodesCountHi     uint16
    34  	UsedDirsCountHi       uint16
    35  	ItableUnusedHi        uint16
    36  	ExcludeBitmapHi       uint32
    37  	BlockBitmapChecksumHi uint16
    38  	InodeBitmapChecksumHi uint16
    39  	_                     uint32 // Padding to 64 bytes.
    40  }
    41  
    42  // Compiles only if BlockGroup64Bit implements BlockGroup.
    43  var _ BlockGroup = (*BlockGroup64Bit)(nil)
    44  
    45  // Methods to override. Checksum() and Flags() are not overridden.
    46  
    47  // InodeTable implements BlockGroup.InodeTable.
    48  func (bg *BlockGroup64Bit) InodeTable() uint64 {
    49  	return (uint64(bg.InodeTableHi) << 32) | uint64(bg.InodeTableLo)
    50  }
    51  
    52  // BlockBitmap implements BlockGroup.BlockBitmap.
    53  func (bg *BlockGroup64Bit) BlockBitmap() uint64 {
    54  	return (uint64(bg.BlockBitmapHi) << 32) | uint64(bg.BlockBitmapLo)
    55  }
    56  
    57  // InodeBitmap implements BlockGroup.InodeBitmap.
    58  func (bg *BlockGroup64Bit) InodeBitmap() uint64 {
    59  	return (uint64(bg.InodeBitmapHi) << 32) | uint64(bg.InodeBitmapLo)
    60  }
    61  
    62  // ExclusionBitmap implements BlockGroup.ExclusionBitmap.
    63  func (bg *BlockGroup64Bit) ExclusionBitmap() uint64 {
    64  	return (uint64(bg.ExcludeBitmapHi) << 32) | uint64(bg.ExcludeBitmapLo)
    65  }
    66  
    67  // FreeBlocksCount implements BlockGroup.FreeBlocksCount.
    68  func (bg *BlockGroup64Bit) FreeBlocksCount() uint32 {
    69  	return (uint32(bg.FreeBlocksCountHi) << 16) | uint32(bg.FreeBlocksCountLo)
    70  }
    71  
    72  // FreeInodesCount implements BlockGroup.FreeInodesCount.
    73  func (bg *BlockGroup64Bit) FreeInodesCount() uint32 {
    74  	return (uint32(bg.FreeInodesCountHi) << 16) | uint32(bg.FreeInodesCountLo)
    75  }
    76  
    77  // DirectoryCount implements BlockGroup.DirectoryCount.
    78  func (bg *BlockGroup64Bit) DirectoryCount() uint32 {
    79  	return (uint32(bg.UsedDirsCountHi) << 16) | uint32(bg.UsedDirsCountLo)
    80  }
    81  
    82  // UnusedInodeCount implements BlockGroup.UnusedInodeCount.
    83  func (bg *BlockGroup64Bit) UnusedInodeCount() uint32 {
    84  	return (uint32(bg.ItableUnusedHi) << 16) | uint32(bg.ItableUnusedLo)
    85  }
    86  
    87  // BlockBitmapChecksum implements BlockGroup.BlockBitmapChecksum.
    88  func (bg *BlockGroup64Bit) BlockBitmapChecksum() uint32 {
    89  	return (uint32(bg.BlockBitmapChecksumHi) << 16) | uint32(bg.BlockBitmapChecksumLo)
    90  }
    91  
    92  // InodeBitmapChecksum implements BlockGroup.InodeBitmapChecksum.
    93  func (bg *BlockGroup64Bit) InodeBitmapChecksum() uint32 {
    94  	return (uint32(bg.InodeBitmapChecksumHi) << 16) | uint32(bg.InodeBitmapChecksumLo)
    95  }