]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Move lsattr/chattr commands into separate file, we need to add some more options...
authorNathan Scott <nathans@sgi.com>
Fri, 17 Sep 2004 06:32:01 +0000 (06:32 +0000)
committerNathan Scott <nathans@sgi.com>
Fri, 17 Sep 2004 06:32:01 +0000 (06:32 +0000)
Merge of xfs-cmds-melb:slinx:19483a by kenmcd.

io/Makefile
io/attr.c [new file with mode: 0644]
io/init.c
io/io.h
io/open.c

index 6a39d5c9cbca56fa789351aff8595229597b3f67..32782c14fce9a47da15ae8a16fbe17fe92dfb6ec 100644 (file)
@@ -37,7 +37,7 @@ LTCOMMAND = xfs_io
 LSRCFILES = xfs_bmap.sh xfs_freeze.sh
 HFILES = command.h input.h init.h io.h
 CFILES = command.c input.c init.c \
-       bmap.c file.c freeze.c fsync.c help.c \
+       attr.c bmap.c file.c freeze.c fsync.c help.c \
        mmap.c open.c pread.c prealloc.c pwrite.c quit.c \
        truncate.c
 
diff --git a/io/attr.c b/io/attr.c
new file mode 100644 (file)
index 0000000..68f0ea0
--- /dev/null
+++ b/io/attr.c
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2003-2004 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/
+ */
+
+#include <xfs/libxfs.h>
+#include "command.h"
+#include "input.h"
+#include "init.h"
+#include "io.h"
+
+static cmdinfo_t chattr_cmd;
+static cmdinfo_t lsattr_cmd;
+
+#define CHATTR_XFLAG_LIST      "riasAdtPn"
+
+static struct xflags {
+       uint    flag;
+       char    *shortname;
+       char    *longname;
+} xflags[] = {
+       { XFS_XFLAG_REALTIME,   "r", "realtime" },
+       { XFS_XFLAG_PREALLOC,   "p", "prealloc" },
+       { XFS_XFLAG_IMMUTABLE,  "i", "immutable" },
+       { XFS_XFLAG_APPEND,     "a", "append-only" },
+       { XFS_XFLAG_SYNC,       "s", "sync" },
+       { XFS_XFLAG_NOATIME,    "A", "no-atime" },
+       { XFS_XFLAG_NODUMP,     "d", "no-dump" },
+       { XFS_XFLAG_RTINHERIT,  "t", "rt-inherit" },
+       { XFS_XFLAG_PROJINHERIT,"P", "proj-inherit" },
+       { XFS_XFLAG_NOSYMLINKS, "n", "nosymlinks" },
+       { 0, NULL, NULL }
+};
+
+static void
+lsattr_help(void)
+{
+       printf(_(
+"\n"
+" displays the set of extended inode flags associated with the current file\n"
+"\n"
+" Each individual flag is displayed as a single character, in this order:\n"
+" r -- file data is stored in the realtime section\n"
+" p -- file has preallocated extents (cannot be changed using chattr)\n"
+" i -- immutable, file cannot be modified\n"
+" a -- append-only, file can only be appended to\n"
+" s -- all updates are synchronous\n"
+" A -- the access time is not updated for this inode\n"
+" d -- do not include this file in a dump of the filesystem\n"
+" t -- child created in this directory has realtime bit set by default\n"
+" P -- child created in this directory has parents project ID by default\n"
+" n -- symbolic links cannot be created in this directory\n"
+"\n"
+" Options:\n"
+" -a -- show all flags which can be set alongside those which are set\n"
+" -v -- verbose mode; show long names of flags, not single characters\n"
+"\n"));
+}
+
+static void
+chattr_help(void)
+{
+       printf(_(
+"\n"
+" modifies the set of extended inode flags associated with the current file\n"
+"\n"
+" Examples:\n"
+" 'chattr +a' - sets the append-only flag\n"
+" 'chattr -a' - clears the append-only flag\n"
+"\n"
+" +/-r -- set/clear the realtime flag\n"
+" +/-i -- set/clear the immutable flag\n"
+" +/-a -- set/clear the append-only flag\n"
+" +/-s -- set/clear the sync flag\n"
+" +/-A -- set/clear the no-atime flag\n"
+" +/-d -- set/clear the no-dump flag\n"
+" +/-t -- set/clear the realtime inheritance flag\n"
+" +/-P -- set/clear the project ID inheritance flag\n"
+" +/-n -- set/clear the no-symbolic-links flag\n"
+" Note1: user must have certain capabilities to modify immutable/append-only.\n"
+" Note2: immutable/append-only files cannot be deleted; removing these files\n"
+"        requires the immutable/append-only flag to be cleared first.\n"
+" Note3: the realtime flag can only be set if the filesystem has a realtime\n"
+"        section, and the (regular) file must be empty when the flag is set.\n"
+"\n"));
+}
+
+void
+printxattr(
+       uint            flags,
+       int             verbose,
+       int             dofname,
+       const char      *fname,
+       int             dobraces,
+       int             doeol)
+{
+       struct xflags   *p;
+       int             first = 1;
+
+       if (dobraces)
+               fputs("[", stdout);
+       for (p = xflags; p->flag; p++) {
+               if (flags & p->flag) {
+                       if (verbose) {
+                               if (first)
+                                       first = 0;
+                               else
+                                       fputs(", ", stdout);
+                               fputs(p->longname, stdout);
+                       } else {
+                               fputs(p->shortname, stdout);
+                       }
+               } else if (!verbose) {
+                       fputs("-", stdout);
+               }
+       }
+       if (dobraces)
+               fputs("]", stdout);
+       if (dofname)
+               printf(" %s ", fname);
+       if (doeol)
+               fputs("\n", stdout);
+}
+
+static int
+lsattr_f(
+       int             argc,
+       char            **argv)
+{
+       struct fsxattr  fsx;
+       char            *name = file->name;
+       int             c, aflag = 0, vflag = 0;
+
+       while ((c = getopt(argc, argv, "av")) != EOF) {
+               switch (c) {
+               case 'a':
+                       aflag = 1;
+                       vflag = 0;
+                       break;
+               case 'v':
+                       aflag = 0;
+                       vflag = 1;
+                       break;
+               default:
+                       printf(_("invalid lsattr argument -- '%c'\n"), c);
+                       return 0;
+               }
+       }
+
+       if ((xfsctl(name, file->fd, XFS_IOC_FSGETXATTR, &fsx)) < 0) {
+               perror("XFS_IOC_FSGETXATTR");
+       } else {
+               printxattr(fsx.fsx_xflags, vflag, !aflag, name, vflag, !aflag);
+               if (aflag) {
+                       fputs("/", stdout);
+                       printxattr(-1, 0, 1, name, 0, 1);
+               }
+       }
+       return 0;
+}
+
+static int
+chattr_f(
+       int             argc,
+       char            **argv)
+{
+       struct fsxattr  attr;
+       struct xflags   *p;
+       unsigned int    i = 0;
+       char            *c, *name = file->name;
+
+       if (xfsctl(name, file->fd, XFS_IOC_FSGETXATTR, &attr) < 0) {
+               perror("XFS_IOC_FSGETXATTR");
+               return 0;
+       }
+       while (++i < argc) {
+               if (argv[i][0] == '+') {
+                       for (c = &argv[i][1]; *c; c++) {
+                               for (p = xflags; p->flag; p++) {
+                                       if (strncmp(p->shortname, c, 1) == 0) {
+                                               attr.fsx_xflags |= p->flag;
+                                               break;
+                                       }
+                               }
+                               if (!p->flag) {
+                                       fprintf(stderr, _("%s: unknown flag\n"),
+                                               progname);
+                                       return 0;
+                               }
+                       }
+               } else if (argv[i][0] == '-') {
+                       for (c = &argv[i][1]; *c; c++) {
+                               for (p = xflags; p->flag; p++) {
+                                       if (strncmp(p->shortname, c, 1) == 0) {
+                                               attr.fsx_xflags &= ~p->flag;
+                                               break;
+                                       }
+                               }
+                               if (!p->flag) {
+                                       fprintf(stderr, _("%s: unknown flag\n"),
+                                               progname);
+                                       return 0;
+                               }
+                       }
+               } else {
+                       fprintf(stderr, _("%s: bad chattr command, not +/-X\n"),
+                               progname);
+                       return 0;
+               }
+       }
+       if (xfsctl(name, file->fd, XFS_IOC_FSSETXATTR, &attr) < 0)
+               perror("XFS_IOC_FSSETXATTR");
+       return 0;
+}
+
+void
+attr_init(void)
+{
+       chattr_cmd.name = _("chattr");
+       chattr_cmd.cfunc = chattr_f;
+       chattr_cmd.args = _("[+/-"CHATTR_XFLAG_LIST"]");
+       chattr_cmd.argmin = 1;
+       chattr_cmd.argmax = -1;
+       chattr_cmd.flags = CMD_NOMAP_OK;
+       chattr_cmd.oneline =
+               _("change extended inode flags on the currently open file");
+       chattr_cmd.help = chattr_help;
+
+       lsattr_cmd.name = _("lsattr");
+       lsattr_cmd.cfunc = lsattr_f;
+       lsattr_cmd.args = _("[-a|-v]");
+       lsattr_cmd.argmin = 0;
+       lsattr_cmd.argmax = 1;
+       lsattr_cmd.flags = CMD_NOMAP_OK;
+       lsattr_cmd.oneline =
+               _("list extended inode flags set on the currently open file");
+       lsattr_cmd.help = lsattr_help;
+
+       add_command(&chattr_cmd);
+       add_command(&lsattr_cmd);
+}
index e0135f0f53425b005c4f6ecf09f0cf0df53993fb..d3089a89d152344177463e395965a568b1e241c6 100644 (file)
--- a/io/init.c
+++ b/io/init.c
@@ -55,6 +55,7 @@ usage(void)
 void
 init_commands(void)
 {
+       attr_init();
        bmap_init();
        fadvise_init();
        file_init();
diff --git a/io/io.h b/io/io.h
index c305c3d9adc03c03cbc65a8ddb0a891a7b706e1a..cc5e76743b7caa5842a4e5f12d4c1ff3b24c96da 100644 (file)
--- a/io/io.h
+++ b/io/io.h
@@ -78,6 +78,7 @@ extern void *check_mapping_range(mmap_region_t *, off64_t, size_t, int);
 extern off64_t         filesize(void);
 extern int             openfile(char *, xfs_fsop_geom_t *, int, mode_t);
 extern int             addfile(char *, int , xfs_fsop_geom_t *, int);
+extern void            printxattr(uint, int, int, const char *, int, int);
 
 extern void            *buffer;
 extern ssize_t         buffersize;
@@ -86,6 +87,7 @@ extern int            read_buffer(int, off64_t, long long, long long *,
                                        int, int);
 extern void            dump_buffer(off64_t, ssize_t);
 
+extern void            attr_init(void);
 extern void            bmap_init(void);
 extern void            file_init(void);
 extern void            freeze_init(void);
index 40d3de3cbc7d0e0108190230bb97f0fc7919dffd..90495132e8b5a154c07985b1bbbdc99dece8c628 100644 (file)
--- a/io/open.c
+++ b/io/open.c
@@ -41,8 +41,6 @@ static cmdinfo_t stat_cmd;
 static cmdinfo_t close_cmd;
 static cmdinfo_t setfl_cmd;
 static cmdinfo_t statfs_cmd;
-static cmdinfo_t chattr_cmd;
-static cmdinfo_t lsattr_cmd;
 static cmdinfo_t chproj_cmd;
 static cmdinfo_t lsproj_cmd;
 static cmdinfo_t extsize_cmd;
@@ -81,53 +79,6 @@ filetype(mode_t mode)
        return NULL;
 }
 
