Loading...
Searching...
No Matches
XrdSysFAttrBsd.icc
Go to the documentation of this file.
/******************************************************************************/
/* */
/* X r d S y s F A t t r B s d . i c c */
/* */
/* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/extattr.h>
#include "XrdSys/XrdSysFAttr.hh"
/******************************************************************************/
/* X r d S y s F A t t r : : D e l */
/******************************************************************************/
int XrdSysFAttr::Del(const char *Aname, const char *Path, int fd)
{
int ec;
// Remove the attrbiute but ignore errors if it doesn't exist
//
ec = (fd < 0 ? extattr_delete_file(Path, EXTATTR_NAMESPACE_USER, Aname)
: extattr_delete_fd( fd, EXTATTR_NAMESPACE_USER, Aname));
// Diagnose errors but ignore errors if it doesn't exist
//
if (ec) ec = Diagnose("remove", Aname, Path, errno);
return ec;
}
/******************************************************************************/
/* X r d S y s F A t t r : : G e t */
/******************************************************************************/
int XrdSysFAttr::Get(const char *Aname, void *Aval, int Avsz,
const char *Path, int fd)
{
int ec;
// Obtain the attribute.
//
ec = (fd < 0 ? extattr_get_file(Path,EXTATTR_NAMESPACE_USER,Aname,Aval,Avsz)
: extattr_get_fd( fd, EXTATTR_NAMESPACE_USER,Aname,Aval,Avsz));
// Diagnose errors.
//
if (ec < 0) ec = Diagnose("get", Aname, Path, errno);
return ec;
}
/******************************************************************************/
/* X r d S y s F A t t r : : L i s t */
/******************************************************************************/
int XrdSysFAttr::List(AList **aPL, const char *Path, int fd, int getSz)
{
AList *aNew;
char *Buff, *bP, *bEnd;
int ec, Tlen, maxSz = 0, *msP = (getSz ? &maxSz : 0);
// First obtain the amount of storage we will need for the whole list
//
*aPL = 0;
Tlen = (fd < 0 ? extattr_list_file(Path,EXTATTR_NAMESPACE_USER, 0, 0)
: extattr_list_fd( fd,EXTATTR_NAMESPACE_USER, 0, 0));
if (Tlen < 0)
{if ((ec = Diagnose("list", "*", Path, errno)) == -ENOATTR) ec = 0;
return ec;
}
// If we don't have any then just return 0. Otherwise, add 4K to the buffer
// size just in case some one is adding attributes while we get the list.
//
if (!Tlen) return 0;
Tlen += 4096;
// Allocate storage to get the whole list
//
if (!(Buff = (char *)malloc(Tlen))) return -ENOMEM;
// Now get the actual list. We will not recover if someone added an attribute
// since the time we actual determined the size of the buffer we need.
//
Tlen = (fd < 0 ? extattr_list_file(Path,EXTATTR_NAMESPACE_USER, Buff, Tlen)
: extattr_list_fd( fd,EXTATTR_NAMESPACE_USER, Buff, Tlen));
if (Tlen < 0)
{if ((ec = Diagnose("list", "*", Path, errno)) == -ENOATTR) ec = 0;
free(Buff);
return ec;
}
if (!Tlen) return 0;
// Run through the memory and allocate an AList entry for each.
//
#ifdef __ubuntu__
// Ubuntu BSD returns attribute names preceeded by the length.
//
int n, i = 0;
char Vname[256];
while(i < Tlen)
{n = (unsigned char)Buff[i];
strncpy(Vname, &Buff[i+1], n);
Vname[n] = '\0';
if (n && (aNew = getEnt(Path, fd, Vname, *aPL, msP))) *aPL = aNew;
i += (n + 1);
}
#else
bP = Buff; bEnd = Buff+Tlen;
while(bP < bEnd)
{if ((aNew = getEnt(Path, fd, bP, *aPL, msP))) *aPL = aNew;
bP = bP + strlen(bP) + 1;
}
#endif
// All done
//
free(Buff);
return maxSz;
}
/******************************************************************************/
/* X r d S y s F A t t r : : S e t */
/******************************************************************************/
int XrdSysFAttr::Set(const char *Aname, const void *Aval, int Avsz,
const char *Path, int fd, int isNew)
{
int ec;
// Check if we should see if the attribute already exists as BSD always replaces
// or creates attributes, as needed. This is not MT safe, sigh.
//
if (isNew)
{ec = (fd < 0 ? extattr_get_file(Path,EXTATTR_NAMESPACE_USER,Aname,0,0)
: extattr_get_fd( fd, EXTATTR_NAMESPACE_USER,Aname,0,0));
if (ec >= 0) return -EEXIST;
}
// Set the attribute
//
ec = (fd < 0 ? extattr_set_file(Path,EXTATTR_NAMESPACE_USER,Aname,Aval,Avsz)
: extattr_set_fd( fd, EXTATTR_NAMESPACE_USER,Aname,Aval,Avsz));
if (ec < 0 || ec != Avsz)
ec = Diagnose("set", Aname, Path, (ec < 0 ? errno : ENOSPC));
// Return appropriately
//
return ec;
}
ENOATTR
#define ENOATTR
Definition XProtocol.hh:1343
Path
XrdOucString Path
Definition XrdSecpwdSrvAdmin.cc:160
ec
ec
Definition XrdSysFAttrSun.icc:100
XrdSysFAttr.hh
XrdSysXAttr::AList
Definition XrdSysXAttr.hh:53