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