-static void
-printxattr(int flags, int verbose, int dofname, int dobraces, int doeol)
-{
-       static struct {
-               int     flag;
-               char    *shortname;
-               char    *longname;
-       } *p, xflags[] = {
-               { XFS_XFLAG_REALTIME,   "r", "realtime" },
-               { XFS_XFLAG_PREALLOC,   "p", "prealloc" },
-               { XFS_XFLAG_IMMUTABLE,  "i", "immutable" },
-               { XFS_XFLAG_APPEND,     "a", "append-only" },
-               { XFS_XFLAG_SYNC,       "s", "sync" },
-               { XFS_XFLAG_NOATIME,    "A", "no-atime" },
-               { XFS_XFLAG_NODUMP,     "d", "no-dump" },
-               { XFS_XFLAG_RTINHERIT,  "R", "rt-inherit" },
-               { XFS_XFLAG_PROJINHERIT,"P", "proj-inherit" },
-               { XFS_XFLAG_NOSYMLINKS, "S", "nosymlinks" },
-               { 0, NULL, NULL }
-       };
-       int     first = 1;
-
-       if (dobraces)
-               fputs("[", stdout);
-       for (p = xflags; p->flag; p++) {
-               if (flags & p->flag) {
-                       if (verbose) {
-                               if (first)
-                                       first = 0;
-                               else
-                                       fputs(", ", stdout);
-                               fputs(p->longname, stdout);
-                       } else {
-                               fputs(p->shortname, stdout);
-                       }
-               } else if (!verbose) {
-                       fputs("-", stdout);
-               }
-       }
-       if (dobraces)
-               fputs("]", stdout);
-       if (dofname)
-               printf(" %s ", file->name);
-       if (doeol)
-               fputs("\n", stdout);
-}
-
 static int
 stat_f(
        int             argc,
@@ -163,7 +114,7 @@ stat_f(
                perror("XFS_IOC_FSGETXATTR");
        } else {
                printf(_("xattr.xflags = 0x%x "), fsx.fsx_xflags);
-               printxattr(fsx.fsx_xflags, verbose, 0, 1, 1);
+               printxattr(fsx.fsx_xflags, verbose, 0, file->name, 1, 1);
                printf(_("xattr.extsize = %u\n"), fsx.fsx_extsize);
                printf(_("xattr.nextents = %u\n"), fsx.fsx_nextents);
        }
@@ -403,163 +354,6 @@ close_f(
        return 0;
 }
 
-static int
-lsattr_f(
-       int             argc,
-       char            **argv)
-{
-       struct fsxattr  fsx;
-       int             c, aflag = 0, vflag = 0;
-
-       while ((c = getopt(argc, argv, "av")) != EOF) {
-               switch (c) {
-               case 'a':
-                       aflag = 1;
-                       vflag = 0;
-                       break;
-               case 'v':
-                       aflag = 0;
-                       vflag = 1;
-                       break;
-               default:
-                       printf(_("invalid lsattr argument -- '%c'\n"), c);
-                       return 0;
-               }
-       }
-
-       if ((xfsctl(file->name, file->fd, XFS_IOC_FSGETXATTR, &fsx)) < 0) {
-               perror("XFS_IOC_FSGETXATTR");
-       } else {
-               printxattr(fsx.fsx_xflags, vflag, !aflag, vflag, !aflag);
-               if (aflag) {
-                       fputs("/", stdout);
-                       printxattr(-1, 0, 1, 0, 1);
-               }
-       }
-       return 0;
-}
-
-static void
-lsattr_help(void)
-{
-       printf(_(
-"\n"
-" displays the set of extended inode flags associated with the current file\n"
-"\n"
-" Each individual flag is displayed as a single character, in this order:\n"
-" r -- file data is stored in the realtime section\n"
-" p -- file has preallocated extents (cannot be changed using chattr)\n"
-" i -- immutable, file cannot be modified\n"
-" a -- append-only, file can only be appended to\n"
-" s -- all updates are synchronous\n"
-" A -- the access time is not updated for this inode\n"
-" d -- do not include this file in a dump of the filesystem\n"
-" R -- child created in this directory has realtime bit set by default\n"
-" P -- child created in this directory has parents project ID by default\n"
-" S -- symbolic links cannot be created in this directory\n"
-"\n"
-" Options:\n"
-" -a -- show all flags which can be set alongside those which are set\n"
-" -v -- verbose mode; show long names of flags, not single characters\n"
-"\n"));
-}
-
-static int
-chattr_f(
-       int             argc,
-       char            **argv)
-{
-       static struct {
-               int     flag;
-               char    optc;
-       } *p, xflags[] = {
-               { XFS_XFLAG_REALTIME,   'r' },
-               { XFS_XFLAG_IMMUTABLE,  'i' },
-               { XFS_XFLAG_APPEND,     'a' },
-               { XFS_XFLAG_SYNC,       's' },
-               { XFS_XFLAG_NOATIME,    'A' },
-               { XFS_XFLAG_NODUMP,     'd' },
-               { XFS_XFLAG_RTINHERIT,  'R' },
-               { XFS_XFLAG_PROJINHERIT,'P' },
-               { XFS_XFLAG_NOSYMLINKS, 'S' },
-               { 0, '\0' }
-       };
-       struct fsxattr  attr;
-       unsigned int    i = 0;
-       char            *c;
-
-       if (xfsctl(file->name, file->fd, XFS_IOC_FSGETXATTR, &attr) < 0) {
-               perror("XFS_IOC_FSGETXATTR");
-               return 0;
-       }
-       while (++i < argc) {
-               if (argv[i][0] == '+') {
-                       for (c = &argv[i][1]; *c; c++) {
-                               for (p = xflags; p->flag; p++) {
-                                       if (p->optc == *c) {
-                                               attr.fsx_xflags |= p->flag;
-                                               break;
-                                       }
-                               }
-                               if (!p->flag) {
-                                       fprintf(stderr, _("%s: unknown flag\n"),
-                                               progname);
-                                       return 0;
-                               }
-                       }
-               } else if (argv[i][0] == '-') {
-                       for (c = &argv[i][1]; *c; c++) {
-                               for (p = xflags; p->flag; p++) {
-                                       if (p->optc == *c) {
-                                               attr.fsx_xflags &= ~p->flag;
-                                               break;
-                                       }
-                               }
-                               if (!p->flag) {
-                                       fprintf(stderr, _("%s: unknown flag\n"),
-                                               progname);
-                                       return 0;
-                               }
-                       }
-               } else {
-                       fprintf(stderr, _("%s: bad chattr command, not +/-X\n"),
-                               progname);
-                       return 0;
-               }
-       }
-       if (xfsctl(file->name, file->fd, XFS_IOC_FSSETXATTR, &attr) < 0)
-               perror("XFS_IOC_FSSETXATTR");
-       return 0;
-}
-
-static void
-chattr_help(void)
-{
-       printf(_(
-"\n"
-" modifies the set of extended inode flags associated with the current file\n"
-"\n"
-" Examples:\n"
-" 'chattr +a' - sets the append-only flag\n"
-" 'chattr -a' - clears the append-only flag\n"
-"\n"
-" +/-r -- set/clear the realtime flag\n"
-" +/-i -- set/clear the immutable flag\n"
-" +/-a -- set/clear the append-only flag\n"
-" +/-s -- set/clear the sync flag\n"
-" +/-A -- set/clear the no-atime flag\n"
-" +/-d -- set/clear the no-dump flag\n"
-" +/-R -- set/clear the realtime inheritance flag\n"
-" +/-P -- set/clear the project ID inheritance flag\n"
-" +/-S -- set/clear the no-symbolic-links flag\n"
-" Note1: user must have certain capabilities to modify immutable/append-only.\n"
-" Note2: immutable/append-only files cannot be deleted; removing these files\n"
-"        requires the immutable/append-only flag to be cleared first.\n"
-" Note3: the realtime flag can only be set if the filesystem has a realtime\n"
-"        section, and the (regular) file must be empty when the flag is set.\n"
-"\n"));
-}
-
 static int
 lsproj_f(
        int             argc,
@@ -768,26 +562,6 @@ open_init(void)
        statfs_cmd.oneline =
                _("statistics on the filesystem of the currently open file");
 
-       chattr_cmd.name = _("chattr");
-       chattr_cmd.cfunc = chattr_f;
-       chattr_cmd.args = _("[+/-riasAd]");
-       chattr_cmd.argmin = 1;
-       chattr_cmd.argmax = 1;
-       chattr_cmd.flags = CMD_NOMAP_OK;
-       chattr_cmd.oneline =
-               _("change extended inode flags on the currently open file");
-       chattr_cmd.help = chattr_help;
-
-       lsattr_cmd.name = _("lsattr");
-       lsattr_cmd.cfunc = lsattr_f;
-       lsattr_cmd.args = _("[-a | -v]");
-       lsattr_cmd.argmin = 0;
-       lsattr_cmd.argmax = 2;
-       lsattr_cmd.flags = CMD_NOMAP_OK;
-       lsattr_cmd.oneline =
-               _("list extended inode flags set on the currently open file");
-       lsattr_cmd.help = lsattr_help;
-
        chproj_cmd.name = _("chproj");
        chproj_cmd.cfunc = chproj_f;
        chproj_cmd.args = _("projid");
@@ -818,8 +592,6 @@ open_init(void)
        add_command(&close_cmd);
        add_command(&setfl_cmd);
        add_command(&statfs_cmd);
-       add_command(&chattr_cmd);
-       add_command(&lsattr_cmd);
        add_command(&chproj_cmd);
        add_command(&lsproj_cmd);