コード例 #1
0
    def unlink(self, path):
        if Format.check_file_data(Format, path):
            self.data.pop(path)
            Format.clear_data_block(Format, path)

        self.files.pop(path)
        Format.clear_metadata_block(Format, path)
コード例 #2
0
    def write(self, path, data, offset, fh):
        self.data[path] = (
            # make sure the data gets inserted at the right offset
            self.data[path][:offset].ljust(offset, '\x00'.encode('ascii')) +
            data
            # and only overwrites the bytes that data is replacing
            + self.data[path][offset + len(data):])
        self.files[path]['st_size'] = len(self.data[path])

        # get the length of input data
        size = len(self.data[path])
        # calculate the number of blocks that need to store the data
        no_of_blocks = (size // BLOCK_SIZE) + 1
        # get the free blocks
        num_array = Format.get_free_block(Format, no_of_blocks)
        Format.clear_data_block(Format, path)
        # set the data block bitmap
        data_block_bitmap = Format.set_data_block_bitmap(Format, num_array)
        # get the input data
        input_data = self.data[path]

        # save the data to disk into the allocated blocks
        for i in range(no_of_blocks):
            if no_of_blocks == 1:
                disktools.write_block(num_array[i], input_data)
            else:
                disktools.write_block(num_array[i],
                                      input_data[i * 64:i * 64 + 64])
        # Add the data block bitmap into the metadata information
        Format.update_file_location(Format, path, data_block_bitmap)
        # update the st_size in the metadata
        Format.update_size(Format, path, self.files[path]['st_size'])
        # update the st_mtime in the metadata
        Format.update_mtime(Format, path, int(time()))
        # update the free block bitmap
        Format.update_bit_map(Format, num_array)

        return len(data)
コード例 #3
0
 def truncate(self, path, length, fh=None):
     # make sure extending the file fills in zero bytes
     self.data[path] = self.data[path][:length].ljust(
         length, '\x00'.encode('ascii'))
     self.files[path]['st_size'] = length
     Format.clear_data_block(Format, path)