Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:33:37

0001 #ifndef _XRDOSS_H
0002 #define _XRDOSS_H
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                             X r d O s s . h h                              */
0006 /*                                                                            */
0007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 #include <dirent.h>
0034 #include <cerrno>
0035 #include <cstdint>
0036 #include <strings.h>
0037 #include <sys/stat.h>
0038 #include <sys/time.h>
0039 #include <sys/types.h>
0040 #include <cstring>
0041 
0042 #include "XrdOss/XrdOssVS.hh"
0043 #include "XrdOuc/XrdOucIOVec.hh"
0044 
0045 class XrdOucEnv;
0046 class XrdSysLogger;
0047 class XrdSfsAio;
0048 
0049 #ifndef XrdOssOK
0050 #define XrdOssOK 0
0051 #endif
0052 
0053 /******************************************************************************/
0054 /*                        C l a s s   X r d O s s D F                         */
0055 /******************************************************************************/
0056 
0057 //! This class defines the object that handles directory as well as file
0058 //! oriented requests. It is instantiated for each file/dir to be opened.
0059 //! The object is obtained by calling newDir() or newFile() in class XrdOss.
0060 //! This allows flexibility on how to structure an oss plugin.
0061   
0062 class XrdOssDF
0063 {
0064 public:
0065 
0066 /******************************************************************************/
0067 /*            D i r e c t o r y   O r i e n t e d   M e t h o d s             */
0068 /******************************************************************************/
0069 
0070 //-----------------------------------------------------------------------------
0071 //! Open a directory.
0072 //!
0073 //! @param  path   - Pointer to the path of the directory to be opened.
0074 //! @param  env    - Reference to environmental information.
0075 //!
0076 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0077 //-----------------------------------------------------------------------------
0078 
0079 virtual int     Opendir(const char *path, XrdOucEnv &env) {return -ENOTDIR;}
0080 
0081 //-----------------------------------------------------------------------------
0082 //! Get the next directory entry.
0083 //!
0084 //! @param  buff   - Pointer to buffer where a null terminated string of the
0085 //!                  entry name is to be returned. If no more entries exist,
0086 //!                  a null string is returned.
0087 //! @param  blen   - Length of the buffer.
0088 //!
0089 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0090 //-----------------------------------------------------------------------------
0091 
0092 virtual int     Readdir(char *buff, int blen) {return -ENOTDIR;}
0093 
0094 //-----------------------------------------------------------------------------
0095 //! Set the stat() buffer where stat information is to be placed corresponding
0096 //! to the directory entry returned by Readdir().
0097 //!
0098 //! @param  buff   - Pointer to stat structure to be used.
0099 //!
0100 //! @return 0 upon success or -ENOTSUP if not supported.
0101 //!
0102 //! @note This is a one-time call as stat structure is reused for each Readdir.
0103 //! @note When StatRet() is in effect, directory entries that have been
0104 //!       deleted from the target directory are quietly skipped.
0105 //-----------------------------------------------------------------------------
0106 
0107 virtual int     StatRet(struct stat *buff) {return -ENOTSUP;}
0108 
0109 /******************************************************************************/
0110 /*                 F i l e   O r i e n t e d   M e t h o d s                  */
0111 /******************************************************************************/
0112 //-----------------------------------------------------------------------------
0113 //! Change file mode settings.
0114 //!
0115 //! @param  mode   - The new file mode setting.
0116 //!
0117 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0118 //-----------------------------------------------------------------------------
0119 
0120 virtual int     Fchmod(mode_t mode) {return -EISDIR;}
0121 
0122 //-----------------------------------------------------------------------------
0123 //! Flush filesystem cached pages for this file (used for checksums).
0124 //-----------------------------------------------------------------------------
0125 
0126 virtual void    Flush() {}
0127 
0128 //-----------------------------------------------------------------------------
0129 //! Return state information for this file.
0130 //!
0131 //! @param  buf    - Pointer to the structure where info it to be returned.
0132 //!
0133 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0134 //-----------------------------------------------------------------------------
0135 
0136 virtual int     Fstat(struct stat *buf) {return -EISDIR;}
0137 
0138 //-----------------------------------------------------------------------------
0139 //! Synchronize associated file with media (synchronous).
0140 //!
0141 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0142 //-----------------------------------------------------------------------------
0143 
0144 virtual int     Fsync() {return -EISDIR;}
0145 
0146 //-----------------------------------------------------------------------------
0147 //! Synchronize associated file with media (asynchronous).
0148 //!
0149 //! @param  aiop   - Pointer to async I/O request object.
0150 //!
0151 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0152 //-----------------------------------------------------------------------------
0153 
0154 virtual int     Fsync(XrdSfsAio *aiop) {return -EISDIR;}
0155 
0156 //-----------------------------------------------------------------------------
0157 //! Set the size of the associated file.
0158 //!
0159 //! @param  flen   - The new size of the file.
0160 //!
0161 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0162 //-----------------------------------------------------------------------------
0163 
0164 virtual int     Ftruncate(unsigned long long flen) {return -EISDIR;}
0165 
0166 //-----------------------------------------------------------------------------
0167 //! Return the memory mapped characteristics of the file.
0168 //!
0169 //! @param  addr   - Pointer to where the memory mapped address is to be returned.
0170 //!
0171 //! @return If mapped, the size of the file is returned and it memory location
0172 //!         is placed in addr. Otherwise, addr is set to zero and zero is
0173 //!         returned. Note that zero length files cannot be memory mapped.
0174 //-----------------------------------------------------------------------------
0175 
0176 virtual off_t   getMmap(void **addr) {*addr = 0; return 0;}
0177 
0178 //-----------------------------------------------------------------------------
0179 //! Return file compression charectistics.
0180 //!
0181 //! @param  cxidp  - Pointer to where the compression algorithm name returned.
0182 //!
0183 //! @return If the file is compressed, the region size if returned. Otherwise,
0184 //!         zero is returned (file not compressed).
0185 //-----------------------------------------------------------------------------
0186 
0187 virtual int     isCompressed(char *cxidp=0) {(void)cxidp; return 0;}
0188 
0189 //-----------------------------------------------------------------------------
0190 //! Open a file.
0191 //!
0192 //! @param  path   - Pointer to the path of the file to be opened.
0193 //! @param  Oflag  - Standard open flags.
0194 //! @param  Mode   - File open mode (ignored unless creating a file).
0195 //! @param  env    - Reference to environmental information.
0196 //!
0197 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0198 //-----------------------------------------------------------------------------
0199 
0200 virtual int     Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env)
0201                     {return -EISDIR;}
0202 
0203 //-----------------------------------------------------------------------------
0204 //! Read file pages into a buffer and return corresponding checksums.
0205 //!
0206 //! @param  buffer  - pointer to buffer where the bytes are to be placed.
0207 //! @param  offset  - The offset where the read is to start. It must be
0208 //!                   page aligned.
0209 //! @param  rdlen   - The number of bytes to read. The amount must be an
0210 //!                   integral number of XrdSfsPage::Size bytes.
0211 //! @param  csvec   - A vector of entries to be filled with the cooresponding
0212 //!                   CRC32C checksum for each page. It must be size to
0213 //!                   rdlen/XrdSys::PageSize + (rdlen%XrdSys::PageSize != 0)
0214 //! @param  opts    - Processing options (see below).
0215 //!
0216 //! @return >= 0      The number of bytes that placed in buffer upon success.
0217 //! @return  < 0       -errno or -osserr upon failure. (see XrdOssError.hh).
0218 //-----------------------------------------------------------------------------
0219 
0220 // pgRead and pgWrite options as noted.
0221 //
0222 static const uint64_t
0223 Verify       = 0x8000000000000000ULL; //!< all: Verify    checksums
0224 static const uint64_t
0225 doCalc       = 0x4000000000000000ULL; //!< pgw: Calculate checksums
0226 
0227 virtual ssize_t pgRead (void* buffer, off_t offset, size_t rdlen,
0228                         uint32_t* csvec, uint64_t opts);
0229 
0230 //-----------------------------------------------------------------------------
0231 //! Read file pages and checksums using asynchronous I/O.
0232 //!
0233 //! @param  aioparm - Pointer to async I/O object controlling the I/O.
0234 //! @param  opts    - Processing options (see above).
0235 //!
0236 //! @return 0 upon if request started success or -errno or -osserr
0237 //!         (see XrdOssError.hh).
0238 //-----------------------------------------------------------------------------
0239 
0240 virtual int     pgRead (XrdSfsAio* aioparm, uint64_t opts);
0241 
0242 //-----------------------------------------------------------------------------
0243 //! Write file pages into a file with corresponding checksums.
0244 //!
0245 //! @param  buffer  - pointer to buffer containing the bytes to write.
0246 //! @param  offset  - The offset where the write is to start.
0247 //! @param  wrlen   - The number of bytes to write.
0248 //! @param  csvec   - A vector which contains the corresponding CRC32 checksum
0249 //!                   for each page. See XrdOucPgrwUtils::csNum() for sizing.
0250 //! @param  opts    - Processing options (see above).
0251 //!
0252 //! @return >= 0      The number of bytes written upon success.
0253 //!                   or -errno or -osserr upon failure. (see XrdOssError.hh).
0254 //! @return  < 0      -errno or -osserr upon failure. (see XrdOssError.hh).
0255 //-----------------------------------------------------------------------------
0256 
0257 virtual ssize_t pgWrite(void* buffer, off_t offset, size_t wrlen,
0258                         uint32_t* csvec, uint64_t opts);
0259 
0260 //-----------------------------------------------------------------------------
0261 //! Write file pages and checksums using asynchronous I/O.
0262 //!
0263 //! @param  aioparm - Pointer to async I/O object controlling the I/O.
0264 //! @param  opts    - Processing options (see above).
0265 //!
0266 //! @return 0 upon if request started success or -errno or -osserr
0267 //!         (see XrdOssError.hh).
0268 //-----------------------------------------------------------------------------
0269 
0270 virtual int     pgWrite(XrdSfsAio* aioparm, uint64_t opts);
0271 
0272 //-----------------------------------------------------------------------------
0273 //! Preread file blocks into the file system cache.
0274 //!
0275 //! @param  offset  - The offset where the read is to start.
0276 //! @param  size    - The number of bytes to pre-read.
0277 //!
0278 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0279 //-----------------------------------------------------------------------------
0280 
0281 virtual ssize_t Read(off_t offset, size_t size) {return (ssize_t)-EISDIR;}
0282 
0283 //-----------------------------------------------------------------------------
0284 //! Read file bytes into a buffer.
0285 //!
0286 //! @param  buffer  - pointer to buffer where the bytes are to be placed.
0287 //! @param  offset  - The offset where the read is to start.
0288 //! @param  size    - The number of bytes to read.
0289 //!
0290 //! @return >= 0      The number of bytes that placed in buffer.
0291 //! @return  < 0      -errno or -osserr upon failure (see XrdOssError.hh).
0292 //-----------------------------------------------------------------------------
0293 
0294 virtual ssize_t Read(void *buffer, off_t offset, size_t size)
0295                     {return (ssize_t)-EISDIR;}
0296 
0297 //-----------------------------------------------------------------------------
0298 //! Read file bytes using asynchronous I/O.
0299 //!
0300 //! @param  aiop    - Pointer to async I/O object controlling the I/O.
0301 //!
0302 //! @return 0 upon if request started success or -errno or -osserr
0303 //!         (see XrdOssError.hh).
0304 //-----------------------------------------------------------------------------
0305 
0306 virtual int     Read(XrdSfsAio *aiop) {(void)aiop; return (ssize_t)-EISDIR;}
0307 
0308 //-----------------------------------------------------------------------------
0309 //! Read uncompressed file bytes into a buffer.
0310 //!
0311 //! @param  buffer  - pointer to buffer where the bytes are to be placed.
0312 //! @param  offset  - The offset where the read is to start.
0313 //! @param  size    - The number of bytes to read.
0314 //!
0315 //! @return >= 0      The number of bytes that placed in buffer.
0316 //! @return  < 0      -errno or -osserr upon failure (see XrdOssError.hh).
0317 //-----------------------------------------------------------------------------
0318 
0319 virtual ssize_t ReadRaw(void *buffer, off_t offset, size_t size)
0320                        {return (ssize_t)-EISDIR;}
0321 
0322 //-----------------------------------------------------------------------------
0323 //! Read file bytes as directed by the read vector.
0324 //!
0325 //! @param  readV     pointer to the array of read requests.
0326 //! @param  rdvcnt    the number of elements in readV.
0327 //!
0328 //! @return >=0       The numbe of bytes read.
0329 //! @return < 0       -errno or -osserr upon failure (see XrdOssError.hh).
0330 //-----------------------------------------------------------------------------
0331 
0332 virtual ssize_t ReadV(XrdOucIOVec *readV, int rdvcnt);
0333 
0334 //-----------------------------------------------------------------------------
0335 //! Write file bytes from a buffer.
0336 //!
0337 //! @param  buffer  - pointer to buffer where the bytes reside.
0338 //! @param  offset  - The offset where the write is to start.
0339 //! @param  size    - The number of bytes to write.
0340 //!
0341 //! @return >= 0      The number of bytes that were written.
0342 //! @return <  0      -errno or -osserr upon failure (see XrdOssError.hh).
0343 //-----------------------------------------------------------------------------
0344 
0345 virtual ssize_t Write(const void *buffer, off_t offset, size_t size)
0346                      {return (ssize_t)-EISDIR;}
0347 
0348 //-----------------------------------------------------------------------------
0349 //! Write file bytes using asynchronous I/O.
0350 //!
0351 //! @param  aiop    - Pointer to async I/O object controlling the I/O.
0352 //!
0353 //! @return 0 upon if request started success or -errno or -osserr
0354 //!         (see XrdOssError.hh).
0355 //-----------------------------------------------------------------------------
0356 
0357 virtual int     Write(XrdSfsAio *aiop) {(void)aiop; return (ssize_t)-EISDIR;}
0358 
0359 //-----------------------------------------------------------------------------
0360 //! Write file bytes as directed by the write vector.
0361 //!
0362 //! @param  writeV    pointer to the array of write requests.
0363 //! @param  wrvcnt    the number of elements in writeV.
0364 //!
0365 //! @return >=0       The numbe of bytes read.
0366 //! @return < 0       -errno or -osserr upon failure (see XrdOssError.hh).
0367 //-----------------------------------------------------------------------------
0368 
0369 virtual ssize_t WriteV(XrdOucIOVec *writeV, int wrvcnt);
0370 
0371 /******************************************************************************/
0372 /*     C o m m o n   D i r e c t o r y   a n d   F i l e   M e t h o d s      */
0373 /******************************************************************************/
0374 //-----------------------------------------------------------------------------
0375 //! Close a directory or file.
0376 //!
0377 //! @param  retsz     If not nil, where the size of the file is to be returned.
0378 //!
0379 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0380 //-----------------------------------------------------------------------------
0381 
0382 virtual int     Close(long long *retsz=0)=0;
0383 
0384 //-----------------------------------------------------------------------------
0385 //! Return the underlying object type.
0386 //!
0387 //! @return Type of object.
0388 //-----------------------------------------------------------------------------
0389 
0390 // Returned value will have one or more bits set as below.
0391 //
0392 static const uint16_t DF_isDir   = 0x0001;  //!< Object is for a directory
0393 static const uint16_t DF_isFile  = 0x0002;  //!< Object is for a file
0394 static const uint16_t DF_isProxy = 0x0010;  //!< Object is a proxy object
0395 
0396 uint16_t        DFType() {return dfType;}
0397 
0398 //-----------------------------------------------------------------------------
0399 //! Execute a special operation on the directory or file.
0400 //!
0401 //! @param  cmd    - The operation to be performed:
0402 //!                  Fctl_ckpObj - Obtain checkpoint object for proxy file.
0403 //!                                Argument: None.
0404 //!                                Response: Pointer to XrdOucChkPnt object.
0405 //!                  Fctl_utimes - Set atime and mtime (no response).
0406 //!                                Argument: struct timeval tv[2]
0407 //! @param  alen   - Length of data pointed to by args.
0408 //! @param  args   - Data sent with request, zero if alen is zero.
0409 //! @param  resp   - Where the response is to be set. The caller must call
0410 //!                  delete on the returned object.
0411 //!
0412 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0413 //-----------------------------------------------------------------------------
0414 
0415 static const int Fctl_ckpObj = 0;
0416 static const int Fctl_utimes = 1;
0417 
0418 virtual int     Fctl(int cmd, int alen, const char *args, char **resp=0);
0419 
0420 //-----------------------------------------------------------------------------
0421 //! Return the underlying file descriptor.
0422 //!
0423 //! @return -1 if there is no file descriptor or a non-negative FD number.
0424 //-----------------------------------------------------------------------------
0425 
0426 virtual int     getFD() {return -1;} // Must override to support sendfile()
0427 
0428 //-----------------------------------------------------------------------------
0429 //! Return trace identifier associated with this object.
0430 //!
0431 //! @return Pointer to trace identifier
0432 //-----------------------------------------------------------------------------
0433 virtual
0434 const char     *getTID() {return tident;}
0435 
0436 //-----------------------------------------------------------------------------
0437 //! Constructor and Destructor
0438 //!
0439 //! @param  tid    - Pointer to the trace identifier.
0440 //! @param  dftype - The type of the object.
0441 //! @param  fdnum  - The value for the file descriptor.
0442 //-----------------------------------------------------------------------------
0443 
0444                 XrdOssDF(const char *tid="", uint16_t dftype=0, int fdnum=-1)
0445                         : tident(tid), pgwEOF(0), fd(fdnum), dfType(dftype),
0446                           rsvd(0) {}
0447 
0448 virtual        ~XrdOssDF() {}
0449 
0450 
0451 protected:
0452 
0453 const char *tident;  // Trace identifier
0454 off_t       pgwEOF;  // Highest short offset on pgWrite (0 means none yet)
0455 int         fd;      // The associated file descriptor.
0456 uint16_t    dfType;  // Type of this object
0457 short       rsvd;    // Reserved
0458 };
0459 
0460 /******************************************************************************/
0461 /*                        X r d O s s   O p t i o n s                         */
0462 /******************************************************************************/
0463 
0464 // Options that can be passed to Create()
0465 //
0466 #define XRDOSS_mkpath  0x01
0467 #define XRDOSS_new     0x02
0468 #define XRDOSS_Online  0x04
0469 #define XRDOSS_isPFN   0x10
0470 #define XRDOSS_isMIG   0x20
0471 #define XRDOSS_setnoxa 0x40
0472 
0473 // Values returned by Features()
0474 //
0475 #define XRDOSS_HASPGRW 0x0000000000000001ULL
0476 #define XRDOSS_HASFSCS 0x0000000000000002ULL
0477 #define XRDOSS_HASPRXY 0x0000000000000004ULL
0478 #define XRDOSS_HASNOSF 0x0000000000000008ULL
0479 #define XRDOSS_HASCACH 0x0000000000000010ULL
0480 #define XRDOSS_HASNAIO 0x0000000000000020ULL
0481 #define XRDOSS_HASRPXY 0x0000000000000040ULL
0482 #define XRDOSS_HASXERT 0x0000000000000080ULL
0483 
0484 // Options that can be passed to Stat()
0485 //
0486 #define XRDOSS_resonly 0x0001
0487 #define XRDOSS_updtatm 0x0002
0488 #define XRDOSS_preop   0x0004
0489 
0490 // Commands that can be passed to FSctl
0491 //
0492 #define XRDOSS_FSCTLFA 0x0001
0493   
0494 /******************************************************************************/
0495 /*                          C l a s s   X r d O s s                           */
0496 /******************************************************************************/
0497   
0498 class XrdOss
0499 {
0500 public:
0501 
0502 //-----------------------------------------------------------------------------
0503 //! Obtain a new director object to be used for future directory requests.
0504 //!
0505 //! @param  tident - The trace identifier.
0506 //!
0507 //! @return pointer- Pointer to an XrdOssDF object.
0508 //! @return nil    - Insufficient memory to allocate an object.
0509 //-----------------------------------------------------------------------------
0510 
0511 virtual XrdOssDF *newDir(const char *tident)=0;
0512 
0513 //-----------------------------------------------------------------------------
0514 //! Obtain a new file object to be used for a future file requests.
0515 //!
0516 //! @param  tident - The trace identifier.
0517 //!
0518 //! @return pointer- Pointer to an XrdOssDF object.
0519 //! @return nil    - Insufficient memory to allocate an object.
0520 //-----------------------------------------------------------------------------
0521 
0522 virtual XrdOssDF *newFile(const char *tident)=0;
0523 
0524 //-----------------------------------------------------------------------------
0525 //! Change file mode settings.
0526 //!
0527 //! @param  path   - Pointer to the path of the file in question.
0528 //! @param  mode   - The new file mode setting.
0529 //! @param  envP   - Pointer to environmental information.
0530 //!
0531 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0532 //-----------------------------------------------------------------------------
0533 
0534 virtual int       Chmod(const char * path, mode_t mode, XrdOucEnv *envP=0)=0;
0535 
0536 //-----------------------------------------------------------------------------
0537 //! Notify storage system that a client has connected.
0538 //!
0539 //! @param  env    - Reference to environmental information.
0540 //-----------------------------------------------------------------------------
0541 
0542 virtual void      Connect(XrdOucEnv &env);
0543 
0544 //-----------------------------------------------------------------------------
0545 //! Create file.
0546 //!
0547 //! @param  tid    - Pointer to the trace identifier.
0548 //! @param  path   - Pointer to the path of the file to create.
0549 //! @param  mode   - The new file mode setting.
0550 //! @param  env    - Reference to environmental information.
0551 //! @param  opts   - Create options:
0552 //!                  XRDOSS_mkpath - create dir path if it does not exist.
0553 //!                  XRDOSS_new    - the file must not already exist.
0554 //!                  oflags<<8     - open flags shifted 8 bits to the left/
0555 //!
0556 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0557 //-----------------------------------------------------------------------------
0558 
0559 virtual int       Create(const char *tid, const char *path,
0560                          mode_t mode, XrdOucEnv &env,
0561                          int opts=0)=0;
0562 
0563 //-----------------------------------------------------------------------------
0564 //! Notify storage system that a client has disconnected.
0565 //!
0566 //! @param  env    - Reference to environmental information.
0567 //-----------------------------------------------------------------------------
0568 
0569 virtual void      Disc(XrdOucEnv &env);
0570 
0571 //-----------------------------------------------------------------------------
0572 //! Notify storage system of initialization information (deprecated).
0573 //!
0574 //! @param  envP   - Pointer to environmental information.
0575 //-----------------------------------------------------------------------------
0576 
0577 virtual void      EnvInfo(XrdOucEnv *envP);
0578 
0579 //-----------------------------------------------------------------------------
0580 //! Return storage system features.
0581 //!
0582 //! @return Storage system features (see XRDOSS_HASxxx flags).
0583 //-----------------------------------------------------------------------------
0584 
0585 virtual uint64_t  Features();
0586 
0587 //-----------------------------------------------------------------------------
0588 //! Execute a special storage system operation.
0589 //!
0590 //! @param  cmd    - The operation to be performed:
0591 //!                  XRDOSS_FSCTLFA - Perform proxy file attribute operation
0592 //! @param  alen   - Length of data pointed to by args.
0593 //! @param  args   - Data sent with request, zero if alen is zero.
0594 //! @param  resp   - Where the response is to be set, if any.
0595 //!
0596 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0597 //-----------------------------------------------------------------------------
0598 
0599 virtual int       FSctl(int cmd, int alen, const char *args, char **resp=0);
0600 
0601 //-----------------------------------------------------------------------------
0602 //! Initialize the storage system V1 (deprecated).
0603 //!
0604 //! @param  lp     - Pointer to the message logging object.
0605 //! @param  cfn    - Pointer to the configuration file.
0606 //!
0607 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0608 //-----------------------------------------------------------------------------
0609 
0610 virtual int       Init(XrdSysLogger *lp, const char *cfn)=0;
0611 
0612 //-----------------------------------------------------------------------------
0613 //! Initialize the storage system V2.
0614 //!
0615 //! @param  lp     - Pointer to the message logging object.
0616 //! @param  cfn    - Pointer to the configuration file.
0617 //! @param  envP   - Pointer to environmental information.
0618 //!
0619 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0620 //-----------------------------------------------------------------------------
0621 
0622 virtual int       Init(XrdSysLogger *lp, const char *cfn, XrdOucEnv *envP)
0623                       {return Init(lp, cfn);}
0624 
0625 //-----------------------------------------------------------------------------
0626 //! Create a directory.
0627 //!
0628 //! @param  path   - Pointer to the path of the directory to be created.
0629 //! @param  mode   - The directory mode setting.
0630 //! @param  mkpath - When true the path is created if it does not exist.
0631 //! @param  envP   - Pointer to environmental information.
0632 //!
0633 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0634 //-----------------------------------------------------------------------------
0635 
0636 virtual int       Mkdir(const char *path, mode_t mode, int mkpath=0,
0637                         XrdOucEnv  *envP=0)=0;
0638 
0639 //-----------------------------------------------------------------------------
0640 //! Relocate/Copy the file at `path' to a new location.
0641 //!
0642 //! @param  tident - -> trace identifier for this operation.
0643 //! @param  path   - -> fully qualified name of the file to relocate.
0644 //! @param  cgName - -> target space name[:path]
0645 //! @param  anchor - Processing directions (see XrdOssReloc.cc example).
0646 //!
0647 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0648 //-----------------------------------------------------------------------------
0649 
0650 virtual int       Reloc(const char *tident, const char *path,
0651                         const char *cgName, const char *anchor=0);
0652 
0653 //-----------------------------------------------------------------------------
0654 //! Remove a directory.
0655 //!
0656 //! @param  path   - Pointer to the path of the directory to be removed.
0657 //! @param  Opts   - The processing options:
0658 //!                  XRDOSS_Online   - only remove online copy
0659 //!                  XRDOSS_isPFN    - path is already translated.
0660 //! @param  envP   - Pointer to environmental information.
0661 //!
0662 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0663 //-----------------------------------------------------------------------------
0664 
0665 virtual int       Remdir(const char *path, int Opts=0, XrdOucEnv *envP=0)=0;
0666 
0667 //-----------------------------------------------------------------------------
0668 //! Rename a file or directory.
0669 //!
0670 //! @param  oPath   - Pointer to the path to be renamed.
0671 //! @param  nPath   - Pointer to the path oPath is to have.
0672 //! @param  oEnvP   - Environmental information for oPath.
0673 //! @param  nEnvP   - Environmental information for nPath.
0674 //!
0675 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0676 //-----------------------------------------------------------------------------
0677 
0678 virtual int       Rename(const char *oPath, const char *nPath,
0679                          XrdOucEnv  *oEnvP=0, XrdOucEnv *nEnvP=0)=0;
0680 
0681 //-----------------------------------------------------------------------------
0682 //! Return state information on a file or directory.
0683 //!
0684 //! @param  path   - Pointer to the path in question.
0685 //! @param  buff   - Pointer to the structure where info it to be returned.
0686 //! @param  opts   - Options:
0687 //!                  XRDOSS_preop    - this is a stat prior to open.
0688 //!                  XRDOSS_resonly  - only look for resident files.
0689 //!                  XRDOSS_updtatm  - update file access time.
0690 //! @param  envP   - Pointer to environmental information.
0691 //!
0692 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0693 //-----------------------------------------------------------------------------
0694 
0695 virtual int       Stat(const char *path, struct stat *buff,
0696                        int opts=0, XrdOucEnv *envP=0)=0;
0697 
0698 //-----------------------------------------------------------------------------
0699 //! Return statistics.
0700 //!
0701 //! @param  buff   - Pointer to the buffer to hold statistics.
0702 //! @param  blen   - Length of the buffer.
0703 //!
0704 //! @return The number of bytes placed in the buffer excluding null byte.
0705 //-----------------------------------------------------------------------------
0706 
0707 virtual int       Stats(char *buff, int blen) {(void)buff; (void)blen; return 0;}
0708 
0709 //-----------------------------------------------------------------------------
0710 //! Return filesystem physical space information associated with a path.
0711 //!
0712 //! @param  path   - Path in the partition in question.
0713 //! @param  buff   - Pointer to the buffer to hold the information.
0714 //! @param  blen   - Length of the buffer. This is updated with the actual
0715 //!                  number of bytes placed in the buffer as in snprintf().
0716 //! @param  envP   - Pointer to environmental information.
0717 //!
0718 //! @return "<wval> <fsp> <utl> <sval> <fsp> <utl>"
0719 //!         where: <wval> is "0" if XRDEXP_NOTRW specified, otherwise "1"
0720 //!                <fsp>  is free space in megabytes.
0721 //!                <utl>  is percentage utilization (i.e. allocated space)
0722 //!                <sval> is "1' if XRDEXP_STAGE specified, otherwise "0"
0723 //!         Upon failure -errno or -osserr (see XrdOssError.hh) returned.
0724 //-----------------------------------------------------------------------------
0725 
0726 virtual int       StatFS(const char *path, char *buff, int &blen,
0727                          XrdOucEnv  *envP=0);
0728 
0729 //-----------------------------------------------------------------------------
0730 //! Return filesystem physical space information associated with a space name.
0731 //!
0732 //! @param  env    - Ref to environmental information. If the environment
0733 //!                  has the key oss.cgroup defined, the associated value is
0734 //!                  used as the space name and the path is ignored.
0735 //! @param  path   - Path in the name space in question. The space name
0736 //!                  associated with gthe path is used unless overridden.
0737 //! @param  buff   - Pointer to the buffer to hold the information.
0738 //! @param  blen   - Length of the buffer. This is updated with the actual
0739 //!                  number of bytes placed in the buffer as in snprintf().
0740 //!
0741 //! @return "oss.cgroup=<name>&oss.space=<totbytes>&oss.free=<freebytes>
0742 //!          &oss.maxf=<maxcontigbytes>&oss.used=<bytesused>
0743 //!          &oss.quota=<quotabytes>" in buff upon success.
0744 //!         Upon failure -errno or -osserr (see XrdOssError.hh) returned.
0745 //-----------------------------------------------------------------------------
0746 
0747 virtual int       StatLS(XrdOucEnv &env, const char *path,
0748                          char *buff, int &blen);
0749 
0750 //-----------------------------------------------------------------------------
0751 //! Return state information on a resident physical file or directory.
0752 //!
0753 //! @param  path   - Pointer to the path in question.
0754 //! @param  buff   - Pointer to the structure where info it to be returned.
0755 //! @param  opts   - Options:
0756 //!                  PF_dInfo - provide bdevID in st_rdev and partID in st_dev
0757 //!                             based on path. If path is nil then the contents
0758 //!                             of the of buff is used as the input source.
0759 //!                  PF_dNums - provide number of bdev's in st_rdev and the
0760 //!                             number of partitions in st_dev. The path
0761 //!                             argument is ignored. This superceeds PF_dInfo.
0762 //!                  PF_dStat - provide file state flags in st_rdev as shown
0763 //!                             below. Path may not be nil. This supercedes
0764 //!                             PF_dInfo and PF_dNums.
0765 //!                  PF_isLFN - Do N2N translation on path (default is none).
0766 //!
0767 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0768 //-----------------------------------------------------------------------------
0769 
0770 static const int  PF_dInfo = 0x00000001;
0771 static const int  PF_dNums = 0x00000002;
0772 static const int  PF_isLFN = 0x00000004;
0773 static const int  PF_dStat = 0x00000008;
0774 
0775 // Bits returned in st_rdev when PF_dStat specified in opts. Absence of either
0776 // PF_csVer and PF_csVun flags means that the file has no checksums present.
0777 //
0778 static const int  PF_csVer = 0x00000001; //!<   verified file checksums present
0779 static const int  PF_csVun = 0x00000002; //!< unverified file checksums present
0780 
0781 virtual int       StatPF(const char *path, struct stat *buff, int opts);
0782 
0783 virtual int       StatPF(const char *path, struct stat *buff)
0784                         {return StatPF(path, buff, 0);} // Backward compat
0785 
0786 //-----------------------------------------------------------------------------
0787 //! Return space information for a space name.
0788 //!
0789 //! @param  vsP    - Pointer to the XrdOssVSInfo object to hold results.
0790 //!                  It should be fully initialized (i.e. a new copy).
0791 //! @param  sname  - Pointer to the space name. If the name starts with a
0792 //!                  plus (e.g. "+public"), partition information is
0793 //!                  returned, should it exist. If nil, space information for
0794 //!                  all spaces is returned. See, XrdOssVS.hh for more info.
0795 //! @param  updt   - When true, a space update occurrs prior to a query.
0796 //!
0797 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0798 //-----------------------------------------------------------------------------
0799 
0800 virtual int       StatVS(XrdOssVSInfo *vsP, const char *sname=0, int updt=0);
0801 
0802 //-----------------------------------------------------------------------------
0803 //! Return logical extended attributes associated with a path.
0804 //!
0805 //! @param  path   - Path in whose information is wanted.
0806 //! @param  buff   - Pointer to the buffer to hold the information.
0807 //! @param  blen   - Length of the buffer. This is updated with the actual
0808 //!                  number of bytes placed in the buffer as in snprintf().
0809 //! @param  envP   - Pointer to environmental information.
0810 //!
0811 //! @return "oss.cgroup=<name>&oss.type={'f'|'d'|'o'}&oss.used=<totbytes>
0812 //!          &oss.mt=<mtime>&oss.ct=<ctime>&oss.at=<atime>&oss.u=*&oss.g=*
0813 //!          &oss.fs={'w'|'r'}"
0814 //!         Upon failure -errno or -osserr (see XrdOssError.hh) returned.
0815 //-----------------------------------------------------------------------------
0816 
0817 virtual int       StatXA(const char *path, char *buff, int &blen,
0818                          XrdOucEnv *envP=0);
0819 
0820 //-----------------------------------------------------------------------------
0821 //! Return export attributes associated with a path.
0822 //!
0823 //! @param  path   - Path in whose information is wanted.
0824 //! @param  attr   - Reference to where the inforamation is to be stored.
0825 //! @param  envP   - Pointer to environmental information.
0826 //!
0827 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0828 //-----------------------------------------------------------------------------
0829 
0830 virtual int       StatXP(const char *path, unsigned long long &attr,
0831                          XrdOucEnv  *envP=0);
0832 
0833 //-----------------------------------------------------------------------------
0834 //! Truncate a file.
0835 //!
0836 //! @param  path   - Pointer to the path of the file to be truncated.
0837 //! @param  fsize  - The size that the file is to have.
0838 //! @param  envP   - Pointer to environmental information.
0839 //!
0840 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0841 //-----------------------------------------------------------------------------
0842 
0843 virtual int       Truncate(const char *path, unsigned long long fsize,
0844                            XrdOucEnv *envP=0)=0;
0845 
0846 //-----------------------------------------------------------------------------
0847 //! Remove a file.
0848 //!
0849 //! @param  path   - Pointer to the path of the file to be removed.
0850 //! @param  Opts   - Options:
0851 //!                  XRDOSS_isMIG  - this is a migratable path.
0852 //!                  XRDOSS_isPFN  - do not apply name2name to path.
0853 //!                  XRDOSS_Online - remove only the online copy.
0854 //! @param  envP   - Pointer to environmental information.
0855 //!
0856 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0857 //-----------------------------------------------------------------------------
0858 
0859 virtual int       Unlink(const char *path, int Opts=0, XrdOucEnv *envP=0)=0;
0860 
0861                   // Default Name-to-Name Methods
0862 
0863 //-----------------------------------------------------------------------------
0864 //! Translate logical name to physical name V1 (deprecated).
0865 //!
0866 //! @param  Path   - Path in whose information is wanted.
0867 //! @param  buff   - Pointer to the buffer to hold the new path.
0868 //! @param  blen   - Length of the buffer.
0869 //!
0870 //! @return 0 upon success or -errno or -osserr (see XrdOssError.hh).
0871 //-----------------------------------------------------------------------------
0872 
0873 virtual int       Lfn2Pfn(const char *Path, char *buff, int blen)
0874                          {if ((int)strlen(Path) >= blen) return -ENAMETOOLONG;
0875                           strcpy(buff, Path); return 0;
0876                          }
0877 
0878 //-----------------------------------------------------------------------------
0879 //! Translate logical name to physical name V2.
0880 //!
0881 //! @param  Path   - Path in whose information is wanted.
0882 //! @param  buff   - Pointer to the buffer to hold the new path.
0883 //! @param  blen   - Length of the buffer.
0884 //! @param  rc     - Place where failure return code is to be returned:
0885 //!                  -errno or -osserr (see XrdOssError.hh).
0886 //!
0887 //! @return Pointer to the translated path upon success or nil on failure.
0888 //-----------------------------------------------------------------------------
0889 virtual
0890 const char       *Lfn2Pfn(const char *Path, char *buff, int blen, int &rc)
0891                          { (void)buff; (void)blen; rc = 0; return Path;}
0892 
0893 //-----------------------------------------------------------------------------
0894 //! Constructor and Destructor.
0895 //-----------------------------------------------------------------------------
0896 
0897                 XrdOss() {}
0898 virtual        ~XrdOss() {}
0899 };
0900 
0901 /******************************************************************************/
0902 /*           S t o r a g e   S y s t e m   I n s t a n t i a t o r            */
0903 /******************************************************************************/
0904 
0905 //------------------------------------------------------------------------------
0906 //! Get an instance of a configured XrdOss object.
0907 //!
0908 //! @param  native_oss -> object that would have been used as the storage
0909 //!                       system. The object is not initialized (i.e., Init()
0910 //!                       has not yet been called). This allows one to easily
0911 //!                       wrap the native implementation or to completely
0912 //!                       replace it, as needed.
0913 //! @param  Logger     -> The message routing object to be used in conjunction
0914 //!                       with an XrdSysError object for error messages.
0915 //! @param  config_fn  -> The name of the config file.
0916 //! @param  parms      -> Any parameters specified after the path on the
0917 //!                       ofs.osslib directive. If there are no parameters, the
0918 //!                       pointer may be zero.
0919 //! @param  envP       -> **Version2 Only** pointer to environmental info.
0920 //!                       This pointer may be nil if no such information exists.
0921 //!
0922 //! @return Success:   -> an instance of the XrdOss object to be used as the
0923 //!                       underlying storage system.
0924 //!         Failure:      Null pointer which causes initialization to fail.
0925 //!
0926 //! The object creation function must be declared as an extern "C" function
0927 //! in the plug-in shared library as follows:
0928 //------------------------------------------------------------------------------
0929 
0930 //------------------------------------------------------------------------------
0931 //! The typedef that describes the XRdOssStatInfoInit external.
0932 //------------------------------------------------------------------------------
0933 
0934 typedef XrdOss *(*XrdOssGetStorageSystem_t) (XrdOss        *native_oss,
0935                                              XrdSysLogger  *Logger,
0936                                              const char    *config_fn,
0937                                              const char    *parms);
0938 
0939 typedef XrdOss *(*XrdOssGetStorageSystem2_t)(XrdOss       *native_oss,
0940                                              XrdSysLogger *Logger,
0941                                              const char   *config_fn,
0942                                              const char   *parms,
0943                                              XrdOucEnv    *envP);
0944 
0945 typedef XrdOssGetStorageSystem2_t XrdOssAddStorageSystem2_t;
0946 
0947 /*!
0948     extern "C" XrdOss *XrdOssGetStorageSystem(XrdOss       *native_oss,
0949                                               XrdSysLogger *Logger,
0950                                               const char   *config_fn,
0951                                               const char   *parms);
0952 
0953     An alternate entry point may be defined in lieu of the previous entry point.
0954     The plug-in loader looks for this entry point first before reverting to the
0955     older version 1 entry point/ Version 2 differs in that an extra parameter,
0956     the environmental pointer, is passed. Note that this pointer is also
0957     supplied via the EnvInfo() method. This, many times, is not workable as
0958     environmental information is needed as initialization time.
0959 
0960     extern "C" XrdOss *XrdOssGetStorageSystem2(XrdOss       *native_oss,
0961                                                XrdSysLogger *Logger,
0962                                                const char   *config_fn,
0963                                                const char   *parms,
0964                                                XrdOucEnv    *envP);
0965 
0966     When pushing additional wrappers, the following entry point is called
0967     for each library that is stacked. The parameter, curr_oss is the pointer
0968     to the fully initialized oss plugin being wrapped. The function should
0969     return a pointer to the wrapping plug-in or nil upon failure.
0970 
0971     extern "C" XrdOss *XrdOssAddStorageSystem2(XrdOss       *curr_oss,
0972                                                XrdSysLogger *Logger,
0973                                                const char   *config_fn,
0974                                                const char   *parms,
0975                                                XrdOucEnv    *envP);
0976 */
0977 
0978 //------------------------------------------------------------------------------
0979 //! Declare compilation version.
0980 //!
0981 //! Additionally, you *should* declare the xrootd version you used to compile
0982 //! your plug-in. While not currently required, it is highly recommended to
0983 //! avoid execution issues should the class definition change. Declare it as:
0984 //------------------------------------------------------------------------------
0985 
0986 /*! #include "XrdVersion.hh"
0987     XrdVERSIONINFO(XrdOssGetStorageSystem,<name>);
0988 
0989     where <name> is a 1- to 15-character unquoted name identifying your plugin.
0990 */
0991 #endif