~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/lib/libciomr/sequential.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* $Log: sequential.c,v $
 
3
/* Revision 1.3  2003/04/22 14:59:26  crinders
 
4
/* Corrected error in sequential.c with an incorrect fprintf on line 476 ud->unit and caller were switched.
 
5
/*
 
6
/* Revision 1.2  2002/04/19 21:48:06  sherrill
 
7
/* Remove some unused functions and do doxygen markup of libciomr.
 
8
/*
 
9
/* Revision 1.1.1.1  2000/02/04 22:53:23  evaleev
 
10
/* Started PSI 3 repository
 
11
/*
 
12
/* Revision 2.11  1997/09/14 03:28:55  sherrill
 
13
/* Added iosize_() to types.h so the function prototype could be passed to
 
14
/* flen.c, which was getting the wrong return type.  Also reformatted some
 
15
/* of my old code just a little to make it look a bit nicer.
 
16
/*
 
17
 * Revision 2.10  1997/09/12  13:53:04  crawdad
 
18
 * Changing marco name from ULL to PSI_FPTR.
 
19
 *
 
20
 * Revision 2.9  1997/08/25  21:50:08  crawdad
 
21
 * Making changes for extension of PSI file size limit.
 
22
 *
 
23
 * Revision 2.8  1997/06/23  12:26:00  crawdad
 
24
 * Multiple changes to libciomr: Moved "param.h" to "iomrparam.h" to avoid
 
25
 *     conflicts with similarly named system file under linux.  Corrected type
 
26
 *    casting in rread(), rwrit(), sread(), and swrit() functions.  Corrected
 
27
 *     unclosed tmpdisks.dat file in sequential.c.  Corrected block_matrix() to
 
28
 *    avoid malloc'ing zero-length arrays.
 
29
 *
 
30
 * -Daniel
 
31
 *
 
32
 * Revision 2.7  1996/07/02  21:06:30  sherrill
 
33
 * Completed the changes needed to use unit numbers greater than 99; changed
 
34
 * a hardwired 99 in init_ptrs.c to MAX_UNIT and increased a "unit" string
 
35
 * from 3 chars to 4.  Also removed a compiler warning in sequential.c by
 
36
 * casting ud to (char *) for malloc_check().
 
37
 *
 
38
 * Revision 2.6  1996/06/18  20:47:47  sherrill
 
39
 * Add the whole set of int_array routines to int_array.c (replacing
 
40
 * init_int_array.c), add block_matrix.c, and add a new function flen
 
41
 * which gets the file size for unit number x.
 
42
 *
 
43
 * Revision 2.5  1995/04/01  20:53:06  fermann
 
44
 * changed bytewise file pointers such as first, last and length to long
 
45
 * unsigned ints in order to handle up to 4 gigabyte tmp files (striped into
 
46
 * individual pieces of less than 2 gigabytes).  added functions li2sec and
 
47
 * sec2li for where they are needed.
 
48
 *
 
49
 * Revision 2.4  1994/06/02  02:28:02  seidl
 
50
 * use SITEDIR for location of tmpdisks.dat
 
51
 *
 
52
 * Revision 1.1  1994/05/02  23:11:21  cljanss
 
53
 * CCQC code as of May 1, 1994 that was missed in the initial cvs checkin.
 
54
 *
 
55
 * Revision 2.3  1993/09/08  20:00:59  psi
 
56
 * Add default disk striping
 
57
 *
 
58
 * Revision 2.2  1991/09/18  20:47:30  seidl
 
59
 * dec changes
 
60
 *
 
61
 * Revision 2.1  1991/06/15  18:30:03  seidl
 
62
 * *** empty log message ***
 
63
 * */
 
64
 
 
65
static char *rcsid = "$Id: sequential.c,v 1.3 2003/04/22 14:59:26 crinders Exp $";
 
66
 
 
67
 
 
68
#include <sys/file.h>
 
69
#include "includes.h"
 
70
#include "iomrparam.h"
 
71
#include "types.h"
 
72
#ifdef SUN
 
73
#include "unistd.h"
 
74
#endif
 
75
 
 
76
#if defined(SGI)
 
77
char* getenv(const char*);
 
78
#endif
 
79
 
 
80
#ifndef FILENAME_MAX
 
81
#define FILENAME_MAX 512
 
82
#endif
 
83
 
 
84
/* CDS 9/93 */
 
