XRootD
XrdDigFile Class Reference

#include <XrdDigFS.hh>

+ Inheritance diagram for XrdDigFile:
+ Collaboration diagram for XrdDigFile:

Public Member Functions

 XrdDigFile (char *user=0, int monid=0)
 
 ~XrdDigFile ()
 
int close ()
 
virtual int fctl (const int cmd, const char *args, XrdOucErrInfo &eInfo)=0
 
int fctl (const int cmd, const char *args, XrdOucErrInfo &out_error)
 
virtual int fctl (const int cmd, int alen, const char *args, const XrdSecEntity *client=0)
 
const char * FName ()
 
int getCXinfo (char cxtype[4], int &cxrsz)
 
int getMmap (void **Addr, off_t &Size)
 
int open (const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecClientName *client=0, const char *opaque=0)
 
int read (XrdSfsAio *aioparm)
 
XrdSfsXferSize read (XrdSfsFileOffset fileOffset, char *buffer, XrdSfsXferSize buffer_size)
 
int read (XrdSfsFileOffset fileOffset, XrdSfsXferSize preread_sz)
 
XrdSfsXferSize readv (XrdOucIOVec *readV, int readCount)
 
int stat (struct stat *buf)
 
int sync ()
 
int sync (XrdSfsAio *aiop)
 
int truncate (XrdSfsFileOffset fileOffset)
 
int write (XrdSfsAio *aioparm)
 
XrdSfsXferSize write (XrdSfsFileOffset fileOffset, const char *buffer, XrdSfsXferSize buffer_size)
 
- Public Member Functions inherited from XrdSfsFile
 XrdSfsFile (const char *user=0, int MonID=0)
 
 XrdSfsFile (XrdOucErrInfo &eInfo)
 
 XrdSfsFile (XrdSfsFile &wrapF)
 
virtual ~XrdSfsFile ()
 Destructor. More...
 
virtual int checkpoint (cpAct act, struct iov *range=0, int n=0)
 
virtual int fctl (const int cmd, int alen, const char *args, const XrdSecEntity *client=0)
 
virtual int open (const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecEntity *client=0, const char *opaque=0)=0
 
virtual int pgRead (XrdSfsAio *aioparm, uint64_t opts=0)
 
virtual XrdSfsXferSize pgRead (XrdSfsFileOffset offset, char *buffer, XrdSfsXferSize rdlen, uint32_t *csvec, uint64_t opts=0)
 
virtual int pgWrite (XrdSfsAio *aioparm, uint64_t opts=0)
 
virtual XrdSfsXferSize pgWrite (XrdSfsFileOffset offset, char *buffer, XrdSfsXferSize wrlen, uint32_t *csvec, uint64_t opts=0)
 
virtual int SendData (XrdSfsDio *sfDio, XrdSfsFileOffset offset, XrdSfsXferSize size)
 
virtual void setXio (XrdSfsXio *xioP)
 
virtual XrdSfsXferSize writev (XrdOucIOVec *writeV, int wdvCnt)
 

Additional Inherited Members

- Public Types inherited from XrdSfsFile
enum  cpAct {
  cpCreate =0 ,
  cpDelete ,
  cpRestore ,
  cpQuery ,
  cpTrunc ,
  cpWrite
}
 
- Public Attributes inherited from XrdSfsFile
XrdOucErrInfoerror
 
- Static Public Attributes inherited from XrdSfsFile
static const uint64_t Verify = 0x8000000000000000ULL
 Options for pgRead() and pgWrite() as noted below. More...
 

Detailed Description

Definition at line 97 of file XrdDigFS.hh.

Constructor & Destructor Documentation

◆ XrdDigFile()

XrdDigFile::XrdDigFile ( char *  user = 0,
int  monid = 0 
)
inline

Definition at line 148 of file XrdDigFS.hh.

149  : XrdSfsFile(user, monid),
150  oh(-1), fname(0), isProc(false) {}
XrdSfsFile(const char *user=0, int MonID=0)

◆ ~XrdDigFile()

XrdDigFile::~XrdDigFile ( )
inline

Definition at line 151 of file XrdDigFS.hh.

151 {if (oh >= 0) close();}
int close()
Definition: XrdDigFS.cc:427

References close().

+ Here is the call graph for this function:

