Asterisk - The Open Source Telephony Project  18.5.0
Functions
bt_conv.c File Reference
#include <sys/param.h>
#include <stdio.h>
#include "../include/db.h"
#include "btree.h"
Include dependency graph for bt_conv.c:

Go to the source code of this file.

Functions

void __bt_pgin (void *t, pgno_t pg, void *pp)
 
void __bt_pgout (void *t, pgno_t pg, void *pp)
 
static void mswap __P ((PAGE *))
 
static void mswap (PAGE *pg)
 

Function Documentation

◆ __bt_pgin()

void __bt_pgin ( void *  t,
pgno_t  pg,
void *  pp 
)

Definition at line 61 of file bt_conv.c.

References B_NEEDSWAP, F_ISSET, _page::flags, GETBINTERNAL, GETBLEAF, _page::linp, _page::lower, mswap(), NEXTINDEX, _page::nextpg, P_BIGDATA, P_BIGKEY, P_BINTERNAL, P_BLEAF, P_META, P_TYPE, _page::pgno, _page::prevpg, and _page::upper.

Referenced by __bt_open().

65 {
66  PAGE *h;
67  indx_t i, top;
68  u_char flags;
69  char *p;
70 
71  if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
72  return;
73  if (pg == P_META) {
74  mswap(pp);
75  return;
76  }
77 
78  h = pp;
79  M_32_SWAP(h->pgno);
80  M_32_SWAP(h->prevpg);
81  M_32_SWAP(h->nextpg);
82  M_32_SWAP(h->flags);
83  M_16_SWAP(h->lower);
84  M_16_SWAP(h->upper);
85 
86  top = NEXTINDEX(h);
87  if ((h->flags & P_TYPE) == P_BINTERNAL)
88  for (i = 0; i < top; i++) {
89  M_16_SWAP(h->linp[i]);
90  p = (char *)GETBINTERNAL(h, i);
91  P_32_SWAP(p);
92  p += sizeof(u_int32_t);
93  P_32_SWAP(p);
94  p += sizeof(pgno_t);
95  if (*(u_char *)p & P_BIGKEY) {
96  p += sizeof(u_char);
97  P_32_SWAP(p);
98  p += sizeof(pgno_t);
99  P_32_SWAP(p);
100  }
101  }
102  else if ((h->flags & P_TYPE) == P_BLEAF)
103  for (i = 0; i < top; i++) {
104  M_16_SWAP(h->linp[i]);
105  p = (char *)GETBLEAF(h, i);
106  P_32_SWAP(p);
107  p += sizeof(u_int32_t);
108  P_32_SWAP(p);
109  p += sizeof(u_int32_t);
110  flags = *(u_char *)p;
111  if (flags & (P_BIGKEY | P_BIGDATA)) {
112  p += sizeof(u_char);
113  if (flags & P_BIGKEY) {
114  P_32_SWAP(p);
115  p += sizeof(pgno_t);
116  P_32_SWAP(p);
117  }
118  if (flags & P_BIGDATA) {
119  p += sizeof(u_int32_t);
120  P_32_SWAP(p);
121  p += sizeof(pgno_t);
122  P_32_SWAP(p);
123  }
124  }
125  }
126 }
Definition: btree.h:75
#define NEXTINDEX(p)
Definition: btree.h:98
#define GETBLEAF(pg, indx)
Definition: btree.h:188
pgno_t pgno
Definition: btree.h:76
#define F_ISSET(p, f)
Definition: btree.h:42
#define P_META
Definition: btree.h:64
indx_t lower
Definition: btree.h:89
#define P_TYPE
Definition: btree.h:85
#define B_NEEDSWAP
Definition: btree.h:371
u_int16_t indx_t
Definition: db.h:80
indx_t upper
Definition: btree.h:90
#define GETBINTERNAL(pg, indx)
Definition: btree.h:138
Definition: btree.h:312
static void mswap(PAGE *pg)
Definition: bt_conv.c:203
u_int32_t flags
Definition: btree.h:87
#define P_BIGKEY
Definition: btree.h:132
indx_t linp[1]
Definition: btree.h:91
u_int32_t pgno_t
Definition: db.h:78
pgno_t nextpg
Definition: btree.h:78
pgno_t prevpg
Definition: btree.h:77
unsigned int u_int32_t
#define P_BIGDATA
Definition: btree.h:131
#define P_BINTERNAL
Definition: btree.h:80
#define P_BLEAF
Definition: btree.h:81

◆ __bt_pgout()

void __bt_pgout ( void *  t,
pgno_t  pg,
void *  pp 
)

Definition at line 129 of file bt_conv.c.

