def writeat_direct(dev, offset, data):
    pg = (offset / PAGE_SIZE)
    assert (pg == ((offset + len(data)) / PAGE_SIZE))
    pg_offset = (pg * PAGE_SIZE)
    f = os.open(dev, (os.O_DIRECT | os.O_RDWR))
    m = mmap.mmap((- 1), PAGE_SIZE)
    try:
        os.lseek(f, pg_offset, os.SEEK_SET)
        pg_data = readat_direct(dev, pg_offset, PAGE_SIZE)
        m.write(pg_data)
        m.seek((offset % PAGE_SIZE))
        m.write(data)
        ret = directio.write(f, m)
    finally:
        m.close()
        os.close(f)
    return ret
def writeat_direct(dev, offset, data):
    pg = (offset / PAGE_SIZE)
    assert (pg == ((offset + len(data)) / PAGE_SIZE))
    pg_offset = (pg * PAGE_SIZE)
    f = os.open(dev, (os.O_DIRECT | os.O_RDWR))
    m = mmap.mmap((- 1), PAGE_SIZE)
    try:
        os.lseek(f, pg_offset, os.SEEK_SET)
        pg_data = readat_direct(dev, pg_offset, PAGE_SIZE)
        m.write(pg_data)
        m.seek((offset % PAGE_SIZE))
        m.write(data)
        ret = directio.write(f, m)
    finally:
        m.close()
        os.close(f)
    return ret