85
#define TMP_VOL_MAX 10          /* max number of tmp drives */
 
86
 
 
87
#define DEBUG 0
 
88
 
 
89
static char open_name[] = "sequential_ioopen";
 
90
 
 
91
sequential_t *
 
92
sequential_ioopen(baseparam,unit)
 
93
char *baseparam;
 
94
int unit;
 
95
{
 
96
  int i,oldinp;
 
97
  sequential_t *ud;
 
98
  char param[MAX_STRING];
 
99
  char volid[MAX_STRING];
 
100
  char name[MAX_STRING];
 
101
  char volpath[MAX_STRING];
 
102
  char path[MAX_STRING];
 
103
  char *mode;
 
104
  struct stat statjunk;
 
105
  char name_format[3];
 
106
  /* This file contains a list of files to be deleted
 
107
   * when we are using batch. */
 
108
  FILE *cleanfilep;
 
109
  /* If we are running in batch then this is set to the $(MBATCH)
 
110
   * environment variable to indicate the job_id. */
 
111
  int job_id;
 
112
  char *mbatchc;
 
113
  char cleanfile[FILENAME_MAX];
 
114
 
 
115
/* CDS 9/93 New variables for automatic tmp drive determination    */
 
116
  char endofvolpath[MAX_STRING] ; /* last part of volume path string */
 
117
  int got_first_volpath ;         /* flag for getting first volume path */
 
118
  int use_default_vols=0 ;        /* flag whether to use default tmp vols */
 
119
  int num_temp_vols;              /* number of tmp drives ava */
 
120
  int temp_vol[TMP_VOL_MAX] ;     /* vector of physical tmp drive numbers */
 
121
  int get_tempinfo() ;            /* func which reads temp drive datafile */
 
122
  int junk ;                      /* temp variable */
 
123
/* CDS 9/93 End of new variables */
 
124
 
 
125
 
 
126
  /* Look at the environment to see if this is a batch job. */
 
127
  if (!(mbatchc = getenv("MBATCH="))) {
 
128
    job_id = 0;
 
129
    }
 
130
  else {
 
131
    job_id = atoi(mbatchc);
 
132
    sprintf(cleanfile,"Batch_Clean.%05d",job_id);
 
133
    /* If the file has not yet been open, then open it and
 
134
     * tell it that we want it to delete itself. */
 
135
    if (stat(cleanfile,&statjunk)!=0) {
 
136
      cleanfilep = fopen(cleanfile,"a");
 
137
      if (!cleanfilep) {
 
138
        fprintf(stderr,"sequential I/O: couldn't open %s\n",cleanfile);
 
139
        }
 
140
      else {
 
141
        fseek(cleanfilep,(long)0,SEEK_END);
 
142
        fprintf(cleanfilep,"%s\n",cleanfile);
 
143
        fclose(cleanfilep);
 
144
        }
 
145
      }
 
146
    }
 
147
 
 
148
  strcpy(name_format,"%s");
 
149
 
 
150
  /* Allocate memory for the unit descriptor. */
 
151
  ud = (sequential_t *) malloc(sizeof(sequential_t));
 
152
  malloc_check(open_name,(char *) ud);
 
153
 
 
154
  /* Find out if we want extra information to be printed about this
 
155
   * unit.  name is used as a temporary buffer here. */
 
156
  strcpy(param,baseparam);
 
157
 
 
158
  oldinp = oldstyleinput();
 
159
  if(oldinp) {
 
160
    strcat(param,"verbose");
 
161
    if (get_param(param,"%s",name)== -1) ud->verbose = 0;
 
162
    else {
 
163
      if (!strcmp(name,"on")) ud->verbose = 1;
 
164
      else if (!strcmp(name,"yes")) ud->verbose = 1;
 
165
      else if (!strcmp(name,"y")) ud->verbose = 1;
 
166
      else ud->verbose = 0;
 
167
      }
 
168
    }
 
169
  else {
 
170
    strcat(param,"VERBOSE");
 
171
    if (get_file_info(param,"%s",name)== -1) ud->verbose = 0;
 
172
    else {
 
173
      if (!strcmp(name,"ON")) ud->verbose = 1;
 
174
      else if (!strcmp(name,"YES")) ud->verbose = 1;
 
175
      else if (!strcmp(name,"Y")) ud->verbose = 1;
 
176
      else if (!strcmp(name,"TRUE")) ud->verbose = 1;
 
177
      else if (!strcmp(name,"1")) ud->verbose = 1;
 
178
      else ud->verbose = 0;
 
179
      }
 
180
    }
 
181
 
 
182
  /* See if we want to keep this file when we are done. */
 
183
  /* Setting job_id = 0 causes the file to be kept. */
 
184
  strcpy(param,baseparam);
 
185
  if (oldinp) {
 
186
    strcat(param,"keep");
 
187
    if (!(get_param(param,"%s",name)== -1)) {
 
188
      if (!strcmp(name,"on")) job_id = 0;
 
189
      else if (!strcmp(name,"1")) job_id = 0;
 
190
      else if (!strcmp(name,"yes")) job_id = 0;
 
191
      else if (!strcmp(name,"y")) job_id = 0;
 
192
      }
 
193
    }
 
194
  else {
 
195
    strcat(param,"KEEP");
 
196
    if (!(get_file_info(param,"%s",name)== -1)) {
 
197
      if (!strcmp(name,"ON")) job_id = 0;
 
198
      else if (!strcmp(name,"1")) job_id = 0;
 
199
      else if (!strcmp(name,"YES")) job_id = 0;
 
200
      else if (!strcmp(name,"TRUE")) job_id = 0;
 
201
      else if (!strcmp(name,"Y")) job_id = 0;
 
202
      }
 
203
    }
 
204
 
 
205
  /* Find out how many volumes to place the unit across. */
 
206
  strcpy(param,baseparam);
 
207
  if(oldinp) {
 
208
    strcat(param,"n");
 
209
    if (get_param(param,"%d",&ud->n) == -1) {
 
210
       ud->n = 1;
 
211
       use_default_vols = 1 ;
 
212
       }
 
213
    }
 
214
  else {
 
215
    strcat(param,"NVOLUME");
 
216
    if (get_file_info(param,"%d",&ud->n) == -1) {
 
217
       ud->n = 1;
 
218
       use_default_vols = 1 ;
 
219
       }
 
220
    }
 
221
  if (ud->n == 0) { ud->n = 1; use_default_vols = 1; }
 
222
 
 
223
  /* Set up the block size for this file system. */
 
224
  strcpy(param,baseparam);
 
225
  if(oldinp) {
 
226
    strcat(param,"blocksize");
 
227
    if (get_param(param,"%d",&ud->blocksize) == -1) ud->blocksize = 8192;
 
228
    }
 
229
  else {
 
230
    strcat(param,"BLOCKSIZE");
 
231
    if (get_file_info(param,"%d",&ud->blocksize) == -1) ud->blocksize = 8192;
 
232
    }
 
233
  if (ud->blocksize == 0) ud->blocksize = 8192;
 
234
 
 
235
  /* Find out how the files are to be named. */
 
236
  if(oldinp) {
 
237
    if (get_param("FILES:name",name_format,name) == -1) 
 
238
      strcpy(name,"sequential");
 
239
    }
 
240
  else {
 
241
    strcpy(param,baseparam);
 
242
    strcat(param,"NAME");
 
243
    if (get_file_info(param,name_format,name) == -1)
 
244
      strcpy(name,"sequential");
 
245
    }
 
246
 
 
247
/* CDS 9/93 modified code begins here -- check how many temp drives ava */
 
248
  got_first_volpath = 1 ;
 
249
  if (oldinp) {
 
250
    sprintf(param,"%s%d",baseparam,1);
 
251
    if (get_param(param,"%s",volpath) == -1) got_first_volpath = 0 ;
 
252
    }
 
253
  else {
 
254
    sprintf(param,"%s%s%d",baseparam,"VOLUME",1);
 
255
    if (get_file_info(param,"%s",volpath) == -1) got_first_volpath = 0 ;
 
256
    }
 
257
 
 
258
  /* fprintf(stdout, "sequential_ioopen: Got volpath1 = %s\n",volpath); */
 
259
 
 
260
  if (got_first_volpath && use_default_vols) {
 
261
     if (strncmp("/tmp",volpath,4)==0) { /*ch defaults for tmp files only*/
 
262
        if (!get_tempinfo(&num_temp_vols, temp_vol) ) {
 
263
           /* if we couldn't read the datafile, abort */
 
264
           fprintf(stderr, "sequential_ioopen: can't read default tmp drive file\n") ;
 
265
           ioabort() ;
 
266
           }
 
267
        ud->n = num_temp_vols ;
 
268
        }
 
269
     }
 
270
/* CDS 9/93 Finished getting temp drive info and setting num of volumes */
 
271
 
 
272
  for (i=0; i<ud->n; i++) {
 
273
    if(oldinp) {
 
274
      sprintf(param,"%s%d",baseparam,i);
 
275
      if (get_param(param,"%s",volpath) == -1) {
 
276
        if (ud->n > 1) no_path_given(open_name);
 
277
        else volpath[0] = '\0';
 
278
        }
 
279
      }
 
280
    else {
 
281
      sprintf(param,"%s%s%d",baseparam,"VOLUME",i+1);
 
282
      if (get_file_info(param,"%s",volpath) == -1) {
 
283
        if (ud->n > 1) no_path_given(open_name);
 
284
        else volpath[0] = '\0';
 
285
        }
 
286
      }
 
287
 
 
288
/* CDS 9/93 Now check again if tmp file and use_default_vols  * 
 
289
 *          If so, fix vol number in pathnames                */
 
290
   if (use_default_vols && (strncmp("/tmp", volpath, 4)==0)) {
 
291
      sscanf(volpath, "/tmp%d%s", &junk, endofvolpath) ;
 
292
      sprintf(volpath, "/tmp%d%s", temp_vol[i], endofvolpath) ;
 
293
   /* fprintf(stdout,"sequential_ioopen:Volpath %d = %s\n",i,volpath); */
 
294
      }
 
295
/* CDS 9/93 Ok, that's all the changes except for the new function at end */
 
296
 
 
297
    sprintf(path,"%s%s%c%d",volpath,name,'.',unit);
 
298
    ud->v[i].path = (char *) malloc(strlen(path)+1);
 
299
    malloc_check(open_name,ud->v[i].path);
 
300
    strcpy(ud->v[i].path,path);
 
301
 
 
302
    /* Any file for with keep is given is kept, otherwise, any
 
303
     * file which has a /tmp as the first four characters in the
 
304
     * path is keep. */
 
305
    if (job_id&&(!strncmp("/tmp",path,4))) {
 
306
      cleanfilep = fopen(cleanfile,"a");
 
307
      if (!cleanfilep) {
 
308
        fprintf(stderr,"sequential I/O: couldn't open %s\n",cleanfile);
 
309
        }
 
310
      else {
 
311
        fseek(cleanfilep,(long)0,SEEK_END);
 
312
        fprintf(cleanfilep,"%s\n",path);
 
313
        fclose(cleanfilep);
 
314
        }
 
315
      }
 
316
 
 
317
#if BUFF
 
318
    if (stat(ud->v[i].path,&statjunk)==0) mode = "r+";
 
319
    else mode = "a+";
 
320
    ud->v[i].stream = fopen(ud->v[i].path,mode);
 
321
    fopen_check(open_name,ud->v[i].path,ud->v[i].stream);
 
322
#else
 
323
    ud->v[i].stream = open(ud->v[i].path,O_RDWR|O_CREAT,0644);
 
324
/*    fprintf(stderr, "Stream = %d\n",ud->v[i].stream); */
 
325
#endif
 
326
    }
 
327
  ud->next = 0;
 
328
  ud->unit = unit;
 
329
  ud->incount = 0;
 
330
  ud->outcount = 0;
 
331
  ud->previous_size = 0;
 
332
  ud->last_ioop = 0;
 
333
 
 
334
  if (ud->verbose) {
 
335
    fprintf(stderr,"SEQ_IO: opened unit %d {\n",unit);
 
336
    fprintf(stderr,"  blocksize = %d\n",ud->blocksize);
 
337
    for (i=0; i<ud->n; i++) {
 
338
      fprintf(stderr,"  v[%d].path = \"%s\"\n",i,ud->v[i].path);
 
339
      }
 
340
    fprintf(stderr,"  }\n");
 
341
    }
 
342
  return(ud);
 
343
  }
 
