43 #include <sys/types.h>
44 #include <sys/param.h>
45 #if defined(__solaris__) || defined(AIX)
46 #include <sys/vnode.h>
117 const int AMode = S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH;
118 char local_path[MAXPATHLEN+1], *p, pc;
119 local_path[0] =
'\0';
120 unsigned long long remotefs;
121 int isLink = 0, Missing = 1, retc = 0, datfd;
131 if ((retc =
GenLocalPath(path, local_path)))
return retc;
135 if ((Missing =
lstat(local_path, &buf))) retc = errno;
136 else {
if ((isLink = ((buf.st_mode & S_IFMT) == S_IFLNK)))
137 {
if (
stat(local_path, &buf))
138 {
if (errno != ENOENT)
return -errno;
139 OssEroute.
Emsg(
"Create",
"removing dangling link",local_path);
140 if (
unlink(local_path)) retc = errno;
141 Missing = 1; isLink = 0;
145 if (retc && retc != ENOENT)
return -retc;
152 access_mode, crInfo.
pOpts);
159 if ((buf.st_mode & S_IFMT) == S_IFDIR)
return -EISDIR;
160 do {datfd =
open(local_path,
Opts>>8, access_mode);}
161 while(datfd < 0 && errno == EINTR);
162 if (datfd < 0)
return -errno;
163 if ((retc =
SetFattr(crInfo, datfd, buf.st_mtime)))
return retc;
164 if (
Opts>>8 & O_TRUNC && buf.st_size)
165 {off_t theSize = buf.st_size;
166 if (isLink) {buf.st_mode = (buf.st_mode & ~S_IFMT) | S_IFLNK;
176 {p++; pc = *p; *p =
'\0';
184 {
char remote_path[MAXPATHLEN+1];
193 {
if ((retc =
MSS_Create(remote_path, access_mode, env)) < 0)
195 <<
" remote path=" <<remote_path);
199 {
if (!(retc =
MSS_Stat(remote_path)))
return -EEXIST;
200 else if (retc != -ENOENT)
return retc;
266 strlen(crInfo.
Path)+1, pbuff, datfd)))
267 {
close(datfd);
return rc;}
272 if ((rc =
SetFattr(crInfo, datfd, 1)))
return rc;
276 if ((symlink(pbuff, crInfo.
Path) && errno != EEXIST)
278 {rc = -errno;
unlink(pbuff);}
296 do {datfd =
open(crInfo.
Path, O_RDWR|O_CREAT|O_TRUNC, crInfo.
Amode);}
297 while(datfd < 0 && errno == EINTR);
298 if (datfd < 0)
return -errno;
303 if ((rc =
SetFattr(crInfo, datfd, 1)))
return rc;
320 int Done(
int rc) {
if (rc)
unlink(
Path);
return rc;}
321 fdCloser(
const char *pn,
int fd) :
Path(pn), theFD(fd) {}
322 ~fdCloser() {
close(theFD);}
323 } Act(crInfo.
Path, fd);
#define Check_RO(act, flags, path, opname)
int stat(const char *path, struct stat *buf)
int open(const char *path, int oflag,...)
int lstat(const char *path, struct stat *buf)
int unlink(const char *path)
static const char * Name()
static int Alloc(allocInfo &aInfo)
static char * Parse(const char *token, char *cbuff, int cblen)
static XrdOssCache_FS * fsfirst
static void Adjust(dev_t devid, off_t size)
XrdOssCreateInfo(const char *path, const char *lfn, mode_t amode, int opts)
static const int minSNbsz
int GenRemotePath(const char *, char *)
virtual int Stage(const char *, const char *, XrdOucEnv &, int, mode_t, unsigned long long)
int SetFattr(XrdOssCreateInfo &crInfo, int datfd, time_t mtime)
int Alloc_Cache(XrdOssCreateInfo &, XrdOucEnv &)
virtual int Create(const char *, const char *, mode_t, XrdOucEnv &, int opts=0)
int GenLocalPath(const char *, char *)
int MSS_Stat(const char *, struct stat *buff=0)
int MSS_Create(const char *path, mode_t, XrdOucEnv &)
int Alloc_Local(XrdOssCreateInfo &, XrdOucEnv &)
char * Get(const char *varname)
XrdOucPList * About(const char *pathname)
void Default(unsigned long long x)
unsigned long long Flag()
static int makePath(char *path, mode_t mode, bool reset=false)
int Set(const char *Path, int fd=-1)
static int a2sz(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
virtual int Set(const char *Aname, const void *Aval, int Avsz, const char *Path, int fd=-1, int isNew=0)=0