Member Function Documentation

◆ close()

int XrdDigFile::close ( )
virtual

Close the file.

Returns
One of SFS_OK or SFS_ERROR.

Implements XrdSfsFile.

Definition at line 427 of file XrdDigFS.cc.

435 {
436  static const char *epname = "close";
437 
438 // Release the handle and return
439 //
440  if (oh >= 0 && XrdDigUFS::Close(oh))
441  return XrdDigFS::Emsg(epname, error, errno, "close", fname);
442  oh = -1;
443  if (fname) {free(fname); fname = 0;}
444  return SFS_OK;
445 }
#define SFS_OK
static int Emsg(const char *, XrdOucErrInfo &, int, const char *x, const char *y="")
Definition: XrdDigFS.cc:605
static int Close(int fd)
Definition: XrdDigFS.cc:90
XrdOucErrInfo & error

References XrdDigUFS::Close(), XrdDigFS::Emsg(), and SFS_OK.

Referenced by ~XrdDigFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fctl() [1/3]

virtual int XrdSfsFile::fctl

Execute a special operation on the file (version 1)

Parameters
cmd- The operation to be performed (see below). SFS_FCTL_GETFD Return file descriptor if possible SFS_FCTL_STATV Reserved for future use.
args- specific arguments to cmd SFS_FCTL_GETFD Set to zero.
eInfo- The object where error info or results are to be returned. This is legacy and the error onject may be used as well.
Returns
If an error occurs or the operation is not support, SFS_ERROR should be returned with error.code set to errno. Otherwise, SFS_FCTL_GETFD error.code holds the real file descriptor number If the value is negative, sendfile() is not used. If the value is SFS_SFIO_FDVAL then the SendData() method is used for future read requests.

◆ fctl() [2/3]

int XrdDigFile::fctl ( const int  cmd,
const char *  args,
XrdOucErrInfo eInfo 
)
virtual

Execute a special operation on the file (version 1)

Parameters
cmd- The operation to be performed (see below). SFS_FCTL_GETFD Return file descriptor if possible SFS_FCTL_STATV Reserved for future use.
args- specific arguments to cmd SFS_FCTL_GETFD Set to zero.
eInfo- The object where error info or results are to be returned. This is legacy and the error onject may be used as well.
Returns
If an error occurs or the operation is not support, SFS_ERROR should be returned with error.code set to errno. Otherwise, SFS_FCTL_GETFD error.code holds the real file descriptor number If the value is negative, sendfile() is not used. If the value is SFS_SFIO_FDVAL then the SendData() method is used for future read requests.

Implements XrdSfsFile.

Definition at line 451 of file XrdDigFS.cc.

454 {
455 // See if we can do this
456 //
457  if (cmd == SFS_FCTL_GETFD)
458  {out_error.setErrCode(isProc ? -1 : oh);
459  return SFS_OK;
460  }
461 
462 // We don't support this
463 //
464  out_error.setErrInfo(ENOTSUP, "fctl operation not supported");
465  return SFS_ERROR;
466 }
#define SFS_ERROR
#define SFS_FCTL_GETFD

References XrdOucErrInfo::setErrCode(), XrdOucErrInfo::setErrInfo(), SFS_ERROR, SFS_FCTL_GETFD, and SFS_OK.

+ Here is the call graph for this function:

◆ fctl() [3/3]

int XrdSfsFile::fctl

Execute a special operation on the file (version 2)

Parameters
cmd- The operation to be performed: SFS_FCTL_SPEC1 Perform implementation defined action
alen- Length of data pointed to by args.
args- Data sent with request, zero if alen is zero.
client- Client's identify (see common description).
Returns
SFS_OK a null response is sent.
SFS_DATA error.code length of the data to be sent. error.message contains the data to be sent. o/w one of SFS_ERROR, SFS_REDIRECT, or SFS_STALL.

Definition at line 489 of file XrdSfsInterface.cc.

84 {
85  (void)cmd; (void)alen; (void)args; (void)client;
86  return SFS_OK;
87 }

◆ FName()

const char* XrdDigFile::FName ( )
inlinevirtual

Get the file path.

Returns
Null terminated string of the path used in open().

Implements XrdSfsFile.

Definition at line 115 of file XrdDigFS.hh.

115 {return fname;}

