def mkdir(self, path, mode): self.files[path] = dict(st_mode=(S_IFDIR | mode), st_nlink=2, st_size=0, st_ctime=time(), st_mtime=time(), st_atime=time()) name = path mode = self.files[path].get('st_mode') ctime = self.files[path].get('st_ctime') mtime = self.files[path].get('st_mtime') atime = self.files[path].get('st_atime') nlink = self.files[path].get('st_nlink') size = self.files[path].get('st_size') uid = os.getuid() gid = os.getgid() self.chown(path, uid, gid) # get free block for the new created file to save the metadata. num_array = Format.get_free_block(Format, 1) block_num = num_array[0] # set up the location in the disk inode_data = Format.set_inode(Format, name, mode, ctime, mtime, atime, nlink, uid, gid, size, block_num) disktools.write_block(block_num, inode_data) # update the free block bitmap Format.update_bit_map(Format, num_array) # find the parent path and add the nlink by 1. parent_path = Format.find_parent_path(Format, path) self.files[parent_path]['st_nlink'] += 1 Format.update_nlink(Format, parent_path, 1)
def create(self, path, mode): self.files[path] = dict(st_mode=(S_IFREG | mode), st_nlink=1, st_size=0, st_ctime=time(), st_mtime=time(), st_atime=time()) name = path mode = self.files[path].get('st_mode') ctime = self.files[path].get('st_ctime') mtime = self.files[path].get('st_mtime') atime = self.files[path].get('st_atime') nlink = self.files[path].get('st_nlink') size = self.files[path].get('st_size') uid = os.getuid() gid = os.getgid() self.chown(path, uid, gid) # get free block for the new created file to save the metadata. num_array = Format.get_free_block(Format, 1) block_num = num_array[0] # set up the location in the disk inode_data = Format.set_inode(Format, name, mode, ctime, mtime, atime, nlink, uid, gid, size, block_num) disktools.write_block(block_num, inode_data) # update the free block bitmap Format.update_bit_map(Format, num_array) self.fd += 1 return self.fd