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.
This commit is contained in:
Colin Walters committed 2022-05-09 12:33:38 -04:00
1 parent 22b8324019
commit f79b2cea91
8 files changed
+148 -14

No files matched your search

+5 -1
View File
@@ -20,7 +20,11 @@
- uncomment the include in Makefile-libostree.am
*/
LIBOSTREE_2022.4 {
global:
ostree_fs_get_all_xattrs;
ostree_fs_get_all_xattrs_at;
} LIBOSTREE_2021.5;
/* Stub section for the stable release *after* this development one; don't
* edit this other than to update the year. This is just a copy/paste
+47 -2
View File
@@ -836,6 +836,51 @@ gboolean ostree_break_hardlink (int dfd,
return TRUE;
}
/**
* 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
@@ -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;
}
+6
View File
@@ -464,6 +464,12 @@ gboolean ostree_break_hardlink (int dfd,
GCancellable *cancellable,
GError **error);
_OSTREE_PUBLIC
GVariant *ostree_fs_get_all_xattrs (int fd, GCancellable *cancellable, GError **error);
_OSTREE_PUBLIC
GVariant *ostree_fs_get_all_xattrs_at (int dfd, const char *path, GCancellable *cancellable, GError **error);
/**
* OstreeChecksumFlags:
* @OSTREE_CHECKSUM_FLAGS_NONE: Default checksumming without tweaks.
+6 -5
View File
@@ -3436,14 +3436,15 @@ get_final_xattrs (OstreeRepo *self,
else if (dfd_subpath == NULL)
{
g_assert (dfd != -1);
if (!glnx_fd_get_all_xattrs (dfd, &original_xattrs, cancellable, error))
original_xattrs = ostree_fs_get_all_xattrs (dfd, cancellable, error);
if (!original_xattrs)
return FALSE;
}
else
{
g_assert (dfd != -1);
if (!glnx_dfd_name_get_all_xattrs (dfd, dfd_subpath, &original_xattrs,
cancellable, error))
original_xattrs = ostree_fs_get_all_xattrs_at (dfd, dfd_subpath, cancellable, error);
if (!original_xattrs)
return FALSE;
}
@@ -4641,8 +4642,8 @@ import_one_object_direct (OstreeRepo *dest_repo,
if (src_repo->mode == OSTREE_REPO_MODE_BARE)
{
g_autoptr(GVariant) xattrs = NULL;
if (!glnx_fd_get_all_xattrs (src_fd, &xattrs,
cancellable, error))
xattrs = ostree_fs_get_all_xattrs (src_fd, cancellable, error);
if (!xattrs)
return FALSE;
if (!glnx_fd_set_all_xattrs (tmp_dest.fd, xattrs,
cancellable, error))
+7 -3
View File
@@ -28,6 +28,7 @@
#include <gio/gunixoutputstream.h>
#include <gio/gfiledescriptorbased.h>
#include "libglnx.h"
#include "ostree-core.h"
#include "otutil.h"
#include <glnx-console.h>
#include <linux/magic.h>
@@ -4345,9 +4346,12 @@ _ostree_repo_load_file_bare (OstreeRepo *self,
{
if (self->disable_xattrs)
ret_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0));
else if (!glnx_fd_get_all_xattrs (fd, &ret_xattrs,
cancellable, error))
return FALSE;
else
{
ret_xattrs = ostree_fs_get_all_xattrs (fd, cancellable, error);
if (!ret_xattrs)
return FALSE;
}
}
else if (S_ISLNK (stbuf.st_mode) && out_xattrs)
{