summaryrefslogtreecommitdiff
path: root/internal/openfiletable/inummap.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-04-12 17:15:03 +0200
committerJakob Unterwurzacher2020-04-13 14:54:04 +0200
commit488111ce390218806fca933b89279b766f7ff49c (patch)
treed75a8aac95f95767410027da14cd0231c17110a3 /internal/openfiletable/inummap.go
parent194030f18ae623fbf5b0bb805b780f81fe9ec7a7 (diff)
inomap: split into separate package
inomap will also be used by fusefrontend_reverse in the future. Split if off openfiletable to make it independent.
Diffstat (limited to 'internal/openfiletable/inummap.go')
-rw-r--r--internal/openfiletable/inummap.go63
1 files changed, 0 insertions, 63 deletions
diff --git a/internal/openfiletable/inummap.go b/internal/openfiletable/inummap.go
deleted file mode 100644
index d9f6862..0000000
--- a/internal/openfiletable/inummap.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package openfiletable
-
-import (
- "sync"
- "syscall"
-)
-
-// UINT64_MAX = 18446744073709551615
-const inumTranslateBase = 10000000000000000000
-
-// InumMap ... see NewInumMap() for description.
-type InumMap struct {
- sync.Mutex
- baseDev uint64
- translate map[QIno]uint64
- translateNext uint64
-}
-
-// NewInumMap returns a new inumMap.
-//
-// inumMap translates (device uint64, inode uint64) pairs to unique uint64
-// inode numbers.
-// Inode numbers on the "baseDev" are passed through unchanged (as long as they
-// are not higher than inumTranslateBase).
-// Inode numbers on other devices are remapped to the number space above
-// 10000000000000000000. The mapping is stored in a simple Go map. Entries
-// can only be added and are never removed.
-func NewInumMap(baseDev uint64) *InumMap {
- return &InumMap{
- baseDev: baseDev,
- translate: make(map[QIno]uint64),
- translateNext: inumTranslateBase,
- }
-}
-
-// Translate maps the passed-in (device, inode) pair to a unique inode number.
-func (m *InumMap) Translate(in QIno) (out uint64) {
- if in.Dev == m.baseDev && in.Ino < inumTranslateBase {
- return in.Ino
- }
- m.Lock()
- defer m.Unlock()
- out = m.translate[in]
- if out != 0 {
- return out
- }
- out = m.translateNext
- m.translate[in] = m.translateNext
- m.translateNext++
- return out
-}
-
-// TranslateStat translates the inode number contained in "st" if neccessary.
-// Convience wrapper around Translate().
-func (m *InumMap) TranslateStat(st *syscall.Stat_t) {
- in := QInoFromStat(st)
- st.Ino = m.Translate(in)
-}
-
-// Count returns the number of entries in the translation table.
-func (m *InumMap) Count() int {
- return len(m.translate)
-}