#include <ext2fs/ext2_fs.h>
#ifdef __GNUC__
-#define EXT2FS_ATTR(x) __attribute__(x)
+# define EXT2FS_ATTR(x) __attribute__(x)
#else
-#define EXT2FS_ATTR(x)
+# define EXT2FS_ATTR(x)
#endif
#include "e2fsbb.h"
STRUCT_STAT st;
if (LSTAT(name, &st) == -1) {
- bb_error_msg("while trying to stat %s", name);
+ bb_error_msg("stat %s failed", name);
return;
}
if (S_ISLNK(st.st_mode) && recursive)
if (flags & OPT_SET_VER)
if (fsetversion(name, version) == -1)
- bb_error_msg("while setting version on %s", name);
+ bb_error_msg("setting version on %s", name);
if (flags & OPT_SET) {
fsflags = sf;
} else {
if (fgetflags(name, &fsflags) == -1) {
- bb_error_msg("while reading flags on %s", name);
+ bb_error_msg("reading flags on %s", name);
goto skip_setflags;
}
if (flags & OPT_REM)
fsflags &= ~EXT2_DIRSYNC_FL;
}
if (fsetflags(name, fsflags) == -1)
- bb_error_msg("while setting flags on %s", name);
+ bb_error_msg("setting flags on %s", name);
skip_setflags:
if (S_ISDIR(st.st_mode) && recursive)
/*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/
if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \
(de->d_name[1] == '.' && de->d_name[2] == '\0'))) {
- char *path;
- if (asprintf(&path, "%s/%s", dir_name, de->d_name) == -1)
- bb_error_msg_and_die(bb_msg_memory_exhausted);
- change_attributes(path);
- free(path);
+ char *path = concat_subpath_file(dir_name, de->d_name);
+ if (path) {
+ change_attributes(path);
+ free(path);
+ }
}
return 0;
}
if (i >= argc)
bb_show_usage();
version = strtol(argv[i], &tmp, 0);
- if (*tmp) {
- bb_error_msg("bad version - %s", arg);
- bb_show_usage();
- }
+ if (*tmp)
+ bb_error_msg_and_die("bad version '%s'", arg);
flags |= OPT_SET_VER;
continue;
}
/* run sanity checks on all the arguments given us */
if (i >= argc)
bb_show_usage();
- if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM))) {
- bb_error_msg("= is incompatible with - and +");
- return EXIT_FAILURE;
- }
- if ((rf & af) != 0) {
- bb_error_msg("Can't both set and unset same flag");
- return EXIT_FAILURE;
- }
- if (!flags) {
- bb_error_msg("Must use '-v', =, - or +");
- return EXIT_FAILURE;
- }
+ if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM)))
+ bb_error_msg_and_die("= is incompatible with - and +");
+ if ((rf & af) != 0)
+ bb_error_msg_and_die("Can't set and unset a flag");
+ if (!flags)
+ bb_error_msg_and_die("Must use '-v', =, - or +");
/* now run chattr on all the files passed to us */
while (i < argc)
#include "e2p/e2p.h"
#ifdef __GNUC__
-#define EXT2FS_ATTR(x) __attribute__(x)
+# define EXT2FS_ATTR(x) __attribute__(x)
#else
-#define EXT2FS_ATTR(x)
+# define EXT2FS_ATTR(x)
#endif
#define OPT_RECUR 1
unsigned long fsflags;
unsigned long generation;
- if (fgetflags(name, &fsflags) == -1) {
- bb_perror_msg("While reading flags on %s", name);
- return;
- }
+ if (fgetflags(name, &fsflags) == -1)
+ goto read_err;
if (flags & OPT_GENERATION) {
- if (fgetversion(name, &generation) == -1) {
- bb_perror_msg("While reading version on %s", name);
- return;
- }
+ if (fgetversion(name, &generation) == -1)
+ goto read_err;
printf("%5lu ", generation);
}
+
if (flags & OPT_PF_LONG) {
printf("%-28s ", name);
print_flags(stdout, fsflags, PFOPT_LONG);
- fputc('\n', stdout);
+ printf("\n");
} else {
print_flags(stdout, fsflags, 0);
printf(" %s\n", name);
}
+
+ return;
+read_err:
+ bb_perror_msg("reading %s", name);
}
static int lsattr_dir_proc(const char *, struct dirent *, void *);
{
STRUCT_STAT st;
- if (LSTAT(name, &st) == -1)
- bb_perror_msg("while trying to stat %s", name);
- else {
+ if (LSTAT(name, &st) == -1) {
+ bb_perror_msg("stating %s", name);
+ } else {
if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT))
iterate_on_dir(name, lsattr_dir_proc, NULL);
else
{
STRUCT_STAT st;
char *path;
- int i = strlen(dir_name);
- if (i && dir_name[i-1] == '/')
- i = asprintf(&path, "%s%s", dir_name, de->d_name);
- else
- i = asprintf(&path, "%s/%s", dir_name, de->d_name);
- if (i == -1)
- bb_error_msg_and_die(bb_msg_memory_exhausted);
+ path = concat_path_file(dir_name, de->d_name);
if (LSTAT(path, &st) == -1)
bb_perror_msg(path);
if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
list_attributes(path);
if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) &&
- strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
+ (de->d_name[0] != '.' && (de->d_name[1] != '\0' ||
+ (de->d_name[1] != '.' && de->d_name[2] != '\0')))) {
printf("\n%s:\n", path);
iterate_on_dir(path, lsattr_dir_proc, NULL);
printf("\n");