◆ getCXinfo()

int XrdDigFile::getCXinfo ( char  cxtype[4],
int &  cxrsz 
)
inlinevirtual

Get compression information for the file.

Parameters
cxtype- Place where the compression algorithm name is to be placed
cxrsz- Place where the compression page size is to be returned
Returns
One of the valid SFS return codes described above. If the file is not compressed or an error is returned, cxrsz must be set to 0.

Implements XrdSfsFile.

Definition at line 146 of file XrdDigFS.hh.

146 {return cxrsz = 0;}

◆ getMmap()

int XrdDigFile::getMmap ( void **  Addr,
off_t &  Size 
)
inlinevirtual

Get file's memory mapping if one exists (memory mapped files only).

Parameters
Addr- Place where the starting memory address is returned.
Size- Place where the file's size is returned.
Returns
SFS_OK when the file is memory mapped or any other code otherwise.

Implements XrdSfsFile.

Definition at line 117 of file XrdDigFS.hh.

118  {if (Addr) Addr = 0; Size = 0; return SFS_OK;}

References SFS_OK.

◆ open()

int XrdDigFile::open ( const char *  fileName,
XrdSfsFileOpenMode  openMode,
mode_t  createMode,
const XrdSecClientName client = 0,
const char *  opaque = 0 
)

Definition at line 348 of file XrdDigFS.cc.

