def readat_direct(dev, offset, length):
    pg = (offset / PAGE_SIZE)
    in_page_offset = (offset % PAGE_SIZE)
    if (in_page_offset != 0):
        assert (pg == ((offset + length) / PAGE_SIZE))
        to_read = PAGE_SIZE
    else:
        assert ((length % PAGE_SIZE) == 0)
        to_read = length
    pg_offset = (pg * PAGE_SIZE)
    f = os.open(dev, (os.O_DIRECT | os.O_RDONLY))
    try:
        os.lseek(f, pg_offset, os.SEEK_SET)
        ret = directio.read(f, to_read)
    finally:
        os.close(f)
    return ret[in_page_offset:(in_page_offset + length)]
def readat_direct(dev, offset, length):
    pg = (offset / PAGE_SIZE)
    in_page_offset = (offset % PAGE_SIZE)
    if (in_page_offset != 0):
        assert (pg == ((offset + length) / PAGE_SIZE))
        to_read = PAGE_SIZE
    else:
        assert ((length % PAGE_SIZE) == 0)
        to_read = length
    pg_offset = (pg * PAGE_SIZE)
    f = os.open(dev, (os.O_DIRECT | os.O_RDONLY))
    try:
        os.lseek(f, pg_offset, os.SEEK_SET)
        ret = directio.read(f, to_read)
    finally:
        os.close(f)
    return ret[in_page_offset:(in_page_offset + length)]