XRootD
Loading...
Searching...
No Matches
XrdPosixExtra.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d P o s i x E x t r a . c c */
4/* */
5/* */
6/* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */
7/* All Rights Reserved */
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/* Modified by Frank Winklmeier to add the full Posix file system definition. */
31/******************************************************************************/
32
33#include <cerrno>
34
39
40
41
42/******************************************************************************/
43/* p g R e a d */
44/******************************************************************************/
45
46ssize_t XrdPosixExtra::pgRead (int fildes, void* buffer,
47 off_t offset, size_t rdlen,
48 std::vector<uint32_t>& csvec,
49 uint64_t opts,
51{
52 XrdPosixFile *fp;
53 long long offs, bytes;
54 uint64_t fOpts;
55 int iosz;
56
57// Find the file object
58//
59 if (!(fp = XrdPosixObject::File(fildes)))
60 {if (!cbp) return -1;
61 cbp->Complete(-1);
62 return 0;
63 }
64
65// Make sure the size is not too large
66//
67 if (rdlen > (size_t)0x7fffffff)
68 {fp->UnLock();
69
70 errno = EOVERFLOW;
71 if (!cbp) return -1;
72 cbp->Complete(-1);
73 return 0;
74 }
75
76// Get the parameters
77//
78 iosz = static_cast<int>(rdlen);
79 offs = static_cast<long long>(offset);
80 csvec.clear();
81 fOpts= (opts & forceCS ? XrdOucCacheIO::forceCS : 0);
82
83// Issue the read in the sync case
84//
85 if (!cbp)
86 {bytes = fp->XCio->pgRead((char *)buffer, offs, (int)iosz, csvec, fOpts);
87 fp->UnLock();
88 return (ssize_t)bytes;
89 }
90
91// Handle the read in the async case
92//
93 cbp->theFile = fp;
94 fp->Ref(); fp->UnLock();
95
96// Issue the read
97//
98 fp->XCio->pgRead(*cbp, (char *)buffer, offs, (int)iosz, csvec, fOpts);
99 return 0;
100}
101
102/******************************************************************************/
103/* p g W r i t e */
104/******************************************************************************/
105
106ssize_t XrdPosixExtra::pgWrite(int fildes, void* buffer,
107 off_t offset, size_t wrlen,
108 std::vector<uint32_t>& csvec,
109 uint64_t opts,
111{
112 XrdPosixFile *fp;
113 long long offs;
114 int iosz, bytes;
115
116// Find the file object
117//
118 if (!(fp = XrdPosixObject::File(fildes)))
119 {if (!cbp) return -1;
120 cbp->Complete(-1);
121 return 0;
122 }
123
124// Make sure the size is not too large
125//
126 if (wrlen > (size_t)0x7fffffff)
127 {fp->UnLock();
128 errno = EOVERFLOW;
129 if (!cbp) return -1;
130 cbp->Complete(-1);
131 return 0;
132 }
133
134// Check if we need to generate checksums or verify that we have the right num.
135//
136 if (csvec.size() == 0)
137 XrdOucPgrwUtils::csCalc((const char *)buffer, offset, wrlen, csvec);
138 else if (XrdOucPgrwUtils::csNum(offset, wrlen) != (int)csvec.size())
139 {fp->UnLock();
140 errno = EINVAL;
141 if (!cbp) return -1;
142 cbp->Complete(-1);
143 return 0;
144 }
145
146// Get the parameters
147//
148 iosz = static_cast<int>(wrlen);
149 offs = static_cast<long long>(offset);
150
151// Sync: Issue the write
152//
153 if (!cbp)
154 {bytes = fp->XCio->pgWrite((char *)buffer, offs, (int)iosz, csvec);
155 fp->UpdtSize(offs + iosz);
156 fp->UnLock();
157 return (ssize_t)bytes;
158 }
159
160// Async: Prepare for writing
161//
162 cbp->theFile = fp;
163 fp->Ref(); fp->UnLock();
164
165// Issue the write
166//
167 fp->XCio->pgWrite(*cbp, (char *)buffer, offs, (int)iosz, csvec);
168 return 0;
169}
struct myOpts opts
static const uint64_t forceCS
virtual int pgRead(char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual int pgWrite(char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
static void csCalc(const char *data, off_t offs, size_t count, uint32_t *csval)
static int csNum(off_t offs, int count)
Compute the required size of a checksum vector based on offset & length.
virtual void Complete(ssize_t Result)=0
static ssize_t pgWrite(int fildes, void *buffer, off_t offset, size_t wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, XrdPosixCallBackIO *cbp=0)
static const uint64_t forceCS
static ssize_t pgRead(int fildes, void *buffer, off_t offset, size_t rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, XrdPosixCallBackIO *cbp=0)
void UpdtSize(size_t newsz)
XrdOucCacheIO * XCio
static XrdPosixFile * File(int fildes, bool glk=false)