fsck strangeness

Ian Smith smithi at nimnet.asn.au
Thu Aug 23 08:08:07 PDT 2007


On Thu, 23 Aug 2007, Karol Kwiatkowski wrote:
 > Ian Smith wrote:
 > > On Thu, 23 Aug 2007, Karol Kwiatkowski wrote:
 > >  > Ian Smith wrote:
 > >  > > On Wed, 22 Aug 2007, Chris wrote:
 > >  > >  > If its bad to run fsck on a mounted read,write then why does
 > >  > >  > background fsck do it? or you talking about foreground fsck only?
 > >  > > 
 > >  > > Well I was referring to foreground fsck, and I still don't know why
 > >  > > running it on a mounted fs is 'bad' when fsck runs in 'NO WRITE' mode
 > >  > > anyway when it finds a fs is mounted, hence my query above.
 > >  > 
 > >  > Here's my understanding:
 > >  > 
 > >  > Mounted fs (rw) isn't in stable state, there may be some writes to it -
 > >  > daemons, buffers flushes, etc. In this condition fsck can report
 > >  > inconsistency. And fsck running in 'NO WRITE' won't help anyway :)
 > > 
 > > a) Absolutely.
 > > 
 > > b) Indeed it usually does, fairly consistently, especially on /var.
 > > 
 > > c) No it won't help (except where it can help locate problems in a real 
 > > mess like bad blocks), but the assertion in question was, can it hurt?
 > 
 > Ah sorry, I missed that. With 'NO WRITE' one can suppose it shouldn't
 > hurt anything except performance ;)
 > 
 > I made a quick scan through the source and it looks like it won't:
 > - in src/sbin/fsck_ffs/setup.c
 > if fs is mounted rw fswritefd is set to -1

Ah, the source, who would have thought .. so it does ..

        if (bkgrdflag == 0 &&
            (nflag || (fswritefd = open(dev, O_WRONLY)) < 0)) {
                fswritefd = -1;
                if (preen)
                        pfatal("NO WRITE ACCESS");
                printf(" (NO WRITE)");
        }

.. which explore answered the flip side of my query, I think: fsck (in
fg mode) _will_ update an fs mounted readonly, unless -n is specified.

 > - in src/sbin/fsck_ffs/fsutil.c
 > blwrite(), flush() and ckfini() won't write anything if fswritefd<0
 > 
 > Unless, of course, I'm missing something.

I'll keep using -n to be sure for 'casual' fsck, never failed me, and
one day I may figure out how bg fsck works.  Thanks for the tute :)

Cheers, Ian



More information about the freebsd-questions mailing list