30 #include <sys/types.h>
38 #include <sys/param.h>
41 #include "XrdVersion.hh"
65 #define IS_PROC(x) !strncmp(x+SFS_LCLPLEN, "proc", 4) \
66 && (*(x+SFS_LCLPLEN+4) == '\0'||*(x+SFS_LCLPLEN+4) == '/')
92 static int Open(
const char *path,
int oflag) {
return open(path, oflag);}
114 Eroute.
Say(
"Copr. 2013 Stanford University/SLAC dig file system");
119 eDest->
Say(
"++++++ DigFS initialization started.");
121 eDest->
Say(
"------ DigFS initialization ",(isOK ?
"completed." :
"failed."));
125 return (isOK ? &myFS : 0);
148 static const char *epname =
"opendir";
153 if (dh || isBase)
return XrdDigFS::Emsg(epname, error, EADDRINUSE,
154 "open directory", dir_path);
161 return XrdDigFS::Emsg(epname,error,EACCES,
"open directory",dir_path);
171 return XrdDigFS::Emsg(epname,error,retc,
"open directory",dir_path);
180 {
if (fname) {free(fname); fname = 0;}
181 return XrdDigFS::Emsg(epname,error,errno,
"open directory",dir_path);
187 if (IS_PROC(dir_path))
216 static const char *epname =
"nextEntry";
217 static const int wMask = ~(S_IWUSR | S_IWGRP | S_IWOTH);
224 {
if (dirFD > 0)
return dirent_full.aEnt[--dirFD];
226 return (
const char *)0;
233 return (
const char *)0;
238 if (ateof)
return (
const char *)0;
242 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
246 {
if (!(retc = errno)) {ateof = 1; error.clear();}
248 d_pnt->d_name[0] =
'\0';
249 return (
const char *)0;
252 do{
if ((retc =
readdir_r(dh, d_pnt, &rp)))
254 d_pnt->d_name[0] =
'\0';
255 return (
const char *)0;
260 if (!rp || !d_pnt->d_name[0])
263 return (
const char *)0;
272 int sFlags = (isProc ? AT_SYMLINK_NOFOLLOW : 0);
273 if (fstatat(dirFD, rp->d_name, sBuff, sFlags))
continue;
274 sBuff->st_mode = (sBuff->st_mode & wMask) | S_IRUSR;
277 snprintf(dPath,
sizeof(dPath),
"%s%s", fname, rp->d_name);
278 if (
stat(dPath, sBuff))
continue;
279 sBuff->st_mode = (sBuff->st_mode & wMask) | S_IRUSR;
291 rc = (sBuff ? 0:fstatat(dirFD,rp->d_name,&
Stat,AT_SYMLINK_NOFOLLOW));
292 if (!rc && !noTag && S_ISLNK(sP->st_mode))
293 {n = strlen(rp->d_name);
294 dP = rp->d_name + n + 4;
295 n =
sizeof(dirent_full.nbf) - (n + 8);
296 if ((n = readlinkat(dirFD,rp->d_name,dP,n)) < 0) strcpy(dP,
"?");
298 memcpy(dP-4,
" -> ", 4);
305 return (
const char *)(rp->d_name);
323 static const char *epname =
"closedir";
335 if (fname) {free(fname); fname = 0;}
337 isProc = isBase =
false;
366 static const char *epname =
"open";
394 else if (!S_ISREG(
Stat.st_mode)) retc = EPERM;
396 if (!retc && strstr(fname,
"/mem")) retc = EACCES;
399 return XrdDigFS::Emsg(epname, error, retc,
"open proc file", path);
410 if (!retc && !(buf.st_mode & S_IFREG))
412 oh = (buf.st_mode & S_IFDIR ? -EISDIR : -ENOTBLK);
418 if (oh >= 0)
return SFS_OK;
419 if (fname) {free(fname); fname = 0;}
436 static const char *epname =
"close";
443 if (fname) {free(fname); fname = 0;}
464 out_error.
setErrInfo(ENOTSUP,
"fctl operation not supported");
487 static const char *epname =
"read";
492 #if _FILE_OFFSET_BITS!=64
493 if (offset > 0x000000007fffffff)
499 do { nbytes =
pread(oh, (
void *)buff, (
size_t)blen, (off_t)offset); }
500 while(nbytes < 0 && errno == EINTR);
529 static const char *epname =
"readv";
534 for (i=0; i<int(readCount); i++)
535 {
do {curCount =
pread(oh, (
void *)readV[i].data, (
size_t)readV[i].size, (off_t)readV[i].offset);}
536 while(curCount < 0 && errno == EINTR);
538 if (curCount != readV[i].size)
539 {
if (curCount > 0) errno = ESPIPE;
577 static const char *epname =
"stat";
578 static const int wMask = ~(S_IWUSR | S_IWGRP | S_IWOTH);
587 if (isProc && !buf->st_size && S_ISREG(buf->st_mode)) buf->st_size = 1048576;
591 buf->st_mode &= wMask;
612 char buffer[MAXPATHLEN+80];
616 if (ecode < 0) ecode = -ecode;
621 snprintf(buffer,
sizeof(buffer),
"Unable to %s %s; %s", op, target, etext);
663 static const char *epname =
"exists";
712 {eInfo.
setErrInfo(EINVAL,
"Invalid locate path");
722 eInfo.
setErrInfo(ENOTSUP,
"Operation not supported.");
736 int XrdDigFS::Reject(
const char *op,
const char *trg,
XrdOucErrInfo &eInfo)
762 static const char *epname =
"stat";
763 static const int wMask = ~(S_IWUSR | S_IWGRP | S_IWOTH);
779 if ((retc = Validate(path))
787 if ((myLink = strstr(fname,
" -> "))) *myLink = 0;
800 buf->st_mode &= wMask;
XrdSfsFileSystem * XrdDigGetFS(XrdSfsFileSystem *native_fs, XrdSysLogger *lp, const char *cFN, const char *parms)
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
int stat(const char *path, struct stat *buf)
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 lstat(const char *path, struct stat *buf)
ssize_t read(int fildes, void *buf, size_t nbyte)
DIR * opendir(const char *path)
@ XrdSfsFileExistIsDirectory
long long XrdSfsFileOffset
const char * XrdSysE2T(int errcode)
int GenAccess(const XrdSecEntity *client, const char *aList[], int aMax)
char * GenPath(int &rc, const XrdSecEntity *client, const char *opname, const char *lfn, pType lfnType=isAny)
static void StatRoot(struct stat *sP)
void GetLocResp(XrdOucErrInfo &eInfo, bool nameok)
bool Configure(const char *cFN, const char *parms)
int open(const char *dirName, const XrdSecClientName *client=0, const char *opaque=0)
const char * getVersion()
int fsctl(const int cmd, const char *args, XrdOucErrInfo &out_error, const XrdSecClientName *client=0)
int exists(const char *fileName, XrdSfsFileExistence &exists_flag, XrdOucErrInfo &out_error, const XrdSecClientName *client=0, const char *opaque=0)
static int Validate(const char *)
static int Emsg(const char *, XrdOucErrInfo &, int, const char *x, const char *y="")
int stat(const char *Name, struct stat *buf, XrdOucErrInfo &out_error, const XrdSecClientName *client=0, const char *opaque=0)
int open(const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecClientName *client=0, const char *opaque=0)
int stat(struct stat *buf)
int read(XrdSfsFileOffset fileOffset, XrdSfsXferSize preread_sz)
XrdSfsXferSize readv(XrdOucIOVec *readV, int readCount)
virtual int fctl(const int cmd, const char *args, XrdOucErrInfo &eInfo)=0
static int Statfd(int fd, struct stat *buf)
static int Statlk(const char *fn, struct stat *buf)
static int Statfn(const char *fn, struct stat *buf)
static int Open(const char *path, int oflag)
int setErrInfo(int code, const char *emsg)
virtual void doneRead()=0
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)