File: lockf.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 (99 lines) | stat: -rw-r--r-- 2,764 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
/*
 * $Id: lockf.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: lockf.c,v $ $Revision: 1.1 $ $Date: 2005/03/31 13:13:00 $ CERN/IT/PDP/DM Antony Simmins";
#endif /* not lint */

/* lockf.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"


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


   INIT_TRACE("RFIO_TRACE");
   TRACE(1, "rfio", "rfio_lockf(%d, %d, %ld)", sd, op, siz);

   /* 
    * The file is local
    */
   if ((s_index=rfio_rfilefdt_findentry(sd, FINDRFILE_WITHOUT_SCAN)) == -1) {
      TRACE(1, "rfio", "rfio_lockf: using local lockf(%d, %d, %ld)",
	    sd, op, siz);
      END_TRACE();
      rfio_errno = 0;
      status = lockf(sd,op,siz);
      if ( status < 0 ) serrno = 0;
      return(status);
   }
   
   /*
    * Checking mode 64.
    */
   if (rfilefdt[s_index]->mode64) {
      off64_t siz64;
      
      siz64 = siz;
      status = rfio_lockf64(sd, op, siz64);
      END_TRACE();
      return(status);
   }

   len = 2*LONGSIZE;
   marshall_WORD(p, RFIO_MAGIC);
   marshall_WORD(p, RQST_LOCKF);
   marshall_WORD(p, geteuid());
   marshall_WORD(p, getegid());
   marshall_LONG(p, len);
   p= buf + RQSTSIZE;
   marshall_LONG(p, op);
   marshall_LONG(p, siz);
   TRACE(1,"rfio","rfio_lockf: op %d, siz %ld", op, siz);
   TRACE(2,"rfio","rfio_lockf: sending %d bytes",RQSTSIZE+len) ;
   if (netwrite_timeout(sd,buf,RQSTSIZE+len,RFIO_CTRL_TIMEOUT) != (RQSTSIZE+len)) {
      TRACE(2, "rfio", "rfio_lockf: write(): ERROR occurred (errno=%d)", errno);
      (void) close(sd);
      END_TRACE();
      return(-1);
   }
   p = buf;
   TRACE(2, "rfio", "rfio_lockf: reading %d bytes", 2*LONGSIZE);
   if (netread_timeout(sd, buf, 2*LONGSIZE, RFIO_CTRL_TIMEOUT) != (2*LONGSIZE))  {
      TRACE(2, "rfio", "rfio_lockf: 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_lockf: return %d",status);
   rfio_errno = rcode;
   if (status)     {
      END_TRACE();
      return(-1);
   }
   END_TRACE();
   return (0);
}