00001
00002
00003 #include "db_config.h"
00004
00005 #include <ctype.h>
00006 #include <errno.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009
00010 #include <db.h>
00011
00012 #include "ex_apprec.h"
00013
00014
00015
00016
00017 int
00018 ex_apprec_mkdir_log(dbenv, txnid, ret_lsnp, flags,
00019 dirname)
00020 DB_ENV *dbenv;
00021 DB_TXN *txnid;
00022 DB_LSN *ret_lsnp;
00023 u_int32_t flags;
00024 const DBT *dirname;
00025 {
00026 DBT logrec;
00027 DB_LSN *lsnp, null_lsn, *rlsnp;
00028 u_int32_t zero, rectype, txn_num;
00029 u_int npad;
00030 u_int8_t *bp;
00031 int ret;
00032
00033 rectype = DB_ex_apprec_mkdir;
00034 npad = 0;
00035 rlsnp = ret_lsnp;
00036
00037 ret = 0;
00038
00039 if (txnid == NULL) {
00040 txn_num = 0;
00041 lsnp = &null_lsn;
00042 null_lsn.file = null_lsn.offset = 0;
00043 } else {
00044
00045
00046
00047
00048
00049
00050 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00051 txn_num = txnid->txnid;
00052 }
00053
00054 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00055 + sizeof(u_int32_t) + (dirname == NULL ? 0 : dirname->size);
00056 if ((logrec.data = malloc(logrec.size)) == NULL)
00057 return (ENOMEM);
00058 bp = logrec.data;
00059
00060 if (npad > 0)
00061 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00062
00063 bp = logrec.data;
00064
00065 memcpy(bp, &rectype, sizeof(rectype));
00066 bp += sizeof(rectype);
00067
00068 memcpy(bp, &txn_num, sizeof(txn_num));
00069 bp += sizeof(txn_num);
00070
00071 memcpy(bp, lsnp, sizeof(DB_LSN));
00072 bp += sizeof(DB_LSN);
00073
00074 if (dirname == NULL) {
00075 zero = 0;
00076 memcpy(bp, &zero, sizeof(u_int32_t));
00077 bp += sizeof(u_int32_t);
00078 } else {
00079 memcpy(bp, &dirname->size, sizeof(dirname->size));
00080 bp += sizeof(dirname->size);
00081 memcpy(bp, dirname->data, dirname->size);
00082 bp += dirname->size;
00083 }
00084
00085 if ((ret = dbenv->log_put(dbenv, rlsnp, (DBT *)&logrec,
00086 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00087 *lsnp = *rlsnp;
00088 if (rlsnp != ret_lsnp)
00089 *ret_lsnp = *rlsnp;
00090 }
00091 #ifdef LOG_DIAGNOSTIC
00092 if (ret != 0)
00093 (void)ex_apprec_mkdir_print(dbenv,
00094 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00095 #endif
00096
00097 free(logrec.data);
00098 return (ret);
00099 }
00100
00101
00102
00103
00104
00105 int
00106 ex_apprec_mkdir_read(dbenv, recbuf, argpp)
00107 DB_ENV *dbenv;
00108 void *recbuf;
00109 ex_apprec_mkdir_args **argpp;
00110 {
00111 ex_apprec_mkdir_args *argp;
00112 u_int8_t *bp;
00113
00114
00115 dbenv = NULL;
00116 if ((argp = malloc(sizeof(ex_apprec_mkdir_args) + sizeof(DB_TXN))) == NULL)
00117 return (ENOMEM);
00118 bp = recbuf;
00119 argp->txnid = (DB_TXN *)&argp[1];
00120
00121 memcpy(&argp->type, bp, sizeof(argp->type));
00122 bp += sizeof(argp->type);
00123
00124 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00125 bp += sizeof(argp->txnid->txnid);
00126
00127 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00128 bp += sizeof(DB_LSN);
00129
00130 memset(&argp->dirname, 0, sizeof(argp->dirname));
00131 memcpy(&argp->dirname.size, bp, sizeof(u_int32_t));
00132 bp += sizeof(u_int32_t);
00133 argp->dirname.data = bp;
00134 bp += argp->dirname.size;
00135
00136 *argpp = argp;
00137 return (0);
00138 }
00139