References B_NEEDSWAP, F_ISSET, _page::flags, GETBINTERNAL, GETBLEAF, _page::linp, _page::lower, mswap(), NEXTINDEX, _page::nextpg, P_BIGDATA, P_BIGKEY, P_BINTERNAL, P_BLEAF, P_META, P_TYPE, _page::pgno, _page::prevpg, and _page::upper.

Referenced by __bt_open().

133 {
134  PAGE *h;
135  indx_t i, top;
136  u_char flags;
137  char *p;
138 
139  if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
140  return;
141  if (pg == P_META) {
142  mswap(pp);
143  return;
144  }
145 
146  h = pp;
147  top = NEXTINDEX(h);
148  if ((h->flags & P_TYPE) == P_BINTERNAL)
149  for (i = 0; i < top; i++) {
150  p = (char *)GETBINTERNAL(h, i);
151  P_32_SWAP(p);
152  p += sizeof(u_int32_t);
153  P_32_SWAP(p);
154  p += sizeof(pgno_t);
155  if (*(u_char *)p & P_BIGKEY) {
156  p += sizeof(u_char);
157  P_32_SWAP(p);
158  p += sizeof(pgno_t);
159  P_32_SWAP(p);
160  }
161  M_16_SWAP(h->linp[i]);
162  }
163  else if ((h->flags & P_TYPE) == P_BLEAF)
164  for (i = 0; i < top; i++) {
165  p = (char *)GETBLEAF(h, i);
166  P_32_SWAP(p);
167  p += sizeof(u_int32_t);
168  P_32_SWAP(p);
169  p += sizeof(u_int32_t);
170  flags = *(u_char *)p;
171  if (flags & (P_BIGKEY | P_BIGDATA)) {
172  p += sizeof(u_char);
173  if (flags & P_BIGKEY) {
174  P_32_SWAP(p);
175  p += sizeof(pgno_t);
176  P_32_SWAP(p);
177  }
178  if (flags & P_BIGDATA) {
179  p += sizeof(u_int32_t);
180  P_32_SWAP(p);
181  p += sizeof(pgno_t);
182  P_32_SWAP(p);
183  }
184  }
185  M_16_SWAP(h->linp[i]);
186  }
187 
188  M_32_SWAP(h->pgno);
189  M_32_SWAP(h->prevpg);
190  M_32_SWAP(h->nextpg);
191  M_32_SWAP(h->flags);
192  M_16_SWAP(h->lower);
193  M_16_SWAP(h->upper);
194 }
Definition: btree.h:75
#define NEXTINDEX(p)
Definition: btree.h:98
#define GETBLEAF(pg, indx)
Definition: btree.h:188
pgno_t pgno
Definition: btree.h:76
#define F_ISSET(p, f)
Definition: btree.h:42
#define P_META
Definition: btree.h:64
indx_t lower
Definition: btree.h:89
#define P_TYPE
Definition: btree.h:85
#define B_NEEDSWAP
Definition: btree.h:371
u_int16_t indx_t
Definition: db.h:80
indx_t upper
Definition: btree.h:90
#define GETBINTERNAL(pg, indx)
Definition: btree.h:138
Definition: btree.h:312
static void mswap(PAGE *pg)
Definition: bt_conv.c:203
u_int32_t flags
Definition: btree.h:87
#define P_BIGKEY
Definition: btree.h:132
indx_t linp[1]
Definition: btree.h:91
u_int32_t pgno_t
Definition: db.h:78
pgno_t nextpg
Definition: btree.h:78
pgno_t prevpg
Definition: btree.h:77
unsigned int u_int32_t
#define P_BIGDATA
Definition: btree.h:131
#define P_BINTERNAL
Definition: btree.h:80
#define P_BLEAF
Definition: btree.h:81

◆ __P()

static void mswap __P ( (PAGE *)  )
static

◆ mswap()

static void mswap ( PAGE pg)
static

Definition at line 203 of file bt_conv.c.

Referenced by __bt_pgin(), and __bt_pgout().

205 {
206  char *p;
207 
208  p = (char *)pg;
209  P_32_SWAP(p); /* magic */
210  p += sizeof(u_int32_t);
211  P_32_SWAP(p); /* version */
212  p += sizeof(u_int32_t);
213  P_32_SWAP(p); /* psize */
214  p += sizeof(u_int32_t);
215  P_32_SWAP(p); /* free */
216  p += sizeof(u_int32_t);
217  P_32_SWAP(p); /* nrecs */
218  p += sizeof(u_int32_t);
219  P_32_SWAP(p); /* flags */
220  p += sizeof(u_int32_t);
221 }
unsigned int u_int32_t