~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innobase/mach/mach0data.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
Utilities for converting data from the database file
 
3
to the machine format.
 
4
 
 
5
(c) 1995 Innobase Oy
 
6
 
 
7
Created 11/28/1995 Heikki Tuuri
 
8
***********************************************************************/
 
9
 
 
10
#include "mach0data.h"
 
11
 
 
12
#ifdef UNIV_NONINL
 
13
#include "mach0data.ic"
 
14
#endif
 
15
 
 
16
/*************************************************************
 
17
Reads a ulint in a compressed form if the log record fully contains it. */
 
18
 
 
19
byte*
 
20
mach_parse_compressed(
 
21
/*==================*/
 
22
                        /* out: pointer to end of the stored field, NULL if
 
23
                        not complete */
 
24
        byte*   ptr,    /* in: pointer to buffer from where to read */
 
25
        byte*   end_ptr,/* in: pointer to end of the buffer */
 
26
        ulint*  val)    /* out: read value (< 2^32) */
 
27
{
 
28
        ulint   flag;
 
29
 
 
30
        ut_ad(ptr && end_ptr && val);
 
31
 
 
32
        if (ptr >= end_ptr) {
 
33
 
 
34
                return(NULL);
 
35
        }
 
36
 
 
37
        flag = mach_read_from_1(ptr);
 
38
 
 
39
        if (flag < 0x80UL) {
 
40
                *val = flag;
 
41
                return(ptr + 1);
 
42
 
 
43
        } else if (flag < 0xC0UL) {
 
44
                if (end_ptr < ptr + 2) {
 
45
                        return(NULL);
 
46
                }
 
47
 
 
48
                *val = mach_read_from_2(ptr) & 0x7FFFUL;
 
49
 
 
50
                return(ptr + 2);
 
51
 
 
52
        } else if (flag < 0xE0UL) {
 
53
                if (end_ptr < ptr + 3) {
 
54
                        return(NULL);
 
55
                }
 
56
 
 
57
                *val = mach_read_from_3(ptr) & 0x3FFFFFUL;
 
58
 
 
59
                return(ptr + 3);
 
60
        } else if (flag < 0xF0UL) {
 
61
                if (end_ptr < ptr + 4) {
 
62
                        return(NULL);
 
63
                }
 
64
 
 
65
                *val = mach_read_from_4(ptr) & 0x1FFFFFFFUL;
 
66
 
 
67
                return(ptr + 4);
 
68
        } else {
 
69
                ut_ad(flag == 0xF0UL);
 
70
 
 
71
                if (end_ptr < ptr + 5) {
 
72
                        return(NULL);
 
73
                }
 
74
 
 
75
                *val = mach_read_from_4(ptr + 1);
 
76
                return(ptr + 5);
 
77
        }
 
78
}
 
79
 
 
80
/*************************************************************
 
81
Reads a dulint in a compressed form if the log record fully contains it. */
 
82
 
 
83
byte*
 
84
mach_dulint_parse_compressed(
 
85
/*=========================*/
 
86
                        /* out: pointer to end of the stored field, NULL if
 
87
                        not complete */
 
88
        byte*   ptr,    /* in: pointer to buffer from where to read */
 
89
        byte*   end_ptr,/* in: pointer to end of the buffer */
 
90
        dulint* val)    /* out: read value */
 
91
{
 
92
        ulint   high;
 
93
        ulint   low;
 
94
        ulint   size;
 
95
 
 
96
        ut_ad(ptr && end_ptr && val);
 
97
 
 
98
        if (end_ptr < ptr + 5) {
 
99
 
 
100
                return(NULL);
 
101
        }
 
102
 
 
103
        high = mach_read_compressed(ptr);
 
104
 
 
105
        size = mach_get_compressed_size(high);
 
106
 
 
107
        ptr += size;
 
108
 
 
109
        if (end_ptr < ptr + 4) {
 
110
 
 
111
                return(NULL);
 
112
        }
 
113
 
 
114
        low = mach_read_from_4(ptr);
 
115
 
 
116
        *val = ut_dulint_create(high, low);
 
117
 
 
118
        return(ptr + 4);
 
119
}