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