LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Tags used in this thread
Popular LQ Tags

Reply
 
Thread Tools
Old 02-16-2007, 06:45 AM   #1
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41
Thanked: 0
libext2fs Help Please.


[Log in to get rid of this advertisement]
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.
Balakrishnan84 is offline  
Tag This Post
Reply With Quote
Old 02-16-2007, 04:04 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938
Thanked: 0
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.

Hope this helps a little.
wjevans_7d1@yahoo.co is offline     Reply With Quote
Old 02-17-2007, 01:26 AM   #3
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41
Thanked: 0

Original Poster
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.
Balakrishnan84 is offline     Reply With Quote
Old 02-17-2007, 04:32 AM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938
Thanked: 0
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.

Could this be the problem?
wjevans_7d1@yahoo.co is offline     Reply With Quote
Old 02-18-2007, 07:33 AM   #5
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41
Thanked: 0

Original Poster
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.
Balakrishnan84 is offline     Reply With Quote
Old 02-18-2007, 02:52 PM   #6
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938
Thanked: 0
"Later he made some changes to that file."

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?
wjevans_7d1@yahoo.co is offline     Reply With Quote
Old 02-19-2007, 02:17 AM   #7
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41
Thanked: 0

Original Poster
Quote:
Originally Posted by wjevans_7d1@yahoo.co
"Later he made some changes to that file."

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?
Either vi or cat command.
Balakrishnan84 is offline     Reply With Quote
Old 02-19-2007, 04:26 AM   #8
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41
Thanked: 0

Original Poster
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.
Balakrishnan84 is offline     Reply With Quote
Old 02-19-2007, 06:40 PM   #9
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938
Thanked: 0
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).

Isn't that a good feeling? (grin)
wjevans_7d1@yahoo.co is offline     Reply With Quote
Old 02-20-2007, 12:56 AM   #10
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41
Thanked: 0

Original Poster
Quote:
Originally Posted by wjevans_7d1@yahoo.co
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).

Isn't that a good feeling? (grin)
Really a good one.
Balakrishnan84 is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 05:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration