OBJS= feature.o fgetflags.o fsetflags.o fgetversion.o fsetversion.o \
getflags.o getversion.o hashstr.o iod.o ls.o mntopts.o \
parse_num.o pe.o pf.o ps.o setflags.o setversion.o uuid.o \
- ostype.o percent.o
+ ostype.o percent.o fgetproject.o fsetproject.o
SRCS= $(srcdir)/feature.c $(srcdir)/fgetflags.c \
$(srcdir)/fsetflags.c $(srcdir)/fgetversion.c \
$(srcdir)/ls.c $(srcdir)/mntopts.c $(srcdir)/parse_num.c \
$(srcdir)/pe.c $(srcdir)/pf.c $(srcdir)/ps.c \
$(srcdir)/setflags.c $(srcdir)/setversion.c $(srcdir)/uuid.c \
- $(srcdir)/ostype.c $(srcdir)/percent.c
+ $(srcdir)/ostype.c $(srcdir)/percent.c $(srcdir)/fgetproject.c \
+ $(srcdir)/fsetproject.c
HFILES= e2p.h
LIBRARY= libe2p
fsetversion.o: $(srcdir)/fsetversion.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/e2p.h \
$(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h
+fsetproject.o: $(srcdir)/fsetproject.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/e2p.h $(srcdir)/project.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h
+fgetproject.o: $(srcdir)/fgetproject.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/e2p.h $(srcdir)/project.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h
getflags.o: $(srcdir)/getflags.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/e2p.h \
$(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h
int fgetversion (const char * name, unsigned long * version);
int fsetflags (const char * name, unsigned long flags);
int fsetversion (const char * name, unsigned long version);
+int fgetproject(const char *name, unsigned long *project);
+int fsetproject(const char *name, unsigned long project);
int getflags (int fd, unsigned long * flags);
int getversion (int fd, unsigned long * version);
int iterate_on_dir (const char * dir_name,
--- /dev/null
+/*
+ * fgetproject.c --- get project id
+ *
+ * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu>
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
+ * %End-Header%
+ */
+
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE
+#endif
+#ifndef _LARGEFILE64_SOURCE
+#define _LARGEFILE64_SOURCE
+#endif
+
+#include "config.h"
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#if HAVE_EXT2_IOCTLS
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include "project.h"
+#endif
+
+#include "e2p.h"
+
+#ifdef O_LARGEFILE
+#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
+#else
+#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
+#endif
+
+int fgetproject(const char *name, unsigned long *project)
+{
+#ifndef FS_IOC_FSGETXATTR
+ errno = EOPNOTSUPP;
+ return -1;
+#else
+ int fd, r, save_errno = 0;
+ struct fsxattr fsx;
+
+ fd = open (name, OPEN_FLAGS);
+ if (fd == -1)
+ return -1;
+ r = ioctl (fd, FS_IOC_FSGETXATTR, &fsx);
+ if (r == 0)
+ *project = fsx.fsx_projid;
+ save_errno = errno;
+ close (fd);
+ if (save_errno)
+ errno = save_errno;
+ return r;
+#endif
+}
--- /dev/null
+/*
+ * fgetproject.c --- get project id
+ *
+ * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu>
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
+ * %End-Header%
+ */
+
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE
+#endif
+#ifndef _LARGEFILE64_SOURCE
+#define _LARGEFILE64_SOURCE
+#endif
+
+#include "config.h"
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#if HAVE_EXT2_IOCTLS
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include "project.h"
+#endif
+
+#include "e2p.h"
+
+#ifdef O_LARGEFILE
+#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
+#else
+#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
+#endif
+
+int fsetproject(const char *name, unsigned long project)
+{
+#ifndef FS_IOC_FSGETXATTR
+ errno = EOPNOTSUPP;
+ return -1;
+#else
+ int fd, r, save_errno = 0;
+ struct fsxattr fsx;
+
+ fd = open (name, OPEN_FLAGS);
+ if (fd == -1)
+ return -1;
+ r = ioctl (fd, FS_IOC_FSGETXATTR, &fsx);
+ if (r == -1) {
+ save_errno = errno;
+ goto errout;
+ }
+ fsx.fsx_projid = project;
+ r = ioctl (fd, FS_IOC_FSSETXATTR, &fsx);
+ if (r == -1)
+ save_errno = errno;
+errout:
+ close (fd);
+ if (save_errno)
+ errno = save_errno;
+ return r;
+#endif
+}
--- /dev/null
+/*
+ * project.h
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
+ * %End-Header%
+ */
+
+#include <ext2fs/ext2_fs.h>
+
+#if defined(__linux__) && !defined(FS_IOC_FSGETXATTR)
+#define FS_IOC_FSGETXATTR _IOR('X', 31, struct fsxattr)
+#define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr)
+
+/*
+ * Structure for FS_IOC_FSGETXATTR and FS_IOC_FSSETXATTR.
+ */
+struct fsxattr {
+ __u32 fsx_xflags; /* xflags field value (get/set) */
+ __u32 fsx_extsize; /* extsize field value (get/set)*/
+ __u32 fsx_nextents; /* nextents field value (get) */
+ __u32 fsx_projid; /* project identifier (get/set) */
+ unsigned char fsx_pad[12];
+};
+#endif
+
.I version
]
[
+.B \-p
+.I project
+]
+[
.I mode
]
.I files...
.TP
.BI \-v " version"
Set the file's version/generation number.
+.TP
+.BI \-p " project"
+Set the file's project number.
.SH ATTRIBUTES
A file with the 'a' attribute set can only be open in append mode for writing.
Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE
static unsigned long version;
+static int set_project;
+static unsigned long project;
+
static int recursive;
static int verbose;
static int silent;
static void usage(void)
{
fprintf(stderr,
- _("Usage: %s [-RVf] [-+=aAcCdDeijPsStTu] [-v version] files...\n"),
+ _("Usage: %s [-RVf] [-+=aAcCdDeijPsStTu] [-v version] [-p project] files...\n"),
program_name);
exit(1);
}
silent = 1;
continue;
}
+ if (*p == 'p') {
+ (*i)++;
+ if (*i >= argc)
+ usage ();
+ project = strtol (argv[*i], &tmp, 0);
+ if (*tmp) {
+ com_err (program_name, 0,
+ _("bad project - %s\n"),
+ argv[*i]);
+ usage ();
+ }
+ set_project = 1;
+ continue;
+ }
if (*p == 'v') {
(*i)++;
if (*i >= argc)
return -1;
}
}
+ if (set_project) {
+ if (verbose)
+ printf (_("Project of %s set as %lu\n"), name, version);
+ if (fsetproject (name, project) == -1) {
+ if (!silent)
+ com_err (program_name, errno,
+ _("while setting project on %s"),
+ name);
+ return -1;
+ }
+
+ }
if (S_ISDIR(st.st_mode) && recursive)
return iterate_on_dir (name, chattr_dir_proc, NULL);
return 0;
fputs("Can't both set and unset same flag.\n", stderr);
exit (1);
}
- if (!(add || rem || set || set_version)) {
+ if (!(add || rem || set || set_version || set_project )) {
fputs(_("Must use '-v', =, - or +\n"), stderr);
exit (1);
}
.SH SYNOPSIS
.B lsattr
[
-.B \-RVadv
+.B \-RVadvp
]
[
.I files...
.TP
.B \-v
List the file's version/generation number.
+.TP
+.B \-p
+List the file's project number.
.SH AUTHOR
.B lsattr
was written by Remy Card <Remy.Card@linux.org>. It is currently being
static int recursive;
static int verbose;
static int generation_opt;
+static int project_opt;
#ifdef _LFS64_LARGEFILE
#define LSTAT lstat64
static void usage(void)
{
- fprintf(stderr, _("Usage: %s [-RVadlv] [files...]\n"), program_name);
+ fprintf(stderr, _("Usage: %s [-RVadlvp] [files...]\n"), program_name);
exit(1);
}
{
unsigned long flags;
unsigned long generation;
+ unsigned long project;
if (fgetflags (name, &flags) == -1) {
com_err (program_name, errno, _("While reading flags on %s"),
name);
return -1;
}
+ if (project_opt) {
+ if (fgetproject(name, &project) == -1) {
+ com_err (program_name, errno,
+ _("While reading project on %s"),
+ name);
+ return -1;
+ }
+ printf ("%5lu ", project);
+ }
if (generation_opt) {
if (fgetversion (name, &generation) == -1) {
com_err (program_name, errno,
#endif
if (argc && *argv)
program_name = *argv;
- while ((c = getopt (argc, argv, "RVadlv")) != EOF)
+ while ((c = getopt (argc, argv, "RVadlvp")) != EOF)
switch (c)
{
case 'R':
case 'v':
generation_opt = 1;
break;
+ case 'p':
+ project_opt = 1;
+ break;
default:
usage();
}