summaryrefslogtreecommitdiff
path: root/src/libostree/ostree-core.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2022-05-07 13:51:31 -0400
committerColin Walters <walters@verbum.org>2022-05-09 12:33:38 -0400
commitf79b2cea91fc54a84e1f7c3f370dbad6e82f1954 (patch)
tree9f10fe73cc0d75494fbbe6d7a34124c31a557457 /src/libostree/ostree-core.c
parent22b8324019da3cff9effc7b8c1131ba2f0828877 (diff)
downloadostree-f79b2cea91fc54a84e1f7c3f370dbad6e82f1954.tar.gz
Add APIs to get xattrs from disk
I'm aiming to do some more work on the Rust side around `fsck` like functionality, and this is a useful primitive. There isn't a great Rust crate for xattrs, and I think it's better to share this code.
Diffstat (limited to 'src/libostree/ostree-core.c')
-rw-r--r--src/libostree/ostree-core.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 794f0e11..56b381d9 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -837,6 +837,51 @@ gboolean ostree_break_hardlink (int dfd,
}
/**
+ * ostree_fs_get_all_xattrs:
+ * @fd: File descriptor
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Retrieve all extended attributes in a canonical (sorted) order from
+ * the given file descriptor.
+ *
+ * Returns: (transfer full): A GVariant of type `a(ayay)`
+ */
+GVariant *
+ostree_fs_get_all_xattrs (int fd, GCancellable *cancellable, GError **error)
+{
+ GVariant *ret = NULL;
+ if (!glnx_fd_get_all_xattrs (fd, &ret, cancellable, error))
+ return NULL;
+ return ret;
+}
+
+/**
+ * ostree_fs_get_all_xattrs_at:
+ * @dfd: Directory file descriptor
+ * @path: Filesystem path
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Retrieve all extended attributes in a canonical (sorted) order from
+ * the given path, relative to the provided directory file descriptor.
+ * The target path will not be dereferenced. Currently on Linux, this
+ * API must be used currently to retrieve extended attributes
+ * for symbolic links because while `O_PATH` exists, it cannot be used
+ * with `fgetxattr()`.
+ *
+ * Returns: (transfer full): A GVariant of type `a(ayay)`
+ */
+GVariant *
+ostree_fs_get_all_xattrs_at (int dfd, const char *path, GCancellable *cancellable, GError **error)
+{
+ GVariant *ret = NULL;
+ if (!glnx_dfd_name_get_all_xattrs (dfd, path, &ret, cancellable, error))
+ return NULL;
+ return ret;
+}
+
+/**
* ostree_checksum_file_from_input:
* @file_info: File information
* @xattrs: (allow-none): Optional extended attributes
@@ -928,8 +973,8 @@ ostree_checksum_file (GFile *f,
g_autoptr(GVariant) xattrs = NULL;
if (objtype == OSTREE_OBJECT_TYPE_FILE)
{
- if (!glnx_dfd_name_get_all_xattrs (AT_FDCWD, gs_file_get_path_cached (f),
- &xattrs, cancellable, error))
+ xattrs = ostree_fs_get_all_xattrs_at (AT_FDCWD, gs_file_get_path_cached (f), cancellable, error);
+ if (!xattrs)
return FALSE;
}