1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
38
/* do not compile in monitoring code */
39
#ifndef NO_SGE_COMPILE_DEBUG
40
#define NO_SGE_COMPILE_DEBUG
43
#include "cull_list.h"
44
#include "cull_lerrnoP.h"
45
#include "cull_listP.h"
46
#include "cull_multitypeP.h"
47
#include "cull_whatP.h"
48
#include "cull_whereP.h"
49
#include "cull_pack.h"
50
#include "cull_parse.h"
51
#include "cull_file.h"
55
#include "sge_unistd.h"
59
/****** cull/file/lWriteElemToDisk() ******************************************
61
* lWriteElemToDisk() -- Writes a element to file
64
* int lWriteElemToDisk(const lListElem *ep, const char *prefix,
65
* const char *name, const char *obj_name)
68
* Writes the Element 'ep' to the file named 'prefix'/'name'.
69
* Either 'prefix' or 'name can be null.
72
* const lListElem *ep - CULL element
73
* const char *prefix - Path
74
* const char *name - Filename
75
* const char *obj_name -
81
******************************************************************************/
82
int lWriteElemToDisk(const lListElem *ep, const char *prefix, const char *name,
89
DENTER(TOP_LAYER, "lWriteElemToDisk");
91
if (!prefix && !name) {
92
ERROR((SGE_EVENT, MSG_CULL_NOPREFIXANDNOFILENAMEINWRITEELMTODISK ));
97
/* init packing buffer */
98
ret = init_packbuffer(&pb, 8192, 0);
100
/* pack ListElement */
101
if (ret == PACK_SUCCESS) {
102
ret = cull_pack_elem(&pb, ep);
110
ERROR((SGE_EVENT, MSG_CULL_NOTENOUGHMEMORYFORPACKINGXY_SS ,
111
obj_name, name ? name : "null"));
112
clear_packbuffer(&pb);
117
ERROR((SGE_EVENT, MSG_CULL_FORMATERRORWHILEPACKINGXY_SS ,
118
obj_name, name ? name : "null"));
119
clear_packbuffer(&pb);
124
ERROR((SGE_EVENT, MSG_CULL_UNEXPECTEDERRORWHILEPACKINGXY_SS ,
125
obj_name, name ? name : "null"));
126
clear_packbuffer(&pb);
131
/* create full file name */
132
if (prefix && name) {
133
sprintf(filename, "%s/%s", prefix, name);
135
sprintf(filename, "%s", prefix);
137
sprintf(filename, "%s", name);
141
if ((fd = SGE_OPEN3(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
142
CRITICAL((SGE_EVENT, MSG_CULL_CANTOPENXFORWRITINGOFYZ_SSS ,
143
filename, obj_name, strerror(errno)));
144
clear_packbuffer(&pb);
149
/* write packing buffer */
150
if (sge_writenbytes(fd, pb.head_ptr, pb_used(&pb)) != pb_used(&pb)) {
151
CRITICAL((SGE_EVENT, MSG_CULL_CANTWRITEXTOFILEY_SS , obj_name,
153
clear_packbuffer(&pb);
159
/* close file and exit */
161
clear_packbuffer(&pb);
167
/****** cull/file/lReadElemFromDisk() ****************************************
169
* lReadElemFromDisk() -- Reads a cull element from file
172
* lListElem* lReadElemFromDisk(const char *prefix,
174
* const lDescr *type,
175
* const char *obj_name)
178
* Reads a lListElem of the specified 'type' from the file
179
* 'prefix'/'name'. Either 'prefix' or 'name' can be null.
180
* Returns a pointer to the read element or NULL in case
184
* const char *prefix - Path
185
* const char *name - Filename
186
* const lDescr *type - Type
187
* const char *obj_name -
190
* lListElem* - Read CULL element
191
*******************************************************************************/
192
lListElem *lReadElemFromDisk(const char *prefix, const char *name,
193
const lDescr *type, const char *obj_name)
197
SGE_STRUCT_STAT statbuf;
203
DENTER(TOP_LAYER, "lReadElemFromDisk");
205
if (!prefix && !name) {
206
ERROR((SGE_EVENT, MSG_CULL_NOPREFIXANDNOFILENAMEINREADELEMFROMDISK ));
211
/* create full file name */
213
sprintf(filename, "%s/%s", prefix, name);
215
sprintf(filename, "%s", prefix);
217
sprintf(filename, "%s", name);
220
if (SGE_STAT(filename, &statbuf) == -1) {
221
CRITICAL((SGE_EVENT, MSG_CULL_CANTGETFILESTATFORXFILEY_SS , obj_name, filename));
226
if (!statbuf.st_size) {
227
CRITICAL((SGE_EVENT, MSG_CULL_XFILEYHASZEROSIYE_SS , obj_name, filename));
232
/* init packing buffer */
233
size = statbuf.st_size;
234
if (((SGE_OFF_T)size != statbuf.st_size)
235
|| !(buf = malloc(statbuf.st_size))) {
236
CRITICAL((SGE_EVENT, MSG_CULL_LEMALLOC));
237
clear_packbuffer(&pb);
243
if ((fd = SGE_OPEN2(filename, O_RDONLY)) < 0) {
244
CRITICAL((SGE_EVENT, MSG_CULL_CANTREADXFROMFILEY_SS , obj_name, filename));
245
clear_packbuffer(&pb); /* this one frees buf */
250
/* read packing buffer */
251
if (sge_readnbytes(fd, buf, statbuf.st_size) != statbuf.st_size) {
252
CRITICAL((SGE_EVENT, MSG_CULL_ERRORREADINGXINFILEY_SS , obj_name, filename));
258
if((ret = init_packbuffer_from_buffer(&pb, buf, statbuf.st_size)) != PACK_SUCCESS) {
259
ERROR((SGE_EVENT, MSG_CULL_ERRORININITPACKBUFFER_S, cull_pack_strerror(ret)));
261
ret = cull_unpack_elem(&pb, &ep, type);
263
clear_packbuffer(&pb); /* this one frees buf */
270
ERROR((SGE_EVENT, MSG_CULL_NOTENOUGHMEMORYFORUNPACKINGXY_SS ,
271
obj_name, filename));
276
ERROR((SGE_EVENT, MSG_CULL_FORMATERRORWHILEUNPACKINGXY_SS ,
277
obj_name, filename));
282
ERROR((SGE_EVENT, MSG_CULL_BADARGUMENTWHILEUNPACKINGXY_SS ,
283
obj_name, filename));
288
ERROR((SGE_EVENT, MSG_CULL_UNEXPECTEDERRORWHILEUNPACKINGXY_SS ,
289
obj_name, filename));