author | Alberto Bertogli
<albertito@gmail.com> 2004-07-13 21:16:42 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-07-15 13:10:37 UTC |
parent | 5b4bcd6eca6b8bad041a61e9d8aa5599aa87fe96 |
check.c | +12 | -5 |
jiofsck.c | +1 | -1 |
libjio.h | +2 | -1 |
trans.c | +10 | -8 |
diff --git a/check.c b/check.c index 2626ee5..e03952f 100644 --- a/check.c +++ b/check.c @@ -60,11 +60,11 @@ static int fill_trans(unsigned char *map, off_t len, struct jtrans *ts) op->offset = *( (uint64_t *) p); p += 8; - if (len < (p - map) + op->plen) + if (len < (p - map) + op->len) goto error; - op->pdata = (void *) p; - p += op->plen; + op->buf = (void *) p; + p += op->len; if (ts->op == NULL) { ts->op = op; @@ -117,6 +117,10 @@ int jfsck(const char *name, struct jfsck_result *res) if (rv < 0 || !S_ISDIR(sinfo.st_mode)) return J_ENOJOURNAL; + fs.jdirfd = open(jdir, O_RDONLY); + if (fs.jdirfd < 0) + return J_ENOJOURNAL; + /* open the lock file, which is only used to complete the jfs * structure */ snprintf(jlockfile, PATH_MAX, "%s/%s", jdir, "lock"); @@ -188,7 +192,10 @@ int jfsck(const char *name, struct jfsck_result *res) goto loop; } - rv = jtrans_rollback(curts); + /* remove flags from the transaction */ + curts->flags = 0; + + rv = jtrans_commit(curts); munmap(map, filelen); @@ -196,7 +203,7 @@ int jfsck(const char *name, struct jfsck_result *res) res->apply_error++; goto loop; } - res->rollbacked++; + res->reapplied++; loop: diff --git a/jiofsck.c b/jiofsck.c index c7df0f0..f9ac3ea 100644 --- a/jiofsck.c +++ b/jiofsck.c @@ -78,7 +78,7 @@ int main(int argc, char **argv) printf("Broken body:\t %d\n", res.broken_body); printf("Load error:\t %d\n", res.load_error); printf("Apply error:\t %d\n", res.apply_error); - printf("Rollbacked:\t %d\n", res.rollbacked); + printf("Reapplied:\t %d\n", res.reapplied); printf("\n"); if (!do_cleanup) { diff --git a/libjio.h b/libjio.h index 83a95fe..968038c 100644 --- a/libjio.h +++ b/libjio.h @@ -59,7 +59,7 @@ struct jfsck_result { int in_progress; /* transactions in progress */ int broken; /* transactions broken */ int apply_error; /* errors applying the transaction */ - int rollbacked; /* transactions that were rollbacked */ + int reapplied; /* transactions that were reapplied */ }; @@ -122,6 +122,7 @@ FILE *jfsopen(struct jfs *stream, const char *mode); /* jfs constants */ #define J_NOLOCK 1 /* don't lock the file before operating on it */ +#define J_NOROLLBACK 2 /* no need to read rollback information */ /* jtrans constants */ #define J_COMMITED 1 /* mark a transaction as commited */ diff --git a/trans.c b/trans.c index d2a7a2d..af392f4 100644 --- a/trans.c +++ b/trans.c @@ -265,10 +265,11 @@ int jtrans_commit(struct jtrans *ts) /* save each transacion in the file */ for (op = ts->op; op != NULL; op = op->next) { - /* read the current content only if it's not there yet, which - * is the normal case, but for rollbacking we fill it + /* read the current content only if the transaction is not + * marked as NOROLLBACK, and if the data is not there yet, + * which is the normal case, but for rollbacking we fill it * ourselves */ - if (op->pdata == NULL) { + if (!(ts->flags & J_NOROLLBACK) && (op->pdata == NULL)) { op->pdata = malloc(op->len); if (op->pdata == NULL) goto exit; @@ -313,11 +314,11 @@ int jtrans_commit(struct jtrans *ts) curpos += J_DISKOPHEADSIZE; /* and save it to the disk */ - rv = spwrite(fd, op->pdata, op->plen, curpos); - if (rv != op->plen) + rv = spwrite(fd, op->buf, op->len, curpos); + if (rv != op->len) goto exit; - curpos += op->plen; + curpos += op->len; } /* this is a simple but efficient optimization: instead of doing @@ -388,8 +389,9 @@ int jtrans_rollback(struct jtrans *ts) /* FIXME: this looks like a mess! */ - if (ts->op == NULL) { - /* we're trying to rollback an empty transaction */ + if (ts->op == NULL || ts->flags & J_NOROLLBACK) { + /* we're either trying to rollback an empty or transaction, or + * a one marked without rollbacking support */ return 0; }