int SSAMPLE_Inc(struct rx_call *call) { afs_int32 code, temp; struct ubik_trans *tt; struct timeval tv; code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt); if (code) return code; printf("about to set lock\n"); /* now set database locks. Must do this or people may read uncommitted * data. Note that we're just setting a lock at position 1, which is * this program's convention for locking the whole database */ code = ubik_SetLock(tt, 1, 1, LOCKWRITE); printf("now have lock\n"); if (code) { ubik_AbortTrans(tt); return code; } /* sleep for a little while to make it possible for us to test for some * race conditions */ if (sleepTime) { tv.tv_sec = sleepTime; tv.tv_usec = 0; #ifdef AFS_PTHREAD_ENV select(0, 0, 0, 0, &tv); #else IOMGR_Select(0, 0, 0, 0, &tv); #endif } /* read the original value */ code = ubik_Read(tt, &temp, sizeof(afs_int32)); if (code == UEOF) { /* short read */ temp = 0; } else if (code) { ubik_AbortTrans(tt); return code; } temp++; /* bump the value here */ /* reset the file pointer back to where it was before the read */ code = ubik_Seek(tt, 0, 0); if (code) { ubik_AbortTrans(tt); return code; } /* write the data back */ code = ubik_Write(tt, &temp, sizeof(afs_int32)); if (code) { ubik_AbortTrans(tt); return code; } /* finally, we commit the transaction */ code = ubik_EndTrans(tt); temp = 0; return code; }
afs_int32 kawrite(struct ubik_trans *tt, afs_int32 pos, char *buff, afs_int32 len) { afs_int32 code; code = ubik_Seek(tt, 0, pos); if (code) return code; code = ubik_Write(tt, buff, len); return code; }
afs_int32 pr_Write(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, void *buff, afs_int32 len) { /* package up seek and write into one procedure for ease of use */ afs_int32 code; if ((pos < sizeof(cheader)) && (buff != (char *)&cheader + pos)) { fprintf(stderr, "ptserver: dbwrite: Illegal attempt to write a location 0\n"); return PRDBFAIL; } code = ubik_Seek(tt, afd, pos); if (code) return code; code = ubik_Write(tt, buff, len); return code; }