patch by Tito which uses a lot more busybox functions to reduce size nicely
This commit is contained in:
parent
6adfd349e9
commit
ea338fffb5
@ -31,9 +31,9 @@
|
|||||||
#include <ext2fs/ext2_fs.h>
|
#include <ext2fs/ext2_fs.h>
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define EXT2FS_ATTR(x) __attribute__(x)
|
# define EXT2FS_ATTR(x) __attribute__(x)
|
||||||
#else
|
#else
|
||||||
#define EXT2FS_ATTR(x)
|
# define EXT2FS_ATTR(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "e2fsbb.h"
|
#include "e2fsbb.h"
|
||||||
@ -122,7 +122,7 @@ static void change_attributes(const char * name)
|
|||||||
STRUCT_STAT st;
|
STRUCT_STAT st;
|
||||||
|
|
||||||
if (LSTAT(name, &st) == -1) {
|
if (LSTAT(name, &st) == -1) {
|
||||||
bb_error_msg("while trying to stat %s", name);
|
bb_error_msg("stat %s failed", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (S_ISLNK(st.st_mode) && recursive)
|
if (S_ISLNK(st.st_mode) && recursive)
|
||||||
@ -137,13 +137,13 @@ static void change_attributes(const char * name)
|
|||||||
|
|
||||||
if (flags & OPT_SET_VER)
|
if (flags & OPT_SET_VER)
|
||||||
if (fsetversion(name, version) == -1)
|
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) {
|
if (flags & OPT_SET) {
|
||||||
fsflags = sf;
|
fsflags = sf;
|
||||||
} else {
|
} else {
|
||||||
if (fgetflags(name, &fsflags) == -1) {
|
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;
|
goto skip_setflags;
|
||||||
}
|
}
|
||||||
if (flags & OPT_REM)
|
if (flags & OPT_REM)
|
||||||
@ -154,7 +154,7 @@ static void change_attributes(const char * name)
|
|||||||
fsflags &= ~EXT2_DIRSYNC_FL;
|
fsflags &= ~EXT2_DIRSYNC_FL;
|
||||||
}
|
}
|
||||||
if (fsetflags(name, fsflags) == -1)
|
if (fsetflags(name, fsflags) == -1)
|
||||||
bb_error_msg("while setting flags on %s", name);
|
bb_error_msg("setting flags on %s", name);
|
||||||
|
|
||||||
skip_setflags:
|
skip_setflags:
|
||||||
if (S_ISDIR(st.st_mode) && recursive)
|
if (S_ISDIR(st.st_mode) && recursive)
|
||||||
@ -167,11 +167,11 @@ static int chattr_dir_proc(const char *dir_name, struct dirent *de,
|
|||||||
/*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/
|
/*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/
|
||||||
if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \
|
if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \
|
||||||
(de->d_name[1] == '.' && de->d_name[2] == '\0'))) {
|
(de->d_name[1] == '.' && de->d_name[2] == '\0'))) {
|
||||||
char *path;
|
char *path = concat_subpath_file(dir_name, de->d_name);
|
||||||
if (asprintf(&path, "%s/%s", dir_name, de->d_name) == -1)
|
if (path) {
|
||||||
bb_error_msg_and_die(bb_msg_memory_exhausted);
|
change_attributes(path);
|
||||||
change_attributes(path);
|
free(path);
|
||||||
free(path);
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -196,10 +196,8 @@ int chattr_main(int argc, char **argv)
|
|||||||
if (i >= argc)
|
if (i >= argc)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
version = strtol(argv[i], &tmp, 0);
|
version = strtol(argv[i], &tmp, 0);
|
||||||
if (*tmp) {
|
if (*tmp)
|
||||||
bb_error_msg("bad version - %s", arg);
|
bb_error_msg_and_die("bad version '%s'", arg);
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
flags |= OPT_SET_VER;
|
flags |= OPT_SET_VER;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -212,18 +210,12 @@ int chattr_main(int argc, char **argv)
|
|||||||
/* run sanity checks on all the arguments given us */
|
/* run sanity checks on all the arguments given us */
|
||||||
if (i >= argc)
|
if (i >= argc)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM))) {
|
if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM)))
|
||||||
bb_error_msg("= is incompatible with - and +");
|
bb_error_msg_and_die("= is incompatible with - and +");
|
||||||
return EXIT_FAILURE;
|
if ((rf & af) != 0)
|
||||||
}
|
bb_error_msg_and_die("Can't set and unset a flag");
|
||||||
if ((rf & af) != 0) {
|
if (!flags)
|
||||||
bb_error_msg("Can't both set and unset same flag");
|
bb_error_msg_and_die("Must use '-v', =, - or +");
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
if (!flags) {
|
|
||||||
bb_error_msg("Must use '-v', =, - or +");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* now run chattr on all the files passed to us */
|
/* now run chattr on all the files passed to us */
|
||||||
while (i < argc)
|
while (i < argc)
|
||||||
|
@ -34,9 +34,9 @@
|
|||||||
#include "e2p/e2p.h"
|
#include "e2p/e2p.h"
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define EXT2FS_ATTR(x) __attribute__(x)
|
# define EXT2FS_ATTR(x) __attribute__(x)
|
||||||
#else
|
#else
|
||||||
#define EXT2FS_ATTR(x)
|
# define EXT2FS_ATTR(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OPT_RECUR 1
|
#define OPT_RECUR 1
|
||||||
@ -59,25 +59,26 @@ static void list_attributes(const char *name)
|
|||||||
unsigned long fsflags;
|
unsigned long fsflags;
|
||||||
unsigned long generation;
|
unsigned long generation;
|
||||||
|
|
||||||
if (fgetflags(name, &fsflags) == -1) {
|
if (fgetflags(name, &fsflags) == -1)
|
||||||
bb_perror_msg("While reading flags on %s", name);
|
goto read_err;
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (flags & OPT_GENERATION) {
|
if (flags & OPT_GENERATION) {
|
||||||
if (fgetversion(name, &generation) == -1) {
|
if (fgetversion(name, &generation) == -1)
|
||||||
bb_perror_msg("While reading version on %s", name);
|
goto read_err;
|
||||||
return;
|
|
||||||
}
|
|
||||||
printf("%5lu ", generation);
|
printf("%5lu ", generation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & OPT_PF_LONG) {
|
if (flags & OPT_PF_LONG) {
|
||||||
printf("%-28s ", name);
|
printf("%-28s ", name);
|
||||||
print_flags(stdout, fsflags, PFOPT_LONG);
|
print_flags(stdout, fsflags, PFOPT_LONG);
|
||||||
fputc('\n', stdout);
|
printf("\n");
|
||||||
} else {
|
} else {
|
||||||
print_flags(stdout, fsflags, 0);
|
print_flags(stdout, fsflags, 0);
|
||||||
printf(" %s\n", name);
|
printf(" %s\n", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
read_err:
|
||||||
|
bb_perror_msg("reading %s", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lsattr_dir_proc(const char *, struct dirent *, void *);
|
static int lsattr_dir_proc(const char *, struct dirent *, void *);
|
||||||
@ -86,9 +87,9 @@ static void lsattr_args(const char *name)
|
|||||||
{
|
{
|
||||||
STRUCT_STAT st;
|
STRUCT_STAT st;
|
||||||
|
|
||||||
if (LSTAT(name, &st) == -1)
|
if (LSTAT(name, &st) == -1) {
|
||||||
bb_perror_msg("while trying to stat %s", name);
|
bb_perror_msg("stating %s", name);
|
||||||
else {
|
} else {
|
||||||
if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT))
|
if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT))
|
||||||
iterate_on_dir(name, lsattr_dir_proc, NULL);
|
iterate_on_dir(name, lsattr_dir_proc, NULL);
|
||||||
else
|
else
|
||||||
@ -101,14 +102,8 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
|
|||||||
{
|
{
|
||||||
STRUCT_STAT st;
|
STRUCT_STAT st;
|
||||||
char *path;
|
char *path;
|
||||||
int i = strlen(dir_name);
|
|
||||||
|
|
||||||
if (i && dir_name[i-1] == '/')
|
path = concat_path_file(dir_name, de->d_name);
|
||||||
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);
|
|
||||||
|
|
||||||
if (LSTAT(path, &st) == -1)
|
if (LSTAT(path, &st) == -1)
|
||||||
bb_perror_msg(path);
|
bb_perror_msg(path);
|
||||||
@ -116,7 +111,8 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
|
|||||||
if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
|
if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
|
||||||
list_attributes(path);
|
list_attributes(path);
|
||||||
if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) &&
|
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);
|
printf("\n%s:\n", path);
|
||||||
iterate_on_dir(path, lsattr_dir_proc, NULL);
|
iterate_on_dir(path, lsattr_dir_proc, NULL);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user