2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3
Copyright (C) 2005- The University of Notre Dame
4
This software is distributed under the GNU General Public License.
5
See the file COPYING for details.
9
Important: This define must come before all include files,
10
in order to indicate that we are working with the 64-bit definition
11
of file sizes in struct stat and other places as needed by xrootd.
12
Note that we do not define it globally, so that we are sure not to break other
13
people's include files. Note also that we are careful to use
14
struct pfs_stat in our own headers, so that our own code isn't
15
sensitive to this setting.
18
#define _FILE_OFFSET_BITS 64
22
#include "pfs_service.h"
26
#include "stringtools.h"
27
#include "domain_name.h"
29
#include "file_cache.h"
31
#include "http_query.h"
40
#include <sys/statfs.h>
41
#include <pfs_types.h>
43
#include <XrdPosix/XrdPosixExtern.hh>
45
#define XROOTD_FILE_MODE (S_IFREG | 0555)
46
#define XROOTD_DEFAULT_PORT 1094
48
static char *translate_file_to_xrootd(pfs_name * name)
50
char file_buf[PFS_PATH_MAX];
51
int string_length = 0;
52
int port_number = XROOTD_DEFAULT_PORT;
55
port_number = name->port;
58
string_length = sprintf(file_buf, "root://%s:%i/%s", name->host, port_number, name->rest);
60
return strdup(file_buf);
64
class pfs_file_xrootd:public pfs_file {
69
pfs_file_xrootd(pfs_name * n, int file_handle):pfs_file(n) {
70
this->file_handle = file_handle;
74
debug(D_XROOTD, "close %i", this->file_handle);
75
return XrdPosix_Close(this->file_handle);
78
virtual pfs_ssize_t read(void *d, pfs_size_t length, pfs_off_t offset) {
79
debug(D_XROOTD, "pread %d %lu %lu",this->file_handle,length,offset);
80
return XrdPosix_Pread(this->file_handle,d,length,offset);
83
virtual pfs_ssize_t write(const void *d, pfs_size_t length, pfs_off_t offset) {
84
debug(D_XROOTD, "pwrite %d %lu %lu",this->file_handle,length,offset);
85
return XrdPosix_Pwrite(this->file_handle,d,length,offset);
88
virtual int fstat(struct pfs_stat *buf) {
89
debug(D_XROOTD, "fstat %d",this->file_handle);
91
int result = XrdPosix_Fstat(this->file_handle, &lbuf);
92
if(result == 0) COPY_STAT(lbuf, *buf);
96
virtual pfs_ssize_t get_size() {
98
if(this->fstat(&buf) == 0) {
108
class pfs_service_xrootd:public pfs_service {
110
virtual pfs_file * open(pfs_name * name, int flags, mode_t mode) {
112
char *file_url = NULL;
114
debug(D_XROOTD, "Opening file: %s", name->rest);
116
if((flags & O_ACCMODE) != O_RDONLY) {
121
file_url = translate_file_to_xrootd(name);
122
file_handle = XrdPosix_Open(file_url, flags, mode);
126
return new pfs_file_xrootd(name, file_handle);
133
virtual pfs_dir * getdir( pfs_name *name ) {
137
char *file_url = NULL;
138
file_url = translate_file_to_xrootd(name);
140
debug(D_XROOTD,"getdir %s",file_url);
142
dir = XrdPosix_Opendir(file_url);
148
pfs_dir *pdir = new pfs_dir(name);
150
while((d=XrdPosix_Readdir(dir))) {
151
pdir->append(d->d_name);
153
XrdPosix_Closedir(dir);
160
virtual int statfs(pfs_name * name, struct pfs_statfs *buf) {
162
char *file_url = translate_file_to_xrootd(name);
163
debug(D_XROOTD, "statfs %s",file_url);
164
int result = XrdPosix_Statfs((const char *) file_url, &lbuf);
166
COPY_STATFS(lbuf, *buf);
170
virtual int stat(pfs_name * name, struct pfs_stat *buf) {
172
char *file_url = translate_file_to_xrootd(name);
173
debug(D_XROOTD, "stat %s",file_url);
174
int result = XrdPosix_Stat((const char *) file_url, &lbuf);
176
COPY_STAT(lbuf, *buf);
180
virtual int lstat(pfs_name * name, struct pfs_stat *buf) {
181
return this->stat(name, buf);
184
virtual int unlink( pfs_name *name ) {
185
char *file_url = translate_file_to_xrootd(name);
186
debug(D_XROOTD, "unlink %s",file_url);
187
int result = XrdPosix_Unlink((const char *) file_url);
192
virtual int access( pfs_name *name, mode_t mode ) {
193
char *file_url = translate_file_to_xrootd(name);
194
debug(D_XROOTD, "access %s %o",file_url,mode);
195
int result = XrdPosix_Access((const char *) file_url,mode);
200
virtual int truncate( pfs_name *name, pfs_off_t length ) {
201
char *file_url = translate_file_to_xrootd(name);
202
debug(D_XROOTD, "truncate %s %lld",file_url,length);
203
int result = XrdPosix_Truncate(file_url,length);
208
virtual int chdir( pfs_name *name, char *newpath ) {
209
struct pfs_stat info;
210
if(this->stat(name,&info)>=0) {
211
if(S_ISDIR(info.st_mode)) {
212
sprintf(newpath,"/%s/%s:%d%s",name->service_name,name->host,name->port,name->rest);
223
virtual int rename( pfs_name *oldname, pfs_name *newname ) {
224
char *old_url = translate_file_to_xrootd(oldname);
225
char *new_url = translate_file_to_xrootd(newname);
227
debug(D_XROOTD,"rename %s %s",old_url,new_url);
228
int result = XrdPosix_Rename(old_url,new_url);
236
virtual int mkdir( pfs_name *name, mode_t mode) {
237
char *file_url = translate_file_to_xrootd(name);
238
debug(D_XROOTD, "mkdir %s %o",file_url,mode);
239
int result = XrdPosix_Mkdir((const char *) file_url,mode);
244
virtual int rmdir( pfs_name *name ) {
245
char *file_url = translate_file_to_xrootd(name);
246
debug(D_XROOTD, "rmdir %s",file_url);
247
int result = XrdPosix_Rmdir((const char *) file_url);
252
virtual int is_seekable() {
259
static pfs_service_xrootd pfs_service_xrootd_instance;
260
pfs_service *pfs_service_xrootd = &pfs_service_xrootd_instance;