File: dbfilop.c

package info (click to toggle)
fis-gtm 6.2-000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,784 kB
  • ctags: 42,554
  • sloc: ansic: 358,483; asm: 4,847; csh: 4,574; sh: 2,261; awk: 200; makefile: 86; sed: 13
file content (131 lines) | stat: -rw-r--r-- 4,269 bytes parent folder | download | duplicates (2)
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
/****************************************************************
 *								*
 *	Copyright 2001, 2012 Fidelity Information Services, Inc	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

#include "mdef.h"

#include "gtm_string.h"

#include <sys/sem.h>
#include "gtm_fcntl.h"
#include "gtm_unistd.h"
#include <errno.h>
#include <stddef.h>

#ifdef __MVS__
#include "gtm_zos_io.h"
#endif
#include "gdsroot.h"
#include "gtm_facility.h"
#include "fileinfo.h"
#include "gdsbt.h"
#include "gdsfhead.h"
#include "filestruct.h"
#include "eintr_wrappers.h"
#include "gtmio.h"
#include "iosp.h"
#include "is_file_identical.h"
#include "dbfilop.h"
#include "anticipatory_freeze.h"
#include "jnl.h"

GBLREF	gd_region	*gv_cur_region;

error_def(ERR_DBFILOPERR);
error_def(ERR_DBNOTGDS);
error_def(ERR_DBOPNERR);
error_def(ERR_DBPREMATEOF);
error_def(ERR_TEXT);
ZOS_ONLY(error_def(ERR_BADTAG);)

uint4 dbfilop(file_control *fc)
{
	unix_db_info		*udi;
	struct stat		stat_buf;
	int4			save_errno;
	int			fstat_res;
	sgmnt_data_ptr_t	csd;
	ZOS_ONLY(int		realfiletag;)

	/* assert((dba_mm == fc->file_type) || (dba_bg == fc->file_type)); not always set in unix */
	udi = (unix_db_info *)fc->file_info;
	switch(fc->op)
	{
		case FC_READ:
				assert(fc->op_pos > 0);		/* gt.m uses the vms convention of numbering the blocks from 1 */
 				LSEEKREAD(udi->fd,
 					  (off_t)(fc->op_pos - 1) * DISK_BLOCK_SIZE,
 					  fc->op_buff,
 					  fc->op_len,
 					  save_errno);
				if (0 != save_errno)
				{
					if (-1 == save_errno)
						rts_error(VARLSTCNT(4) ERR_DBPREMATEOF, 2, LEN_AND_STR(udi->fn));
					else
						rts_error(VARLSTCNT(5) ERR_DBFILOPERR, 2, LEN_AND_STR(udi->fn), save_errno);
				}
				if (1 == fc->op_pos)
				{
					if (0 != memcmp(fc->op_buff, GDS_LABEL, GDS_LABEL_SZ - 3))
						rts_error(VARLSTCNT(4) ERR_DBNOTGDS, 2, LEN_AND_STR(udi->fn));
					if (0 == memcmp(fc->op_buff, GDS_LABEL, GDS_LABEL_SZ - 1))	/* current GDS */
					{
						csd = (sgmnt_data_ptr_t)fc->op_buff;
						if (offsetof(sgmnt_data, minor_dbver) < fc->op_len)
							CHECK_DB_ENDIAN((sgmnt_data_ptr_t)fc->op_buff, strlen(udi->fn), udi->fn);
					}
				}
				break;
		case FC_WRITE:
				if ((1 == fc->op_pos) && ((0 != memcmp(fc->op_buff, GDS_LABEL, GDS_LABEL_SZ - 1))
						|| (0 == ((sgmnt_data_ptr_t)fc->op_buff)->acc_meth)))
					GTMASSERT;
				assert((1 != fc->op_pos) || fc->op_len <= SIZEOF_FILE_HDR(fc->op_buff));
 				DB_LSEEKWRITE(&udi->s_addrs, udi->fn, udi->fd,
 					   (off_t)(fc->op_pos - 1) * DISK_BLOCK_SIZE,
 					   fc->op_buff,
 					   fc->op_len,
 					   save_errno);
 				if (0 != save_errno)
					rts_error(VARLSTCNT(5) ERR_DBFILOPERR, 2, LEN_AND_STR(udi->fn), save_errno);
				break;
		case FC_OPEN:
				gv_cur_region->read_only = FALSE;	/* maintain csa->read_write simultaneously */
				udi->s_addrs.read_write = TRUE;		/* maintain reg->read_only simultaneously */
				if (FD_INVALID == (udi->fd = OPEN((char *)gv_cur_region->dyn.addr->fname, O_RDWR)))
				{
					if (FD_INVALID == (udi->fd = OPEN((char *)gv_cur_region->dyn.addr->fname, O_RDONLY)))
						return ERR_DBOPNERR;
					gv_cur_region->read_only = TRUE;	/* maintain csa->read_write simultaneously */
					udi->s_addrs.read_write = FALSE;	/* maintain reg->read_only simultaneously */
				}
				FSTAT_FILE(udi->fd, &stat_buf, fstat_res);
				if (-1 == fstat_res)
					return ERR_DBOPNERR;
#ifdef __MVS__
				if (-1 == gtm_zos_tag_to_policy(udi->fd, TAG_BINARY, &realfiletag))
					TAG_POLICY_SEND_MSG((char_ptr_t)gv_cur_region->dyn.addr->fname, errno,
								realfiletag, TAG_BINARY);
#endif
				set_gdid_from_stat(&udi->fileid, &stat_buf);
				udi->raw = (S_ISCHR(stat_buf.st_mode) || S_ISBLK(stat_buf.st_mode));
				udi->fn = (char *)gv_cur_region->dyn.addr->fname;
				break;
		case FC_CLOSE:
				CLOSEFILE_RESET(udi->fd, save_errno);	/* resets "udi->fd" to FD_INVALID */
 				if (0 != save_errno)
					rts_error(VARLSTCNT(5) ERR_DBFILOPERR, 2, LEN_AND_STR(udi->fn), save_errno);
				break;
		default:
				GTMASSERT;
	}
	return SS_NORMAL;
}