344
 
 
345
void
 
346
sequential_ioclos(ud,status)
 
347
sequential_t *ud;
 
348
int status;
 
349
{
 
350
  int i;
 
351
 
 
352
  for (i=0; i<ud->n; i++) {
 
353
#if BUFF
 
354
    fclose(ud->v[i].stream);
 
355
#else
 
356
    close(ud->v[i].stream);
 
357
#endif
 
358
    if (status == 4) unlink(ud->v[i].path);
 
359
    free(ud->v[i].path);
 
360
    ud->v[i].path = NULL;
 
361
    }
 
362
  if (ud->verbose) {
 
363
    fprintf(stderr,"SEQ_IO: closed unit %d {\n",ud->unit);
 
364
    fprintf(stderr,"  incount = %lu\n",ud->incount);
 
365
    fprintf(stderr,"  outcount = %lu\n",ud->outcount);
 
366
    fprintf(stderr,"  }\n");
 
367
    }
 
368
  }
 
369
 
 
370
void
 
371
sequential_iordr(ud,buffer,first,length)
 
372
sequential_t *ud;
 
373
char *buffer;
 
374
int length;
 
375
PSI_FPTR first;
 
376
{
 
377
  ud->incount += length;
 
378
  sequential_iordwrr("sequential_iordr",IOOP_READ,ud,buffer,first,length);
 
379
  }
 
