Click here to get back home

RFC: new module Linux::xattr

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
RFC: new module Linux::xattr Kevin Goess 11-11-2005
Posted by Kevin Goess on November 11, 2005, 11:25 am
Please log in for more thread options


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.


Posted by Ilya Zakharevich on November 12, 2005, 7:29 am
Please log in for more thread options


[A complimentary Cc of this posting was sent to
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?

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


Similar ThreadsPosted
What Is Linux? December 31, 2007, 10:07 am
Is there any method/way to use API(Windows or Linux) November 30, 2006, 7:26 am
Problems finding gd.pm in perl 5.8.6 using linux February 16, 2006, 4:59 pm
VC++ Application Connecting PostgreSQL on Linux February 17, 2006, 2:11 am
Urgent Need for Sr.Perl/Linux Programmer July 17, 2008, 3:44 pm
flood coming to vmware.for-linux.experimental August 7, 2007, 3:32 pm
A c program which printing the tag value of a xml file using expat parser in linux environment October 25, 2007, 7:05 am
[RESOLVED] DBD::mysql unresolved symbol _intel_fast_memcpy & mysql-standard-5.0.22-linux-i686-icc-glibc23 August 29, 2006, 6:33 pm
Lower case module name for non-pragma module January 4, 2005, 10:19 am
RFC: New module 'Module::Bundled::Files' August 26, 2005, 3:49 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap