read implementation of Fuse in python not returning as expected, cat: <mountpoint>: bad address

I am trying to fetch data from some repository and am trying to display file contents of any file for instance with cat <filename> inside a repository directory.

def read(self, path, size, offset, fh=None):
	file_content = ''
	path_ele = path.split('/')
	if path.endswith('/') or path[1] == '.':
		return file_content
		path = path.split('/')
		repo_name = path[-2]
		file_name = path[-1]
		print(repo_name, file_name)
		for item in self.user.get_user().get_repos():
			if == repo_name:
				files = item.get_dir_contents('/')
				for file_ in files:
					if file_name ==
						file_content = item.get_file_contents(file_name).decoded_content
						return file_content

When I do cat on a file in a repository directory it gives me an error caused by the following line

assert retsize <= size, 'actual amount read %d greater than expected %d' % (retsize, size)

in fusepys read function link.


You do not respect all parameters of read, i.e. size and offset. Certain programs or commands read only chunks of files at a time. This means that they expect to be able to read x bytes (size) starting at position y bytes (offset). So your primary mistake in your code snipped is that you just return the entire file for every read operation.

A fix could start with something trivial like returning file_content[offset:(offset+size)]. When I say "start", you have to keep in mind that you must also raise proper errors if the offset or size (for the given offset) passed into your read function are out of bounds.

Posted on by s-m-e