-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathblock_group_descriptor_list.go
61 lines (47 loc) · 1.6 KB
/
block_group_descriptor_list.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
51
52
53
54
55
56
57
58
59
60
61
package ext4
import (
"io"
"github.com/dsoprea/go-logging"
)
type BlockGroupDescriptorList struct {
sb *Superblock
bgds []*BlockGroupDescriptor
}
// NewBlockGroupDescriptorListWithReadSeeker returns a
// `BlockGroupDescriptorsList`, which has all block-group-descriptors in a big
// slice. Filesystems with the flex_bg capability flag (most) will group all of
// the BGD data together right at the top.
func NewBlockGroupDescriptorListWithReadSeeker(rs io.ReadSeeker, sb *Superblock) (bgdl *BlockGroupDescriptorList, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
}
}()
// QUESTION(dustin): This whole group is replicated/backed-up along with the superblock?
// currentBlock initially points at the block with the first BGD.
initialBlock := uint64(sb.Data().SFirstDataBlock) + 1
initialOffset := initialBlock * uint64(sb.BlockSize())
_, err = rs.Seek(int64(initialOffset), io.SeekStart)
log.PanicIf(err)
blockGroupsCount := sb.BlockGroupCount()
bgds := make([]*BlockGroupDescriptor, blockGroupsCount)
for i := uint64(0); i < blockGroupsCount; i++ {
bgd, err := NewBlockGroupDescriptorWithReader(rs, sb)
log.PanicIf(err)
bgds[i] = bgd
}
bgdl = &BlockGroupDescriptorList{
sb: sb,
bgds: bgds,
}
return bgdl, nil
}
func (bgdl *BlockGroupDescriptorList) GetWithAbsoluteInode(n int) (bgd *BlockGroupDescriptor, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
}
}()
blockGroupNumber := bgdl.sb.BlockGroupNumberWithAbsoluteInodeNumber(n)
return bgdl.bgds[blockGroupNumber], nil
}