[PATCH V2 1/7] ntdll: Implement retrieving DOS attributes in NtQueryInformationFile
Vijay Kiran Kamuju
infyquest at gmail.com
Sat Apr 27 21:19:58 CDT 2019
From: "Erich E. Hoover" <erich.e.hoover at gmail.com>
v2: merge macos support
From: Erich E. Hoover <erich.e.hoover at gmail.com>
Signed-off-by: Vijay Kiran Kamuju <infyquest at gmail.com>
---
configure.ac | 8 ++++++++
dlls/ntdll/file.c | 22 +++++++++++++++++++++-
include/wine/port.h | 8 ++++++++
libs/port/Makefile.in | 3 ++-
libs/port/xattr.c | 44 +++++++++++++++++++++++++++++++++++++++++++
5 files changed, 83 insertions(+), 2 deletions(-)
create mode 100644 libs/port/xattr.c
diff --git a/configure.ac b/configure.ac
index d1502bacf7..5782df2a3f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -702,6 +702,14 @@ AC_CHECK_HEADERS([libprocstat.h],,,
#include <sys/socket.h>
#endif])
+AC_CHECK_HEADERS([attr/xattr.h sys/xattr.h])
+if test "$ac_cv_header_sys_xattr_h" = "yes"
+then
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/xattr.h>]], [[getxattr("", "", "", 0, 0, 0);]])]
+ [AC_DEFINE(XATTR_ADDITIONAL_OPTIONS, 1,
+ [Define if xattr functions take additional arguments (Mac OS X)])])
+fi
+
dnl **** Check for working dll ****
AC_SUBST(DLLFLAGS,"-D_REENTRANT")
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 3dafdcfb44..d62126df6e 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -122,6 +122,22 @@ mode_t FILE_umask = 0;
static const WCHAR ntfsW[] = {'N','T','F','S'};
+/* Match the Samba conventions for storing DOS file attributes */
+#define SAMBA_XATTR_DOS_ATTRIB XATTR_USER_PREFIX "DOSATTRIB"
+/* We are only interested in some attributes, the others have corresponding Unix attributes */
+#define XATTR_ATTRIBS_MASK (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)
+
+/* decode the xattr-stored DOS attributes */
+static inline int get_file_xattr( char *hexattr, int attrlen )
+{
+ if (attrlen > 2 && hexattr[0] == '0' && hexattr[1] == 'x')
+ {
+ hexattr[attrlen] = 0;
+ return strtol( hexattr+2, NULL, 16 ) & XATTR_ATTRIBS_MASK;
+ }
+ return 0;
+}
+
/* fetch the attributes of a file */
static inline ULONG get_file_attributes( const struct stat *st )
{
@@ -139,12 +155,16 @@ static inline ULONG get_file_attributes( const struct stat *st )
/* get the stat info and file attributes for a file (by file descriptor) */
int fd_get_file_info( int fd, struct stat *st, ULONG *attr )
{
- int ret;
+ char hexattr[11];
+ int len, ret;
*attr = 0;
ret = fstat( fd, st );
if (ret == -1) return ret;
*attr |= get_file_attributes( st );
+ len = xattr_fget( fd, SAMBA_XATTR_DOS_ATTRIB, hexattr, sizeof(hexattr)-1 );
+ if (len == -1) return ret;
+ *attr |= get_file_xattr( hexattr, len );
return ret;
}
diff --git a/include/wine/port.h b/include/wine/port.h
index d23e2b033f..2be2afe421 100644
--- a/include/wine/port.h
+++ b/include/wine/port.h
@@ -335,6 +335,14 @@ int usleep (unsigned int useconds);
extern int mkstemps(char *template, int suffix_len);
+/* Extended attribute functions */
+
+#ifndef XATTR_USER_PREFIX
+# define XATTR_USER_PREFIX "user."
+#endif
+
+extern int xattr_fget( int filedes, const char *name, void *value, size_t size );
+
/* Interlocked functions */
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
diff --git a/libs/port/Makefile.in b/libs/port/Makefile.in
index a2e96d1500..dcc1ea1769 100644
--- a/libs/port/Makefile.in
+++ b/libs/port/Makefile.in
@@ -108,4 +108,5 @@ C_SRCS = \
usleep.c \
utf8.c \
wctomb.c \
- wctype.c
+ wctype.c \
+ xattr.c
diff --git a/libs/port/xattr.c b/libs/port/xattr.c
new file mode 100644
index 0000000000..1c06b89a86
--- /dev/null
+++ b/libs/port/xattr.c
@@ -0,0 +1,44 @@
+/*
+ * extended attributes functions
+ *
+ * Copyright 2014 Erich E. Hoover
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#if defined(HAVE_ATTR_XATTR_H)
+# undef XATTR_ADDITIONAL_OPTIONS
+# include <attr/xattr.h>
+#elif defined(HAVE_SYS_XATTR_H)
+# include <sys/xattr.h>
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+int xattr_fget( int filedes, const char *name, void *value, size_t size )
+{
+#if defined(XATTR_ADDITIONAL_OPTIONS)
+ return fgetxattr( filedes, name, value, size, 0, 0 );
+#elif defined(HAVE_ATTR_XATTR_H) || defined(HAVE_SYS_XATTR_H)
+ return fgetxattr( filedes, name, value, size );
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
--
2.21.0
More information about the wine-devel
mailing list