mirror of https://github.com/ceph/go-ceph
timespec: move to internal pkg
There are functions from librbd that can use the Timespec type too. Instead of consuming 'cephfs.Timespec' in the rbd package, create an internal type that can be exposed through both packages. This looks a bit like duplication, but it does not break the current users of Timespec in the cephfs package. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
3a0bacb039
commit
c4714165a6
|
@ -7,6 +7,13 @@ package cephfs
|
|||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
ts "github.com/ceph/go-ceph/internal/timespec"
|
||||
)
|
||||
|
||||
// Timespec is a public type for the internal C 'struct timespec'
|
||||
type Timespec ts.Timespec
|
||||
|
||||
// StatxMask values contain bit-flags indicating what data should be
|
||||
// populated by a statx-type call.
|
||||
type StatxMask uint32
|
||||
|
@ -109,10 +116,10 @@ func cStructToCephStatx(s C.struct_ceph_statx) *CephStatx {
|
|||
Blocks: uint64(s.stx_blocks),
|
||||
Dev: uint64(s.stx_dev),
|
||||
Rdev: uint64(s.stx_rdev),
|
||||
Atime: cStructToTimespec(s.stx_atime),
|
||||
Ctime: cStructToTimespec(s.stx_ctime),
|
||||
Mtime: cStructToTimespec(s.stx_mtime),
|
||||
Btime: cStructToTimespec(s.stx_btime),
|
||||
Atime: Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&s.stx_atime))),
|
||||
Ctime: Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&s.stx_ctime))),
|
||||
Mtime: Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&s.stx_mtime))),
|
||||
Btime: Timespec(ts.CStructToTimespec(ts.CTimespecPtr(&s.stx_btime))),
|
||||
Version: uint64(s.stx_version),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cephfs
|
||||
package timespec
|
||||
|
||||
/*
|
||||
#include <time.h>
|
||||
|
@ -6,6 +6,8 @@ package cephfs
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
|
@ -14,7 +16,13 @@ import (
|
|||
// apis that could be lossy with the use of Go time types.
|
||||
type Timespec unix.Timespec
|
||||
|
||||
func cStructToTimespec(t C.struct_timespec) Timespec {
|
||||
// CTimespecPtr is an unsafe pointer wrapping C's `struct timespec`.
|
||||
type CTimespecPtr unsafe.Pointer
|
||||
|
||||
// CStructToTimespec creates a new Timespec for the C 'struct timespec'.
|
||||
func CStructToTimespec(cts CTimespecPtr) Timespec {
|
||||
t := (*C.struct_timespec)(cts)
|
||||
|
||||
return Timespec{
|
||||
Sec: int64(t.tv_sec),
|
||||
Nsec: int64(t.tv_nsec),
|
Loading…
Reference in New Issue