~ubuntu-branches/ubuntu/karmic/firebird2.1/karmic

« back to all changes in this revision

Viewing changes to src/jrd/blb.h

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2008-05-26 23:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20080526235925-2pnqj6nxpppoeaer
Tags: upstream-2.1.0.17798-0.ds2
ImportĀ upstreamĀ versionĀ 2.1.0.17798-0.ds2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      PROGRAM:        JRD Access Method
 
3
 *      MODULE:         blb.h
 
4
 *      DESCRIPTION:    Blob handling definitions
 
5
 *
 
6
 * The contents of this file are subject to the Interbase Public
 
7
 * License Version 1.0 (the "License"); you may not use this file
 
8
 * except in compliance with the License. You may obtain a copy
 
9
 * of the License at http://www.Inprise.com/IPL.html
 
10
 *
 
11
 * Software distributed under the License is distributed on an
 
12
 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
 
13
 * or implied. See the License for the specific language governing
 
14
 * rights and limitations under the License.
 
15
 *
 
16
 * The Original Code was created by Inprise Corporation
 
17
 * and its predecessors. Portions created by Inprise Corporation are
 
18
 * Copyright (C) Inprise Corporation.
 
19
 *
 
20
 * All Rights Reserved.
 
21
 * Contributor(s): ______________________________________.
 
22
 *
 
23
 * 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "DecOSF" port
 
24
 *
 
25
 */
 
26
 
 
27
#ifndef JRD_BLB_H
 
28
#define JRD_BLB_H
 
29
 
 
30
#include "../jrd/RecordNumber.h"
 
