File: lockf64.c

package info (click to toggle)
lfc-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,676 kB
  • ctags: 10,779
  • sloc: ansic: 146,136; sh: 13,176; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 861; fortran: 113
file content (123 lines) | stat: -rw-r--r-- 3,862 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
/*
 * $Id: lockf64.c,v 1.1 2005/03/31 13:13:00 baud Exp $
 */

/*
 * Copyright (C) 1994-2002 by CERN/IT/PDP/DM
 * All rights reserved
 */

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

/* lockf64.c       Remote File I/O - record locking on files      */

#define RFIO_KERNEL     1     /* KERNEL part of the routines          */

#include "rfio.h"             /* Remote File I/O general definitions  */
#include "rfio_rfilefdt.h"
#include "u64subr.h"


int DLL_DECL rfio_lockf64(sd, op, siz)    /* Remote lockf             */
int      sd;                              /* file descriptor          */
int      op;                              /* lock operation           */
off64_t  siz;                             /* locked region            */
{
   static char    buf[256];       /* General input/output buffer      */
   int            status;         /* remote lockf() status            */
   int      len;
   int      replen;
   char     *p=buf;
   int      rt ;
   int      rcode ;
   int      s_index;
   char     tmpbuf[21];

   INIT_TRACE("RFIO_TRACE");
   TRACE(1, "rfio", "rfio_lockf64(%d, %d, %s)", sd, op, i64tostr(siz,tmpbuf,0));

   /* 
    * The file is local
    */
   if ((s_index = rfio_rfilefdt_findentry(sd,FINDRFILE_WITHOUT_SCAN)) == -1) {
      TRACE(1, "rfio", "rfio_lockf64: using local lockf64(%d, %d, %s)",
         sd, op, i64tostr(siz,tmpbuf,0));
      END_TRACE();
      rfio_errno = 0;
      status = lockf64(sd,op,siz);
      if ( status < 0 ) serrno = 0;
      return(status);
   }
   
   /*
    * Reject call if bufferized or streamed mode
    */
   if ( rfilefdt[s_index]->_iobuf.base != NULL || rfilefdt[s_index]->version3 ) {
      TRACE(1, "rfio","rfio_lockf64: lockf rejected in bufferized or streamed mode");
      END_TRACE();
      errno = EBADF;
      return(-1);
   } 

   /*
    * Repositionning file mark if needed.
    */
   if (  (rfilefdt[s_index]->lseekhow == -1)
      && ( rfilefdt[s_index]->readissued || rfilefdt[s_index]->preseek ) ) {
      rfilefdt[s_index]->lseekhow= SEEK_SET ;
      rfilefdt[s_index]->lseekoff64= rfilefdt[s_index]->offset64 ;
   }
   /*
    * Resetting flags
    */
   rfilefdt[s_index]->eof= 0 ; 
   rfilefdt[s_index]->preseek= 0 ;
   rfilefdt[s_index]->nbrecord= 0 ;
   rfilefdt[s_index]->readissued= 0 ; 
   if ( rfilefdt[s_index]->_iobuf.base ) {
      rfilefdt[s_index]->_iobuf.count= 0 ; 
      rfilefdt[s_index]->_iobuf.ptr= iodata(rfilefdt[s_index]) ; 
   }
   /*
    * Sending request.
    */
   
   len = 1*LONGSIZE+ 2*HYPERSIZE;
   marshall_WORD(p, RFIO_MAGIC);
   marshall_WORD(p, RQST_LOCKF64);
   marshall_LONG(p, rfilefdt[s_index]->lseekhow) ; 
   marshall_LONG(p, len);
   p= buf + RQSTSIZE;
   marshall_LONG(p, op);
   marshall_HYPER(p, siz);
   marshall_HYPER(p, rfilefdt[s_index]->lseekoff64) ; 
   TRACE(1,"rfio","rfio_lockf64: op %d, siz %s", op, i64tostr(siz,tmpbuf,0));
   TRACE(2,"rfio","rfio_lockf64: sending %d bytes",RQSTSIZE+len) ;
   if (netwrite_timeout(sd, buf, RQSTSIZE+len, RFIO_CTRL_TIMEOUT) != (RQSTSIZE+len)) {
      TRACE(2, "rfio", "rfio_lockf64: write(): ERROR occurred (errno=%d)", errno);
      (void) close(sd);
      END_TRACE();
      return(-1);
   }
   p = buf;
   replen = 2*LONGSIZE;
   TRACE(2, "rfio", "rfio_lockf64: reading %d bytes", replen);
   if (netread_timeout(sd, buf, replen, RFIO_DATA_TIMEOUT) != replen)  {
      TRACE(2, "rfio", "rfio_lockf64: read(): ERROR occurred (errno=%d)", errno);
      (void) close(sd);
      END_TRACE();
      return(-1);
   }
   unmarshall_LONG(p, status);
   unmarshall_LONG(p, rcode);
   TRACE(1, "rfio", "rfio_lockf64: return %d",status);
   rfio_errno = rcode;
   if (status)     {
      END_TRACE();
      return(-1);
   }
   END_TRACE();
   return (0);
}