Unix Programming - allocating appropriate amount of space for readdir result

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2004 > allocating appropriate amount of space for readdir result





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author allocating appropriate amount of space for readdir result
Raja Sambasivan

2004-01-23, 5:17 pm

Hello,

Here's a potential issue I've been unable to propperly resolve.

I'm simply trying to read a directory result from NFS using a MT-safe
version of rpc. The readdir prototype looks like this:

nfsproc_readdir_2( readdirargs *, readdirres *)


If the readdirres pointer I pass in is null, the necessary space will
be malloced for me in some local static variable, and hence will be
overwritten on successive calls (I think). However, if I do malloc
space for every single pointer in the readdirres structure (i.e. each
individual entry, and the name field in each individual entry), the
rpc call will use the pointers I have provided as the locations in
which it will write data.

Since I wish to multithread all of this eventually, I'm assuming that
I should be the one allocating space for all the necessary fields in
the readdirress structure (I think!)..but I'm confused as to how to go
about doing this. I know that the readdirargs struct has a count
field which I claim is the maximum number of bytes the client is
willing to receive...however, the size of each entry in the readdirres
structure is variable depending upon the length of each filename in
the directory, so I as the client never have any idea how many entries
to expect, and hence how many entries to allocate space for before
calling the readdir command.

To make it worse, the rpc call overwrites the nextentry field in the
last entry it returns to null, so if allocate more entries than
necessary, I essentially 'lose' them as a result of the rpc call.

So is there a better way to keep allocate space for a readdirres? Any
help/clarification would be appreciated. I'm really learning RPC and
such on the fly here, and hence I'd like to know about any conceptual
mistakes I'm making.

Raja
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com