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 #include <cmplrs/fio.h>
00042 #include <mutex.h>
00043 #include <string.h>
00044 #include "fmt.h"
00045 #include "iomode.h"
00046 #include "due.h"
00047 #include "err.h"
00048 #include "open.h"
00049 #include "uio.h"
00050 #include "fio_direct_io.h"
00051 #include <sys/types.h>
00052 #include <unistd.h>
00053 #include "bcompat.h"
00054
00055
00056 #define ASSOCV 12
00057
00058
00059 static int c_due (cilist64 *a, unit **fu);
00060 static int f_find_com (flist64 *a, int lock);
00061
00062 int
00063 f_find (flist *a)
00064 {
00065 #if 11
00066 flist64 a64;
00067
00068 a64.ferr = a->ferr;;
00069 a64.funit = a->funit;;
00070 a64.frec = a->frec;
00071 return( f_find_com( &a64, 0 ) );
00072 #else
00073 return( f_find_com( a, 0 ) );
00074 #endif
00075 }
00076
00077 int
00078 f_find_mp (flist *a)
00079 {
00080 #if 11
00081 flist64 a64;
00082
00083 a64.ferr = a->ferr;;
00084 a64.funit = a->funit;;
00085 a64.frec = a->frec;
00086 return( f_find_com( &a64, 1 ) );
00087 #else
00088 return( f_find_com( a, 1 ) );
00089 #endif
00090 }
00091
00092 #if 11
00093 int
00094 f_find64 (flist64 *a)
00095 {
00096 return( f_find_com( a, 0 ) );
00097 }
00098
00099 int
00100 f_find64_mp (flist64 *a)
00101 {
00102 return( f_find_com( a, 1 ) );
00103 }
00104
00105
00106 static int
00107 f_find_com (flist64 *a, int lock)
00108 #else
00109 static int
00110 f_find_com (flist *a, int lock)
00111 #endif
00112 {
00113 unit *ftnunit;
00114
00115 if (!f77init)
00116 f_init ();
00117 if ((ftnunit = map_luno (a->funit)) == NULL)
00118 err(a->ferr, 101, "find");
00119 while (lock && test_and_set( &ftnunit->lock_unit, 1L ))
00120 ;
00121 if (ftnunit->uconn <= 0 && fk_open (DIR, UNF, a->funit)) {
00122 ftnunit->uconn = 0;
00123 errret(a->ferr, 114, "find");
00124 }
00125 ftnunit->f77recpos = 0;
00126 ftnunit->ufd = ftnunit->ufd;
00127 if (!ftnunit->useek)
00128 errret(a->ferr, 104, "find");
00129
00130
00131
00132 if (ftnunit->ufmt == 0) {
00133 ftnll offset = (a->frec - 1) * ftnunit->url;
00134 (void) LSEEK ((int) ftnunit->ufd, offset, 0);
00135
00136 _fio_set_seek((int) ftnunit->ufd, offset, 0);
00137 } else
00138 (void) FSEEK ( ftnunit->ufd, (ftnll)(a->frec - 1) * ftnunit->url, 0);
00139
00140 if (ftnunit->uassocv)
00141 set_var ((ftnintu *)ftnunit->uassocv, ftnunit->umask, ASSOCV, a->frec);
00142 if (ftnunit->umaxrec && (a->frec > ftnunit->umaxrec))
00143 errret(a->ferr, 159, "find");
00144 ftnunit->uend = 0;
00145 if (lock) ftnunit->lock_unit = 0;
00146 return (0);
00147 }
00148
00149 int
00150 s_rdue (cilist *a)
00151 {
00152 return (s_rdue_mp (a, &f77curunit));
00153 }
00154
00155 #if 11
00156
00157 int
00158 s_rdue_mp (cilist *a, unit **fu)
00159 {
00160 cilist64 a64;
00161
00162 get_cilist64( &a64, a );
00163 return( s_rdue64_mp( &a64, fu ) );
00164 }
00165
00166 int
00167 s_rdue64(cilist64 *a)
00168 {
00169 return( s_rdue64_mp( a, &f77curunit ));
00170 }
00171
00172 int
00173 s_rdue64_mp (cilist64 *a, unit **fu)
00174 #else
00175
00176 int
00177 s_rdue_mp (cilist *a, unit **fu)
00178 #endif
00179 {
00180 int n;
00181 unit *ftnunit;
00182
00183 if (n = c_due (a, fu)) {
00184 if (*fu) (*fu)->lock_unit = 0;
00185 return (n);
00186 }
00187
00188 ftnunit = *fu;
00189 ftnunit->uwrt &= ~WR_OP;
00190 ftnunit->f77do_unf = do_ud;
00191 #ifdef I90
00192 if (ftnunit->uaction == WRITEONLY )
00193 errret(ftnunit->f77errlist.cierr,180,"startread");
00194 #endif
00195 return (0);
00196 }
00197
00198 int
00199 s_wdue (cilist *a)
00200 {
00201 return( s_wdue_mp( a, &f77curunit ));
00202 }
00203
00204 #if 11
00205
00206 int
00207 s_wdue_mp (cilist *a, unit **fu)
00208 {
00209 cilist64 a64;
00210
00211 get_cilist64( &a64, a );
00212 return( s_wdue64_mp( &a64, fu ) );
00213 }
00214
00215 int
00216 s_wdue64(cilist64 *a)
00217 {
00218 return( s_wdue64_mp( a, &f77curunit ));
00219 }
00220
00221 int
00222 s_wdue64_mp (cilist64 *a, unit **fu)
00223 #else
00224
00225 int
00226 s_wdue_mp (cilist *a, unit **fu)
00227 #endif
00228 {
00229 int n;
00230
00231 if (n = c_due (a, fu)) {
00232 if (*fu) (*fu)->lock_unit = 0;
00233 return (n);
00234 }
00235
00236
00237 (*fu)->uwrt |= WR_OP;
00238 (*fu)->f77do_unf = do_ud;
00239 return (0);
00240 }
00241
00242 static int
00243 c_due (cilist64 *a, unit **fu)
00244 {
00245 unit *ftnunit;
00246 if (!f77init)
00247 f_init ();
00248
00249 ftnunit = *fu = map_luno (a->ciunit);
00250 while (fu != &f77curunit && test_and_set( &ftnunit->lock_unit, 1L ))
00251 ;
00252
00253
00254
00255
00256 if (ftnunit->uconn <= 0 && fk_open (DIR, UNF, a->ciunit)) {
00257 ftnunit->uconn = 0;
00258 err(a->cierr, 104, "due");
00259 }
00260 ftnunit->f77recpos = 0;
00261
00262 ftnunit->f77errlist.cierr = a->cierr;
00263 ftnunit->f77errlist.ciend = a->ciend;
00264 ftnunit->f77errlist.cieor = a->cieor;
00265 ftnunit->f77errlist.cisize = a->cisize;
00266 ftnunit->f77errlist.iciunit = 0;
00267
00268 ftnunit->ufd = ftnunit->ufd;
00269
00270 if (ftnunit->ufmt > 0)
00271 err(a->cierr, 102, "cdue");
00272 if (!ftnunit->useek)
00273 err(a->cierr, 104, "cdue");
00274 if (ftnunit->uconn <= 0)
00275 err(a->cierr, 114, "cdue");
00276 if (a->cirec < 1)
00277 err(a->cierr, 168, "dfe");
00278
00279
00280
00281
00282
00283 if (ftnunit->url != 1) {
00284 ftnunit->uirec = a->cirec;
00285 } else
00286 ftnunit->uirec = a->cirec - 1;
00287
00288 if (ftnunit->uassocv)
00289 set_var ((ftnintu *)ftnunit->uassocv, ftnunit->umask, ASSOCV, a->cirec);
00290 if (ftnunit->umaxrec && (a->cirec > ftnunit->umaxrec))
00291 err(a->cierr, 159, "cdue");
00292 ftnunit->uend = 0;
00293 return (0);
00294 }
00295
00296
00297 int
00298 e_rdue (void)
00299 {
00300 return( e_rdue_mp( &f77curunit ) );
00301 }
00302
00303
00304 int
00305 e_rdue_mp (unit **fu)
00306 {
00307 inc_var ((ftnintu *)(*fu)->uassocv, (*fu)->umask, ASSOCV);
00308 (*fu)->lock_unit = 0;
00309 return (0);
00310 }
00311
00312
00313 int
00314 e_wdue (void)
00315 {
00316 return( e_wdue_mp( &f77curunit ) );
00317 }
00318
00319
00320 int
00321 e_wdue_mp (unit **fu)
00322 {
00323 int n;
00324 unit *ftnunit = *fu;
00325
00326 if (ftnunit->uassocv)
00327 inc_var ((ftnintu *)ftnunit->uassocv, ftnunit->umask, ASSOCV);
00328
00329 if (ftnunit->url == 1 || ftnunit->f77recpos == ftnunit->url) {
00330 if (ftnunit->ushared)
00331 _fio_du_flush ((int) ftnunit->ufd);
00332 ftnunit->lock_unit = 0;
00333 return (0);
00334 }
00335 n = ftnunit->url - ftnunit->f77recpos;
00336 if (n > ftnunit->f77fio_size)
00337 check_buflen (ftnunit, n);
00338
00339 memset (ftnunit->f77fio_buf, 0, n);
00340 if (ftnunit->url != 1) {
00341 if (-1 == (_fio_du_write (ftnunit, ftnunit->f77fio_buf, n,
00342 ((ftnunit->uirec - 1) * ftnunit->url) + ftnunit->f77recpos,
00343 (int) ftnunit->ufd)))
00344 errret(ftnunit->f77errlist.cierr, errno, "system write error");
00345 } else {
00346 if (-1 == (_fio_du_write (ftnunit, ftnunit->f77fio_buf, n,
00347 ftnunit->uirec, (int) ftnunit->ufd)))
00348 errret(ftnunit->f77errlist.cierr, errno, "system write error");
00349 }
00350
00351 if (ftnunit->ushared)
00352 _fio_du_flush ((int) ftnunit->ufd);
00353
00354 ftnunit->lock_unit = 0;
00355 return (0);
00356 }
00357
00358 #if 11
00359 #pragma weak e_rdue64 = e_rdue
00360 #pragma weak e_rdue64_mp = e_rdue_mp
00361 #pragma weak e_wdue64 = e_wdue
00362 #pragma weak e_wdue64_mp = e_wdue_mp
00363 #endif
00364