develooper Front page | perl.beginners | Postings from December 2011

Re: File health check on *nix system using stat

Thread Previous | Thread Next
From:
John W. Krahn
Date:
December 12, 2011 05:58
Subject:
Re: File health check on *nix system using stat
Message ID:
4EE6087D.2080802@shaw.ca
frank cui wrote:
> Thanks John and Peter for the reply.
>
> Ok, to make this question more specific, the author of this book is making
> a program to check if the files can be read off from the disk.
> And he does so by checking two steps, first is making sure the meta data of
> this file looks fine,

Yes, but the stat fields he checks could be valid and still all have the 
value of zero.  I would expect that only fields 0, 1 and 12 (DEV, INO 
and MODE) would normally be non-zero.


> and secondly by reading byte by byte from this file
> to actually check the file's content readability.

You would probably only need to read one byte to see if the file is 
readable.  He is checking that the operating system returns the same 
number of bytes that stat says the file contains.  And you couldn't 
confirm that by seeking to the end of the file and reading one byte 
because there may be invalid disk sectors in the middle of the file that 
are unreadable.



John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About