From 24e8c78cb22952b5ba6dace99c5378cd7762b977 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Thu, 18 Jul 2013 15:04:37 +0200 Subject: [PATCH] cwfs: add rtmp flag for check command to remove temporary files after recover --- sys/man/8/fs | 11 +++++++++++ sys/src/cmd/cwfs/chk.c | 28 +++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/sys/man/8/fs b/sys/man/8/fs index 6889739b3..7ec89abe7 100644 --- a/sys/man/8/fs +++ b/sys/man/8/fs @@ -277,6 +277,17 @@ Running .B "check free" afterward will construct a new free list that contains no blocks outside the new, smaller file system. +.TP +.B rtmp +Removes temporary files after a recovery from worm. +After a cache ream and recover, temporary files and directories +refer to invalid data blocks producing checktag errors +on access. To get rid of these errors, the +.I rtmp +flag can be used with the +.I check +command which will truncate temporary directories +and remove temporary files. .PP .I Clean prints the block numbers in diff --git a/sys/src/cmd/cwfs/chk.c b/sys/src/cmd/cwfs/chk.c index eb50920ff..6aa434505 100644 --- a/sys/src/cmd/cwfs/chk.c +++ b/sys/src/cmd/cwfs/chk.c @@ -81,11 +81,12 @@ enum Cpfile = (1<<2), /* print files */ Cpdir = (1<<3), /* print directories */ Cfree = (1<<4), /* rebuild free list */ -// Csetqid = (1<<5), /* resequence qids */ + Csetqid = (1<<5), /* resequence qids */ Cream = (1<<6), /* clear all bad tags */ Cbad = (1<<7), /* clear all bad blocks */ Ctouch = (1<<8), /* touch old dir and indir */ - Ctrim = (1<<9), /* trim fsize back to fit when checking free list */ + Ctrim = (1<<9), /* trim fsize back to fit when checking free list */ + Crtmp = (1<<10), /* clear temporary files (after recover) */ }; static struct { @@ -102,6 +103,7 @@ static struct { "bad", Cbad, "touch", Ctouch, "trim", Ctrim, + "rtmp", Crtmp, 0, }; @@ -351,15 +353,16 @@ indirck(Extdentry *ed, Off a, int tag) if (p1 = xtag(a, tag, ed->qpath)) { for(i=0; iiobuf)[i], &p1->flags); - if (a) + if (a) { /* * check each block named in this * indirect(^n) block (a). */ if (tag == Tind1) - dmod += dirck(ed, a); + dmod += dirck(ed, a); else dmod += indirck(ed, a, tag-1); + } } putbuf(p1); } @@ -434,6 +437,21 @@ fsck(Dentry *d) if(edent.qpath > maxq) maxq = edent.qpath; + /* clear temporary files (after recover) */ + if((d->mode & DTMP) && (flags & Crtmp)){ + for(i=0; idblock[i] = 0; + for(i=0; iiblocks[i] = 0; + d->size = 0; + + /* if not directory, delete file */ + if((d->mode & DDIR) == 0) + memset(d, 0, sizeof(Dentry)); + + return 1; + } + /* check direct blocks (the common case) */ dmod = 0; { @@ -656,7 +674,7 @@ modd(Off a, int s, Dentry *d1) Iobuf *p; Dentry *d; - if(!(flags & Cbad)) + if(!(flags & (Cbad|Crtmp))) return; p = getbuf(dev, a, Brd); d = getdir(p, s);