示例#1
0
def write_inode(nbr, data):
    assert (dk.file_name != None), "NO DISK OPEN"
    assert (len(data) == 8), "Inode has 8 fields, not {}".format(len(data))
    sb = sfs.get_superblock()
    inode_block, inode_start = divmod(nbr, sfs.INODES_PER_BLOCK)
    assert (inode_block >= 0 and inode_block < sfs.INODE_BLOCK_COUNT * sfs.INODES_PER_BLOCK), "Invalid inode requested"
    ib = dk.disk_read(inode_block + sb[8])
    for v in data:
        inode_start = sfs.add_field(ib, v, inode_start)
    dk.disk_write(inode_block + sb[8], ib)

    ibp.set_used(nbr)
示例#2
0
def write_buffer():
    global buffer
    if buffer is None:
        print(noBuffer)
        return
    block = get_number("Which block on that disk?")
    as_byte_array = bytearray(buffer)
    try:
        dk.disk_write(block, as_byte_array)
        print("Wrote from buffer to disk.")
    except Exception as e:
        print(e)
示例#3
0
def empty_inode_blocks():
    sb = get_superblock()
    for i in range(INODE_BLOCK_COUNT):
        # i + sb[8] to skip over the superblock
        data = dk.disk_read(i + sb[8])
        field = 0
        for i in range(INODES_PER_BLOCK):

            # "isvalid" field
            field = add_field(data, INVALID_INODE, field)

            # "size" field
            field = add_field(data, INODE_SIZE, field)

            # dir1,...dir5, indir
            for i in range(6):
                field = add_field(data, 0, field)

        dk.disk_write(i + sb[8], data)
示例#4
0
def write_dir(inode, name, file=True):
    assert (dk.file_name != None), "NO DISK OPEN"

    if file:
        name = "f{}".format(name)
    else:
        name = "d{}".format(name)

    # Gets dir tuples and replaces one
    sb = sfs.get_superblock()
    dirs = get_dirs()
    for i, v in enumerate(dirs):
        if v[0] == sfs.INVALID_INODE:
            dirs[i] = (inode, name)
            break
    data, dblock = get_dir_block()
    field = 0
    for i in dirs:
        field = sfs.add_field(data, i[0], field)
        field = sfs.add_string(data, i[1], field, 28)
    dk.disk_write(dblock + sb[7], data)
示例#5
0
def superblock():

    # Gets data
    data = dk.disk_read(0)

    # Keeps track of which field writing to
    field = 0

    # Adds magic numbers - 0
    field = add_field(data, MAGIC, field)

    # Writes number of blocks - 1
    field = add_field(data, dk.NUMBER_OF_BLOCKS, field)

    # Adds ninodeblocks - 2
    field = add_field(data, INODE_BLOCK_COUNT, field)

    # Adds ninodes - 3
    field = add_field(data, INODES_PER_BLOCK, field)

    # Adds dentry - 4
    field = add_field(data, 1, field)

    # datablock bitmap - 5
    field = add_field(data, 1, field)

    # inode bitmap - 6
    field = add_field(data, 2, field)

    # first datablock - 7
    field = add_field(data, 3 + INODE_BLOCK_COUNT, field)

    # first inode block - 8
    field = add_field(data, 3, field)

    # Writes data
    dk.disk_write(0, data)
示例#6
0
def save_to_disk():
    global ibitmap
    assert(ibitmap != None), NO_BITMAP
    superblock = sfs.get_superblock()
    ibitmap_block = superblock[6]
    dk.disk_write(ibitmap_block, ibitmap)
示例#7
0
def save_to_disk():
    global bitmap
    assert (bitmap != None), NO_BITMAP
    superblock = sfs.get_superblock()
    bitmap_block = superblock[5]
    dk.disk_write(bitmap_block, bitmap)
示例#8
0
def write_buffer(ctx, filename, block):
    as_byte_array = bytearray(ctx.obj)
    result = dk.disk_write(filename, block, as_byte_array)
    if result == dk.SUCCESS:
        click.echo("Successfully wrote buffer to block {} in disk {}".format(
            block, filename))