TEST_F(MemkindPmemTests, test_TC_MEMKIND_PmemPriv) { size_t total_mem = 0; size_t free_mem = 0; pmem_get_size(pmem_kind, total_mem, free_mem); ASSERT_TRUE(total_mem != 0); ASSERT_TRUE(free_mem != 0); EXPECT_EQ(total_mem, roundup(PMEM_PART_SIZE, MEMKIND_PMEM_CHUNK_SIZE)); size_t offset = total_mem - free_mem; EXPECT_LT(offset, MEMKIND_PMEM_CHUNK_SIZE); EXPECT_LT(offset, total_mem); }
/* Read the buffer requested by copying as much as needed from each page. Invalid pages will be replaced with NULLs. */ static ssize_t pmem_read(struct file *file, char *buf, size_t count, loff_t *poff) { loff_t file_size = pmem_get_size(); /* How much data is available in the entire memory range. */ size_t available = file_size - *poff; size_t to_read = min(count, available); size_t remaining = to_read; if(file_size < *poff) return 0; /* Just keep going until the full buffer is copied. Due to the null padding on error its impossible to fail here. */ while(remaining > 0) { remaining -= pmem_read_partial(file, buf + (to_read - remaining), remaining, poff); }; return to_read; }
/* Implement seeking behaviour. For whence=2 we need to figure out the size of RAM which is the end address of the last "System RAM" resource. */ static loff_t pmem_llseek(struct file *file, loff_t offset, int whence) { switch (whence) { case 0: { file->f_pos = offset; break; }; case 1: { file->f_pos += offset; break; }; case 2: { file->f_pos = pmem_get_size() + offset; break; }; default: return -EINVAL; } return file->f_pos; }