2020-04-12 17:15:03 +02:00
|
|
|
package inomap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2020-04-19 21:57:53 +02:00
|
|
|
type namespaceData struct {
|
|
|
|
// Stat_t.Dev is uint64 on 32- and 64-bit Linux
|
|
|
|
Dev uint64
|
2020-05-03 15:22:10 +02:00
|
|
|
// Tag acts like an extension of the Dev field.
|
2020-04-19 21:57:53 +02:00
|
|
|
// It is used by reverse mode for virtual files.
|
2020-05-03 15:22:10 +02:00
|
|
|
// Normal (forward) mode does not use it and it
|
|
|
|
// stays always zero there.
|
|
|
|
Tag uint8
|
2020-04-19 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
2020-04-12 17:15:03 +02:00
|
|
|
// QIno = Qualified Inode number.
|
2021-08-16 17:14:14 +02:00
|
|
|
// Uniquely identifies a backing file through the
|
|
|
|
// (device number, tag, inode number) tuple.
|
2020-04-12 17:15:03 +02:00
|
|
|
type QIno struct {
|
2020-04-19 21:57:53 +02:00
|
|
|
namespaceData
|
|
|
|
// Stat_t.Ino is uint64 on 32- and 64-bit Linu
|
2020-04-12 17:15:03 +02:00
|
|
|
Ino uint64
|
|
|
|
}
|
|
|
|
|
2020-05-03 15:22:10 +02:00
|
|
|
// NewQIno returns a filled QIno struct
|
|
|
|
func NewQIno(dev uint64, tag uint8, ino uint64) QIno {
|
2020-04-12 17:15:03 +02:00
|
|
|
return QIno{
|
2020-04-19 21:57:53 +02:00
|
|
|
namespaceData: namespaceData{
|
2020-05-03 15:22:10 +02:00
|
|
|
Dev: dev,
|
|
|
|
Tag: tag,
|
2020-04-19 21:57:53 +02:00
|
|
|
},
|
2020-05-03 15:22:10 +02:00
|
|
|
Ino: ino,
|
2020-04-12 17:15:03 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-03 15:22:10 +02:00
|
|
|
|
|
|
|
// QInoFromStat fills a new QIno struct with the passed Stat_t info.
|
|
|
|
func QInoFromStat(st *syscall.Stat_t) QIno {
|
|
|
|
// There are some architectures that use 32-bit values here
|
|
|
|
// (darwin, freebsd-32, maybe others). Add an explicit cast to make
|
|
|
|
// this function work everywhere.
|
|
|
|
return NewQIno(uint64(st.Dev), 0, uint64(st.Ino))
|
|
|
|
}
|