Praveen Raj(deleted)
|
Facing problem with ftruncate() API
|
Praveen Raj(deleted)
10/13/2010 7:21 AM
post70399
|
Facing problem with ftruncate() API
Hi,
I'm a new bee to QNX platform and facing issue with the ftruncate() API on QNX 6.5.
I'm validating a database test harness (which has lots of test cases)on QNX. As part of the test validation a file is
created as shared memory object for storing the database page indexes. The shared memory is getting created without any
issues.
The actual problem i'm facing is explained below:
- I create a shared memory object (a file which is part of database) and truncate it to 32kb (In my case shared memory
is extended/truncated in multiples of 32kb) and store the database indexes here. This shared memory is in turn mmapped
to my process address space.
- Now as the database grows, even the shared memory needs to be increased to accomodate the new indexes. At this point
when i try to truncate my shared memory to new size(i.e 64kb), my previous 32kb data is getting zeroed. The ftruncate()
API description tells that only the extended memory region is filled with NULL. But here the entire shared memory
(file)is getting filled with NULL.
- When this data (indexes) is mmapped to my process address space and is used to retrieve data from database, it pops up
"database corrupted" error (as all the indexes are NULL).
--------------------------------------------------------------------------------------------
API details:
int ftruncate( int fildes,
off_t length );
Arguments:
fildes
The descriptor for the file that you want to truncate.
length
The length that you want the file to be, in bytes.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
These functions cause the file referenced by fildes to have a size of length bytes. If the size of the file previously
exceeded length, the extra data is discarded (this is similar to using the F_FREESP option with fcntl()). If the size of
the file was previously shorter than length, the file size is extended with NUL characters (similar to the F_ALLOCSP
option to fcntl()).
The value of the seek pointer isn't modified by a call to ftruncate().
---------------------------------------------------------------------------------
Not sure what could be happening here and why the entire shared memory is made NULL while truncating.
Any inputs/suggestions for the above issue will be highly appreciated.
Note: If i hardcode the shared memory object size to a very high value, the issue is not seen (because ftruncate is not
called, as database has sufficient space for storing the indexes)
Thanks,
Praveen
|
|
|