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
00039
00040
00041
00042 #pragma ident "@(#) libf/fio/inquire.c 92.1 06/21/99 10:37:55"
00043
00044 #include <errno.h>
00045 #include <limits.h>
00046 #if !defined(_ABSOFT)
00047 #include <malloc.h>
00048 #else
00049 #include <stdlib.h>
00050 #endif
00051 #include <string.h>
00052 #include <cray/assign.h>
00053 #include <sys/types.h>
00054 #include <sys/stat.h>
00055 #include "fio.h"
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 int _f_inqu(
00068 FIOSPTR css,
00069 unit *cup,
00070
00071 inlist *a)
00072 {
00073 int aifound;
00074 int byfile;
00075 int exists;
00076 int opened;
00077 int valunit;
00078 int errn;
00079 char *buf, *fn, *s;
00080 struct stat st;
00081 assign_info ai;
00082 unit *p;
00083
00084 p = cup;
00085 errn = 0;
00086
00087
00088
00089
00090
00091 OPENLOCK();
00092
00093 if (a->infile != NULL)
00094 byfile = 1;
00095 else {
00096 byfile = 0;
00097 valunit = GOOD_UNUM(a->inunit) &&
00098 !RSVD_UNUM(a->inunit);
00099 }
00100
00101 if ((buf = malloc(MAX(a->infilen + 1, MXUNITSZ + 1))) == NULL) {
00102 errn = FENOMEMY;
00103 if (a->inerr)
00104 goto out_of_here;
00105 _ferr(css, errn);
00106 }
00107
00108 *buf = '\0';
00109 opened = 0;
00110 fn = buf;
00111
00112 if (byfile) {
00113
00114 _copy_n_trim(a->infile, a->infilen, buf);
00115
00116 if ((aifound = _get_a_options(0, buf, -1, 0, &ai, NULL,
00117 _LELVL_RETURN)) == -1) {
00118
00119 errn = errno;
00120
00121 if (a->inerr) {
00122 free(buf);
00123 goto out_of_here;
00124 }
00125 _ferr(css, errn);
00126 }
00127
00128 if (aifound && ai.a_actfil_flg)
00129 s = ai.a_actfil;
00130 else
00131 s = buf;
00132
00133 exists = (stat(s, &st) != -1);
00134
00135 if (exists) {
00136
00137 p = _get_next_unit(NULL, 1, 1);
00138
00139 while (p != NULL) {
00140 unum_t unum;
00141
00142 unum = p->uid;
00143
00144 if (! RSVD_UNUM(unum) &&
00145 (p->uinode == st.st_ino) &&
00146 (p->udevice == st.st_dev)) {
00147 fn = p->ufnm;
00148 opened = 1;
00149 break;
00150 }
00151 p = _get_next_unit(p, 1, 1);
00152 }
00153
00154
00155
00156
00157
00158 }
00159 }
00160 else {
00161 if (valunit) {
00162 opened = (cup != NULL);
00163 if (opened) {
00164 p = cup;
00165 fn = p->ufnm;
00166 }
00167 }
00168 }
00169
00170 if (fn == NULL)
00171 fn = "";
00172
00173
00174
00175 if (a->inex != NULL)
00176 if (byfile)
00177 *a->inex = _btol(exists);
00178 else
00179 *a->inex = _btol(valunit);
00180
00181
00182
00183 if (a->inopen != NULL)
00184 *a->inopen = _btol(opened);
00185
00186
00187
00188 if (a->innamed != NULL)
00189 if (byfile)
00190 *a->innamed = _btol(1);
00191 else
00192 *a->innamed = _btol(opened && p->ufnm != NULL);
00193
00194
00195
00196 if (a->innum != NULL) {
00197 if (opened) {
00198 if (byfile)
00199 *a->innum = (opened) ? p->uid : -1;
00200 else
00201 *a->innum = a->inunit;
00202 }
00203 else
00204 *a->innum = -1;
00205 }
00206
00207
00208
00209 if (a->inrecl != NULL)
00210 if (opened) {
00211 if (p->urecl > 0)
00212 *a->inrecl = p->urecl;
00213 else
00214 *a->inrecl = (p->ufmt) ? p->urecsize : LONG_MAX;
00215 }
00216 else
00217 *a->inrecl = -1;
00218
00219
00220
00221 if (a->innrec != NULL)
00222 if (opened && p->useq == 0)
00223 *a->innrec = p->udalast + 1;
00224 else
00225 *a->innrec = -1;
00226
00227
00228
00229 if (a->inname != NULL)
00230 _b_char(fn, a->inname, a->innamlen);
00231
00232
00233
00234 if (a->inacc != NULL) {
00235 if (opened)
00236 s = (p->useq) ? "SEQUENTIAL" : "DIRECT";
00237 else
00238 s = "UNDEFINED";
00239 _b_char(s, a->inacc, a->inacclen);
00240 }
00241
00242
00243
00244 if (a->inseq != NULL) {
00245 if (opened)
00246 s = (p->useq) ? "YES" : "NO";
00247 else
00248 s = "UNKNOWN";
00249 _b_char(s, a->inseq, a->inseqlen);
00250 }
00251
00252
00253
00254 if (a->indir != NULL) {
00255 if (opened)
00256 s = (p->useq) ? "NO" : "YES";
00257 else
00258 s = "UNKNOWN";
00259 _b_char(s, a->indir, a->indirlen);
00260 }
00261
00262
00263
00264 if (a->inform != NULL) {
00265 if (opened)
00266 s = (p->ufmt) ? "FORMATTED" : "UNFORMATTED";
00267 else
00268 s = "UNDEFINED";
00269 _b_char(s, a->inform, (ftnlen)a->informlen);
00270 }
00271
00272
00273
00274 if (a->infmt != NULL) {
00275 if (opened)
00276 s = (p->ufmt) ? "YES" : "NO";
00277 else
00278 s = "UNKNOWN";
00279 _b_char(s, a->infmt, a->infmtlen);
00280 }
00281
00282
00283
00284 if (a->inunf != NULL) {
00285 if (opened)
00286 s = (p->ufmt) ? "NO" : "YES";
00287 else
00288 s = "UNKNOWN";
00289 _b_char(s, a->inunf, a->inunflen);
00290 }
00291
00292
00293
00294 if (a->inblank != NULL) {
00295 if (opened && p->ufmt)
00296 s = (p->ublnk) ? "ZERO" : "NULL";
00297 else
00298 s = "UNDEFINED";
00299 _b_char(s, a->inblank, a->inblanklen);
00300 }
00301
00302
00303
00304 if (a->inposit != NULL) {
00305 if (opened && p->useq) {
00306 switch (p->uposition) {
00307 case OS_REWIND:
00308 s = "REWIND";
00309 break;
00310 case OS_ASIS:
00311 s = "ASIS";
00312 break;
00313 case OS_APPEND:
00314 s = "APPEND";
00315 break;
00316 case 0:
00317 s = "UNKNOWN";
00318 break;
00319 default:
00320 _ferr(css, FEINTUNK);
00321 }
00322 }
00323 else
00324 s = "UNDEFINED";
00325 _b_char(s, a->inposit, a->inpositlen);
00326 }
00327
00328
00329
00330 if (a->inaction != NULL) {
00331 if (opened) {
00332 switch (p->uaction) {
00333 case OS_READWRITE:
00334 s = "READWRITE";
00335 break;
00336 case OS_READ:
00337 s = "READ";
00338 break;
00339 case OS_WRITE:
00340 s = "WRITE";
00341 break;
00342 default:
00343 _ferr(css, FEINTUNK);
00344 }
00345 }
00346 else
00347 s = "UNDEFINED";
00348 _b_char(s, a->inaction, a->inactonlen);
00349 }
00350
00351
00352
00353 if (a->inread != NULL) {
00354 if (opened) {
00355 if ((p->uaction == OS_READ) ||
00356 (p->uaction == OS_READWRITE))
00357 s = "YES";
00358 else
00359 s = "NO";
00360 }
00361 else
00362 s = "UNKNOWN";
00363 _b_char(s, a->inread, a->inreadlen);
00364 }
00365
00366
00367
00368 if (a->inwrite != NULL) {
00369 if (opened) {
00370 if ((p->uaction == OS_WRITE) ||
00371 (p->uaction == OS_READWRITE))
00372 s = "YES";
00373 else
00374 s = "NO";
00375 }
00376 else
00377 s = "UNKNOWN";
00378 _b_char(s, a->inwrite, a->inwritelen);
00379 }
00380
00381
00382
00383 if (a->inredwrit != NULL) {
00384 if (opened) {
00385 if (p->uaction == OS_READWRITE)
00386 s = "YES";
00387 else
00388 s = "NO";
00389 }
00390 else
00391 s = "UNKNOWN";
00392 _b_char(s, a->inredwrit, a->inrdwrtlen);
00393 }
00394
00395
00396
00397 if (a->indelim != NULL) {
00398 if (opened && p->ufmt) {
00399 switch (p->udelim) {
00400 case OS_NONE:
00401 s = "NONE";
00402 break;
00403 case OS_QUOTE:
00404 s = "QUOTE";
00405 break;
00406 case OS_APOSTROPHE:
00407 s = "APOSTROPHE";
00408 break;
00409 default:
00410 _ferr(css, FEINTUNK);
00411 }
00412 }
00413 else
00414 s = "UNDEFINED";
00415 _b_char(s, a->indelim, a->indelimlen);
00416 }
00417
00418
00419
00420 if (a->inpad != NULL) {
00421 if(opened && p->ufmt) {
00422 switch (p->upad) {
00423 case OS_YES:
00424 s = "YES";
00425 break;
00426 case OS_NO:
00427 s = "NO";
00428 break;
00429 default:
00430 _ferr(css, FEINTUNK);
00431 }
00432 }
00433 else
00434 s = "YES";
00435 _b_char(s, a->inpad, a->inpadlen);
00436 }
00437
00438
00439
00440
00441
00442 out_of_here:
00443
00444 OPENUNLOCK();
00445
00446 if (p != NULL)
00447 _release_cup(p);
00448
00449 free(buf);
00450 return(errn);
00451 }