30 #include <sys/types.h>
38 #include <sys/param.h>
41 #include "XrdVersion.hh"
77 static int Chmod(
const char *fn, mode_t mode) {
return chmod(fn, mode);}
81 static int Mkdir(
const char *fn, mode_t mode) {
return mkdir(fn, mode);}
83 static int Open(
const char *path,
int oflag, mode_t omode)
84 {
return open(path, oflag, omode);}
90 static int Rename(
const char *ofn,
const char *nfn) {
return rename(ofn, nfn);}
118 Eroute.
Say(
"Copr. 2007 Stanford University/SLAC "
119 "sfs (Standard File System) v 9.0n");
144 static const char *epname =
"opendir";
150 "open directory", dir_path);
155 fname = strdup(dir_path);
159 if (!(dh =
opendir(dir_path)))
return
183 static const char *epname =
"nextEntry";
191 return (
const char *)0;
196 if (ateof)
return (
const char *)0;
200 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
204 {
if (!(retc = errno)) {ateof = 1;
error.
clear();}
206 d_pnt->d_name[0] =
'\0';
207 return (
const char *)0;
209 return (
const char *)(rp->d_name);
213 d_pnt->d_name[0] =
'\0';
214 return (
const char *)0;
219 if (!rp || !d_pnt->d_name[0])
222 return (
const char *)0;
227 return (
const char *)(d_pnt->d_name);
244 static const char *epname =
"closedir";
255 if (fname) free(fname);
293 static const char *epname =
"open";
294 const int AMode = S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH;
297 int retc, open_flag = 0;
304 fname = strdup(path);
313 default: open_flag = O_RDONLY;
break;
319 {open_flag = O_RDWR | O_CREAT | O_EXCL;
320 opname = (
char *)
"create";
324 {open_flag = O_RDWR | O_CREAT | O_TRUNC;
325 opname = (
char *)
"truncate";
326 }
else opname = (
char *)
"open";
332 if (!retc && !(buf.st_mode & S_IFREG))
333 {
close(); oh = (buf.st_mode & S_IFDIR ? -EISDIR : -ENOTBLK);}
338 while(retc && errno == EINTR);
339 if (!retc && (buf.st_mode & S_IFDIR)) oh = -EISDIR;
362 static const char *epname =
"close";
369 if (fname) {free(fname); fname = 0;}
390 out_error.
setErrInfo(ENOTSUP,
"fctl operation not supported");
413 static const char *epname =
"read";
418 #if _FILE_OFFSET_BITS!=64
419 if (offset > 0x000000007fffffff)
425 do { nbytes =
pread(oh, (
void *)buff, (
size_t)blen, (off_t)offset); }
426 while(nbytes < 0 && errno == EINTR);
455 static const char *epname =
"readv";
460 for (i=0; i<int(readCount); i++)
461 {
do {curCount =
pread(oh, (
void *)readV[i].data, (
size_t)readV[i].size, (off_t)readV[i].offset);}
462 while(curCount < 0 && errno == EINTR);
464 if (curCount != readV[i].size)
465 {
if (curCount > 0) errno = ESPIPE;
512 static const char *epname =
"write";
517 #if _FILE_OFFSET_BITS!=64
518 if (offset > 0x000000007fffffff)
524 do { nbytes =
pwrite(oh, (
void *)buff, (
size_t)blen, (off_t)offset); }
525 while(nbytes < 0 && errno == EINTR);
564 static const char *epname =
"stat";
589 static const char *epname =
"sync";
634 static const char *epname =
"trunc";
638 if (
sizeof(off_t) <
sizeof(flen) && flen > 0x000000007fffffff)
674 static const char *epname =
"chmod";
714 static const char *epname =
"exists";
744 out_error.
setErrInfo(ENOTSUP,
"Operation not supported.");
776 static const char *epname =
"mkdir";
808 char actual_path[MAXPATHLEN], *local_path, *next_path;
814 if (!(plen = strlen(path)))
return -ENOENT;
815 if (plen >=
sizeof(actual_path))
return -ENAMETOOLONG;
816 strcpy(actual_path, path);
817 if (actual_path[plen-1] ==
'/') actual_path[plen-1] =
'\0';
821 if (!(local_path = rindex(actual_path, (
int)
'/'))
822 || local_path == actual_path)
return 0;
830 local_path = actual_path+1;
831 while((next_path = index(local_path,
int(
'/'))))
836 local_path = next_path+1;
863 static const char *epname =
"rem";
894 static const char *epname =
"remdir";
911 const char *new_name,
929 static const char *epname =
"rename";
962 static const char *epname =
"stat";
1001 static const char *epname =
"trunc";
1005 if (
sizeof(off_t) <
sizeof(flen) && flen > 0x000000007fffffff)
1029 char buffer[MAXPATHLEN+80];
1033 if (ecode < 0) ecode = -ecode;
1038 snprintf(buffer,
sizeof(buffer),
"Unable to %s %s; %s", op, target, etext);
static XrdSysError eDest(0,"crypto_")
int truncate(const char *path, off_t offset)
ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
int stat(const char *path, struct stat *buf)
int ftruncate(int fildes, off_t offset)
struct dirent * readdir(DIR *dirp)
int open(const char *path, int oflag,...)
ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
int fstat(int fildes, struct stat *buf)
int unlink(const char *path)
int rename(const char *oldpath, const char *newpath)
int mkdir(const char *path, mode_t mode)
int rmdir(const char *path)
DIR * opendir(const char *path)
@ XrdSfsFileExistIsDirectory
long long XrdSfsFileOffset
XrdSfsFileSystem * XrdSfsGetFileSystem(XrdSfsFileSystem *native_fs, XrdSysLogger *lp)
const char * XrdSysE2T(int errcode)
void clear()
Reset data and error information to null. Any appenadges are released.
int setErrInfo(int code, const char *emsg)
virtual void doneRead()=0
virtual void doneWrite()=0
int open(const char *dirName, const XrdSecClientName *client=0, const char *opaque=0)
XrdSfsXferSize readv(XrdOucIOVec *readV, int readCount)
int stat(struct stat *buf)
int open(const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecClientName *client=0, const char *opaque=0)
XrdSfsXferSize write(XrdSfsFileOffset fileOffset, const char *buffer, XrdSfsXferSize buffer_size)
virtual int fctl(const int cmd, const char *args, XrdOucErrInfo &eInfo)=0
int read(XrdSfsFileOffset fileOffset, XrdSfsXferSize preread_sz)
int truncate(XrdSfsFileOffset fileOffset)
XrdSfsNative(XrdSysError *lp)
int rem(const char *path, XrdOucErrInfo &out_error, const XrdSecClientName *client=0, const char *opaque=0)
int exists(const char *fileName, XrdSfsFileExistence &exists_flag, XrdOucErrInfo &out_error, const XrdSecClientName *client=0, const char *opaque=0)
int truncate(const char *Name, XrdSfsFileOffset fileOffset, XrdOucErrInfo &out_error, const XrdSecEntity *client=0, const char *opaque=0)
int rename(const char *oldFileName, const char *newFileName, XrdOucErrInfo &out_error, const XrdSecClientName *client=0, const char *opaqueO=0, const char *opaqueN=0)
int fsctl(const int cmd, const char *args, XrdOucErrInfo &out_error, const XrdSecClientName *client=0)
static int Mkpath(const char *path, mode_t mode, const char *info=0)
int stat(const char *Name, struct stat *buf, XrdOucErrInfo &out_error, const XrdSecClientName *client=0, const char *opaque=0)
int chmod(const char *Name, XrdSfsMode Mode, XrdOucErrInfo &out_error, const XrdSecClientName *client=0, const char *opaque=0)
int remdir(const char *dirName, XrdOucErrInfo &out_error, const XrdSecClientName *client=0, const char *opaque=0)
static int Emsg(const char *, XrdOucErrInfo &, int, const char *x, const char *y="")
const char * getVersion()
int mkdir(const char *dirName, XrdSfsMode Mode, XrdOucErrInfo &out_error, const XrdSecClientName *client=0, const char *opaque=0)
static int Mkdir(const char *fn, mode_t mode)
static int Rem(const char *fn)
static int Rename(const char *ofn, const char *nfn)
static int Truncate(const char *fn, off_t flen)
static int Open(const char *path, int oflag, mode_t omode)
static int Remdir(const char *fn)
static int Statfd(int fd, struct stat *buf)
static int Statfn(const char *fn, struct stat *buf)
static int Chmod(const char *fn, mode_t mode)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)