ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hello All,
I have written a program to get a filename as input and print its data directly from data blocks using libext2fs library. My problem is my program is not working in case of updated files. But once the system is rebooted my program prints the old updated data. So I think this related to buffer cache. But cat command lists the updated file content but mine is not. What may be the problem? I tried sync command too. Is there any command to write cache data? Am I reading from cache or disc? I use ext2fs_open, ext2fs_read_inode and io_channel_block_read_blk. Any help on this would be appreciated. If you need any technical information let me know.
I hope someone can come up with a better answer than mine, but until they come across this thread:
Are you calling sync from inside your program, using a system() call? If so, you might want to wait a bit after that for the data to actually write out.
There's an old tradition in which people typing at the command line would type not
Code:
sync
but
Code:
sync
sync
sync
because superstition (which is not always a bad thing in this business) told them that they'd lead a simpler life in the long run if they did so.
Thanks for response. I haven't used sync command in my program. Since my program is not updating the data, I tried it in command line and now inside the program also but no use.
I've reread your original post, and the pieces are not clear to me. I'm thinking (please correct me if I'm wrong) that there are two actors in this puzzle.
Fred is writing stuff to disk files periodically.
Barney is trying to read that data using libext2fs.
Sometimes stuff which is written by Fred is not picked up by Barney in a reasonable time frame.
Is this understanding correct?
Ok, if it is, let's focus less on Barney, and more on Fred.
What is Fred, exactly? Is it a C program? Perl script? What?
If it's a C program, is it outputting its data via fprintf() calls? If so, you can't expect the data to be shipped to disk with any reasonable promptness unless Fred does an fflush() after every output.
There is a similar problem (and matching solution) in Perl as well. Probably in other languages too.
Sorry.There are no file sharing at all. Just a user logs in a standalone machine and uses my program and reads a file by blocks. Then later he made some changes to that file and runs my program now he wont get the updated content rather the old one. But once the system is rebooted the user can able to view the change.
How exactly did he make those changes? vi? A C program which exited completely? A C program which might still be running when he's trying to read that file via libext2fs? How?
How exactly did he make those changes? vi? A C program which exited completely? A C program which might still be running when he's trying to read that file via libext2fs? How?
Thanks for your participation. I have found the answer. I need to use ext2fs_sync_device function in order to synchronize the file content. Just sync command in command line is not enough. Now my code is working perfectly. Thanks once again.
I've been in the same spot, where I looked everywhere, and the answer turned out to be simple (which meant that actually fixing the problem wouldn't take a long time).
I've been in the same spot, where I looked everywhere, and the answer turned out to be simple (which meant that actually fixing the problem wouldn't take a long time).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.