* Khan, Khader Nawaz (MED) <[EMAIL PROTECTED]> [2003-09-20 21:12 PST]:
> 
> 
> -----Original Message-----
> From: Khan, Khader Nawaz (MED) 
> 
> Hi friends,
>    I have a common problem in linux.
>   Is there any way to protect the files from corrupting
> when power is failed suddenly and when my application is 
> reading/writing into the file.

Yes, you save the file regularly.

This a necessary condition but not a sufficient one. Consider what happens
when you write to the file system. The FS needs to update some metadata to
reflect updated atime etc. If that is all the FS is going when the power
goes out then all you end up with an older atime, which though not
desirable in itself, is not the end of the world.

However, consider that you just typed the "definitive guide to Indian
Politics" and are saving that. Now the FS needs to allocate new
blocks(which means traversing the free block list) and updating the inode
to reflect them. If the free list is corrupt you'd probably have to sit
through an agonizingly slow fsck, unless you use a journaling file
system. However, if while updating the inode with the blocks power fails
you might be in a little bit of hotter soup. Again a journaling file system
helps a bit. But you can potentially lose the data blocks. In this case
you'd look for it in the lost+found directory.

>   if the file is currupted or some part of the file is corrupted
> then how to recover is back. What is the mechanism for recovering
> it from my application.

Your only hope is the fsck operation which will happen automatically on
next system restart. Since there is no redundant copy of the data I can not
think of anything you can do about it.

To make a long story short, frequent updates to disk(via write/flush) are
good. They are not the last word though. They only minimize the effort in
what you'd have to redo.

BTW, none of the above applies to any files that need transactional
integrity. For that check out double commit method.

Hope this helps.
Aseem.

-- 
"Where the clear stream of reason has not lost its way into the dreary
desert sand of dead habit" -- Geetanjali


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to