00001
00002 #include "config.h"
00003
00004 #ifndef NO_SYSTEM_INCLUDES
00005 #include <sys/types.h>
00006
00007 #include <ctype.h>
00008 #include <errno.h>
00009 #include <string.h>
00010 #endif
00011
00012 #include "db_int.h"
00013 #include "db_page.h"
00014 #include "db_dispatch.h"
00015 #include "db_am.h"
00016 #include "txn.h"
00017
00018 int CDB___crdel_fileopen_log(dbenv, txnid, ret_lsnp, flags,
00019 name, mode)
00020 DB_ENV *dbenv;
00021 DB_TXN *txnid;
00022 DB_LSN *ret_lsnp;
00023 u_int32_t flags;
00024 const DBT *name;
00025 u_int32_t mode;
00026 {
00027 DBT logrec;
00028 DB_LSN *lsnp, null_lsn;
00029 u_int32_t zero;
00030 u_int32_t rectype, txn_num;
00031 int ret;
00032 u_int8_t *bp;
00033
00034 if (txnid != NULL &&
00035 TAILQ_FIRST(&txnid->kids) != NULL && CDB___txn_activekids(txnid) != 0)
00036 return (CDB___db_child_active_err(dbenv));
00037 rectype = DB_crdel_fileopen;
00038 txn_num = txnid == NULL ? 0 : txnid->txnid;
00039 if (txnid == NULL) {
00040 ZERO_LSN(null_lsn);
00041 lsnp = &null_lsn;
00042 } else
00043 lsnp = &txnid->last_lsn;
00044 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00045 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
00046 + sizeof(mode);
00047 if ((ret = CDB___os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
00048 return (ret);
00049
00050 bp = logrec.data;
00051 memcpy(bp, &rectype, sizeof(rectype));
00052 bp += sizeof(rectype);
00053 memcpy(bp, &txn_num, sizeof(txn_num));
00054 bp += sizeof(txn_num);
00055 memcpy(bp, lsnp, sizeof(DB_LSN));
00056 bp += sizeof(DB_LSN);
00057 if (name == NULL) {
00058 zero = 0;
00059 memcpy(bp, &zero, sizeof(u_int32_t));
00060 bp += sizeof(u_int32_t);
00061 } else {
00062 memcpy(bp, &name->size, sizeof(name->size));
00063 bp += sizeof(name->size);
00064 memcpy(bp, name->data, name->size);
00065 bp += name->size;
00066 }
00067 memcpy(bp, &mode, sizeof(mode));
00068 bp += sizeof(mode);
00069 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
00070 ret = CDB_log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
00071 if (txnid != NULL)
00072 txnid->last_lsn = *ret_lsnp;
00073 CDB___os_free(logrec.data, logrec.size);
00074 return (ret);
00075 }
00076
00077 int
00078 CDB___crdel_fileopen_print(dbenv, dbtp, lsnp, notused2, notused3)
00079 DB_ENV *dbenv;
00080 DBT *dbtp;
00081 DB_LSN *lsnp;
00082 db_recops notused2;
00083 void *notused3;
00084 {
00085 __crdel_fileopen_args *argp;
00086 u_int32_t i;
00087 u_int ch;
00088 int ret;
00089
00090 i = 0;
00091 ch = 0;
00092 notused2 = 0;
00093 notused3 = NULL;
00094
00095 if ((ret = CDB___crdel_fileopen_read(dbenv, dbtp->data, &argp)) != 0)
00096 return (ret);
00097 printf("[%lu][%lu]crdel_fileopen: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
00098 (u_long)lsnp->file,
00099 (u_long)lsnp->offset,
00100 (u_long)argp->type,
00101 (u_long)argp->txnid->txnid,
00102 (u_long)argp->prev_lsn.file,
00103 (u_long)argp->prev_lsn.offset);
00104 printf("\tname: ");
00105 for (i = 0; i < argp->name.size; i++) {
00106 ch = ((u_int8_t *)argp->name.data)[i];
00107 if (isprint(ch) || ch == 0xa)
00108 putchar(ch);
00109 else
00110 printf("%#x ", ch);
00111 }
00112 printf("\n");
00113 printf("\tmode: %o\n", argp->mode);
00114 printf("\n");
00115 CDB___os_free(argp, 0);
00116 return (0);
00117 }
00118
00119 int
00120 CDB___crdel_fileopen_read(dbenv, recbuf, argpp)
00121 DB_ENV *dbenv;
00122 void *recbuf;
00123 __crdel_fileopen_args **argpp;
00124 {
00125 __crdel_fileopen_args *argp;
00126 u_int8_t *bp;
00127 int ret;
00128
00129 ret = CDB___os_malloc(dbenv, sizeof(__crdel_fileopen_args) +
00130 sizeof(DB_TXN), NULL, &argp);
00131 if (ret != 0)
00132 return (ret);
00133 argp->txnid = (DB_TXN *)&argp[1];
00134 bp = recbuf;
00135 memcpy(&argp->type, bp, sizeof(argp->type));
00136 bp += sizeof(argp->type);
00137 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00138 bp += sizeof(argp->txnid->txnid);
00139 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00140 bp += sizeof(DB_LSN);
00141 memset(&argp->name, 0, sizeof(argp->name));
00142 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00143 bp += sizeof(u_int32_t);
00144 argp->name.data = bp;
00145 bp += argp->name.size;
00146 memcpy(&argp->mode, bp, sizeof(argp->mode));
00147 bp += sizeof(argp->mode);
00148 *argpp = argp;
00149 return (0);
00150 }
00151
00152 int CDB___crdel_metasub_log(dbenv, txnid, ret_lsnp, flags,
00153 fileid, pgno, page, lsn)
00154 DB_ENV *dbenv;
00155 DB_TXN *txnid;
00156 DB_LSN *ret_lsnp;
00157 u_int32_t flags;
00158 int32_t fileid;
00159 db_pgno_t pgno;
00160 const DBT *page;
00161 DB_LSN * lsn;
00162 {
00163 DBT logrec;
00164 DB_LSN *lsnp, null_lsn;
00165 u_int32_t zero;
00166 u_int32_t rectype, txn_num;
00167 int ret;
00168 u_int8_t *bp;
00169
00170 if (txnid != NULL &&
00171 TAILQ_FIRST(&txnid->kids) != NULL && CDB___txn_activekids(txnid) != 0)
00172 return (CDB___db_child_active_err(dbenv));
00173 rectype = DB_crdel_metasub;
00174 txn_num = txnid == NULL ? 0 : txnid->txnid;
00175 if (txnid == NULL) {
00176 ZERO_LSN(null_lsn);
00177 lsnp = &null_lsn;
00178 } else
00179 lsnp = &txnid->last_lsn;
00180 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00181 + sizeof(fileid)
00182 + sizeof(pgno)
00183 + sizeof(u_int32_t) + (page == NULL ? 0 : page->size)
00184 + sizeof(*lsn);
00185 if ((ret = CDB___os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
00186 return (ret);
00187
00188 bp = logrec.data;
00189 memcpy(bp, &rectype, sizeof(rectype));
00190 bp += sizeof(rectype);
00191 memcpy(bp, &txn_num, sizeof(txn_num));
00192 bp += sizeof(txn_num);
00193 memcpy(bp, lsnp, sizeof(DB_LSN));
00194 bp += sizeof(DB_LSN);
00195 memcpy(bp, &fileid, sizeof(fileid));
00196 bp += sizeof(fileid);
00197 memcpy(bp, &pgno, sizeof(pgno));
00198 bp += sizeof(pgno);
00199 if (page == NULL) {
00200 zero = 0;
00201 memcpy(bp, &zero, sizeof(u_int32_t));
00202 bp += sizeof(u_int32_t);
00203 } else {
00204 memcpy(bp, &page->size, sizeof(page->size));
00205 bp += sizeof(page->size);
00206 memcpy(bp, page->data, page->size);
00207 bp += page->size;
00208 }
00209 if (lsn != NULL)
00210 memcpy(bp, lsn, sizeof(*lsn));
00211 else
00212 memset(bp, 0, sizeof(*lsn));
00213 bp += sizeof(*lsn);
00214 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
00215 ret = CDB_log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
00216 if (txnid != NULL)
00217 txnid->last_lsn = *ret_lsnp;
00218 CDB___os_free(logrec.data, logrec.size);
00219 return (ret);
00220 }
00221
00222 int
00223 CDB___crdel_metasub_print(dbenv, dbtp, lsnp, notused2, notused3)
00224 DB_ENV *dbenv;
00225 DBT *dbtp;
00226 DB_LSN *lsnp;
00227 db_recops notused2;
00228 void *notused3;
00229 {
00230 __crdel_metasub_args *argp;
00231 u_int32_t i;
00232 u_int ch;
00233 int ret;
00234
00235 i = 0;
00236 ch = 0;
00237 notused2 = 0;
00238 notused3 = NULL;
00239
00240 if ((ret = CDB___crdel_metasub_read(dbenv, dbtp->data, &argp)) != 0)
00241 return (ret);
00242 printf("[%lu][%lu]crdel_metasub: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
00243 (u_long)lsnp->file,
00244 (u_long)lsnp->offset,
00245 (u_long)argp->type,
00246 (u_long)argp->txnid->txnid,
00247 (u_long)argp->prev_lsn.file,
00248 (u_long)argp->prev_lsn.offset);
00249 printf("\tfileid: %ld\n", (long)argp->fileid);
00250 printf("\tpgno: %d\n", argp->pgno);
00251 printf("\tpage: ");
00252 for (i = 0; i < argp->page.size; i++) {
00253 ch = ((u_int8_t *)argp->page.data)[i];
00254 if (isprint(ch) || ch == 0xa)
00255 putchar(ch);
00256 else
00257 printf("%#x ", ch);
00258 }
00259 printf("\n");
00260 printf("\tlsn: [%lu][%lu]\n",
00261 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
00262 printf("\n");
00263 CDB___os_free(argp, 0);
00264 return (0);
00265 }
00266
00267 int
00268 CDB___crdel_metasub_read(dbenv, recbuf, argpp)
00269 DB_ENV *dbenv;
00270 void *recbuf;
00271 __crdel_metasub_args **argpp;
00272 {
00273 __crdel_metasub_args *argp;
00274 u_int8_t *bp;
00275 int ret;
00276
00277 ret = CDB___os_malloc(dbenv, sizeof(__crdel_metasub_args) +
00278 sizeof(DB_TXN), NULL, &argp);
00279 if (ret != 0)
00280 return (ret);
00281 argp->txnid = (DB_TXN *)&argp[1];
00282 bp = recbuf;
00283 memcpy(&argp->type, bp, sizeof(argp->type));
00284 bp += sizeof(argp->type);
00285 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00286 bp += sizeof(argp->txnid->txnid);
00287 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00288 bp += sizeof(DB_LSN);
00289 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
00290 bp += sizeof(argp->fileid);
00291 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
00292 bp += sizeof(argp->pgno);
00293 memset(&argp->page, 0, sizeof(argp->page));
00294 memcpy(&argp->page.size, bp, sizeof(u_int32_t));
00295 bp += sizeof(u_int32_t);
00296 argp->page.data = bp;
00297 bp += argp->page.size;
00298 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
00299 bp += sizeof(argp->lsn);
00300 *argpp = argp;
00301 return (0);
00302 }
00303
00304 int CDB___crdel_metapage_log(dbenv, txnid, ret_lsnp, flags,
00305 fileid, name, pgno, page)
00306 DB_ENV *dbenv;
00307 DB_TXN *txnid;
00308 DB_LSN *ret_lsnp;
00309 u_int32_t flags;
00310 int32_t fileid;
00311 const DBT *name;
00312 db_pgno_t pgno;
00313 const DBT *page;
00314 {
00315 DBT logrec;
00316 DB_LSN *lsnp, null_lsn;
00317 u_int32_t zero;
00318 u_int32_t rectype, txn_num;
00319 int ret;
00320 u_int8_t *bp;
00321
00322 if (txnid != NULL &&
00323 TAILQ_FIRST(&txnid->kids) != NULL && CDB___txn_activekids(txnid) != 0)
00324 return (CDB___db_child_active_err(dbenv));
00325 rectype = DB_crdel_metapage;
00326 txn_num = txnid == NULL ? 0 : txnid->txnid;
00327 if (txnid == NULL) {
00328 ZERO_LSN(null_lsn);
00329 lsnp = &null_lsn;
00330 } else
00331 lsnp = &txnid->last_lsn;
00332 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00333 + sizeof(fileid)
00334 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
00335 + sizeof(pgno)
00336 + sizeof(u_int32_t) + (page == NULL ? 0 : page->size);
00337 if ((ret = CDB___os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
00338 return (ret);
00339
00340 bp = logrec.data;
00341 memcpy(bp, &rectype, sizeof(rectype));
00342 bp += sizeof(rectype);
00343 memcpy(bp, &txn_num, sizeof(txn_num));
00344 bp += sizeof(txn_num);
00345 memcpy(bp, lsnp, sizeof(DB_LSN));
00346 bp += sizeof(DB_LSN);
00347 memcpy(bp, &fileid, sizeof(fileid));
00348 bp += sizeof(fileid);
00349 if (name == NULL) {
00350 zero = 0;
00351 memcpy(bp, &zero, sizeof(u_int32_t));
00352 bp += sizeof(u_int32_t);
00353 } else {
00354 memcpy(bp, &name->size, sizeof(name->size));
00355 bp += sizeof(name->size);
00356 memcpy(bp, name->data, name->size);
00357 bp += name->size;
00358 }
00359 memcpy(bp, &pgno, sizeof(pgno));
00360 bp += sizeof(pgno);
00361 if (page == NULL) {
00362 zero = 0;
00363 memcpy(bp, &zero, sizeof(u_int32_t));
00364 bp += sizeof(u_int32_t);
00365 } else {
00366 memcpy(bp, &page->size, sizeof(page->size));
00367 bp += sizeof(page->size);
00368 memcpy(bp, page->data, page->size);
00369 bp += page->size;
00370 }
00371 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
00372 ret = CDB_log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
00373 if (txnid != NULL)
00374 txnid->last_lsn = *ret_lsnp;
00375 CDB___os_free(logrec.data, logrec.size);
00376 return (ret);
00377 }
00378
00379 int
00380 CDB___crdel_metapage_print(dbenv, dbtp, lsnp, notused2, notused3)
00381 DB_ENV *dbenv;
00382 DBT *dbtp;
00383 DB_LSN *lsnp;
00384 db_recops notused2;
00385 void *notused3;
00386 {
00387 __crdel_metapage_args *argp;
00388 u_int32_t i;
00389 u_int ch;
00390 int ret;
00391
00392 i = 0;
00393 ch = 0;
00394 notused2 = 0;
00395 notused3 = NULL;
00396
00397 if ((ret = CDB___crdel_metapage_read(dbenv, dbtp->data, &argp)) != 0)
00398 return (ret);
00399 printf("[%lu][%lu]crdel_metapage: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
00400 (u_long)lsnp->file,
00401 (u_long)lsnp->offset,
00402 (u_long)argp->type,
00403 (u_long)argp->txnid->txnid,
00404 (u_long)argp->prev_lsn.file,
00405 (u_long)argp->prev_lsn.offset);
00406 printf("\tfileid: %ld\n", (long)argp->fileid);
00407 printf("\tname: ");
00408 for (i = 0; i < argp->name.size; i++) {
00409 ch = ((u_int8_t *)argp->name.data)[i];
00410 if (isprint(ch) || ch == 0xa)
00411 putchar(ch);
00412 else
00413 printf("%#x ", ch);
00414 }
00415 printf("\n");
00416 printf("\tpgno: %d\n", argp->pgno);
00417 printf("\tpage: ");
00418 for (i = 0; i < argp->page.size; i++) {
00419 ch = ((u_int8_t *)argp->page.data)[i];
00420 if (isprint(ch) || ch == 0xa)
00421 putchar(ch);
00422 else
00423 printf("%#x ", ch);
00424 }
00425 printf("\n");
00426 printf("\n");
00427 CDB___os_free(argp, 0);
00428 return (0);
00429 }
00430
00431 int
00432 CDB___crdel_metapage_read(dbenv, recbuf, argpp)
00433 DB_ENV *dbenv;
00434 void *recbuf;
00435 __crdel_metapage_args **argpp;
00436 {
00437 __crdel_metapage_args *argp;
00438 u_int8_t *bp;
00439 int ret;
00440
00441 ret = CDB___os_malloc(dbenv, sizeof(__crdel_metapage_args) +
00442 sizeof(DB_TXN), NULL, &argp);
00443 if (ret != 0)
00444 return (ret);
00445 argp->txnid = (DB_TXN *)&argp[1];
00446 bp = recbuf;
00447 memcpy(&argp->type, bp, sizeof(argp->type));
00448 bp += sizeof(argp->type);
00449 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00450 bp += sizeof(argp->txnid->txnid);
00451 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00452 bp += sizeof(DB_LSN);
00453 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
00454 bp += sizeof(argp->fileid);
00455 memset(&argp->name, 0, sizeof(argp->name));
00456 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00457 bp += sizeof(u_int32_t);
00458 argp->name.data = bp;
00459 bp += argp->name.size;
00460 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
00461 bp += sizeof(argp->pgno);
00462 memset(&argp->page, 0, sizeof(argp->page));
00463 memcpy(&argp->page.size, bp, sizeof(u_int32_t));
00464 bp += sizeof(u_int32_t);
00465 argp->page.data = bp;
00466 bp += argp->page.size;
00467 *argpp = argp;
00468 return (0);
00469 }
00470
00471 int
00472 CDB___crdel_old_delete_print(dbenv, dbtp, lsnp, notused2, notused3)
00473 DB_ENV *dbenv;
00474 DBT *dbtp;
00475 DB_LSN *lsnp;
00476 db_recops notused2;
00477 void *notused3;
00478 {
00479 __crdel_old_delete_args *argp;
00480 u_int32_t i;
00481 u_int ch;
00482 int ret;
00483
00484 i = 0;
00485 ch = 0;
00486 notused2 = 0;
00487 notused3 = NULL;
00488
00489 if ((ret = CDB___crdel_old_delete_read(dbenv, dbtp->data, &argp)) != 0)
00490 return (ret);
00491 printf("[%lu][%lu]crdel_old_delete: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
00492 (u_long)lsnp->file,
00493 (u_long)lsnp->offset,
00494 (u_long)argp->type,
00495 (u_long)argp->txnid->txnid,
00496 (u_long)argp->prev_lsn.file,
00497 (u_long)argp->prev_lsn.offset);
00498 printf("\tname: ");
00499 for (i = 0; i < argp->name.size; i++) {
00500 ch = ((u_int8_t *)argp->name.data)[i];
00501 if (isprint(ch) || ch == 0xa)
00502 putchar(ch);
00503 else
00504 printf("%#x ", ch);
00505 }
00506 printf("\n");
00507 printf("\n");
00508 CDB___os_free(argp, 0);
00509 return (0);
00510 }
00511
00512 int
00513 CDB___crdel_old_delete_read(dbenv, recbuf, argpp)
00514 DB_ENV *dbenv;
00515 void *recbuf;
00516 __crdel_old_delete_args **argpp;
00517 {
00518 __crdel_old_delete_args *argp;
00519 u_int8_t *bp;
00520 int ret;
00521
00522 ret = CDB___os_malloc(dbenv, sizeof(__crdel_old_delete_args) +
00523 sizeof(DB_TXN), NULL, &argp);
00524 if (ret != 0)
00525 return (ret);
00526 argp->txnid = (DB_TXN *)&argp[1];
00527 bp = recbuf;
00528 memcpy(&argp->type, bp, sizeof(argp->type));
00529 bp += sizeof(argp->type);
00530 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00531 bp += sizeof(argp->txnid->txnid);
00532 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00533 bp += sizeof(DB_LSN);
00534 memset(&argp->name, 0, sizeof(argp->name));
00535 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00536 bp += sizeof(u_int32_t);
00537 argp->name.data = bp;
00538 bp += argp->name.size;
00539 *argpp = argp;
00540 return (0);
00541 }
00542
00543 int CDB___crdel_rename_log(dbenv, txnid, ret_lsnp, flags,
00544 fileid, name, newname)
00545 DB_ENV *dbenv;
00546 DB_TXN *txnid;
00547 DB_LSN *ret_lsnp;
00548 u_int32_t flags;
00549 int32_t fileid;
00550 const DBT *name;
00551 const DBT *newname;
00552 {
00553 DBT logrec;
00554 DB_LSN *lsnp, null_lsn;
00555 u_int32_t zero;
00556 u_int32_t rectype, txn_num;
00557 int ret;
00558 u_int8_t *bp;
00559
00560 if (txnid != NULL &&
00561 TAILQ_FIRST(&txnid->kids) != NULL && CDB___txn_activekids(txnid) != 0)
00562 return (CDB___db_child_active_err(dbenv));
00563 rectype = DB_crdel_rename;
00564 txn_num = txnid == NULL ? 0 : txnid->txnid;
00565 if (txnid == NULL) {
00566 ZERO_LSN(null_lsn);
00567 lsnp = &null_lsn;
00568 } else
00569 lsnp = &txnid->last_lsn;
00570 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00571 + sizeof(fileid)
00572 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
00573 + sizeof(u_int32_t) + (newname == NULL ? 0 : newname->size);
00574 if ((ret = CDB___os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
00575 return (ret);
00576
00577 bp = logrec.data;
00578 memcpy(bp, &rectype, sizeof(rectype));
00579 bp += sizeof(rectype);
00580 memcpy(bp, &txn_num, sizeof(txn_num));
00581 bp += sizeof(txn_num);
00582 memcpy(bp, lsnp, sizeof(DB_LSN));
00583 bp += sizeof(DB_LSN);
00584 memcpy(bp, &fileid, sizeof(fileid));
00585 bp += sizeof(fileid);
00586 if (name == NULL) {
00587 zero = 0;
00588 memcpy(bp, &zero, sizeof(u_int32_t));
00589 bp += sizeof(u_int32_t);
00590 } else {
00591 memcpy(bp, &name->size, sizeof(name->size));
00592 bp += sizeof(name->size);
00593 memcpy(bp, name->data, name->size);
00594 bp += name->size;
00595 }
00596 if (newname == NULL) {
00597 zero = 0;
00598 memcpy(bp, &zero, sizeof(u_int32_t));
00599 bp += sizeof(u_int32_t);
00600 } else {
00601 memcpy(bp, &newname->size, sizeof(newname->size));
00602 bp += sizeof(newname->size);
00603 memcpy(bp, newname->data, newname->size);
00604 bp += newname->size;
00605 }
00606 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
00607 ret = CDB_log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
00608 if (txnid != NULL)
00609 txnid->last_lsn = *ret_lsnp;
00610 CDB___os_free(logrec.data, logrec.size);
00611 return (ret);
00612 }
00613
00614 int
00615 CDB___crdel_rename_print(dbenv, dbtp, lsnp, notused2, notused3)
00616 DB_ENV *dbenv;
00617 DBT *dbtp;
00618 DB_LSN *lsnp;
00619 db_recops notused2;
00620 void *notused3;
00621 {
00622 __crdel_rename_args *argp;
00623 u_int32_t i;
00624 u_int ch;
00625 int ret;
00626
00627 i = 0;
00628 ch = 0;
00629 notused2 = 0;
00630 notused3 = NULL;
00631
00632 if ((ret = CDB___crdel_rename_read(dbenv, dbtp->data, &argp)) != 0)
00633 return (ret);
00634 printf("[%lu][%lu]crdel_rename: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
00635 (u_long)lsnp->file,
00636 (u_long)lsnp->offset,
00637 (u_long)argp->type,
00638 (u_long)argp->txnid->txnid,
00639 (u_long)argp->prev_lsn.file,
00640 (u_long)argp->prev_lsn.offset);
00641 printf("\tfileid: %ld\n", (long)argp->fileid);
00642 printf("\tname: ");
00643 for (i = 0; i < argp->name.size; i++) {
00644 ch = ((u_int8_t *)argp->name.data)[i];
00645 if (isprint(ch) || ch == 0xa)
00646 putchar(ch);
00647 else
00648 printf("%#x ", ch);
00649 }
00650 printf("\n");
00651 printf("\tnewname: ");
00652 for (i = 0; i < argp->newname.size; i++) {
00653 ch = ((u_int8_t *)argp->newname.data)[i];
00654 if (isprint(ch) || ch == 0xa)
00655 putchar(ch);
00656 else
00657 printf("%#x ", ch);
00658 }
00659 printf("\n");
00660 printf("\n");
00661 CDB___os_free(argp, 0);
00662 return (0);
00663 }
00664
00665 int
00666 CDB___crdel_rename_read(dbenv, recbuf, argpp)
00667 DB_ENV *dbenv;
00668 void *recbuf;
00669 __crdel_rename_args **argpp;
00670 {
00671 __crdel_rename_args *argp;
00672 u_int8_t *bp;
00673 int ret;
00674
00675 ret = CDB___os_malloc(dbenv, sizeof(__crdel_rename_args) +
00676 sizeof(DB_TXN), NULL, &argp);
00677 if (ret != 0)
00678 return (ret);
00679 argp->txnid = (DB_TXN *)&argp[1];
00680 bp = recbuf;
00681 memcpy(&argp->type, bp, sizeof(argp->type));
00682 bp += sizeof(argp->type);
00683 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00684 bp += sizeof(argp->txnid->txnid);
00685 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00686 bp += sizeof(DB_LSN);
00687 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
00688 bp += sizeof(argp->fileid);
00689 memset(&argp->name, 0, sizeof(argp->name));
00690 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00691 bp += sizeof(u_int32_t);
00692 argp->name.data = bp;
00693 bp += argp->name.size;
00694 memset(&argp->newname, 0, sizeof(argp->newname));
00695 memcpy(&argp->newname.size, bp, sizeof(u_int32_t));
00696 bp += sizeof(u_int32_t);
00697 argp->newname.data = bp;
00698 bp += argp->newname.size;
00699 *argpp = argp;
00700 return (0);
00701 }
00702
00703 int CDB___crdel_delete_log(dbenv, txnid, ret_lsnp, flags,
00704 fileid, name)
00705 DB_ENV *dbenv;
00706 DB_TXN *txnid;
00707 DB_LSN *ret_lsnp;
00708 u_int32_t flags;
00709 int32_t fileid;
00710 const DBT *name;
00711 {
00712 DBT logrec;
00713 DB_LSN *lsnp, null_lsn;
00714 u_int32_t zero;
00715 u_int32_t rectype, txn_num;
00716 int ret;
00717 u_int8_t *bp;
00718
00719 if (txnid != NULL &&
00720 TAILQ_FIRST(&txnid->kids) != NULL && CDB___txn_activekids(txnid) != 0)
00721 return (CDB___db_child_active_err(dbenv));
00722 rectype = DB_crdel_delete;
00723 txn_num = txnid == NULL ? 0 : txnid->txnid;
00724 if (txnid == NULL) {
00725 ZERO_LSN(null_lsn);
00726 lsnp = &null_lsn;
00727 } else
00728 lsnp = &txnid->last_lsn;
00729 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00730 + sizeof(fileid)
00731 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size);
00732 if ((ret = CDB___os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
00733 return (ret);
00734
00735 bp = logrec.data;
00736 memcpy(bp, &rectype, sizeof(rectype));
00737 bp += sizeof(rectype);
00738 memcpy(bp, &txn_num, sizeof(txn_num));
00739 bp += sizeof(txn_num);
00740 memcpy(bp, lsnp, sizeof(DB_LSN));
00741 bp += sizeof(DB_LSN);
00742 memcpy(bp, &fileid, sizeof(fileid));
00743 bp += sizeof(fileid);
00744 if (name == NULL) {
00745 zero = 0;
00746 memcpy(bp, &zero, sizeof(u_int32_t));
00747 bp += sizeof(u_int32_t);
00748 } else {
00749 memcpy(bp, &name->size, sizeof(name->size));
00750 bp += sizeof(name->size);
00751 memcpy(bp, name->data, name->size);
00752 bp += name->size;
00753 }
00754 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
00755 ret = CDB_log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
00756 if (txnid != NULL)
00757 txnid->last_lsn = *ret_lsnp;
00758 CDB___os_free(logrec.data, logrec.size);
00759 return (ret);
00760 }
00761
00762 int
00763 CDB___crdel_delete_print(dbenv, dbtp, lsnp, notused2, notused3)
00764 DB_ENV *dbenv;
00765 DBT *dbtp;
00766 DB_LSN *lsnp;
00767 db_recops notused2;
00768 void *notused3;
00769 {
00770 __crdel_delete_args *argp;
00771 u_int32_t i;
00772 u_int ch;
00773 int ret;
00774
00775 i = 0;
00776 ch = 0;
00777 notused2 = 0;
00778 notused3 = NULL;
00779
00780 if ((ret = CDB___crdel_delete_read(dbenv, dbtp->data, &argp)) != 0)
00781 return (ret);
00782 printf("[%lu][%lu]crdel_delete: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
00783 (u_long)lsnp->file,
00784 (u_long)lsnp->offset,
00785 (u_long)argp->type,
00786 (u_long)argp->txnid->txnid,
00787 (u_long)argp->prev_lsn.file,
00788 (u_long)argp->prev_lsn.offset);
00789 printf("\tfileid: %ld\n", (long)argp->fileid);
00790 printf("\tname: ");
00791 for (i = 0; i < argp->name.size; i++) {
00792 ch = ((u_int8_t *)argp->name.data)[i];
00793 if (isprint(ch) || ch == 0xa)
00794 putchar(ch);
00795 else
00796 printf("%#x ", ch);
00797 }
00798 printf("\n");
00799 printf("\n");
00800 CDB___os_free(argp, 0);
00801 return (0);
00802 }
00803
00804 int
00805 CDB___crdel_delete_read(dbenv, recbuf, argpp)
00806 DB_ENV *dbenv;
00807 void *recbuf;
00808 __crdel_delete_args **argpp;
00809 {
00810 __crdel_delete_args *argp;
00811 u_int8_t *bp;
00812 int ret;
00813
00814 ret = CDB___os_malloc(dbenv, sizeof(__crdel_delete_args) +
00815 sizeof(DB_TXN), NULL, &argp);
00816 if (ret != 0)
00817 return (ret);
00818 argp->txnid = (DB_TXN *)&argp[1];
00819 bp = recbuf;
00820 memcpy(&argp->type, bp, sizeof(argp->type));
00821 bp += sizeof(argp->type);
00822 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00823 bp += sizeof(argp->txnid->txnid);
00824 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00825 bp += sizeof(DB_LSN);
00826 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
00827 bp += sizeof(argp->fileid);
00828 memset(&argp->name, 0, sizeof(argp->name));
00829 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00830 bp += sizeof(u_int32_t);
00831 argp->name.data = bp;
00832 bp += argp->name.size;
00833 *argpp = argp;
00834 return (0);
00835 }
00836
00837 int
00838 CDB___crdel_init_print(dbenv)
00839 DB_ENV *dbenv;
00840 {
00841 int ret;
00842
00843 if ((ret = CDB___db_add_recovery(dbenv,
00844 CDB___crdel_fileopen_print, DB_crdel_fileopen)) != 0)
00845 return (ret);
00846 if ((ret = CDB___db_add_recovery(dbenv,
00847 CDB___crdel_metasub_print, DB_crdel_metasub)) != 0)
00848 return (ret);
00849 if ((ret = CDB___db_add_recovery(dbenv,
00850 CDB___crdel_metapage_print, DB_crdel_metapage)) != 0)
00851 return (ret);
00852 if ((ret = CDB___db_add_recovery(dbenv,
00853 CDB___crdel_old_delete_print, DB_crdel_old_delete)) != 0)
00854 return (ret);
00855 if ((ret = CDB___db_add_recovery(dbenv,
00856 CDB___crdel_rename_print, DB_crdel_rename)) != 0)
00857 return (ret);
00858 if ((ret = CDB___db_add_recovery(dbenv,
00859 CDB___crdel_delete_print, DB_crdel_delete)) != 0)
00860 return (ret);
00861 return (0);
00862 }
00863
00864 int
00865 CDB___crdel_init_recover(dbenv)
00866 DB_ENV *dbenv;
00867 {
00868 int ret;
00869
00870 if ((ret = CDB___db_add_recovery(dbenv,
00871 CDB___crdel_fileopen_recover, DB_crdel_fileopen)) != 0)
00872 return (ret);
00873 if ((ret = CDB___db_add_recovery(dbenv,
00874 CDB___crdel_metasub_recover, DB_crdel_metasub)) != 0)
00875 return (ret);
00876 if ((ret = CDB___db_add_recovery(dbenv,
00877 CDB___crdel_metapage_recover, DB_crdel_metapage)) != 0)
00878 return (ret);
00879 if ((ret = CDB___db_add_recovery(dbenv,
00880 CDB___deprecated_recover, DB_crdel_old_delete)) != 0)
00881 return (ret);
00882 if ((ret = CDB___db_add_recovery(dbenv,
00883 CDB___crdel_rename_recover, DB_crdel_rename)) != 0)
00884 return (ret);
00885 if ((ret = CDB___db_add_recovery(dbenv,
00886 CDB___crdel_delete_recover, DB_crdel_delete)) != 0)
00887 return (ret);
00888 return (0);
00889 }
00890