380
 
 
381
void
 
382
sequential_iowrr(ud,buffer,first,length)
 
383
sequential_t *ud;
 
384
char *buffer;
 
385
int length;
 
386
PSI_FPTR first;
 
387
{
 
388
  ud->outcount += length;
 
389
  sequential_iordwrr("sequential_iowrr",IOOP_WRITE,ud,buffer,first,length);
 
390
  }
 
391
 
 
392
void
 
393
sequential_iordwrr(caller,ioop,ud,buffer,first,length)
 
394
char *caller;
 
395
int ioop;
 
396
sequential_t *ud;
 
397
char *buffer;
 
398
int length;
 
399
PSI_FPTR first;
 
400
{
 
401
  PSI_FPTR i;
 
402
  PSI_FPTR firstbyte, lastbyte;
 
403
  PSI_FPTR firstblock, lastblock;
 
404
  PSI_FPTR offset;
 
405
  PSI_FPTR ncycles;
 
406
  PSI_FPTR remainingbytes;
 
407
  PSI_FPTR remainingseek;
 
408
  PSI_FPTR fullvol;
 
409
  PSI_FPTR offset1, offset2;
 
410
  PSI_FPTR ibuf;
 
411
  PSI_FPTR len;
 
412
 
 
413
  firstbyte = first;
 
414
  lastbyte = first + length - 1;
 
415
 
 
416
  ncycles = firstbyte/(ud->n*ud->blocksize);
 
417
  remainingseek = firstbyte - 
 
418
        ncycles*((PSI_FPTR) ud->n)*((PSI_FPTR) ud->blocksize);
 
419
 
 
420
/*  fprintf(stderr, "ncycles = %lu firstbyte = %lu remainingseek = %lu\n",
 
421
          ncycles,firstbyte,remainingseek); */
 
422
  fullvol = remainingseek/ud->blocksize;
 
423
 
 
424
  offset2 = ncycles * ud->blocksize;
 
425
  offset1 = offset2 + ud->blocksize;
 
426
 
 
427
  /* Seek all volumes to the appropiate positions. */
 
428
  if ((ud->next != firstbyte)||(ud->last_ioop != ioop)) {
 
429
    for (i=0; i<ud->n; i++) {
 
430
/*      long offset; */
 
431
      if (i < fullvol) offset = offset1;
 
432
      else if (i == fullvol) offset = offset2 + remainingseek%ud->blocksize;
 
433
      else offset = offset2;
 
434
#if DEBUG
 
435
      fprintf(stdout,"seeking volume %d to %ld\n",i,offset);
 
436
#endif
 
437
#if BUFF
 
438
      if (fseek(ud->v[i].stream, offset, SEEK_SET)) {
 
439
        fprintf(stderr,"%s: fseek: offset = %ld, vol = %d\n",caller,offset,i);
 
440
        perror(caller);
 
441
        ioabort();
 
442
        }
 
443
#else
 
444
      if (lseek(ud->v[i].stream, offset, SEEK_SET)<0) {
 
445
        fprintf(stderr,"%s: fseek: offset = %ld, vol = %d\n",caller,offset,i);
 
446
        perror(caller);
 
447
        ioabort();
 
448
        }
 
449
#endif
 
450
      }
 
451
    if (length > 0) ud->last_ioop = ioop;
 
452
    }
 
453
  ud->next = lastbyte + 1;
 
454
 
 
455
  /* Do the io. */
 
456
  i = fullvol;
 
457
  len = ud->blocksize - remainingseek%ud->blocksize;
 
458
  remainingbytes = lastbyte - firstbyte + 1;
 
459
#if DEBUG
 
460
  fprintf(stdout,"%s: len=%ld,remainingbytes=%ld,firstbyte=%ld,lastbyte=%ld,i=%ld\n",
 
461
          caller,len,remainingbytes,firstbyte,lastbyte,i);
 
462
#endif
 
463
  ibuf = 0;
 
464
  while (remainingbytes > 0) {
 
465
    if (len > remainingbytes) len = remainingbytes;
 
466
#if DEBUG
 
467
    fprintf(stdout,"       len=%ld,remainingbytes=%ld,i=%ld\n",
 
468
          len,remainingbytes,i);
 
469
#endif
 
470
    if (ioop == IOOP_READ) {
 
471
#if BUFF
 
472
      if (fread(&buffer[ibuf],len,1,ud->v[i].stream)!=1) {
 
473
        fprintf(stderr,"%s: len = %ld, volume = %ld\n",caller,len,i);
 
474
        if (ferror(ud->v[i].stream)) fread_error(caller);
 
475
        }
 
476
#else
 
477
      if (read(ud->v[i].stream,&buffer[ibuf],len)<1) {
 
478
        fprintf(stderr,"%s: unit = %ld, len = %ld, volume = %ld\n",
 
479
                caller, ud->unit,len,i);
 
480
        fread_error(caller);
 
481
        }
 
482
#endif
 
483
      }
 
484
    else if (ioop == IOOP_WRITE) {
 
485
#if BUFF
 
486
      if (fwrite(&buffer[ibuf],len,1,ud->v[i].stream)!=1) {
 
487
        fprintf(stderr,"%s: len = %ld, volume = %ld\n",caller,len,i);
 
488
        if (ferror(ud->v[i].stream)) fwrite_error(caller);
 
489
        }
 
490
#else
 
491
      if ((write(ud->v[i].stream,&buffer[ibuf],len))!=len) {
 
492
        fprintf(stderr,"%s: len = %ld, volume = %ld\n",caller,len,i);
 
493
        fwrite_error(caller);
 
494
        }
 
495
#endif
 
496
      }
 
497
    else {
 
498
      fprintf(stderr,"%s: illegal ioop = %d\n",caller,ioop);
 
499
      ioabort();
 
500
      }
 
501
    i++;
 
502
    if (i == ud->n) i=0;
 
503
    remainingbytes -= len;
 
504
    ibuf += len;
 
505
    len = ud->blocksize;
 
506
    }
 
507
  }
 
