54 #if defined(_GFAL2_API_) || defined(GFAL2_API_) || defined(_GFAL2_API) || defined(_GFAL2_API_H_) || defined(GFAL2_API_H_) || defined(_GFAL2_API_H) 
   55 #define gfal_lseek64   gfal_lseek 
   56 #define gfal_open64    gfal_open 
   57 #define gfal_readdir64 gfal_readdir 
   58 #define gfal_stat64    gfal_stat 
   59 #define dirent64       dirent 
   66 ClassImp(TGFALSystem);
 
   80 TGFALFile::TGFALFile(
const char *url, Option_t *option, 
const char *ftitle,
 
   82          : TFile(url, 
"NET", ftitle, compress)
 
   92    Bool_t create   = (fOption == 
"CREATE") ? kTRUE : kFALSE;
 
   93    Bool_t recreate = (fOption == 
"RECREATE") ? kTRUE : kFALSE;
 
   94    Bool_t update   = (fOption == 
"UPDATE") ? kTRUE : kFALSE;
 
   95    Bool_t read     = (fOption == 
"READ") ? kTRUE : kFALSE;
 
   96    if (!create && !recreate && !update && !read) {
 
  103    if ((fname = gSystem->ExpandPathName(fUrl.GetFileAndOptions()))) {
 
  106       fname = (
char *)stmp.Data();
 
  108       Error(
"TGFALFile", 
"error expanding path %s", fUrl.GetFileAndOptions());
 
  113       if (::gfal_access(fname, kFileExists) == 0)
 
  114          ::gfal_unlink(fname);
 
  119    if (create && ::gfal_access(fname, kFileExists) == 0) {
 
  120       Error(
"TGFALFile", 
"file %s already exists", fname);
 
  124       if (::gfal_access(fname, kFileExists) != 0) {
 
  128       if (update && ::gfal_access(fname, kWritePermission) != 0) {
 
  129          Error(
"TGFALFile", 
"no write permission, could not open file %s", fname);
 
  134 #ifdef GFAL_ACCESS_FIXED 
  135       if (::gfal_access(fname, kFileExists) != 0) {
 
  136          Error(
"TGFALFile", 
"file %s does not exist", fname);
 
  139       if (::gfal_access(fname, kReadPermission) != 0) {
 
  140          Error(
"TGFALFile", 
"no read permission, could not open file %s", fname);
 
  149    if (create || update) {
 
  151       fD = SysOpen(fname, O_RDWR | O_CREAT, 0644);
 
  153       fD = SysOpen(fname, O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
 
  156          SysError(
"TGFALFile", 
"file %s can not be opened", fname);
 
  162       fD = SysOpen(fname, O_RDONLY, 0644);
 
  164       fD = SysOpen(fname, O_RDONLY | O_BINARY, S_IREAD | S_IWRITE);
 
  167          SysError(
"TGFALFile", 
"file %s can not be opened for reading", fname);
 
  186 TGFALFile::~TGFALFile()
 
  194 Int_t TGFALFile::SysOpen(
const char *pathname, Int_t flags, UInt_t mode)
 
  196    Int_t ret = ::gfal_open64(pathname, flags, (Int_t) mode);
 
  204 Int_t TGFALFile::SysClose(Int_t fd)
 
  206    Int_t ret = ::gfal_close(fd);
 
  214 Int_t TGFALFile::SysRead(Int_t fd, 
void *buf, Int_t len)
 
  216    Int_t ret = ::gfal_read(fd, buf, len);
 
  224 Int_t TGFALFile::SysWrite(Int_t fd, 
const void *buf, Int_t len)
 
  226    Int_t ret = ::gfal_write(fd, buf, len);
 
  236 Long64_t TGFALFile::SysSeek(Int_t fd, Long64_t offset, Int_t whence)
 
  238    Long64_t ret = ::gfal_lseek64(fd, offset, whence);
 
  247 Int_t TGFALFile::SysStat(Int_t , Long_t *
id, Long64_t *size, Long_t *flags,
 
  250    struct stat64 &statbuf = fStatBuffer;
 
  252    if (fOption != 
"READ" || !fStatCached) {
 
  256       if (::gfal_stat64(fRealName, &statbuf) >= 0)
 
  262          *
id = (statbuf.st_dev << 24) + statbuf.st_ino;
 
  264          *size = statbuf.st_size;
 
  266          *modtime = statbuf.st_mtime;
 
  269          if (statbuf.st_mode & ((S_IEXEC)|(S_IEXEC>>3)|(S_IEXEC>>6)))
 
  271          if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
 
  273          if ((statbuf.st_mode & S_IFMT) != S_IFREG &&
 
  274              (statbuf.st_mode & S_IFMT) != S_IFDIR)
 
  287 Bool_t TGFALFile::ReadBuffer(
char *buf, Int_t len)
 
  290    if ((st = ReadBufferViaCache(buf, len))) {
 
  296    return TFile::ReadBuffer(buf, len);
 
  303 Bool_t TGFALFile::ReadBuffer(
char *buf, Long64_t pos, Int_t len)
 
  307    if ((st = ReadBufferViaCache(buf, len))) {
 
  313    return TFile::ReadBuffer(buf, pos, len);
 
  320 Bool_t TGFALFile::WriteBuffer(
const char *buf, Int_t len)
 
  322    if (!IsOpen() || !fWritable) 
return kTRUE;
 
  325    if ((st = WriteBufferViaCache(buf, len))) {
 
  331    return TFile::WriteBuffer(buf, len);
 
  344 TGFALSystem::TGFALSystem() : TSystem(
"-gfal", 
"GFAL Helper System")
 
  355 Int_t TGFALSystem::MakeDirectory(
const char *dir)
 
  359    Int_t ret = ::gfal_mkdir(url.GetFileAndOptions(), 0755);
 
  368 void *TGFALSystem::OpenDirectory(
const char *dir)
 
  371       Error(
"OpenDirectory", 
"invalid directory pointer (should never happen)");
 
  379    if (::gfal_stat64(url.GetFileAndOptions(), &finfo) < 0)
 
  382    if ((finfo.st_mode & S_IFMT) != S_IFDIR)
 
  385    fDirp = (
void*) ::gfal_opendir(url.GetFileAndOptions());
 
  393 void TGFALSystem::FreeDirectory(
void *dirp)
 
  396       Error(
"FreeDirectory", 
"invalid directory pointer (should never happen)");
 
  401       ::gfal_closedir((DIR*)dirp);
 
  409 const char *TGFALSystem::GetDirEntry(
void *dirp)
 
  412       Error(
"GetDirEntry", 
"invalid directory pointer (should never happen)");
 
  419       dp = ::gfal_readdir64((DIR*)dirp);
 
  433 Int_t TGFALSystem::GetPathInfo(
const char *path, FileStat_t &buf)
 
  439    if (path && ::gfal_stat64(url.GetFileAndOptions(), &sbuf) >= 0) {
 
  441       buf.fDev    = sbuf.st_dev;
 
  442       buf.fIno    = sbuf.st_ino;
 
  443       buf.fMode   = sbuf.st_mode;
 
  444       buf.fUid    = sbuf.st_uid;
 
  445       buf.fGid    = sbuf.st_gid;
 
  446       buf.fSize   = sbuf.st_size;
 
  447       buf.fMtime  = sbuf.st_mtime;
 
  448       buf.fIsLink = kFALSE;
 
  460 Bool_t TGFALSystem::AccessPathName(
const char *path, EAccessMode mode)
 
  464    if (::gfal_access(url.GetFileAndOptions(), mode) == 0)