1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/files/test_file_accessor.cc Sun Mar 14 17:17:09 2021 +0100
1.3 @@ -0,0 +1,54 @@
1.4 +#include <stdio.h>
1.5 +#include <string.h>
1.6 +
1.7 +#include "test_file_accessor.h"
1.8 +
1.9 +TestFileAccessor::TestFileAccessor(fileid_t fileid, offset_t size)
1.10 +: Accessor(fileid, size)
1.11 +{
1.12 +}
1.13 +
1.14 +/* Data transfer methods. */
1.15 +
1.16 +void TestFileAccessor::fill(Flexpage *flexpage)
1.17 +{
1.18 + Region *region = flexpage->region;
1.19 + offset_t filepos = flexpage->base_offset;
1.20 +
1.21 + /* Tag the region with file state. */
1.22 +
1.23 + region->fill(fileid, filepos);
1.24 +
1.25 + /* Write some data to each page of the flexpage in each region. This
1.26 + allows each page to be tested regardless of how large each flexpage
1.27 + or region is. */
1.28 +
1.29 + offset_t addr = flexpage->base_addr;
1.30 + offset_t limit = addr + flexpage->size;
1.31 +
1.32 + while (addr < limit)
1.33 + {
1.34 + /* Overwrite enough of any previous data to make the new data
1.35 + readable. */
1.36 +
1.37 + char tag[32];
1.38 +
1.39 + sprintf(tag, "%ld:%ld", fileid, filepos);
1.40 +
1.41 + memset((void *) addr, 0, strlen(tag) + 1);
1.42 + strcpy((char *) addr, tag);
1.43 +
1.44 + filepos += PAGE_SIZE;
1.45 + addr += PAGE_SIZE;
1.46 + }
1.47 +}
1.48 +
1.49 +void TestFileAccessor::flush(Flexpage *flexpage)
1.50 +{
1.51 + /* NOTE: Flushing would not necessarily blank the region as this does.
1.52 + Also, a real flush operation would store the memory content. */
1.53 +
1.54 + flexpage->region->flush();
1.55 +}
1.56 +
1.57 +// vim: tabstop=4 expandtab shiftwidth=4