508
 
 
509
 
 
510
/*
 
511
** SEQUENTIAL_IOSIZE
 
512
** This function determines the file size (bytes) for a given unit
 
513
** David Sherrill, June 1996
 
514
*/
 
515
PSI_FPTR sequential_iosize(ud)
 
516
sequential_t *ud;
 
517
{
 
518
   int i, errcod;
 
519
   struct stat fstat;
 
520
   PSI_FPTR fsize=0;
 
521
 
 
522
   for (i=0; i<ud->n; i++) {
 
523
      errcod = stat(ud->v[i].path, &fstat);
 
524
      if (errcod == -1) {
 
525
         fprintf(stderr,"sequential_iosize: can't access %s\n",
 
526
            ud->v[i].path);
 
527
         ioabort();
 
528
         }
 
529
      fsize += fstat.st_size;
 
530
      }
 
531
 
 
532
   return(fsize);
 
533
}
 
534
   
 
535
 
 
536
 
 
537
 
 
538
/*
 
539
** CDS 9/93
 
540
** GET_TEMPINFO : David Sherrill, April 1993
 
541
**
 
542
** This function will allow PSI to figure out how many temp drives
 
543
** to use for sequential io.  The data will be contained in a
 
544
** host table file listing each host, the number of temp drives
 
545
** it has, and the number labels for each of these drives
 
546
**
 
547
** Arguments: 
 
548
**    num_temp_vols = ptr to number of temp vols to use
 
549
**    temp_vol      = array of physical temp disks to use 
 
550
**                      (i.e. {1 2} to use /tmp1 and /tmp2)
 
551
**  
 
552
** Returns: 1 for success, 0 otherwise
 
553
*/
 
