-
Notifications
You must be signed in to change notification settings - Fork 1
/
dauflush.c
147 lines (118 loc) · 4.27 KB
/
dauflush.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#if HAVE_CONFIG_H
# include <config.h>
#endif
/*+DAUFLUSH.C-*/
/* Include files */
#include "ems.h" /* EMS error reporting routines */
#include "hds1.h" /* Global definitions for HDS */
#include "rec.h" /* Public rec_ definitions */
#include "str.h" /* Character string import/export macros */
#include "dat1.h" /* Internal dat_ definitions */
#include "dat_err.h" /* DAT__ error code definitions */
/* Control Blocks */
int
dau_flush_data(struct LCP_DATA *data)
/*+
* DAU_FLUSH_DATA - Flush mapped data
*
* This routine will unmap any primitive data that is currently mapped to the
* specified locator. If the data object is a discontiguous slice, then a
* scatter write-back is performed if mapped in either 'WRITE' or 'UPDATE' mode.
*
* Calling sequence:
*
* DAU_FLUSH_DATA(DATA)
*
* DATA is the address of the data part of the Locator Control Packet.
*
* Routine value:
*
* DAT__OK if successful.
*/
{
struct LCP_STATE *state;
struct PDD *app;
struct PDD *obj;
unsigned char *dom;
int writing;
INT_BIG objlen;
INT_BIG objoff;
INT_BIG applen;
int nbad;
int mapsave;
/* Return if no data currently mapped. */
state = &data->state;
if ( !state->mapped )
return hds_gl_status;
/* Begin a new error reporting context. */
emsBegin( &hds_gl_status );
/* Set the global file mapping flag to the value used when the data were */
/* originally mapped. */
mapsave = hds_gl_map;
hds_gl_map = data->filemap;
/* Associate the application data and object data attributes descriptors. */
app = &data->app;
obj = &data->obj;
writing = (data->mode != 'R');
/* Calculate the length (in bytes) of the virtual memory allocated to the
application program data and the corresponding length of the object data.
Determine the byte-offset into the object record's dynamic domain. */
applen = app->length * data->size;
objlen = obj->length * data->size;
objoff = obj->length * data->offset;
/* Scatter discontiguous object data if the program is writing or updating. */
if (state->broken)
{
if (writing)
{
dau_scatter_data(1, data, &nbad );
/* If conversion errors occurred, then report contextual information. */
if ( hds_gl_status == DAT__CONER )
{
emsSeti( "NBAD", nbad );
emsRep( "DAU_FLUSH_1",
"A total of ^NBAD data conversion error(s) occurred.",
&hds_gl_status );
}
}
rec_deall_xmem( applen, (void **) &app->body );
}
/* If a copy of the object data was given to the program, then locate the
record's dynamic domain and translate the data from the virtual memory copy.
*/
else if (state->vmcopy)
{
if (writing)
{
rec_locate_data(&data->han, objlen, objoff, 'W', &dom);
obj->body = dom;
dat1_cvt( 1, data->size, app, obj, &nbad );
/* If conversion errors occurred, then report contextual information. */
if ( hds_gl_status == DAT__CONER )
{
emsSeti( "NBAD", nbad );
emsRep( "DAU_FLUSH_2",
"A total of ^NBAD data conversion error(s) occurred.",
&hds_gl_status );
}
rec_release_data(&data->han, objlen, objoff, 'W', &dom);
}
rec_deall_xmem( applen, (void **) &app->body );
}
/* Otherwise, the application program was given direct access to the data. */
else
{
dom = app->body;
rec_release_data(&data->han, objlen, objoff, data->mode, &dom);
}
/* Clear the pointer and the map flags. */
app->body = 0;
state->mapped = 0;
state->unlike = 0;
state->vmcopy = 0;
/* Restore the global file mapping flag. */
hds_gl_map = mapsave;
/* End the error reporting context. */
emsEnd( &hds_gl_status );
return hds_gl_status;
}