Commit 48c38201 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent d6640f97
......@@ -233,6 +233,14 @@ class tFile:
mm.unmap(t.fmmap)
t.f.close()
# sizeblk returns file size in blocks.
def sizeblk(t):
st = os.fstat(t.f.fileno())
assert st.st_size % t.blksize == 0
assert st.st_size // t.blksize <= t._max_tracked
return st.st_size // t.blksize
"""
# readblk reads ZBigFile[blk] from wcfs.
# XXX not needed?
......@@ -258,7 +266,9 @@ class tFile:
#
# incorev is [] of 1/0 representing whether block data is present or not.
def assertCache(t, incorev):
pass # TODO
pass
# XXX todo
#mm.incore(
# blk returns bytearray connected to view of file[blk].
......@@ -266,6 +276,24 @@ class tFile:
assert blk <= t._max_tracked
return bytearray(t.fmmap[blk*t.blksize:(blk+1)*t.blksize])
# cached returns [] with indicating whether of file block is cached or not.
# 1 - cached, 0 - not cached, fractional (0,1) - some pages of the block are cached some not.
def cached(t):
l = t.sizeblk()
incorev = mm.incore(t.fmmap[:l*t.blksize])
# incorev is in pages; convert to in blocks
assert t.blksize % mm.PAGE_SIZE == 0
blkpages = t.blksize // mm.PAGE_SIZE
cachev = [0.]*l
for i, v in enumerate(incorev):
blk = i // blkpages
cachev[blk] += bool(v)
for blk in range(l):
cachev[blk] /= blkpages
if cachev[blk] == int(cachev[blk]):
cachev[blk] = int(cachev[blk]) # 0.0 -> 0, 1.0 -> 1
return cachev
# assertBlk asserts that file block #blk has data as expected.
#
# Expected data may be given with size < t.blksize. In such case the data
......@@ -280,6 +308,9 @@ class tFile:
assert t.blk(blk) == data, ("#blk: %d" % blk)
# we just accessed the block - it has to be in OS cache
assert t.cached()[blk] == 1
# assertData asserts that file has data blocks as specified.
#
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment