git » libjio » commit 7f3bdae

Transaction IDs are unsigned and always greater than 0.

author Alberto Bertogli
2004-07-22 14:04:45 UTC
committer Alberto Bertogli
2007-07-15 13:16:57 UTC
parent e5320ea8918919fcde62db84a7514ab19e9caba3

Transaction IDs are unsigned and always greater than 0.

Transaction IDs are unsigned and always greater than 0.

There was a bug that might cause it to be negative because the mmap was casted
to a signed integer and not to an unsigned one.

Besides, start from 0 instead of 1; there's no reason to begin with 1.

Note that the number stored in the lockfile is the maximum number in use, 0
meaning there are no transactions in course. But for no reason a transaction
can have a tid 0.

libjio.h +1 -1
trans.c +1 -1

diff --git a/libjio.h b/libjio.h
index bfae927..9e57ffe 100644
--- a/libjio.h
+++ b/libjio.h
@@ -26,7 +26,7 @@ struct jfs {
 	char *name;		/* and its name */
 	int jdirfd;		/* journal directory file descriptor */
 	int jfd;		/* journal's lock file descriptor */
-	int *jmap;		/* journal's lock file mmap area */
+	unsigned int *jmap;	/* journal's lock file mmap area */
 	int flags;		/* journal flags */
 	struct jlinger *ltrans;	/* lingered transactions */
 	pthread_mutex_t lock;	/* a soft lock used in some operations */
diff --git a/trans.c b/trans.c
index 09071d8..eec5aef 100644
--- a/trans.c
+++ b/trans.c
@@ -555,7 +555,7 @@ int jopen(struct jfs *fs, const char *name, int flags, int mode, int jflags)
 	plockf(jfd, F_LOCKW, 0, 0);
 	lstat(jlockfile, &sinfo);
 	if (sinfo.st_size != sizeof(unsigned int)) {
-		t = 1;
+		t = 0;
 		rv = spwrite(jfd, &t, sizeof(t), 0);
 		if (rv != sizeof(t)) {
 			plockf(jfd, F_UNLOCK, 0, 0);