31
 
 
32
namespace Jrd {
 
33
 
 
34
/* Blob id.  A blob has two states -- temporary and permanent.  In each
 
35
   case, the blob id is 8 bytes (2 longwords) long.  In the case of a
 
36
   temporary blob, the first word is NULL and the second word points to
 
37
   an internal blob block.  In the case of a permanent blob, the first
 
38
   word contains the relation id of the blob and the second the record
 
39
   number of the first segment-clump.  The two types of blobs can be
 
40
   reliably distinguished by a zero or non-zero relation id. */
 
41
 
 
42
class Attachment;
 
43
class BlobControl;
 
44
class jrd_rel;
 
45
class jrd_req;
 
46
class jrd_tra;
 
47
class vcl;
 
48
 
 
49
// This structure must occupy 8 bytes
 
50
struct bid {
 
51
        union {
 
52
                // Internal decomposition of the structure
 
53
                RecordNumber::Packed bid_internal;
 
54
 
 
55
                // This is how bid structure represented in public API.
 
56
                // Must be present to enforce alignment rules when structure is declared on stack
 
57
                struct {
 
58
                        ULONG bid_quad_high;
 
59
                        ULONG bid_quad_low;
 
60
                } bid_quad;
 
61
        };
 
62
 
 
63
        ULONG& bid_temp_id() {
 
64
                // Make sure that compiler packed structure like we wanted
 
65
                fb_assert(sizeof(*this) == 8);
 
66
 
 
67
                return bid_internal.bid_temp_id();
 
68
        }
 
69
 
 
70
        ULONG bid_temp_id() const {
 
71
                // Make sure that compiler packed structure like we wanted
 
72
                fb_assert(sizeof(*this) == 8);
 
73
 
 
74
                return bid_internal.bid_temp_id();
 
75
        }
 
76
 
 
77
        bool isEmpty() const { 
 
78
                // Make sure that compiler packed structure like we wanted
 
79
                fb_assert(sizeof(*this) == 8);
 
80
 
 
81
                return bid_quad.bid_quad_high == 0 && bid_quad.bid_quad_low == 0; 
 
82
        }
 
83
 
 
84
        void clear() {
 
85
                // Make sure that compiler packed structure like we wanted
 
86
                fb_assert(sizeof(*this) == 8);
 
87
 
 
88
                bid_quad.bid_quad_high = 0;
 
89
                bid_quad.bid_quad_low = 0;
 
90
        }
 
91
 
 
92
        void set_temporary(ULONG temp_id) {
 
93
                // Make sure that compiler packed structure like we wanted
 
94
                fb_assert(sizeof(*this) == 8);
 
95
 
 
96
                clear();
 
97
                bid_temp_id() = temp_id;
 
98
        }
 
99
 
 
100
        void set_permanent(USHORT relation_id, RecordNumber num) {
 
101
                // Make sure that compiler packed structure like we wanted
 
102
                fb_assert(sizeof(*this) == 8);
 
103
 
 
104
                clear();
 
105
                bid_internal.bid_relation_id = relation_id;
 
106
                num.bid_encode(&bid_internal);
 
107
        }
 
108
 
 
109
        RecordNumber get_permanent_number() const {
 
110
                // Make sure that compiler packed structure like we wanted
 
111
                fb_assert(sizeof(*this) == 8);
 
112
 
 
113
                RecordNumber temp;
 
114
                temp.bid_decode(&bid_internal);
 
115
                return temp;
 
116
        }
 
117
 
 
118
        bool operator == (const bid& other) const {
 
119
                // Make sure that compiler packed structure like we wanted
 
120
                fb_assert(sizeof(*this) == 8);
 
121
 
 
122
                return bid_quad.bid_quad_high == other.bid_quad.bid_quad_high && 
 
123
                        bid_quad.bid_quad_low == other.bid_quad.bid_quad_low;
 
124
        }
 
125
};
 
126
 
 
127
/* Your basic blob block. */
 
128
 
 
129
class blb : public pool_alloc_rpt<UCHAR, type_blb>
 
130
{
 
131
    public:
 
132
        Attachment*     blb_attachment; /* database attachment */
 
133
        jrd_rel*        blb_relation;   /* Relation, if known */
 
134
        jrd_tra*        blb_transaction;        /* Parent transaction block */
 
135
        blb*            blb_next;               /* Next blob in transaction */
 
136
        UCHAR*          blb_segment;    /* Next segment to be addressed */
 
137
        BlobControl*    blb_filter;     /* Blob filter control block, if any */
 
138
        bid                     blb_blob_id;    /* Id of materialized blob */
 
139
        vcl*            blb_pages;              /* Vector of pages */
 
140
        USHORT blb_pointers;            /* Max pointer on a page */
 
141
        USHORT blb_level;                       /* Storage type */
 
142
        USHORT blb_max_segment;         /* Longest segment */
 
143
        USHORT blb_flags;                       /* Interesting stuff (see below) */
 
144
        USHORT blb_clump_size;          /* Size of data clump */
 
145
        USHORT blb_space_remaining;     /* Data space left */
 
146
        USHORT blb_max_pages;           /* Max pages in vector */
 
147
        USHORT blb_fragment_size;       /* Residual fragment size */
 
148
        USHORT blb_source_interp;       /* source interp (for writing) */
 
149
        USHORT blb_target_interp;       /* destination interp (for reading) */
 
150
        SSHORT blb_sub_type;            /* Blob's declared sub-type */
 
151
        UCHAR blb_charset;                      // Blob's charset
 
152
        USHORT blb_pg_space_id;         // page space
 
153
        ULONG blb_sequence;                     /* Blob page sequence */
 
154
        ULONG blb_max_sequence;         /* Number of data pages */
 
155
        ULONG blb_count;                        /* Number of segments */
 
156
        ULONG blb_length;                       /* Total length of data sans segments */
 
157
        ULONG blb_lead_page;            /* First page number */
 
158
        ULONG blb_seek;                         /* Seek location */
 
159
        ULONG blb_temp_id;          // ID of newly created blob in transaction
 
160
        /* blb_data must be longword aligned */
 
161
        UCHAR blb_data[1];                      /* A page's worth of blob */
 
162
};
 
163
 
 
164
const int BLB_temporary = 1;                    /* Newly created blob */
 
165
const int BLB_eof               = 2;                    /* This blob is exhausted */
 
166
const int BLB_stream    = 4;                    /* Stream style blob */
 
167
const int BLB_closed    = 8;                    /* Temporary blob has been closed */
 
168
const int BLB_damaged   = 16;                   /* Blob is busted */
 
169
const int BLB_seek              = 32;                   /* Seek is pending */
 
170
const int BLB_user_def  = 64;                   /* Blob is user created */
 
171
const int BLB_large_scan        = 128;          /* Blob is larger than page buffer cache */
 
172
 
 
173
/* Blob levels are:
 
174
 
 
175
        0       small blob -- blob "record" is actual data
 
176
        1       medium blob -- blob "record" is pointer to pages
 
177
        2       large blob -- blob "record" is pointer to pages of pointers
 
178
*/
 
179
 
 
180
// mapping blob ids for REPLAY
 
181
// Useful only with REPLAY_OSRI_API_CALLS_SUBSYSTEM defined.
 
182
class blb_map : public pool_alloc<type_map>
 
183
{
 
184
    public:
 
185
        blb_map*        map_next;
 
186
        blb*            map_old_blob;
 
187
        blb*            map_new_blob;
 
188
};
 
189
 
 
190
} //namespace Jrd
 
191
 
 
192
#endif // JRD_BLB_H
 
193