xrootd
XrdXrootdFile.hh
Go to the documentation of this file.
1 #ifndef _XROOTD_FILE_H_
2 #define _XROOTD_FILE_H_
3 /******************************************************************************/
4 /* */
5 /* X r d X r o o t d F i l e . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <string.h>
33 
34 #include "XProtocol/XPtypes.hh"
36 
37 /******************************************************************************/
38 /* X r d X r o o t d F i l e */
39 /******************************************************************************/
40 
41 class XrdSfsFile;
42 class XrdXrootdFileLock;
43 class XrdXrootdMonitor;
44 
46 {
47 public:
48 
49 XrdSfsFile *XrdSfsp; // -> Actual file object
50 char *mmAddr; // Memory mapped location, if any
51 char FileKey[34]; // -> Unique hash name for the file
52 char Reserved[2];
53 char FileMode; // 'r' or 'w'
54 char AsyncMode; // 1 -> if file in async r/w mode
55 char isMMapped; // 1 -> file is memory mapped
56 char sfEnabled; // 1 -> file is sendfile enabled
57 int fdNum; // File descriptor number if regular file
58 const char *ID; // File user
59 
60 XrdXrootdFileStats Stats; // File access statistics
61 
62 static void Init(XrdXrootdFileLock *lp, int sfok) {Locker = lp; sfOK = sfok;}
63 
64  XrdXrootdFile(const char *id, XrdSfsFile *fp, char mode='r',
65  char async='\0', int sfOK=0, struct stat *sP=0);
67 
68 private:
69 int bin2hex(char *outbuff, char *inbuff, int inlen);
71 static int sfOK;
72 static const char *TraceID;
73 };
74 
75 /******************************************************************************/
76 /* X r d X r o o t d F i l e T a b l e */
77 /******************************************************************************/
78 
79 // The before define the structure of the file table. We will have FTABSIZE
80 // internal table entries. We will then provide an external linear table
81 // that increases by FTABSIZE entries. There is one file table per link and
82 // it is owned by the base protocol object.
83 //
84 #define XRD_FTABSIZE 16
85 
86 // WARNING! Manipulation (i.e., Add/Del/delete) of this object must be
87 // externally serialized at the link level. Only one thread
88 // may be active w.r.t this object during manipulation!
89 //
91 {
92 public:
93 
94  int Add(XrdXrootdFile *fp);
95 
96  void Del(int fnum);
97 
98 inline XrdXrootdFile *Get(int fnum)
99  {if (fnum >= 0)
100  {if (fnum < XRD_FTABSIZE) return FTab[fnum];
101  if (XTab && (fnum-XRD_FTABSIZE)<XTnum)
102  return XTab[fnum-XRD_FTABSIZE];
103  }
104  return (XrdXrootdFile *)0;
105  }
106 
107  void Recycle(XrdXrootdMonitor *monP=0, bool monF=false);
108 
109  XrdXrootdFileTable(unsigned int mid=0) : FTfree(0), monID(mid),
110  XTab(0), XTnum(0), XTfree(0)
111  {memset((void *)FTab, 0, sizeof(FTab));}
112 
113 private:
114 
115  ~XrdXrootdFileTable() {} // Always use Recycle() to delete this object!
116 
117 static const char *TraceID;
118 
120 int FTfree;
121 unsigned int monID;
122 
124 int XTnum;
125 int XTfree;
126 };
127 #endif