File: fstat64.c

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (167 lines) | stat: -rw-r--r-- 5,523 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * $Id: fstat64.c,v 1.1 2005/03/31 13:13:00 baud Exp $
 */

/*
 * Copyright (C) 1990-2003 by CERN/IT/PDP/DM
 * All rights reserved
 */

#ifndef lint
static char sccsid[] = "@(#)$RCSfile: fstat64.c,v $ $Revision: 1.1 $ $Date: 2005/03/31 13:13:00 $ CERN/IT/PDP/DM F. Hemmer, A. Trannoy, P. Gaillardon";
#endif /* not lint */

/* fstat64.c      Remote File I/O - get file status                       */

/*
 * System remote file I/O definitions
 */
#define RFIO_KERNEL     1   
#include "rfio.h"          
#include "rfio_rfilefdt.h"

#include <stdlib.h>            /* malloc prototype */

/*
 * Remote file stat
 */
int DLL_DECL rfio_fstat64(s, statbuf)  
int            s;
struct stat64  *statbuf;
{
   int status ;
   char   * p ;
   char * trp ;
   int temp=0 ;
   char     rfio_buf[BUFSIZ];
   int s_index = -1;

   INIT_TRACE("RFIO_TRACE");
   TRACE(1, "rfio", "rfio_fstat64(%d, %x)", s, statbuf);
   /* 
    * The file is local
    */
   if ((s_index = rfio_rfilefdt_findentry(s,FINDRFILE_WITHOUT_SCAN)) == -1) {
      TRACE(2, "rfio", "rfio_fstat64: using local fstat(%d, %x)", s, statbuf);
      status = fstat64(s, statbuf);
      if ( status < 0 ) serrno = 0;
      rfio_errno = 0;
      END_TRACE();
      return(status);
   }
   /*
    * Checking magic number.
    */
   if (rfilefdt[s_index]->magic != RFIO_MAGIC) {
      serrno = SEBADVERSION ; 
      rfio_rfilefdt_freeentry(s_index);
      (void) close(s) ;
      END_TRACE();
      return(-1);
   }
   /*
    * Sending request.
    */
   p= rfio_buf ;
   marshall_WORD(p, RFIO_MAGIC);
   marshall_WORD(p, RQST_FSTAT64);
   TRACE(2,"rfio","rfio_fstat64: sending %d bytes", RQSTSIZE, rfilefdt[s_index]->lseekhow);
   if (netwrite_timeout(s,rfio_buf,RQSTSIZE,RFIO_CTRL_TIMEOUT) != RQSTSIZE) {
      TRACE(2, "rfio", "rfio_fstat64: write(): ERROR occured (errno=%d)", errno);
      END_TRACE();
      return(-1);
   }
   /*
    * Getting data from the network.
    */
   for(;;) {
      WORD    req ; 
      LONG  rcode ;
      LONG msgsiz ;
      int       n ;

      TRACE(2, "rfio", "rfio_fstat64: reading %d bytes",rfilefdt[s_index]->_iobuf.hsize) ;
      n = netread_timeout(s,rfio_buf,rfilefdt[s_index]->_iobuf.hsize,RFIO_DATA_TIMEOUT); 
      if (n != rfilefdt[s_index]->_iobuf.hsize) {
         TRACE(2, "rfio", "rfio_fstat64: read(): ERROR occured (errno=%d)", errno);
         if ( temp ) (void) free(trp) ;
         END_TRACE() ;
         return -1 ; 
      }
      p = rfio_buf ;
      unmarshall_WORD(p,req) ;
      unmarshall_LONG(p,status) ; 
      unmarshall_LONG(p, rcode) ; 
      unmarshall_LONG(p,msgsiz) ;
      switch(req) {
         case RQST_FSTAT64:
            TRACE(2, "rfio", "rfio_fstat64: reading %d bytes",msgsiz);
            if (netread_timeout(s,rfio_buf,msgsiz,RFIO_DATA_TIMEOUT) != msgsiz ) {
               TRACE(2,"rfio","rfio_fstat64: read(): ERROR occured (errno=%d)",errno) ;
               if ( temp ) (void) free(trp) ;
               END_TRACE() ;
               return -1 ; 
            }
            p = rfio_buf ;
            unmarshall_WORD(p,statbuf->st_dev);
            unmarshall_HYPER(p,statbuf->st_ino);
            unmarshall_WORD(p,statbuf->st_mode);
            unmarshall_WORD(p,statbuf->st_nlink);
            unmarshall_WORD(p,statbuf->st_uid);
            unmarshall_WORD(p,statbuf->st_gid);
            unmarshall_HYPER(p,statbuf->st_size);
            unmarshall_LONG(p,statbuf->st_atime);
            unmarshall_LONG(p,statbuf->st_mtime);
            unmarshall_LONG(p,statbuf->st_ctime);
#if !defined(_WIN32)
            if ( msgsiz > (5*WORDSIZE+3*LONGSIZE+2*HYPERSIZE) ) {
               unmarshall_LONG(p, statbuf->st_blksize);
               unmarshall_HYPER(p, statbuf->st_blocks);
            } else {
               statbuf->st_blksize = 0;
               statbuf->st_blocks  = 0;
            }
#endif
            rfio_errno= rcode ;
            if ( temp ) (void) free(trp) ;
            TRACE(1,"rfio","rfio_fstat64: return status %d, rcode %d", status, rcode) ;
            END_TRACE() ;
            return status ;
         case RQST_READAHEAD:
         case RQST_READAHD64:
         case RQST_LASTSEEK:
         case RQST_PRESEEK:
         case RQST_PRESEEK64:
            /* 
             * At this point a temporary buffer may need to be created
             * to receive data which is going to be thrown away.
             */
            if ( temp == 0 ) {
               if ( rfilefdt[s_index]->_iobuf.base==NULL || rfilefdt[s_index]->_iobuf.dsize<msgsiz ) {
                  temp= 1 ; 
                  TRACE(3,"rfio","rfio_fstat: allocating momentary buffer of size %d",msgsiz) ; 
                  if ( (trp= ( char *) malloc(msgsiz)) == NULL ) {
                     TRACE(3,"rfio","rfio_fstat: malloc(): ERROR occured (errno=%d)",errno) ; 
                     END_TRACE() ; 
                     return -1 ;
                  }
               }
               else
                  trp= iodata(rfilefdt[s_index]) ;
            }
            if ( netread_timeout(s,trp,msgsiz,RFIO_DATA_TIMEOUT) != msgsiz ) {
               TRACE(2,"rfio","rfio_fstat: read(): ERROR occured (errno=%d)",errno) ;
               if ( temp ) (void) free(trp) ; 
               END_TRACE() ; 
               return -1 ;
            }
            break ; 
         default:
            TRACE(1,"rfio","rfio_fstat64(): Bad control word received\n") ; 
            serrno= SEINTERNAL ;
            if ( temp ) (void) free(trp) ;
            END_TRACE() ;
            return -1 ;
      }
   }
}