*/
#define _LARGEFILE64_SOURCE
-#define _FILE_OFFSET_BITS 64
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include "ext2fs/ext2_fs.h"
+#ifdef __GNUC__
+#define EXT2FS_ATTR(x) __attribute__(x)
+#else
+#define EXT2FS_ATTR(x)
+#endif
+
#ifndef S_ISLNK /* So we can compile even with gcc-warn */
# ifdef __S_IFLNK
# define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK)
static unsigned long rf;
static unsigned long sf;
+#ifdef _LFS64_LARGEFILE
+#define LSTAT lstat64
+#define STRUCT_STAT struct stat64
+#else
+#define LSTAT lstat
+#define STRUCT_STAT struct stat
+#endif
+
static void fatal_error(const char * fmt_string, int errcode)
{
fprintf (stderr, fmt_string, program_name);
exit (errcode);
}
-#define usage() fatal_error(_("usage: %s [-RV] [-+=AacdijsSu] [-v version] files...\n"), \
+#define usage() fatal_error(_("usage: %s [-RV] [-+=AacDdijsSu] [-v version] files...\n"), \
1)
struct flags_char {
static const struct flags_char flags_array[] = {
{ EXT2_NOATIME_FL, 'A' },
{ EXT2_SYNC_FL, 'S' },
+ { EXT2_DIRSYNC_FL, 'D' },
{ EXT2_APPEND_FL, 'a' },
{ EXT2_COMPR_FL, 'c' },
{ EXT2_NODUMP_FL, 'd' },
{ EXT3_JOURNAL_DATA_FL, 'j' },
{ EXT2_SECRM_FL, 's' },
{ EXT2_UNRM_FL, 'u' },
+ { EXT2_NOTAIL_FL, 't' },
+ { EXT2_TOPDIR_FL, 'T' },
{ 0, 0 }
};
static void change_attributes (const char * name)
{
unsigned long flags;
- struct stat st;
+ STRUCT_STAT st;
- if (lstat (name, &st) == -1) {
+ if (LSTAT (name, &st) == -1) {
com_err (program_name, errno, _("while trying to stat %s"),
name);
return;
print_flags (stdout, flags, 0);
printf ("\n");
}
+ if (!S_ISDIR(st.st_mode))
+ flags &= ~EXT2_DIRSYNC_FL;
if (fsetflags (name, flags) == -1)
com_err (program_name, errno,
_("while setting flags on %s"), name);
}
static int chattr_dir_proc (const char * dir_name, struct dirent * de,
- void * unused_private)
+ void * private EXT2FS_ATTR((unused)))
{
if (strcmp (de->d_name, ".") && strcmp (de->d_name, "..")) {
char *path;
#ifdef ENABLE_NLS
setlocale(LC_MESSAGES, "");
+ setlocale(LC_CTYPE, "");
bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
textdomain(NLS_CAT_NAME);
#endif
program_name = *argv;
i = 1;
while (i < argc && !end_arg) {
- if (decode_arg (&i, argc, argv) == EOF)
+ /* '--' arg should end option processing */
+ if (strcmp(argv[i], "--") == 0) {
+ i++;
+ end_arg = 1;
+ } else if (decode_arg (&i, argc, argv) == EOF)
end_arg = 1;
else
i++;
if (i >= argc)
usage ();
if (set && (add || rem)) {
- fprintf (stderr, _("= is incompatible with - and +\n"));
+ fputs(_("= is incompatible with - and +\n"), stderr);
exit (1);
}
if ((rf & af) != 0) {
- fprintf (stderr, "Can't both set and unset same flag.\n");
+ fputs("Can't both set and unset same flag.\n", stderr);
exit (1);
}
if (!(add || rem || set || set_version)) {
- fprintf (stderr, _("Must use '-v', =, - or +\n"));
+ fputs(_("Must use '-v', =, - or +\n"), stderr);
exit (1);
}
if (verbose)
- fprintf (stderr, _("chattr %s, %s for EXT2 FS %s, %s\n"),
- E2FSPROGS_VERSION, E2FSPROGS_DATE,
- EXT2FS_VERSION, EXT2FS_DATE);
+ fprintf (stderr, "chattr %s (%s)\n",
+ E2FSPROGS_VERSION, E2FSPROGS_DATE);
for (j = i; j < argc; j++)
change_attributes (argv[j]);
exit(0);