RFC: new module Linux::xattr

RFC: new module Linux::xattr

am 11.11.2005 20:25:30 von Kevin Goess

This is a new module to work with extended file attributes on Linux
(that's a newish Linux kernel feature that allows you to associate
arbitrary name/value pairs with a file).

I'm proposing Linux::xattr as the namespace (that mirrors the python and
ruby packages). Any comments on the namespace?

Regarding the interface and Perl function names, the command-line tools
in the original attr package from http://acl.bestbits.at/ are named

setfattr
getfattr

and their C library functions are named

attr_set
attr_get
attr_remove

I was going to make the Perl functions look like the command-line tools
and call them

setfattr()
getfattr()
delfattr()

Any comments on that?

Lastly, the early-draft XS for getfattr() is below. If an XS expert
could look at it and let me know if I'm doing anything dumb, dangerous
or un-idiomatic it would greatly advance civilization as we know it. If
more context is desired, the current working code is at
http://kevin.goess.org/software/Linux-xattr-0.01.tar.gz

SV *
getfattr(path, attrname, flags)
const char *path
const char *attrname
int flags
CODE:
char * attrvalue;
char * errstr;
int rc;
STRLEN junklen;
attrvalue = NULL;
junklen = ATTR_MAX_VALUELEN;

//I wonder if it would be faster to pre-allocate a buffer
//and re-use it, but then it wouldn't be thread-safe?
New(1, attrvalue, ATTR_MAX_VALUELEN, char);

rc = attr_get(path,attrname,attrvalue,&junklen,flags);

//uh-oh, attr_get failed
if (rc == -1){

//key not found, just return undef
if(errno == ENOATTR){
XSRETURN_UNDEF;

//print warning and return undef
}else{
New(1, errstr, 1000, char);
warn("attr_get failed: %s",strerror_r(errno,errstr,1000));
Safefree(errstr);
XSRETURN_UNDEF;
}
}
RETVAL = newSVpv(attrvalue, junklen);
Safefree(attrvalue);
OUTPUT:
RETVAL


Thanks a lot.

Re: RFC: new module Linux::xattr

am 12.11.2005 08:29:27 von Ilya Zakharevich

[A complimentary Cc of this posting was sent to
Kevin Goess
], who wrote in article :
> This is a new module to work with extended file attributes on Linux
> (that's a newish Linux kernel feature that allows you to associate
> arbitrary name/value pairs with a file).
>
> I'm proposing Linux::xattr as the namespace (that mirrors the python and
> ruby packages). Any comments on the namespace?

Well, on OS/2 it is called OS2::ExtAttr. Do not know how Win* ports
have it (NTFS has this feature too - actually, it is even easier
to accessible - just open "Filename:FieldName").

> Regarding the interface and Perl function names, the command-line tools
> in the original attr package from http://acl.bestbits.at/ are named
>
> setfattr
> getfattr
>
> and their C library functions are named
>
> attr_set
> attr_get
> attr_remove
>
> I was going to make the Perl functions look like the command-line tools
> and call them

OS2::ExtAttr is supposed to be used mostly via tie(). It comes with
Perl distribution; consult it for details.

Hope this helps,
Ilya