Add procfd.c with gpfs_set_winattrs_path()
authorRalph Boehme <slow@samba.org>
Mon, 23 Aug 2021 09:37:29 +0000 (11:37 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 10 Jan 2023 14:07:34 +0000 (15:07 +0100)
procfd.c [new file with mode: 0644]

diff --git a/procfd.c b/procfd.c
new file mode 100644 (file)
index 0000000..6e1e7b7
--- /dev/null
+++ b/procfd.c
@@ -0,0 +1,68 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/xattr.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/acl.h>
+#include <gpfs.h>
+
+static const char *sys_proc_fd_path(int fd, char *buf, size_t bufsize)
+{
+       int written;
+
+       written = snprintf(buf,
+                          bufsize,
+                          "/proc/self/fd/%d",
+                          fd);
+       if (written >= bufsize) {
+               return NULL;
+       }
+
+       return buf;
+}
+
+int main(int argc, char **argv)
+{
+       const char *p = NULL;
+       char buf[PATH_MAX];
+       int fd;
+       int ret;
+       struct gpfs_winattr attrs = {0};
+
+       if (argc < 2) {
+               printf("Usage: %s FILE\n");
+               return 1;
+       }
+
+       fd = open(argv[1], O_PATH);
+       if (fd == -1) {
+               return 1;
+       }
+
+       p = sys_proc_fd_path(fd, buf, sizeof(buf));
+       if (p == NULL) {
+               return 1;
+       }
+
+       attrs.winAttrs = GPFS_WINATTR_HIDDEN;
+
+       ret = gpfs_set_winattrs_path(p,
+                                    GPFS_WINATTR_SET_ATTRS,
+                                    &attrs);
+       if (ret != 0) {
+               printf("gpfswrap_set_winattrs_path [%s] failed: %s\n",
+                       p, strerror(errno));
+               return 1;
+       }
+
+       return 0;
+}
+