mirror of
https://github.com/aaru-dps/fstester.git
synced 2025-12-16 19:24:39 +00:00
Dynamically load setxattr(2) in Linux.
This commit is contained in:
@@ -38,11 +38,11 @@ void DarwinExtendedAttributes(const char* path)
|
||||
FILE* file;
|
||||
int rc;
|
||||
int cRc;
|
||||
_darwin_setxattr setxattr;
|
||||
_darwin_setxattr darwin_setxattr;
|
||||
|
||||
setxattr = (_darwin_setxattr)dlsym(RTLD_DEFAULT, "setxattr");
|
||||
darwin_setxattr = (_darwin_setxattr)dlsym(RTLD_DEFAULT, "setxattr");
|
||||
|
||||
if(!setxattr)
|
||||
if(!darwin_setxattr)
|
||||
{
|
||||
log_write("Error loading setxattr(2) from libSystem: %s\n", dlerror());
|
||||
return;
|
||||
@@ -82,7 +82,7 @@ void DarwinExtendedAttributes(const char* path)
|
||||
{
|
||||
fprintf(file, "This file has an extended attribute called \"com.ibm.os2.comment\" that is 72 bytes long.\n");
|
||||
fclose(file);
|
||||
ret = setxattr("com.ibm.os2.comment", "user.com.ibm.os2.comment", CommentsEA, 72, 0, 0);
|
||||
ret = darwin_setxattr("com.ibm.os2.comment", "user.com.ibm.os2.comment", CommentsEA, 72, 0, 0);
|
||||
|
||||
if(ret) cRc = errno;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ void DarwinExtendedAttributes(const char* path)
|
||||
{
|
||||
fprintf(file, "This file has an extended attribute called \"com.ibm.os2.icon\" that is 3516 bytes long.\n");
|
||||
fclose(file);
|
||||
ret = setxattr("com.ibm.os2.icon", "user.com.ibm.os2.icon", IconEA, 3516, 0, 0);
|
||||
ret = darwin_setxattr("com.ibm.os2.icon", "user.com.ibm.os2.icon", IconEA, 3516, 0, 0);
|
||||
|
||||
if(ret) cRc = errno;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ Aaru Data Preservation Suite
|
||||
Copyright (C) 2011-2021 Natalia Portillo
|
||||
*****************************************************************************/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <features.h>
|
||||
#include <stdio.h>
|
||||
@@ -29,21 +32,26 @@ Copyright (C) 2011-2021 Natalia Portillo
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../log.h"
|
||||
#include "linux.h"
|
||||
#include "xattr.h"
|
||||
|
||||
#if((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 3)) || (__GLIBC__ > 2)
|
||||
#include <sys/xattr.h>
|
||||
#endif
|
||||
#include "../log.h"
|
||||
#include "linux.h"
|
||||
|
||||
void LinuxExtendedAttributes(const char* path)
|
||||
{
|
||||
#if((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 3)) || (__GLIBC__ > 2)
|
||||
int ret;
|
||||
FILE* file;
|
||||
int rc;
|
||||
int cRc;
|
||||
int ret;
|
||||
FILE* file;
|
||||
int rc;
|
||||
int cRc;
|
||||
_linux_setxattr linux_setxattr;
|
||||
|
||||
linux_setxattr = (_linux_setxattr)dlsym(RTLD_DEFAULT, "setxattr");
|
||||
|
||||
if(!linux_setxattr)
|
||||
{
|
||||
log_write("Error loading setxattr(2) from libc: %s\n", dlerror());
|
||||
return;
|
||||
}
|
||||
|
||||
ret = chdir(path);
|
||||
|
||||
@@ -79,7 +87,7 @@ void LinuxExtendedAttributes(const char* path)
|
||||
{
|
||||
fprintf(file, "This file has an extended attribute called \"com.ibm.os2.comment\" that is 72 bytes long.\n");
|
||||
fclose(file);
|
||||
ret = setxattr("com.ibm.os2.comment", "user.com.ibm.os2.comment", CommentsEA, 72, XATTR_CREATE);
|
||||
ret = linux_setxattr("com.ibm.os2.comment", "user.com.ibm.os2.comment", CommentsEA, 72, 0);
|
||||
|
||||
if(ret) cRc = errno;
|
||||
}
|
||||
@@ -93,10 +101,9 @@ void LinuxExtendedAttributes(const char* path)
|
||||
{
|
||||
fprintf(file, "This file has an extended attribute called \"com.ibm.os2.icon\" that is 3516 bytes long.\n");
|
||||
fclose(file);
|
||||
ret = setxattr("com.ibm.os2.icon", "user.com.ibm.os2.icon", IconEA, 3516, XATTR_CREATE);
|
||||
ret = linux_setxattr("com.ibm.os2.icon", "user.com.ibm.os2.icon", IconEA, 3516, 0);
|
||||
|
||||
if(ret) cRc = errno;
|
||||
}
|
||||
log_write("\tFile with an extended attribute called \"com.ibm.os2.icon\", rc = %d, cRc = %d\n", rc, cRc);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ Copyright (C) 2011-2021 Natalia Portillo
|
||||
#ifndef AARU_FSTESTER_SETTER_SRC_LINUX_XATTR_H_
|
||||
#define AARU_FSTESTER_SETTER_SRC_LINUX_XATTR_H_
|
||||
|
||||
typedef int (*_linux_setxattr)(const char* path, const char* name, const void* value, size_t size, int flags);
|
||||
|
||||
static unsigned char CommentsEA[72] = {
|
||||
0x45, 0x00, 0x00, 0x00, 0x00, 0x09, 0x33, 0x00, 0x2E, 0x43, 0x4F, 0x4D, 0x4D, 0x45, 0x4E, 0x54, 0x53, 0x00,
|
||||
0xFD, 0xFF, 0x2E, 0x00, 0x54, 0x68, 0x69, 0x73, 0x20, 0x45, 0x41, 0x20, 0x63, 0x6F, 0x6E, 0x74, 0x61, 0x69,
|
||||
|
||||
Reference in New Issue
Block a user