xrootd
XrdFrcXAttr.hh
Go to the documentation of this file.
1 #ifndef __XRDFRCXATTR_HH__
2 #define __XRDFRCXATTR_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d F r c X A t t r . h h */
6 /* */
7 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <sys/types.h>
34 #include <inttypes.h>
35 #include <netinet/in.h>
36 #include <sys/types.h>
37 
38 #include "XrdSys/XrdSysPlatform.hh"
39 
40 /* XrdFrcXAttr encapsulates the extended attributes needed to determine
41  file residency. It is used by the FRM in migrate and purge processing as well
42  as for the OSS to determine file residency in memory. It is self-contained
43  to prevent circular dependencies.
44 */
45 
46 /******************************************************************************/
47 /* X r d F r c X A t t r C p y */
48 /******************************************************************************/
49 
51 {
52 public:
53 
54 long long cpyTime; // Last time file was copied
55 char Rsvd[16]; // Reserved fields
56 
57 /* postGet() will put cpyTime in host byte order (see preSet()).
58 */
59  int postGet(int Result)
60  {if (Result > 0) cpyTime = ntohll(cpyTime);
61  return Result;
62  }
63 
64 /* preSet() will put cpyTime in network byte order to allow the attribute to
65  to be copied to different architectures and still work.
66 */
68  {tmp.cpyTime = htonll(cpyTime); return &tmp;}
69 
70 /* Name() returns the extended attribute name for this object.
71 */
72 static const char *Name() {return "XrdFrm.Cpy";}
73 
74 /* sizeGet() and sizeSet() return the actual size of the object is used.
75 */
76 static int sizeGet() {return sizeof(XrdFrcXAttrCpy);}
77 static int sizeSet() {return sizeof(XrdFrcXAttrCpy);}
78 
79  XrdFrcXAttrCpy() : cpyTime(0) {memset(Rsvd, 0, sizeof(Rsvd));}
81 };
82 
83 /******************************************************************************/
84 /* X r d F r c X A t t r M e m */
85 /******************************************************************************/
86 
88 {
89 public:
90 
91 char Flags; // See definitions below
92 char Rsvd[7]; // Reserved fields
93 
94 // The following flags are defined for Flags
95 //
96 static const char memMap = 0x01; // Mmap the file
97 static const char memKeep = 0x02; // Mmap the file and keep mapping
98 static const char memLock = 0x04; // Mmap the file and lock it in memory
99 
100 /* postGet() and preSet() are minimal as no chages are needed
101 */
102 static int postGet(int Result) {return Result;}
103  XrdFrcXAttrMem *preSet(XrdFrcXAttrMem &tmp) {return this;}
104 
105 /* Name() returns the extended attribute name for this object.
106 */
107 static const char *Name() {return "XrdFrm.Mem";}
108 
109 /* sizeGet() and sizeSet() return the actual size of the object is used.
110 */
111 static int sizeGet() {return sizeof(XrdFrcXAttrMem);}
112 static int sizeSet() {return sizeof(XrdFrcXAttrMem);}
113 
114  XrdFrcXAttrMem() : Flags(0) {memset(Rsvd, 0, sizeof(Rsvd));}
116 };
117 
118 /******************************************************************************/
119 /* X r d F r c X A t t r P i n */
120 /******************************************************************************/
121 
123 {
124 public:
125 
126 long long pinTime; // Pin-to-time or pin-for-time value
127 char Flags; // See definitions below
128 char Rsvd[7]; // Reserved fields
129 
130 // The following flags are defined for Flags
131 //
132 static const char pinPerm = 0x01; // Pin forever
133 static const char pinIdle = 0x02; // Pin unless pinTime idle met
134 static const char pinKeep = 0x04; // Pin until pinTime
135 static const char pinSet = 0x07; // Pin is valid
136 
137 /* postGet() will put pinTime in host byte order (see preSet()).
138 */
139  int postGet(int Result)
140  {if (Result > 0) pinTime = ntohll(pinTime);
141  return Result;
142  }
143 
144 /* preSet() will put pinTime in network byte order to allow the attribute to
145  to be copied to different architectures and still work.
146 */
148  {tmp.pinTime = htonll(pinTime); tmp.Flags = Flags;
149  return &tmp;
150  }
151 
152 /* Name() returns the extended attribute name for this object.
153 */
154 static const char *Name() {return "XrdFrm.Pin";}
155 
156 
157 /* sizeGet() and sizeSet() return the actual size of the object is used.
158 */
159 static int sizeGet() {return sizeof(XrdFrcXAttrCpy);}
160 static int sizeSet() {return sizeof(XrdFrcXAttrCpy);}
161 
162  XrdFrcXAttrPin() : pinTime(0), Flags(0) {memset(Rsvd, 0, sizeof(Rsvd));}
164 };
165 
166 /******************************************************************************/
167 /* X r d F r c X A t t r P f n */
168 /******************************************************************************/
169 
171 {
172 public:
173 
174 char Pfn[MAXPATHLEN+8]; // Enough room for the Pfn
175 
176 /* postGet() and preSet() are minimal as no chages are needed
177 */
178 static int postGet(int Result) {return Result;}
179  XrdFrcXAttrPfn *preSet(XrdFrcXAttrPfn &tmp) {return this;}
180 
181 /* Name() returns the extended attribute name for this object.
182 */
183 static const char *Name() {return "XrdFrm.Pfn";}
184 
185 /* sizeGet() return the actual size of the object is used.
186 */
187 static int sizeGet() {return sizeof(XrdFrcXAttrPfn);}
188 
189 /* sizeSet() returns the length of the Pfn string plus the null byte.
190 */
191  int sizeSet() {return strlen(Pfn)+1;}
192 
193  XrdFrcXAttrPfn() {*Pfn = 0;}
195 };
196 #endif