0

I'm writing an FUSE overlay fs (notifyfs), which can be an database clients can get data from through queries. My intention is to make it a cache/overlayfs/database clients can get data from when showing entries and their properties (attributes but also mimetype, icon etc).

A query is to get the contents of a directory. The client, which has already a connection (=fd) to notifyfs, asks for the data via a "list_message". My question is now howto programm the response notifyfs has to give. I'm thinking about three/two different methods. Note the following:

notifyfs responses in the basic form with different entries, where every entry is sort of:

int mode
uid_t uid
gid_t gid
size_t size
timespec ctime
timespec mtime
timespec atime
int lenname
char name[]

(call this notifyfs_entry_struct)

Note that the len of the name is not fixed, and is maximum 255. Futher clients ask for a certain number of entries, with a maximum. I'm not sure about this maximum exactly, but it will be something like 80.

a. one big buffer. The size is something like:

80 x (255+sizeof(struct notifyfs_entry_struct))

which will be more than 20400 bytes to be sure.

b. chunks of fixed size, using something like iovec or readdir.

What is the best option? The first method uses a buffer which will be at least 20400 bytes, it's a lot, but is it still doable?

Stef

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
user1388973
  • 119
  • 1
  • 11

1 Answers1

0

Since you mentioned "connection" I assume you are talking about TCP sockets.

It doesn't really matter which method you choose. a. is a little easier - contiguous memory, simple offsets into the buffer.

What you have to watch out for is that TCP socket is a stream of bytes. It doesn't know about your message boundaries, so since your messages are variable size, you don't know if you got a complete message from the return value of read(2) or recv(2). You will have to handle partial message reads and buffer unprocessed bytes.

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
  • Thanks a lot. No I'm using local sockets. Clients are local apps which want to get to contents of a directory from a certain name (dir or normal file) and with a max number of entries. So It's sort of a database fs. You say it does not really matter what method. But the size in the first case (one big buffer) will be very big (25 K). Is that still ok? – user1388973 Nov 06 '12 at 08:35