LCOV - code coverage report
Current view: top level - vhd/lib - xattr.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 10 0.0 %
Date: 2025-03-10 18:15:27 Functions: 0 2 0.0 %
Branches: 0 6 0.0 %

           Branch data     Line data    Source code
       1                 :            : #include "xattr.h"
       2                 :            : 
       3                 :            : #include <errno.h>
       4                 :            : #include <unistd.h>
       5                 :            : #include <string.h>
       6                 :            : #include <features.h>
       7                 :            : 
       8                 :            : #ifndef ENOATTR
       9                 :            : # define ENOATTR ENODATA        /* No such attribute */
      10                 :            : #endif
      11                 :            : 
      12                 :            : #if defined (__i386__)
      13                 :            : # define HAVE_XATTR_SYSCALLS 1
      14                 :            : # define __NR_fsetxattr         228
      15                 :            : # define __NR_fgetxattr         231
      16                 :            : #elif defined (__sparc__)
      17                 :            : # define HAVE_XATTR_SYSCALLS 1
      18                 :            : # define __NR_fsetxattr         171
      19                 :            : # define __NR_fgetxattr         177
      20                 :            : #elif defined (__ia64__)
      21                 :            : # define HAVE_XATTR_SYSCALLS 1
      22                 :            : # define __NR_fsetxattr         1219
      23                 :            : # define __NR_fgetxattr         1222
      24                 :            : #elif defined (__powerpc__)
      25                 :            : # define HAVE_XATTR_SYSCALLS 1
      26                 :            : # define __NR_fsetxattr         211
      27                 :            : # define __NR_fgetxattr         214
      28                 :            : #elif defined (__x86_64__)
      29                 :            : # define HAVE_XATTR_SYSCALLS 1
      30                 :            : # define __NR_fsetxattr         190
      31                 :            : # define __NR_fgetxattr         193
      32                 :            : #elif defined (__s390__)
      33                 :            : # define HAVE_XATTR_SYSCALLS 1
      34                 :            : # define __NR_fsetxattr         226
      35                 :            : # define __NR_fgetxattr         229
      36                 :            : #elif defined (__arm__)
      37                 :            : # define HAVE_XATTR_SYSCALLS 1
      38                 :            : # if defined(__ARM_EABI__) || defined(__thumb__)
      39                 :            : #  define __NR_SYSCALL_BASE 0
      40                 :            : # else
      41                 :            : #  define __NR_SYSCALL_BASE 0x900000
      42                 :            : # endif
      43                 :            : # define __NR_fsetxattr         (__NR_SYSCALL_BASE+228)
      44                 :            : # define __NR_fgetxattr         (__NR_SYSCALL_BASE+231)
      45                 :            : #elif defined (__mips64)
      46                 :            : # define HAVE_XATTR_SYSCALLS 1
      47                 :            : # ifdef __LP64__ /* mips64 using n64 ABI */
      48                 :            : #  define __NR_Linux 5000
      49                 :            : # else /* mips64 using n32 ABI */
      50                 :            : #  define __NR_Linux 6000
      51                 :            : # endif
      52                 :            : # define __NR_fsetxattr         (__NR_Linux + 182)
      53                 :            : # define __NR_fgetxattr         (__NR_Linux + 185)
      54                 :            : #elif defined (__mips__) /* mips32, or mips64 using o32 ABI */
      55                 :            : # define HAVE_XATTR_SYSCALLS 1
      56                 :            : # define __NR_Linux 4000
      57                 :            : # define __NR_fsetxattr         (__NR_Linux + 226)
      58                 :            : # define __NR_fgetxattr         (__NR_Linux + 229)
      59                 :            : #elif defined (__alpha__)
      60                 :            : # define HAVE_XATTR_SYSCALLS 1
      61                 :            : # define __NR_fsetxattr         384
      62                 :            : # define __NR_fgetxattr         387
      63                 :            : #elif defined (__mc68000__)
      64                 :            : # define HAVE_XATTR_SYSCALLS 1
      65                 :            : # define __NR_fsetxattr         225
      66                 :            : # define __NR_fgetxattr         228
      67                 :            : #else
      68                 :            : # warning "Extended attribute syscalls undefined for this architecture"
      69                 :            : # define HAVE_XATTR_SYSCALLS 0
      70                 :            : #endif
      71                 :            : 
      72                 :            : #if HAVE_XATTR_SYSCALLS
      73                 :            : # define SYSCALL(args...)       syscall(args)
      74                 :            : #else
      75                 :            : # define SYSCALL(args...)       ( errno = ENOSYS, -1 )
      76                 :            : #endif
      77                 :            : 
      78                 :            : static ssize_t
      79                 :            : _fgetxattr(int fd, const char *name, void *value, size_t size)
      80                 :            : {
      81                 :          0 :         return SYSCALL(__NR_fgetxattr, fd, name, value, size);
      82                 :            : }
      83                 :            : 
      84                 :            : static int
      85                 :            : _fsetxattr(int fd, const char *name, const void *value, size_t size, int flags)
      86                 :            : {
      87                 :          0 :         return SYSCALL(__NR_fsetxattr, fd, name, value, size, flags);
      88                 :            : }
      89                 :            : 
      90                 :            : int
      91                 :          0 : xattr_get(int fd, const char *name, void *value, size_t size)
      92                 :            : {
      93         [ #  # ]:          0 :         if (_fgetxattr(fd, name, value, size) == -1) {
      94         [ #  # ]:          0 :                 if ((errno == ENOATTR) || (errno == ENOTSUP)) {
      95                 :            :                         memset(value, 0, size);
      96                 :          0 :                         return 0;
      97                 :            :                 }
      98                 :          0 :                 return -errno;
      99                 :            :         }
     100                 :            : 
     101                 :            :         return 0;
     102                 :            : }
     103                 :            : 
     104                 :            : int
     105                 :          0 : xattr_set(int fd, const char *name, const void *value, size_t size)
     106                 :            : {
     107         [ #  # ]:          0 :         if (_fsetxattr(fd, name, value, size, 0) == -1)
     108                 :          0 :                 return -errno;
     109                 :            :         return 0;
     110                 :            : }

Generated by: LCOV version 1.13