365 {
366  static const char *epname = "open";
367  int retc;
368  struct stat buf;
369 
370 // Verify that this object is not already associated with an open file
371 //
372  if (oh >= 0)
373  return XrdDigFS::Emsg(epname,error,EADDRINUSE,"open file",path);
374 
375 // Allow only opens in readonly mode
376 //
377  open_mode &= (SFS_O_RDONLY | SFS_O_WRONLY | SFS_O_RDWR | SFS_O_CREAT);
378  if (open_mode && open_mode != SFS_O_RDONLY)
379  return XrdDigFS::Emsg(epname,error,EROFS,"open file",path);
380 
381 // Authorize this open and get actual file name to open
382 //
383  if ( (retc = XrdDigFS::Validate(path))
384  || !(fname = Config.GenPath(retc, client, "open",
386  return XrdDigFS::Emsg(epname,error,retc,"open file",path);
387 
388 // Prohibit opening of a symlink in /proc (linux only) and memory
389 //
390 #ifdef __linux__
391  if (IS_PROC(path))
392  {struct stat Stat;
393  if (XrdDigUFS::Statlk(fname, &Stat)) retc = errno;
394  else if (!S_ISREG(Stat.st_mode)) retc = EPERM;
395  else retc = 0;
396  if (!retc && strstr(fname, "/mem")) retc = EACCES;
397  if (retc)
398  {free(fname);
399  return XrdDigFS::Emsg(epname, error, retc, "open proc file", path);
400  }
401  isProc = true;
402  }
403 #endif
404 
405 
406 // Open the file and make sure it is a file
407 //
408  if ((oh = XrdDigUFS::Open(fname, O_RDONLY)) >= 0)
409  {do {retc = XrdDigUFS::Statfd(oh, &buf);} while(retc && errno == EINTR);
410  if (!retc && !(buf.st_mode & S_IFREG))
411  {XrdDigUFS::Close(oh);
412  oh = (buf.st_mode & S_IFDIR ? -EISDIR : -ENOTBLK);
413  }
414  } else oh = -errno;
415 
416 // All done.
417 //
418  if (oh >= 0) return SFS_OK;
419  if (fname) {free(fname); fname = 0;}
420  return XrdDigFS::Emsg(epname,error,oh,"open file",path);
421 }
struct stat Stat
Definition: XrdCks.cc:49
#define SFS_O_RDONLY
#define SFS_O_WRONLY
#define SFS_O_CREAT
#define SFS_LCLPLEN
#define SFS_O_RDWR
static int Validate(const char *)
Definition: XrdDigFS.cc:812
int stat(struct stat *buf)
Definition: XrdDigFS.cc:568
static int Statfd(int fd, struct stat *buf)
Definition: XrdDigFS.cc:94
static int Statlk(const char *fn, struct stat *buf)
Definition: XrdDigFS.cc:98
static int Open(const char *path, int oflag)
Definition: XrdDigFS.cc:92
XrdCmsConfig Config

References XrdDigUFS::Close(), XrdDig::Config, XrdDigFS::Emsg(), XrdDigConfig::GenPath(), XrdDigConfig::isFile, XrdDigUFS::Open(), SFS_LCLPLEN, SFS_O_CREAT, SFS_O_RDONLY, SFS_O_RDWR, SFS_O_WRONLY, SFS_OK, Stat, stat(), XrdDigUFS::Statfd(), XrdDigUFS::Statlk(), and XrdDigFS::Validate().

+ Here is the call graph for this function:

◆ read() [1/3]

int XrdDigFile::read ( XrdSfsAio aioparm)
virtual

Read file bytes using asynchronous I/O.

Parameters
aioparm- Pointer to async I/O object controlling the I/O.
Returns
SFS_OK Request accepted and will be scheduled.
SFS_ERROR File could not be read, error holds the reason.

Implements XrdSfsFile.

Definition at line 552 of file XrdDigFS.cc.

553 {
554 
555 // Execute this request in a synchronous fashion
556 //
557  aiop->Result = this->read((XrdSfsFileOffset)aiop->sfsAio.aio_offset,
558  (char *)aiop->sfsAio.aio_buf,
559  (XrdSfsXferSize)aiop->sfsAio.aio_nbytes);
560  aiop->doneRead();
561  return 0;
562 }
long long XrdSfsFileOffset
int XrdSfsXferSize
int read(XrdSfsFileOffset fileOffset, XrdSfsXferSize preread_sz)
Definition: XrdDigFS.hh:120

References aiocb::aio_buf, aiocb::aio_nbytes, aiocb::aio_offset, XrdSfsAio::doneRead(), read(), XrdSfsAio::Result, and XrdSfsAio::sfsAio.

+ Here is the call graph for this function:

◆ read() [2/3]

XrdSfsXferSize XrdDigFile::read ( XrdSfsFileOffset  offset,
char *  buffer,
XrdSfsXferSize  size 
)
virtual

Read file bytes into a buffer.

Parameters
offset- The offset where the read is to start.
buffer- pointer to buffer where the bytes are to be placed.
size- The number of bytes to read.
Returns
>= 0 The number of bytes that placed in buffer.
SFS_ERROR File could not be read, error holds the reason.

Implements XrdSfsFile.

Definition at line 472 of file XrdDigFS.cc.

486 {
487  static const char *epname = "read";
488  XrdSfsXferSize nbytes;
489 
490 // Make sure the offset is not too large
491 //
492 #if _FILE_OFFSET_BITS!=64
493  if (offset > 0x000000007fffffff)
494  return XrdDigFS::Emsg(epname, error, EFBIG, "read", fname);
495 #endif
496 
497 // Read the actual number of bytes
498 //
499  do { nbytes = pread(oh, (void *)buff, (size_t)blen, (off_t)offset); }
500  while(nbytes < 0 && errno == EINTR);
501 
502  if (nbytes < 0)
503  return XrdDigFS::Emsg(epname, error, errno, "read", fname);
504 
505 // Return number of bytes read
506 //
507  return nbytes;
508 }
ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)

References XrdDigFS::Emsg(), and pread().

+ Here is the call graph for this function:

◆ read() [3/3]

int XrdDigFile::read ( XrdSfsFileOffset  offset,
XrdSfsXferSize  size 
)
inlinevirtual

Preread file blocks into the file system cache.

Parameters
offset- The offset where the read is to start.
size- The number of bytes to pre-read.
Returns
>= 0 The number of bytes that will be pre-read.
SFS_ERROR File could not be preread, error holds the reason.

Implements XrdSfsFile.

Definition at line 120 of file XrdDigFS.hh.

121  {return SFS_OK;}

References SFS_OK.

◆ readv()

XrdSfsXferSize XrdDigFile::readv ( XrdOucIOVec readV,
int  rdvCnt 
)
virtual

Given an array of read requests (size rdvCnt), read them from the file and place the contents consecutively in the provided buffer. A dumb default implementation is supplied but should be replaced to increase performance.

Parameters
readVpointer to the array of read requests.
rdvCntthe number of elements in readV.
Returns
>=0 The numbe of bytes placed into the buffer.
SFS_ERROR File could not be read, error holds the reason.

Reimplemented from XrdSfsFile.

Definition at line 514 of file XrdDigFS.cc.

528 {
529  static const char *epname = "readv";
530  XrdSfsXferSize nbytes = 0;
531  ssize_t curCount;
532  int i;
533 
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);
537 
538  if (curCount != readV[i].size)
539  {if (curCount > 0) errno = ESPIPE;
540  return XrdDigFS::Emsg(epname, error, errno, "readv", fname);
541  }
542  nbytes += curCount;
543  }
544 
545  return nbytes;
546 }

