Get libhandle working on IRIX for qa. Put back fd_to_handle.
authorTim Shimmin <tes@sgi.com>
Mon, 4 Jul 2005 06:00:09 +0000 (06:00 +0000)
committerTim Shimmin <tes@sgi.com>
Mon, 4 Jul 2005 06:00:09 +0000 (06:00 +0000)
Merge of master-melb:xfs-cmds:23053a by kenmcd.

aclocal.m4
configure.in
m4/package_xfslibs.m4
src/Makefile
src/open_unlink.c [new file with mode: 0644]

index 06f2b51b4458912878c55cbf34d610adf52a0253..8f8c7dad813e598fb87f134c29cdb83a8773f4bf 100644 (file)
@@ -1,6 +1,6 @@
-# aclocal.m4 generated automatically by aclocal 1.6.3 -*- Autoconf -*-
+# generated automatically by aclocal 1.7.5 -*- Autoconf -*-
 
-# Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
 # Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -421,6 +421,19 @@ AC_DEFUN([AC_PACKAGE_NEED_ATTRLIST_LIBHANDLE],
     AC_SUBST(libhdl)
   ])
 
+AC_DEFUN([AC_PACKAGE_NEED_IRIX_LIBHANDLE],
+  [ 
+    AC_MSG_CHECKING([libhandle.a for IRIX])
+    libhdl="`pwd`/../irix/libhandle/libhandle.a"
+    if ! test -f $libhdl; then
+       echo 'no'
+        echo 'FATAL ERROR: could not find IRIX XFS handle library.'
+        exit 1
+    fi
+    echo 'yes'
+    AC_SUBST(libhdl)
+  ])
+
 AC_DEFUN([AC_PACKAGE_NEED_XFSCTL_MACRO],
   [ AC_MSG_CHECKING([xfsctl from xfs/libxfs.h])
     AC_TRY_LINK([#include <xfs/libxfs.h>], [ int x = xfsctl(0, 0, 0, 0); ],
index bb0297a347afd34d36033464653726752c1fd670..a9c638deece837ce0b9a2a659f349b7a0e833780 100644 (file)
@@ -38,6 +38,7 @@ in
                AC_PACKAGE_NEED_SYS_ACL_H
                AC_PACKAGE_NEED_ATTRIBUTES_H
                AC_PACKAGE_WANT_NDBM
+               AC_PACKAGE_NEED_IRIX_LIBHANDLE
                ;;
        *)
                AC_PACKAGE_NEED_XFS_LIBXFS_H
index be9a74d37fc0b140c82fda138fcdd2ab6e2aa72f..af718c257b69b525bcaa743bb0293018dcab3bff 100644 (file)
@@ -76,6 +76,19 @@ AC_DEFUN([AC_PACKAGE_NEED_ATTRLIST_LIBHANDLE],
     AC_SUBST(libhdl)
   ])
 
+AC_DEFUN([AC_PACKAGE_NEED_IRIX_LIBHANDLE],
+  [ 
+    AC_MSG_CHECKING([libhandle.a for IRIX])
+    libhdl="`pwd`/../irix/libhandle/libhandle.a"
+    if ! test -f $libhdl; then
+       echo 'no'
+        echo 'FATAL ERROR: could not find IRIX XFS handle library.'
+        exit 1
+    fi
+    echo 'yes'
+    AC_SUBST(libhdl)
+  ])
+
 AC_DEFUN([AC_PACKAGE_NEED_XFSCTL_MACRO],
   [ AC_MSG_CHECKING([xfsctl from xfs/libxfs.h])
     AC_TRY_LINK([#include <xfs/libxfs.h>], [ int x = xfsctl(0, 0, 0, 0); ],
index 25b17166e6cd5a769ba3a683a8bb2217cfe15447..1096dbf8ef9ebda0d22f6c5d23e9ae564aa712ae 100644 (file)
@@ -1,5 +1,5 @@
 # 
-# Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
+# Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
 # 
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of version 2 of the GNU General Public License as
@@ -37,14 +37,20 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \
        nametest permname randholes runas truncfile usemem \
        mmapcat append_reader append_writer dirperf metaperf \
        devzero feature alloc fault fstest t_access_root \
-       godown resvtest writemod 
+       godown resvtest writemod
 
 LINUX_TARGETS = loggen xfsctl bstat t_mtab getdevicesize
 
+IRIX_TARGETS = open_unlink
+
 ifeq ($(PKG_PLATFORM),linux)
 TARGETS += $(LINUX_TARGETS)
 endif
 
+ifeq ($(PKG_PLATFORM),irix)
+TARGETS += $(IRIX_TARGETS)
+endif
+
 ifeq ($(HAVE_DB), true)
 TARGETS += dbtest
 endif
@@ -101,4 +107,8 @@ fill2: fill2.o
 
 runas: runas.o 
        $(LINKTEST)  -lgen
+
+open_unlink: open_unlink.o $(LIBHANDLE)
+       $(LINKTEST) $(LIBHANDLE) $(LDLIBS)
+
 endif
diff --git a/src/open_unlink.c b/src/open_unlink.c
new file mode 100644 (file)
index 0000000..4697bbf
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
+ * 
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * 
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like.  Any license provided herein, whether implied or
+ * otherwise, applies only to this software file.  Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ * 
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA  94043, or:
+ * 
+ * http://www.sgi.com 
+ * 
+ * For further information regarding this notice, see: 
+ * 
+ * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ *
+ *
+ * Create a file given path argument and then unlink it but
+ * keep fd open.
+ * Then do an attr_list for parentptrs. (supported on IRIX)
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/attributes.h>
+#include <sys/fs/xfs_itable.h>
+
+#ifndef ATTR_PARENT
+#define ATTR_PARENT 0x0040
+#endif
+
+#define EA_LISTBUF_SZ 16384
+
+int
+main(int argc, char *argv[])
+{
+       char *path;
+       int fd;
+       char *prog = argv[0];
+       void *handle;
+       size_t hlen;
+       attrlist_cursor_t cursor;
+       attrlist_t *ea_listbuf = (attrlist_t *)malloc(EA_LISTBUF_SZ);
+       uint64_t parent_ino;
+       uint64_t link_cnt;
+       int sts;
+       int nameix;
+       attrlist_ent_t *entp;
+
+       if (argc < 2) {
+               fprintf(stderr, "%s: missing pathname argument\n", prog);
+               return 1;
+       }
+       path = argv[1];
+
+       if (argc > 2) {
+               fprintf(stderr, "%s: too many arguments\n", prog);
+               return 1;
+       }
+
+       /* if file already exists then error out */
+       if (access(path, F_OK) == 0) {
+               fprintf(stderr, "%s: file \"%s\" already exists\n", prog, path);
+               return 1;
+       }
+
+       fd = open(path, O_RDWR|O_CREAT|O_EXCL);
+       if (fd == -1) {
+               fprintf(stderr, "%s: failed to create \"%s\": %s\n", prog, path, strerror(errno));
+               return 1;
+       }
+
+
+       /* for linux libhandle version - to set libhandle fsfd cache */
+       {
+               void *fshandle;
+               size_t fshlen;
+
+               if (path_to_fshandle(path, &fshandle, &fshlen) != 0) {
+                       fprintf(stderr, "%s: failed path_to_fshandle \"%s\": %s\n",
+                               prog, path, strerror(errno));
+                       return 1;
+               }
+       }
+
+
+       /* 
+        * look at parentptr EAs and see if the path exists now that
+        * it has been unlinked.
+        */ 
+       if (fd_to_handle(fd, &handle, &hlen) != 0) {
+               fprintf(stderr, "%s: failed to fd_to_handle \"%s\": %s\n",
+                       prog, path, strerror(errno));
+               return 1;
+       }
+
+       if (unlink(path) == -1) {
+               fprintf(stderr, "%s: failed to unlink \"%s\": %s\n", prog, path, strerror(errno));
+               return 1;
+       }
+
+       memset(&cursor, 0, sizeof(cursor));
+
+       /* just do one call - don't bother with continue logic */
+       sts = attr_list_by_handle(handle,
+                       hlen,
+                       (char*)ea_listbuf,
+                       EA_LISTBUF_SZ,
+                       ATTR_PARENT,
+                       &cursor);
+       if (sts != 0) {
+               fprintf(stderr, "%s: failed to list attr for \"%s\": %s\n", prog, path, strerror(errno));
+               return 1;
+       }
+
+       printf("ea count = %d\n", ea_listbuf->al_count);
+
+       /*
+        * process EA list
+        */
+       for (nameix = 0; nameix < ea_listbuf->al_count; nameix++) {
+               entp = ATTR_ENTRY(ea_listbuf, nameix);
+
+               sts = sscanf(entp->a_name, "%llx %llx", &parent_ino, &link_cnt);
+               if (sts != 2) {
+                       fprintf(stderr,
+                               "inode-path for \"%s\" is corrupted\n",
+                               path);
+
+                       /* go onto next EA name */
+                       continue;
+               }
+               /* just print the info out */
+               printf("[%d] parent_ino = %llu, link_cnt = %llu\n", nameix, parent_ino, link_cnt);
+       }
+
+
+       free_handle(handle, hlen);
+
+       if (close(fd) == -1) {
+               fprintf(stderr, "%s: failed to close \"%s\": %s\n", prog, path, strerror(errno));
+               return 1;
+       }
+
+       return 0;
+}