-2

I need to run the linux 'read' system call with my arguments. Any ideas?

read(const char *path, char *buf, size_t size, off_t offset,struct fuse_file_info *fi)

I need to call the above function with my arguments.

ifryed
  • 605
  • 9
  • 21
  • **Why** do you need to call the read system call? Do you have a filehandle already? – Martijn Pieters Jul 01 '14 at 15:25
  • I'm building a testing script for a FUSE program and I need to check if the 'read' works correctly. – ifryed Jul 01 '14 at 15:30
  • A regular Python `open()` call into the mounted filesystem would work just fine. If you used Python to implement the FUSE plugin and you are building a unittest, then just call the Python implementation directly without bothering with actually firing up FUSE to drive it. – Martijn Pieters Jul 01 '14 at 15:31

1 Answers1

1

Python exposes the C stdlib read() function as the os.read() function:

os.read(fd, n)
Read at most n bytes from file descriptor fd. Return a string containing the bytes read. If the end of the file referred to by fd has been reached, an empty string is returned.

Errors are raised as OSError exceptions, with the errno attribute set to an integer as documented in the C read() documentation. You could use the errno module if you wanted constants to test against.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Thanks, do you happen to know how I specify the flags I want to read with? – ifryed Jul 01 '14 at 15:33
  • @ifryed: What do you mean, 'flags'? That's not an argument you can pass to the C-level `read()` function. – Martijn Pieters Jul 01 '14 at 15:35
  • @ifryed: are you confusing the 'read' function implemented by a FUSE plugin with the system read call, perhaps? – Martijn Pieters Jul 01 '14 at 15:37
  • I think I did mix them up, I edited the question – ifryed Jul 01 '14 at 15:38
  • That is indeed *not* the Linux `read()` function (I linked to the man page in my answer). You are basically asking how to test an arbitrary API, coded in whatever user-space language you coded your plugin in. If it is in Python, there is *no need to call a C function*. – Martijn Pieters Jul 01 '14 at 15:45