References XrdDigFS::Emsg(), and pread().

+ Here is the call graph for this function:

◆ stat()

int XrdDigFile::stat ( struct stat *  buf)
virtual

Return state information on the file.

Parameters
buf- Pointer to the structure where info it to be returned.
Returns
One of SFS_OK, SFS_ERROR, SFS_REDIRECT, or SFS_STALL. When SFS_OK is returned, buf must hold stat information.

Implements XrdSfsFile.

Definition at line 568 of file XrdDigFS.cc.

576 {
577  static const char *epname = "stat";
578  static const int wMask = ~(S_IWUSR | S_IWGRP | S_IWOTH);
579 
580 // Execute the function
581 //
582  if (XrdDigUFS::Statfd(oh, buf))
583  return XrdDigFS::Emsg(epname, error, errno, "stat", fname);
584 
585 // Fixup size when stat is issued into /proc (linux only would set isProc)
586 //
587  if (isProc && !buf->st_size && S_ISREG(buf->st_mode)) buf->st_size = 1048576;
588 
589 // Turn off write bits in the mode
590 //
591  buf->st_mode &= wMask;
592 
593 // All went well
594 //
595  return SFS_OK;
596 }

References XrdDigFS::Emsg(), SFS_OK, and XrdDigUFS::Statfd().

+ Here is the call graph for this function:

◆ sync() [1/2]

int XrdDigFile::sync ( )
inlinevirtual

Make sure all outstanding data is actually written to the file (sync).

Returns
One of SFS_OK, SFS_ERROR, SFS_REDIRECT, SFS_STALL, or SFS_STARTED

Implements XrdSfsFile.

Definition at line 138 of file XrdDigFS.hh.

138 {return SFS_OK;}

References SFS_OK.

◆ sync() [2/2]

int XrdDigFile::sync ( XrdSfsAio aiop)
inlinevirtual

Make sure all outstanding data is actually written to the file (async).

Returns
SFS_OK Request accepted and will be scheduled.
SFS_ERROR Request could not be accepted, return error has reason.

Implements XrdSfsFile.

Definition at line 140 of file XrdDigFS.hh.

140 {return SFS_OK;}

References SFS_OK.

◆ truncate()

int XrdDigFile::truncate ( XrdSfsFileOffset  fsize)
inlinevirtual

Truncate the file.

Parameters
fsize- The size that the file is to have.
Returns
One of SFS_OK, SFS_ERROR, SFS_REDIRECT, or SFS_STALL

Implements XrdSfsFile.

Definition at line 144 of file XrdDigFS.hh.

144 {return SFS_OK;}

References SFS_OK.

◆ write() [1/2]

int XrdDigFile::write ( XrdSfsAio aioparm)
inlinevirtual

Write file bytes using asynchronous I/O.

Parameters
aioparm- Pointer to async I/O object controlling the I/O.
Returns
0 Request accepted and will be scheduled.
!0 Request not accepted, returned value is errno.

Implements XrdSfsFile.

Definition at line 136 of file XrdDigFS.hh.

136 {return SFS_OK;}

References SFS_OK.

◆ write() [2/2]

XrdSfsXferSize XrdDigFile::write ( XrdSfsFileOffset  offset,
const char *  buffer,
XrdSfsXferSize  size 
)
inlinevirtual

Write file bytes from a buffer.

Parameters
offset- The offset where the write is to start.
buffer- pointer to buffer where the bytes reside.
size- The number of bytes to write.
Returns
>= 0 The number of bytes that were written.
SFS_ERROR File could not be written, error holds the reason.

Implements XrdSfsFile.

Definition at line 132 of file XrdDigFS.hh.

134  {return SFS_OK;}

References SFS_OK.


The documentation for this class was generated from the following files: