1 #include <stdio.h> 2 #include <string.h> 3 4 #include "test_file_accessor.h" 5 6 TestFileAccessor::TestFileAccessor(fileid_t fileid, offset_t size) 7 : Accessor(fileid, size) 8 { 9 } 10 11 /* Data transfer methods. */ 12 13 void TestFileAccessor::fill(Flexpage *flexpage) 14 { 15 Region *region = flexpage->region; 16 offset_t filepos = flexpage->base_offset; 17 18 /* Tag the region with file state. */ 19 20 region->fill(fileid, filepos); 21 22 /* Write some data to each page of the flexpage in each region. This 23 allows each page to be tested regardless of how large each flexpage 24 or region is. */ 25 26 offset_t addr = flexpage->base_addr; 27 offset_t limit = addr + flexpage->size; 28 29 while (addr < limit) 30 { 31 /* Overwrite enough of any previous data to make the new data 32 readable. */ 33 34 char tag[32]; 35 36 sprintf(tag, "%ld:%ld", fileid, filepos); 37 38 memset((void *) addr, 0, strlen(tag) + 1); 39 strcpy((char *) addr, tag); 40 41 filepos += PAGE_SIZE; 42 addr += PAGE_SIZE; 43 } 44 } 45 46 void TestFileAccessor::flush(Flexpage *flexpage) 47 { 48 /* NOTE: Flushing would not necessarily blank the region as this does. 49 Also, a real flush operation would store the memory content. */ 50 51 flexpage->region->flush(); 52 } 53 54 // vim: tabstop=4 expandtab shiftwidth=4