XRootD
Loading...
Searching...
No Matches
XrdSysXAttr.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d S y s X A t t r . c c */
4/* */
5/* (c) 2014 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include <cerrno>
32#include <cstdio>
33#include <cstdlib>
34
35#include "XrdSys/XrdSysError.hh"
36#include "XrdSys/XrdSysXAttr.hh"
37
38/******************************************************************************/
39/* C o p y */
40/******************************************************************************/
41
42int XrdSysXAttr::Copy(const char *iPath, int iFD, const char *oPath, int oFD,
43 const char *Aname)
44{
45 char *bP;
46 int sz, rc = 0;
47
48// Check if all attributes are to be copied. If so, do it.
49//
50 if (!Aname)
51 {AList *aP = 0, *aNow;
52 char *Buff;
53 int maxSz;
54
55 // Get all of the attributes for the input
56 //
57 if ((maxSz = List(&aP, iPath, iFD, 1)) <= 0)
58 return maxSz == 0 || maxSz == -ENOTSUP;
59
60 // Allocate a buffer to hold the largest attribute value (plus some)
61 //
62 maxSz += 4096;
63 Buff = (char *)malloc(maxSz);
64
65 // Get each value and set it
66 //
67 aNow = aP;
68 while(aNow && (rc = Get(aNow->Name, Buff, maxSz, iPath, iFD)) >= 0
69 && (rc = Set(aNow->Name, Buff, aNow->Vlen, oPath, oFD)) >= 0)
70 {aNow = aNow->Next;}
71
72 // Free up resources and return
73 //
74 Free(aP);
75 free(Buff);
76 return rc;
77 }
78
79// First obtain the size of the attribute (if zero ignore it)
80//
81 if ((sz = Get(Aname, 0, 0, iPath, iFD)) <= 0)
82 return (!sz || sz == -ENOTSUP ? 0 : sz);
83
84// Obtain storage
85//
86 if (!(bP = (char *)malloc(sz)))
87 {if (Say)
88 {char eBuff[512];
89 snprintf(eBuff, sizeof(eBuff), "copy attr %s from", Aname);
90 Say->Emsg("XAttr", ENOMEM, eBuff, iPath);
91 }
92 return -ENOMEM;
93 }
94
95// Copy over any extended attributes
96//
97 if ((rc = Get(Aname, bP, sz, iPath, iFD)) > 0)
98 {if ((rc = Set(Aname, bP, rc, oPath, oFD)) < 0 && rc == -ENOTSUP) rc = 0;}
99 else if (rc < 0 && rc == -ENOTSUP) rc = 0;
100
101// All done
102//
103 free(bP);
104 return rc;
105}
106
107/******************************************************************************/
108/* S e t M s g R o u t e */
109/******************************************************************************/
110
112{
113 XrdSysError *msgP = Say;
114 Say = errP;
115 return msgP;
116}
virtual int Copy(const char *iPath, int iFD, const char *oPath, int oFD, const char *Aname=0)
virtual int List(AList **aPL, const char *Path, int fd=-1, int getSz=0)=0
XrdSysError * Say
virtual int Get(const char *Aname, void *Aval, int Avsz, const char *Path, int fd=-1)=0
virtual int Set(const char *Aname, const void *Aval, int Avsz, const char *Path, int fd=-1, int isNew=0)=0
virtual void Free(AList *aPL)=0
virtual XrdSysError * SetMsgRoute(XrdSysError *errP)