It is currently Thu, 20 Jan 2022 05:23:32 GMT



 
Author Message
 Phanomen with using write() function on AIX when no space left
Hello,

I want to use mmap() on AIX 4.3.3

When no space lefts on device I get a buserror.

Following you can see my testprogram:

***************************************************************

#include <stdio.h>
#include <errno.h>
#include <stropts.h>
#include <memory.h>

#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>

int main(int argc, char* argv[])
{
        int fdout;
        FILE *fdoutFile;
        void *dst;

        int length = 4000;

        umask(0);

        /* open file */
        if((fdout = open("./tempfile", O_RDWR | O_CREAT | O_TRUNC, 0644)) <
0)
        {
                return 1;
        }

        /* open a FILE from the int value */
        fdoutFile = fdopen(fdout,"w+");

        /* set buffering to 0 */
        setvbuf(fdoutFile,NULL,_IONBF,0);

        /* set position of file to length */
        if(fseek(fdoutFile,length,SEEK_SET) != NULL)
        {
                fprintf(stderr,"FSEEK ERROR\n");
                return 1;
        }

        /* write one byte to check if some space is left */
        if(fwrite("",1,1,fdoutFile) < 1)
        {
                fprintf(stderr,"FWRITE ERROR\n");
                return 1;
        }

        /* set position of file to length */
        if(lseek(fdout, length, SEEK_SET) == -1)
        {
                fprintf(stderr,"LSEEK ERROR\n");
                return 1;
        }

        /* write one byte to check if some space is left */
        if(write(fdout,"",1) != 1)
        {
                fprintf(stderr,"WRITE ERROR\n");
                fprintf(stderr,"errno: %d\n",errno);
                return 1;
        }

        if((dst=mmap(0,length, PROT_READ | PROT_WRITE, MAP_SHARED, fdout,0))
==(caddr_t)-1)
        {
                fprintf(stderr,"MMAP ERROR\n");
                return 1;
        }

        char * temp = new char[length];
        memset(temp,0,length);
        memcpy(dst,temp,length);

        return 0;

*************************************************************************

The programm checks this Phanomen with write() and fwrite().
When length is 4000, both write functions came back with an error (that is
what I want).

When length is 4100, both write functions came back with ok. The problem is,
that the memcpy at the end of the program terminates with a buserror.

When length is 8000, both write functinos came back with an error (that is
what I want).

Can anybody tell me if this is a bug in my program, or a bug in the
operating system? Have anybody an idea for a workaround?

Thanks,

Aignerma



 Sun, 04 Sep 2005 23:42:54 GMT   
 
   [ 1 post ] 

Similar Threads

1. Phanomen with using write() function on AIX when no space left

2. cat: write error: no space left on device [was From RedHat to Slackware)

3. No space left on device (although space exists)

4. How to make space (no space left on device)

5. Writing to address space with /proc (AIX 5.1)

6. AIX fortran calling character function written in C

7. AIX 4.2 - serial communication using POSIX functions

8. Using functions and trap in aix's ksh - Problem

9. Problem using function and trap under aix and ksh


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software