Beispiel #1
0
def mkdir(filename, directory): 
        inum = inode_number.get_free_inode()
        i = inode_number.inode_number_to_inode(inum)
        i.inode_type = FileType.directory
        i.add_block()
        d_inode = inode_number.inode_number_to_inode(directory)
        d_block = inode_number.inode_number_to_block((d_inode.size - 1) * blockLayer._block_size, directory)
        data = filename + "|" + str(inum) + ","
        d_block.write(d_block.size, data, 0, len(data))
        b_string = [""] * d_block.size
        b_string = d_block.read(0, b_string, 0, d_block.size)
Beispiel #2
0
def ls():
    b = inode_number.inode_number_to_block((inode_number.inode_number_to_inode(path_name_layer._wd)).size, path_name_layer._wd)
    buf = [''] * b.size
    buf = b.read(0, buf, 0, b.size - 1)
    d = "".join(buf)
    if(0 != b.size):
        dic = file_name_layer.createDict(d)
        for key in dic.keys():
            print "- ", key
    else:
        print "Empty Directory"
Beispiel #3
0
def lookup(filename, directory): 
    if(valid_filename(filename) == 0):
        i = inode_number.inode_number_to_inode(directory)
        if (i.inode_type != FileType.directory):
            raise Exception ("Not a directory.")
        offset = 0
        while (offset < i.size):
            b = inode_number.inode_number_to_block(offset,  directory)
            if (string_match(filename, b)):
                return inode_num(filename, b)  # may need to be returned as an int
            offset = offset + blockLayer._block_size
        return 0
    else:
        raise Exception("The filename %s is not a valid name." % filename)