From patchwork Thu Oct 11 19:09:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 190979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from rcsinet15.oracle.com (rcsinet15.oracle.com [148.87.113.117]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "rcsinet15.oracle.com", Issuer "VeriSign Class 3 International Server CA - G3" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 9339F2C008E for ; Fri, 12 Oct 2012 06:10:00 +1100 (EST) Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q9BJ9vqM002242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 11 Oct 2012 19:09:58 GMT Received: from oss.oracle.com (oss-external.oracle.com [137.254.96.51]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q9BJ9uxV010309 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 11 Oct 2012 19:09:57 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1TMO8q-0004YW-PK; Thu, 11 Oct 2012 12:09:56 -0700 Received: from acsinet21.oracle.com ([141.146.126.237]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1TMO8l-0004YA-5h for fedfs-utils-devel@oss.oracle.com; Thu, 11 Oct 2012 12:09:51 -0700 Received: from rcsinet12.oracle.com (rcsinet12.oracle.com [148.87.113.124]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q9BJ9oni010087 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 11 Oct 2012 19:09:51 GMT Received: from mail-ie0-f171.google.com (mail-ie0-f171.google.com [209.85.223.171]) by rcsinet12.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q9BJ8i2I031915 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 11 Oct 2012 19:09:49 GMT Received: by mail-ie0-f171.google.com with SMTP id s9so3817388iec.2 for ; Thu, 11 Oct 2012 12:09:49 -0700 (PDT) Received: by 10.50.202.73 with SMTP id kg9mr1935474igc.42.1349982589624; Thu, 11 Oct 2012 12:09:49 -0700 (PDT) Received: from seurat.1015granger.net ([99.26.161.222]) by mx.google.com with ESMTPS id pq3sm20876igc.8.2012.10.11.12.09.48 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 11 Oct 2012 12:09:49 -0700 (PDT) From: Chuck Lever To: fedfs-utils-devel@oss.oracle.com Date: Thu, 11 Oct 2012 15:09:48 -0400 Message-ID: <20121011190948.31447.51820.stgit@seurat.1015granger.net> In-Reply-To: <20121011190220.31447.12725.stgit@seurat.1015granger.net> References: <20121011190220.31447.12725.stgit@seurat.1015granger.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Flow-Control-Info: class=Default reputation=ipRepBelow100 ip=209.85.223.171 ct-class=R5 ct-vol1=0 ct-vol2=9 ct-vol3=8 ct-risk=49 ct-spam1=75 ct-spam2=8 ct-bulk=6 rcpts=1 size=4624 X-MM-CT-Classification: not spam X-MM-CT-RefID: str=0001.0A090207.5077197E.0029,ss=1,re=0.000,fgs=0 Subject: [fedfs-utils] [PATCH 8/8] libjunction: Add a small tool for content of a live junction X-BeenThere: fedfs-utils-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list Reply-To: fedfs-utils Developers List-Id: fedfs-utils Developers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: fedfs-utils-devel-bounces@oss.oracle.com Errors-To: fedfs-utils-devel-bounces@oss.oracle.com X-Source-IP: acsinet21.oracle.com [141.146.126.237] Introduce the "display-junction" command, which takes a pathname and displays the contents of the junction XML. This is a debugging tool, not an installed program, so no man page is provided. Signed-off-by: Chuck Lever --- .gitignore | 1 src/libjunction/Makefile.am | 4 + src/libjunction/display-junction.c | 111 ++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 0 deletions(-) create mode 100644 src/libjunction/display-junction.c diff --git a/.gitignore b/.gitignore index 10c43a2..57e67c0 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ libparser.a libpath.a libsi.a libxlog.a +display-junction fedfs-create-junction fedfs-create-replication fedfs-delete-junction diff --git a/src/libjunction/Makefile.am b/src/libjunction/Makefile.am index 4898d01..fd35365 100644 --- a/src/libjunction/Makefile.am +++ b/src/libjunction/Makefile.am @@ -26,8 +26,12 @@ noinst_HEADERS = junction-internal.h noinst_LTLIBRARIES = libjunction.la +noinst_PROGRAMS = display-junction libjunction_la_SOURCES = export-cache.c fedfs.c junction.c \ locations.c nfs.c xml.c +LDADD = $(top_builddir)/src/libxlog/libxlog.la \ + $(top_builddir)/src/libjunction/libjunction.la \ + $(top_builddir)/src/libnsdb/libnsdb.la CLEANFILES = cscope.in.out cscope.out cscope.po.out *~ DISTCLEANFILES = Makefile.in diff --git a/src/libjunction/display-junction.c b/src/libjunction/display-junction.c new file mode 100644 index 0000000..8635bfc --- /dev/null +++ b/src/libjunction/display-junction.c @@ -0,0 +1,111 @@ +/** + * @file src/libjunction/display-junction.c + * @brief Tool to retrieve and display junction XML document + */ + +/* + * Copyright 2012 Oracle. All rights reserved. + * + * This file is part of fedfs-utils. + * + * fedfs-utils is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 as + * published by the Free Software Foundation. + * + * fedfs-utils 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 General Public License version 2.0 for more details. + * + * You should have received a copy of the GNU General Public License + * version 2.0 along with fedfs-utils. If not, see: + * + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "junction.h" +#include "junction-internal.h" +#include "xlog.h" + +/** + * Restore an object's mode bits + * + * @param pathname NUL-terminated C string containing pathname of a directory + * @return a FedFsStatus code + */ +int +main(int argc, char **argv) +{ + char *progname, *pathname, *buf = NULL; + FedFsStatus retval; + int fd; + + /* Ensure UTF-8 strings can be handled transparently */ + if (setlocale(LC_CTYPE, "") == NULL || + strcmp(nl_langinfo(CODESET), "UTF-8") != 0) { + fprintf(stderr, "Failed to set locale and langinfo\n"); + exit(EXIT_FAILURE); + } + + /* For the libraries */ + if ((progname = strrchr(argv[0], '/')) != NULL) + progname++; + else + progname = argv[0]; + xlog_stderr(1); + xlog_syslog(0); + xlog_open(progname); + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", progname); + return EXIT_FAILURE; + } + pathname = argv[1]; + + retval = junction_open_path(pathname, &fd); + switch (retval) { + case FEDFS_OK: + break; + case FEDFS_ERR_PERM: + fprintf(stderr, "Failed to open junction %s: not running as root\n", + pathname); + return EXIT_FAILURE; + default: + fprintf(stderr, "Failed to open junction %s: %s\n", + pathname, nsdb_display_fedfsstatus(retval)); + return EXIT_FAILURE; + } + + retval = junction_read_xattr(fd, pathname, JUNCTION_XATTR_NAME_NFS, &buf); + switch (retval) { + case FEDFS_OK: + break; + case FEDFS_ERR_ACCESS: + fprintf(stderr, "Object %s is not a junction\n", pathname); + return EXIT_FAILURE; + default: + fprintf(stderr, "Failed to read junction %s: %s\n", + pathname, nsdb_display_fedfsstatus(retval)); + return EXIT_FAILURE; + } + + printf("%s\n", buf); + + free(buf); + (void)close(fd); + return retval; +}