Fuse C++ driver - read() implementation

679 views Asked by At

I'm trying to implement a FUSE driver. What I've done, is taken the basic operations that you override with your own function, and I've added a cout << operation << path << endl; So I can see which operation gets called. Here is my open function:

int Router::open(const char *path, struct fuse_file_info *fi) {
  std::cout << "open " << path << std::endl;
  return 0;
}

This returns 0 so the open should succeed all the time. Then, here is my read function:

int Router::read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
  std::cout << "read " << path << "Size: " << size << "Offset: " << offset << std::endl;
  buf[0] = 'h';
  buf[1] = '\0';
  return 2;
}

This should copy over h\0 to the buffer. But when I do: cat myfile it runs my open() function, which succeeds, then it runs my read() function, but the output of cat is nothing. It should output h but it doesn't. What am I doing wrong?

Also I find that under OSX, the exact same code only runs the open function, but never the read()

What could be the problem?

1

There are 1 answers

0
Benjamin Tamasi On

So my problem was that in the function: getattr(...) I did not specify the file size. After doing: st->st_size = 4096; Everything was working fine :)