00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #pragma ident "@(#) libf/fio/openutil.c 92.2 06/21/99 16:28:21"
00039
00040 #include <errno.h>
00041 #include <ffio.h>
00042 #include <memory.h>
00043 #include <string.h>
00044 #include <liberrno.h>
00045 #include <stdarg.h>
00046 #include <unistd.h>
00047 #include <cray/assign.h>
00048 #include <sys/types.h>
00049 #include <sys/stat.h>
00050 #include "fio.h"
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 int
00089 _deduce_fstruct(
00090 int ufs,
00091 struct fdinfo *fffd,
00092 int formatted)
00093 {
00094 switch (ufs) {
00095 case FS_TEXT:
00096 case FS_COS:
00097 case FS_UNBLOCKED:
00098 case FS_PURE:
00099 case FS_TAPE:
00100 case FS_AUX:
00101 return(ufs);
00102 case FS_BIN:
00103 case FS_U:
00104 return(FS_UNBLOCKED);
00105 case STD:
00106 if (formatted == -1)
00107 return(STD);
00108 else {
00109 switch (formatted) {
00110 case 0:
00111 return(FS_UNBLOCKED);
00112 case 1:
00113 return(FS_TEXT);
00114 default:
00115 return(STD);
00116 }
00117 }
00118 case FS_FDC:
00119 if (fffd == NULL)
00120 return(0);
00121 else {
00122 switch (fffd->class) {
00123 case CLASS_COS:
00124 return(FS_COS);
00125 case CLASS_TEXT:
00126 return(FS_TEXT);
00127 #ifndef _UNICOS
00128 case CLASS_X:
00129 return(FS_F77);
00130 #endif
00131 case CLASS_SYSTEM:
00132 case CLASS_SDS:
00133 case CLASS_MR:
00134 case CLASS_CACHE:
00135 case CLASS_CACHEA:
00136 return(FS_UNBLOCKED);
00137 default:
00138 return(0);
00139 }
00140 }
00141 }
00142 return(0);
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 void
00156 _setup_cvrt(unit *cup)
00157 {
00158 if (cup->ucharset == 0 && cup->unumcvrt != 0)
00159 switch(cup->unumcvrt) {
00160 case NCV_IBM:
00161 cup->ucharset = CS_EBCDIC;
00162 break;
00163 case NCV_CDC:
00164 cup->ucharset = CS_CDC;
00165 break;
00166 default:
00167 break;
00168 }
00169
00170
00171
00172 if (cup->unumcvrt == NCV_NATIVE)
00173 cup->unumcvrt = 0;
00174
00175 if (cup->ucharset == CS_NATIVE)
00176 cup->ucharset = 0;
00177
00178 return;
00179 }
00180
00181
00182
00183
00184
00185
00186
00187 void
00188 _set_device_and_inode(
00189 int sysfd,
00190 dev_t *devp,
00191 ino_t *inodep)
00192 {
00193 struct stat statbuf;
00194
00195 if (sysfd >= 0 && fstat(sysfd, &statbuf) == 0) {
00196 *inodep = statbuf.st_ino;
00197 *devp = statbuf.st_dev;
00198 }
00199 else {
00200 *inodep = -1;
00201 *devp = -1;
00202 }
00203
00204 return;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 int
00224 _uniqinod(
00225 unit *cup,
00226 assign_info *aip)
00227 {
00228 register int multup;
00229 unit *uptr;
00230 ino_t inode;
00231 dev_t device;
00232 struct stat statbuf;
00233
00234 inode = cup->uinode;
00235 device = cup->udevice;
00236 multup = (aip != NULL && aip->m_multup_flg && aip->m_multup);
00237
00238 if (RSVD_UNUM(cup->uid))
00239 return(0);
00240
00241
00242
00243
00244
00245 if (STDIN_FILENO <= cup->usysfd && cup->usysfd <= STDERR_FILENO)
00246 return(0);
00247
00248
00249
00250
00251 if (inode == -1)
00252 return(0);
00253
00254 if (fstat(cup->usysfd, &statbuf) != -1) {
00255
00256
00257
00258
00259
00260 if(S_ISCHR(statbuf.st_mode))
00261 return(0);
00262 if(S_ISFIFO(statbuf.st_mode))
00263 return(0);
00264 }
00265
00266
00267
00268
00269
00270 uptr = _get_next_unit(NULL, 0, 1);
00271
00272 for ( ; uptr != NULL ; uptr = _get_next_unit(uptr, 0, 1)) {
00273
00274 if (uptr == cup) continue;
00275 if (RSVD_UNUM(uptr->uid)) continue;
00276 if (multup && uptr->umultup) continue;
00277
00278 if (inode == uptr->uinode && device == uptr->udevice) {
00279 if (multup)
00280 return(FEMDUPOP);
00281 else
00282 return(FEOPFNCN);
00283 }
00284 }
00285
00286 return(0);
00287 }
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 int
00302 _mixed_scope(unit *cup)
00303 {
00304 unit *uptr;
00305 ino_t inode;
00306 dev_t device;
00307 struct stat statbuf;
00308
00309
00310
00311
00312
00313 uptr = _get_next_unit(NULL, 0, 0);
00314
00315 for ( ; uptr != NULL ; uptr = _get_next_unit(uptr, 0, 0)) {
00316 if (uptr->uid == cup->uid && uptr->private != cup->private)
00317 return(FEMIXSCP);
00318 }
00319
00320 return(0);
00321 }