]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libhandle/handle.c
add lpath_to_handle to libhandle
[thirdparty/xfsprogs-dev.git] / libhandle / handle.c
index 935dcb65318aecf47e979eba73e54d7adf820970..6c9380de3b29049fde4942b46bf5dc60f8bac6b8 100644 (file)
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <xfs/libxfs.h>
-
-/* attributes.h (purposefully) unavailable to xfsprogs, make do */
-struct attrlist_cursor { __u32 opaque[4]; };
-
+#include <xfs/xfs.h>
 #include <xfs/handle.h>
+#include <xfs/parent.h>
 
 /* just pick a value we know is more than big enough */
 #define        MAXHANSIZ       64
@@ -113,17 +110,30 @@ path_to_handle(
        char            *path,          /* input,  path to convert */
        void            **hanp,         /* output, pointer to data */
        size_t          *hlen)          /* output, size of returned data */
+{
+       return lpath_to_handle(path, path, hanp, hlen);
+}
+
+/* Like path_to_handle, but reliable for paths which are either dangling
+ * symlinks or symlinks whose targets are not in XFS filesystems.
+ */
+int
+lpath_to_handle(
+       char            *fspath,        /* input,  path in filesystem */
+       char            *path,          /* input,  path to convert */
+       void            **hanp,         /* output, pointer to data */
+       size_t          *hlen)          /* output, size of returned data */
 {
        int             fd;
        int             result;
        comarg_t        obj;
 
-       fd = open(path, O_RDONLY);
+       fd = open(fspath, O_RDONLY);
        if (fd < 0)
                return -1;
 
        obj.path = path;
-       result = obj_to_handle(path, fd, XFS_IOC_PATH_TO_HANDLE,
+       result = obj_to_handle(fspath, fd, XFS_IOC_PATH_TO_HANDLE,
                                obj, hanp, hlen);
        close(fd);
        return result;
@@ -346,7 +356,7 @@ attr_list_by_handle(
        int             flags,
        struct attrlist_cursor *cursor)
 {
-       int             fd;
+       int             error, fd;
        char            *path;
        xfs_fsop_attrlist_handlereq_t alhreq;
 
@@ -363,10 +373,41 @@ attr_list_by_handle(
 
        memcpy(&alhreq.pos, cursor, sizeof(alhreq.pos));
        alhreq.flags = flags;
-       alhreq.buflen = bufsize;
        alhreq.buffer = buf;
+       alhreq.buflen = bufsize;
+       /* prevent needless EINVAL from the kernel */
+       if (alhreq.buflen > XATTR_LIST_MAX)
+               alhreq.buflen = XATTR_LIST_MAX;
+
+       error = xfsctl(path, fd, XFS_IOC_ATTRLIST_BY_HANDLE, &alhreq);
 
-       return xfsctl(path, fd, XFS_IOC_ATTRLIST_BY_HANDLE, &alhreq);
+       memcpy(cursor, &alhreq.pos, sizeof(alhreq.pos));
+       return error;
+}
+
+int
+parents_by_handle(
+       void            *hanp,
+       size_t          hlen,
+       parent_t        *buf,
+       size_t          bufsiz,
+       unsigned int    *count)
+       
+{
+       errno = EOPNOTSUPP;
+       return -1;
+}
+
+int
+parentpaths_by_handle(
+       void            *hanp,
+       size_t          hlen,
+       parent_t        *buf,
+       size_t          bufsiz,
+       unsigned int    *count)
+{
+       errno = EOPNOTSUPP;
+       return -1;
 }
 
 int