pmdk_sys/
base.rs

1//
2// Copyright (c) 2019 RepliXio Ltd. All rights reserved.
3// Use is subject to license terms.
4//
5
6use serde::{Deserialize, Serialize};
7use std::fmt;
8
9#[repr(C)]
10#[derive(Copy, Clone, Serialize, Deserialize)]
11pub struct pmemoid {
12    pool_uuid_lo: u64,
13    off: u64,
14}
15
16impl Default for pmemoid {
17    #[inline(always)]
18    fn default() -> Self {
19        Self {
20            pool_uuid_lo: 0,
21            off: 0,
22        }
23    }
24}
25
26impl fmt::Debug for pmemoid {
27    #[inline(always)]
28    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29        write!(
30            f,
31            "pmemoid pool: {}, off: {:x}",
32            self.pool_uuid_lo, self.off
33        )
34    }
35}
36
37impl pmemoid {
38    pub fn new(pool_uuid_lo: u64, off: u64) -> Self {
39        Self { pool_uuid_lo, off }
40    }
41
42    pub fn off(&self) -> u64 {
43        self.off
44    }
45
46    pub fn pool_uuid_lo(&self) -> u64 {
47        self.pool_uuid_lo
48    }
49
50    pub fn is_null(&self) -> bool {
51        self.off == 0 && self.pool_uuid_lo == 0
52    }
53}
54
55// struct of 2 u64, (pool-id, offset): (u64, u64)
56// PMEM holds a global variable in memory and lookup offset in pool (obj, block, or misc)
57// must be translated into a pointer
58pub type PMEMoid = pmemoid;