1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2019 EDF R&D, CEA/DEN
4 * MED is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * MED is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with MED. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 #include <med.h>
20 #include <med_config.h>
21 #include <med_outils.h>
22 #include <string.h>
23
24 #ifdef PPRO_NT_CALL
25 #define F_OK 0
26 #else
27 #include <unistd.h>
28 #endif
29
30 #include <2.3.6/med23v30.h>
31 #include <2.3.6/med23v30_proto.h>
32 #include "2.3.6/med23v30_misc.h"
33
_MEDfileObjectsMount236(int dummy,...)34 void _MEDfileObjectsMount236(int dummy,...) {
35
36
37 med_idt _ret = -1;
38 med_idt _id, _rootId=0;
39 char _mountPath[2*MED_NAME_SIZE+1];
40 char _link[MED_NAME_SIZE+1];
41 med_access_mode _accessMode;
42 med_int majeur=0, mineur=0, release=0;
43 med_int rfileversionMMR,rfileversionMM,rfileversionM;
44 med_int lfileversionMMR,lfileversionMM,lfileversionM;
45 med_bool _datagroupexist=MED_FALSE,_isasoftlink=MED_FALSE;
46
47 MED_VARGS_DECL(const, med_idt , , fid );
48 MED_VARGS_DECL(const, med_idt , , gid );
49 MED_VARGS_DECL(const, char* , const , mountfilename );
50 MED_VARGS_DECL(const, med_class , , medclass );
51 MED_VARGS_DECL(, med_idt * ,, fret );
52
53 va_list params;
54 va_start(params,dummy);
55
56 MED_VARGS_DEF(const, med_idt , , fid );
57 MED_VARGS_DEF(const, med_idt , , gid );
58 MED_VARGS_DEF(const, char* , const , mountfilename );
59 MED_VARGS_DEF(const, med_class , , medclass );
60 MED_VARGS_DEF(, med_idt * ,, fret );
61
62 _MEDmodeErreurVerrouiller();
63
64 if ( MEDfileNumVersionRd(fid, &majeur, &mineur, &release) < 0) {
65 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDfileNumVersionRd");
66 ISCRUTE(majeur);ISCRUTE(mineur);ISCRUTE(release);
67 goto ERROR;
68 }
69 lfileversionM = 100*majeur;
70 lfileversionMM = 100*majeur+10*mineur;
71 lfileversionMMR = lfileversionMM+release;
72
73 /*
74 * does the file exist ?
75 */
76 if (access(mountfilename,F_OK)) {
77 MED_ERR_(_ret,MED_ERR_EXIST,MED_ERR_FILE,mountfilename);
78 goto ERROR;
79 }
80
81 if ( (_accessMode = (med_access_mode)_MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
82 MED_ERR_(_ret,MED_ERR_ACCESS,MED_ERR_FILE,"");
83 ISCRUTE_int(_accessMode);
84 goto ERROR;
85 }
86
87 /*
88 * Open the file "mountfilename".
89 */
90 if ((_id = _MEDfileOpen(mountfilename,_accessMode)) < 0) {
91 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,mountfilename);
92 goto ERROR;
93 }
94
95 if ( MEDfileNumVersionRd(_id, &majeur, &mineur, &release) < 0 ) {
96 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDfileNumVersionRd");
97 SSCRUTE(mountfilename);ISCRUTE(majeur);ISCRUTE(mineur); ISCRUTE(release);
98 goto ERROR;
99 }
100 rfileversionM = 100*majeur;
101 rfileversionMM = 100*majeur+10*mineur;
102 rfileversionMMR = rfileversionMM+release;
103
104 if ( !( ( (rfileversionMM >= 220) && (lfileversionMM >= 220)
105 && (rfileversionMMR <= 236) && (lfileversionMMR <= 236) ) ) ){
106 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_FILE,mountfilename);
107 ISCRUTE(rfileversionMMR);ISCRUTE(lfileversionMMR);
108 goto ERROR;
109 }
110
111 /*
112 * Mount point creation in the local file
113 */
114 _rootId = _MEDdatagroupOuvrir(fid,MED_MNT);
115 if (_rootId < 0)
116 if ((_rootId = _MEDdatagroupCreer(fid,MED_MNT)) < 0) {
117 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,MED_MNT);
118 goto ERROR;
119 }
120
121 /*
122 * The file "mountfilename" is mounted in the local file
123 */
124 strncpy(_mountPath,MED_MNT,strlen(MED_MNT)-1);
125 _mountPath[strlen(MED_MNT)-1] = '\0';
126 if (_MEDfichierMonter(fid,_mountPath,_id) < 0) {
127 MED_ERR_(_ret,MED_ERR_MOUNT,MED_ERR_FILE,mountfilename);
128 goto ERROR;
129 }
130
131
132 /*
133 * Give access to the class object in the local file
134 */
135 switch(medclass) {
136
137 case MED_MESH :
138 strcpy(_link,MED_MESH_GRP);
139 break;
140
141 case MED_FIELD :
142 strcpy(_link,MED_FIELD_GRP);
143 break;
144
145 default :
146 goto ERROR;
147 }
148
149 strcat(_mountPath,_link);
150 _mountPath[strlen(_mountPath)-1] = '\0';
151 _link[strlen(_link)-1] = '\0';
152 if (_MEDdatagroupLienCreer(fid,_mountPath,_link) < 0) {
153 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_LINK,_link);
154 SSCRUTE(_mountPath);
155 goto ERROR;
156 }
157
158 _ret = _id;
159 ERROR:
160
161 if (_rootId > 0)
162 if (_MEDdatagroupFermer(_rootId) < 0) {
163 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,MED_MNT);
164 }
165
166 va_end(params);
167 *fret = _ret;
168 return;
169 }
170