man-pages/man2/getxattr.2.html
2021-03-31 01:06:50 +01:00

246 lines
6.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GETXATTR</TITLE>
</HEAD><BODY>
<H1>GETXATTR</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
getxattr, lgetxattr, fgetxattr - retrieve an extended attribute value
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/sys/xattr.h">sys/xattr.h</A>&gt;</B>
<B>ssize_t getxattr(const char&nbsp;*</B><I>path</I><B>, const char&nbsp;*</B><I>name</I><B>,</B>
<B> void&nbsp;*</B><I>value</I><B>, size_t </B><I>size</I><B>);</B>
<B>ssize_t lgetxattr(const char&nbsp;*</B><I>path</I><B>, const char&nbsp;*</B><I>name</I><B>,</B>
<B> void&nbsp;*</B><I>value</I><B>, size_t </B><I>size</I><B>);</B>
<B>ssize_t fgetxattr(int </B><I>fd</I><B>, const char&nbsp;*</B><I>name</I><B>,</B>
<B> void&nbsp;*</B><I>value</I><B>, size_t </B><I>size</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
Extended attributes are
<I>name</I>:<I>value</I>
pairs associated with inodes (files, directories, symbolic links, etc.).
They are extensions to the normal attributes which are associated
with all inodes in the system (i.e., the
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2)
data).
A complete overview of extended attributes concepts can be found in
<B><A HREF="/cgi-bin/man/man2html?7+xattr">xattr</A></B>(7).
<P>
<B>getxattr</B>()
retrieves the value of the extended attribute identified by
<I>name</I>
and associated with the given
<I>path</I>
in the filesystem.
The attribute value is placed in the buffer pointed to by
<I>value</I>;
<I>size</I>
specifies the size of that buffer.
The return value of the call is the number of bytes placed in
<I>value</I>.
<P>
<B>lgetxattr</B>()
is identical to
<B>getxattr</B>(),
except in the case of a symbolic link, where the link itself is
interrogated, not the file that it refers to.
<P>
<B>fgetxattr</B>()
is identical to
<B>getxattr</B>(),
only the open file referred to by
<I>fd</I>
(as returned by
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2))
is interrogated in place of
<I>path</I>.
<P>
An extended attribute
<I>name</I>
is a null-terminated string.
The name includes a namespace prefix; there may be several, disjoint
namespaces associated with an individual inode.
The value of an extended attribute is a chunk of arbitrary textual or
binary data that was assigned using
<B><A HREF="/cgi-bin/man/man2html?2+setxattr">setxattr</A></B>(2).
<P>
If
<I>size</I>
is specified as zero, these calls return the current size of the
named extended attribute (and leave
<I>value</I>
unchanged).
This can be used to determine the size of the buffer that
should be supplied in a subsequent call.
(But, bear in mind that there is a possibility that the
attribute value may change between the two calls,
so that it is still necessary to check the return status
from the second call.)
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, these calls return a nonnegative value which is
the size (in bytes) of the extended attribute value.
On failure, -1 is returned and
<I>errno</I>
is set appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>E2BIG</B>
<DD>
The size of the attribute value is larger than the maximum size allowed; the
attribute cannot be retrieved.
This can happen on filesystems that support
very large attribute values such as NFSv4, for example.
<DT id="2"><B>ENODATA</B>
<DD>
The named attribute does not exist, or the process has no access to
this attribute.
<DT id="3"><B>ENOTSUP</B>
<DD>
Extended attributes are not supported by the filesystem, or are disabled.
<DT id="4"><B>ERANGE</B>
<DD>
The
<I>size</I>
of the
<I>value</I>
buffer is too small to hold the result.
</DL>
<P>
In addition, the errors documented in
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2)
can also occur.
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
These system calls have been available on Linux since kernel 2.4;
glibc support is provided since version 2.3.
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
These system calls are Linux-specific.
<A NAME="lbAI">&nbsp;</A>
<H2>EXAMPLE</H2>
See
<B><A HREF="/cgi-bin/man/man2html?2+listxattr">listxattr</A></B>(2).
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+getfattr">getfattr</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+setfattr">setfattr</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+listxattr">listxattr</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+removexattr">removexattr</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+setxattr">setxattr</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?7+symlink">symlink</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+xattr">xattr</A></B>(7)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="5"><A HREF="#lbAB">NAME</A><DD>
<DT id="6"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="7"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="8"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="9"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="10"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="11"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="12"><A HREF="#lbAI">EXAMPLE</A><DD>
<DT id="13"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="14"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:32 GMT, March 31, 2021
</BODY>
</HTML>