554
 
 
555
#define HOSTNAME_MAX 26
 
556
 
 
557
int
 
558
get_tempinfo(num_temp_vols, temp_vol)
 
559
      int *num_temp_vols, *temp_vol ;
 
560
{
 
561
   FILE *fpi ;                        /* for reading in the host table data */
 
562
   char hostname[HOSTNAME_MAX] ;      /* name of machine we're running on */
 
563
   char *hostfile;                    /* filename containing tmp disk info */
 
564
   char line[MAX_STRING] ;            /* hold line from hostfile */
 
565
   int found = 0 ;                    /* is host found in data file ? */
 
566
   char *sptr ;                       /* keep place in input string */
 
567
   int i, data_in ;
 
568
 
 
569
   hostfile = SITEDIR "/tmpdisks.dat" ;
 
570
 
 
571
   /* open data file on hosts' temp disks */
 
572
   fpi = fopen(hostfile, "r");
 
573
 
 
574
   /* open datafile on hosts' temp disks */
 
575
   if (fpi == NULL) {
 
576
      fprintf(stderr, "get_tempinfo: couldn't open %s\n", hostfile);
 
577
      fclose(fpi);
 
578
      return(0) ;
 
579
      }
 
580
 
 
581
   /* get hostname */
 
582
   if (gethostname(hostname,HOSTNAME_MAX) == -1) {
 
583
      fprintf(stderr, "get_tempinfo: trouble getting hostname\n") ;
 
584
      fclose(fpi);
 
585
      return(0) ;
 
586
      }
 
587
 
 
588
   /* fprintf(stdout, "get_tempinfo: got hostname = %s\n", hostname) ; */
 
589
 
 
590
   /* scan for that hostname in the datafile, get the info */
 
591
   while (io_getline(fpi, line) != -1) {
 
592
      if (strstr(line, hostname)) { found = 1 ; break ; }
 
593
      }
 
594
   if (!found) {
 
595
      fprintf(stdout, "get_tempinfo: no host %s in datafile\n", hostname) ;
 
596
      fclose(fpi);
 
597
      return(0) ;
 
598
      }
 
599
 
 
600
   else { /* get the info */
 
601
      if ( (sptr = strchr(line, '=')) == NULL) {
 
602
         fprintf(stderr, "get_tempinfo: %s has bad format\n", hostfile) ;
 
603
         fclose(fpi);
 
604
         return(0) ;
 
605
         }
 
606
      sptr++ ;
 
607
      while ( (*sptr == ' ') && (*sptr != '\0') ) sptr++ ;
 
608
 
 
609
      if (sscanf(sptr, "%d", num_temp_vols) != 1) {
 
610
         fprintf(stderr, "get_tempinfo: %s has bad format\n", hostfile) ;
 
611
         fclose(fpi);
 
612
         return(0) ;
 
613
         }
 
614
 
 
615
      if (*num_temp_vols > TMP_VOL_MAX) {
 
616
         fprintf(stderr, "get_tempinfo: %d exceeds %d maximum vols\n",
 
617
            *num_temp_vols, TMP_VOL_MAX) ;
 
618
         *num_temp_vols = TMP_VOL_MAX ;
 
619
         }
 
620
 
 
621
      for (i=0; i<(*num_temp_vols); i++) {
 
622
         while ( (*sptr != ' ') && (*sptr != '\0') ) sptr++ ;
 
623
         while ( (*sptr == ' ') && (*sptr != '\0') ) sptr++ ;
 
624
         if (*sptr == '\0') {
 
625
            fprintf(stderr, "get_tempinfo: %s bad format\n", hostfile) ;
 
626
            fclose(fpi);
 
627
            return(0) ;
 
628
            }
 
629
         if (sscanf(sptr, "%d", &data_in) != 1) {
 
630
            fprintf(stderr, "get_tempinfo: %s has bad format\n", hostfile) ;
 
631
            fclose(fpi);
 
632
            return(0) ;
 
633
            }
 
634
         else temp_vol[i] = data_in ;
 
635
         }
 
636
 
 
637
   /* 
 
638
   fprintf(stdout, "get_tempinfo: got %d vols : ", *num_temp_vols) ;
 
639
   for (i=0; i<(*num_temp_vols); i++) {
 
640
      fprintf(stdout, "%d ", temp_vol[i]) ;
 
641
      }
 
642
   fprintf(stdout, "\n") ;
 
643
   */
 
644
 
 
645
      fclose(fpi);
 
646
      return(1) ;
 
647
      }
 
648
}
 
649