File flush problem - VxWorks

This is a discussion on File flush problem - VxWorks ; Hi, I am finding a problem in file flushing. I am writing in to a file and calling appropriate flush function calls. But I found that the file is not updated/flushed until I close the file. As I have frequent ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: File flush problem

  1. File flush problem

    Hi,

    I am finding a problem in file flushing. I am writing in to a file and
    calling appropriate flush function calls. But I found that the file is
    not updated/flushed until I close the file. As I have frequent update
    to the file, I do not want to open and close the file each time I
    write to it as it is a large file and open() and close() are expensive
    operations.

    I am using the following file-flush related function calls:

    ioctl(fd, FIOWFLUSH, 0);
    ioctl(fd, FIOFLUSH, 0);
    ioctl(fd, FIOSYNC, 0);


    Following is code snippet I am using just to test file flush:

    void test_file_flush(void)
    {
    int fd;
    char buf[128] = "Test string for testing file flush\n";

    fd = open("foo", O_WRONLY, 0777);
    if(fd == ERROR)
    {
    printf("Error: Unable to open file\n");
    return;
    }
    if(write(fd, buf, strlen(buf)) != strlen(buf))
    {
    printf("Error occurred while writing to the file\n");
    return;
    }

    ioctl(fd, FIOWFLUSH, 0);
    ioctl(fd, FIOFLUSH, 0);
    ioctl(fd, FIOSYNC, 0);

    // close(fd);
    }

    Thank you,

    Ragards,
    Prashanth

  2. Re: File flush problem

    A few questions ...

    1. What version of VxWorks are you using?
    2. What type of file system? (DosFS, HRFS, NFSv2, NFSv3, ...)
    3. What options are the file system initialized with?
    4. How are determining that the file has not been flushed/updated?
    5. What is your backing media? (disk, ram, flash, ... ).

    Also, from what I remember FIOSYNC should be sufficient to flush the
    file system cache to disk.

    Sparky

    On Nov 11, 7:20*am, Prashanth wrote:
    > Hi,
    >
    > I am finding a problem in file flushing. I am writing in to a file and
    > calling appropriate flush function calls. But I found that the file is
    > not updated/flushed until I close the file. As I have frequent update
    > to the file, I do not want to open and close the file each time I
    > write to it as it is a large file and open() and close() are expensive
    > operations.
    >
    > I am using the following file-flush related function calls:
    >
    > * * * ioctl(fd, FIOWFLUSH, 0);
    > * * * ioctl(fd, FIOFLUSH, 0);
    > * * * ioctl(fd, FIOSYNC, 0);
    >
    > Following is code snippet I am using just to test file flush:
    >
    > void test_file_flush(void)
    > {
    > * * * int fd;
    > * * * char buf[128] = "Test string for testing file flush\n";
    >
    > * * * fd = open("foo", O_WRONLY, 0777);
    > * * * if(fd == ERROR)
    > * * * {
    > * * * * * * printf("Error: Unable to open file\n");
    > * * * * * * return;
    > * * * }
    > * * * if(write(fd, buf, strlen(buf)) != strlen(buf))
    > * * * {
    > * * * * * * printf("Error occurred while writing to the file\n");
    > * * * * * * return;
    > * * * }
    >
    > * * * ioctl(fd, FIOWFLUSH, 0);
    > * * * ioctl(fd, FIOFLUSH, 0);
    > * * * ioctl(fd, FIOSYNC, 0);
    >
    > * * * // close(fd);
    >
    > }
    >
    > Thank you,
    >
    > Ragards,
    > Prashanth



  3. Re: File flush problem

    one question. Are you using a netDrv(ftp) to write file ?

    The netDrv is not affected by fflush and ioctl's flush .

    The VxWorks netDrv keep data in memory until file is close.

    Try to use NFS.





    On 11월11일, 오후9시20분, Prashanth wrote:
    > Hi,
    >
    > I am finding a problem in file flushing. I am writing in to a file and
    > calling appropriate flush function calls. But I found that the file is
    > not updated/flushed until I close the file. As I have frequent update
    > to the file, I do not want to open and close the file each time I
    > write to it as it is a large file and open() and close() are expensive
    > operations.
    >
    > I am using the following file-flush related function calls:
    >
    > ioctl(fd, FIOWFLUSH, 0);
    > ioctl(fd, FIOFLUSH, 0);
    > ioctl(fd, FIOSYNC, 0);
    >
    > Following is code snippet I am using just to test file flush:
    >
    > void test_file_flush(void)
    > {
    > int fd;
    > char buf[128] = "Test string for testing file flush\n";
    >
    > fd = open("foo", O_WRONLY, 0777);
    > if(fd == ERROR)
    > {
    > printf("Error: Unable to open file\n");
    > return;
    > }
    > if(write(fd, buf, strlen(buf)) != strlen(buf))
    > {
    > printf("Error occurred while writing to the file\n");
    > return;
    > }
    >
    > ioctl(fd, FIOWFLUSH, 0);
    > ioctl(fd, FIOFLUSH, 0);
    > ioctl(fd, FIOSYNC, 0);
    >
    > // close(fd);
    >
    > }
    >
    > Thank you,
    >
    > Ragards,
    > Prashanth



+ Reply to Thread