-
Notifications
You must be signed in to change notification settings - Fork 24
/
caching.go
68 lines (55 loc) · 1.33 KB
/
caching.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
62
63
64
65
66
67
68
// Manage caching of MFT Entry metadata. This is mainly used for path
// traversal calculation.
package parser
import "sync"
type FNSummary struct {
Name string
NameType string
ParentEntryNumber uint64
ParentSequenceNumber uint16
}
type MFTEntrySummary struct {
Sequence uint16
Filenames []FNSummary
}
type MFTEntryCache struct {
mu sync.Mutex
ntfs *NTFSContext
lru *LRU
}
func NewMFTEntryCache(ntfs *NTFSContext) *MFTEntryCache {
lru, _ := NewLRU(10000, nil, "MFTEntryCache")
return &MFTEntryCache{
ntfs: ntfs,
lru: lru,
}
}
func (self *MFTEntryCache) GetSummary(id uint64) (*MFTEntrySummary, error) {
self.mu.Lock()
defer self.mu.Unlock()
res_any, pres := self.lru.Get(int(id))
if pres {
res, ok := res_any.(*MFTEntrySummary)
if ok {
return res, nil
}
}
mft_entry, err := self.ntfs.GetMFT(int64(id))
if err != nil {
return nil, err
}
cache_record := &MFTEntrySummary{
Sequence: mft_entry.Sequence_value(),
}
for _, fn := range mft_entry.FileName(self.ntfs) {
cache_record.Filenames = append(cache_record.Filenames,
FNSummary{
Name: fn.Name(),
NameType: fn.NameType().Name,
ParentEntryNumber: fn.MftReference(),
ParentSequenceNumber: fn.Seq_num(),
})
}
self.lru.Add(int(id), cache_record)
return cache_record, nil
}