mirror of
https://github.com/sheumann/hush.git
synced 2024-08-20 19:29:02 +00:00
libbb: introduce and use print_flags().
Mostly by Natanael Copa <natanael.copa AT gmail.com> function old new delta print_e2flags - 189 +189 print_flags_separated - 86 +86 static.flag_labels - 60 +60 static.dma_wmode_masks - 32 +32 static.flag_masks - 28 +28 static.arp_labels - 16 +16 static.arp_masks - 12 +12 ls_main 836 843 +7 ... popstring 140 134 -6 arp_show 740 708 -32 print_flags 189 25 -164 ipaddr_list_or_flush 2396 2170 -226 process_dev 5306 4706 -600 ------------------------------------------------------------------------------ (add/remove: 10/0 grow/shrink: 5/10 up/down: 458/-1043) Total: -585 bytes text data bss dec hex filename 810564 624 7060 818248 c7c48 busybox_old 810002 624 7060 817686 c7a16 busybox_unstripped
This commit is contained in:
parent
f0d6c25586
commit
53354ac47d
@ -192,7 +192,7 @@ static const char e2attr_flags_lname[] =
|
|||||||
"Top_of_Directory_Hierarchies" "\0"
|
"Top_of_Directory_Hierarchies" "\0"
|
||||||
/* Another trailing NUL is added by compiler */;
|
/* Another trailing NUL is added by compiler */;
|
||||||
|
|
||||||
void print_flags(FILE *f, unsigned long flags, unsigned options)
|
void print_e2flags(FILE *f, unsigned long flags, unsigned options)
|
||||||
{
|
{
|
||||||
const uint32_t *fv;
|
const uint32_t *fv;
|
||||||
const char *fn;
|
const char *fn;
|
||||||
|
@ -31,7 +31,7 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f
|
|||||||
/* Must be 1 for compatibility with `int long_format'. */
|
/* Must be 1 for compatibility with `int long_format'. */
|
||||||
#define PFOPT_LONG 1
|
#define PFOPT_LONG 1
|
||||||
/* Print file attributes on an ext2 file system */
|
/* Print file attributes on an ext2 file system */
|
||||||
void print_flags(FILE *f, unsigned long flags, unsigned options);
|
void print_e2flags(FILE *f, unsigned long flags, unsigned options);
|
||||||
|
|
||||||
extern const uint32_t e2attr_flags_value[];
|
extern const uint32_t e2attr_flags_value[];
|
||||||
extern const char e2attr_flags_sname[];
|
extern const char e2attr_flags_sname[];
|
||||||
|
@ -45,10 +45,10 @@ static void list_attributes(const char *name)
|
|||||||
|
|
||||||
if (option_mask32 & OPT_PF_LONG) {
|
if (option_mask32 & OPT_PF_LONG) {
|
||||||
printf("%-28s ", name);
|
printf("%-28s ", name);
|
||||||
print_flags(stdout, fsflags, PFOPT_LONG);
|
print_e2flags(stdout, fsflags, PFOPT_LONG);
|
||||||
bb_putchar('\n');
|
bb_putchar('\n');
|
||||||
} else {
|
} else {
|
||||||
print_flags(stdout, fsflags, 0);
|
print_e2flags(stdout, fsflags, 0);
|
||||||
printf(" %s\n", name);
|
printf(" %s\n", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040
|
#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* `options' for print_flags() */
|
/* `options' for print_e2flags() */
|
||||||
|
|
||||||
#define PFOPT_LONG 1 /* Must be 1 for compatibility with `int long_format'. */
|
#define PFOPT_LONG 1 /* Must be 1 for compatibility with `int long_format'. */
|
||||||
|
|
||||||
|
@ -56,10 +56,10 @@ static void list_attributes(const char *name)
|
|||||||
|
|
||||||
if (flags & OPT_PF_LONG) {
|
if (flags & OPT_PF_LONG) {
|
||||||
printf("%-28s ", name);
|
printf("%-28s ", name);
|
||||||
print_flags(stdout, fsflags, PFOPT_LONG);
|
print_e2flags(stdout, fsflags, PFOPT_LONG);
|
||||||
bb_putchar('\n');
|
bb_putchar('\n');
|
||||||
} else {
|
} else {
|
||||||
print_flags(stdout, fsflags, 0);
|
print_e2flags(stdout, fsflags, 0);
|
||||||
printf(" %s\n", name);
|
printf(" %s\n", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1304,6 +1304,14 @@ extern const char bb_default_login_shell[];
|
|||||||
/* "sh" */
|
/* "sh" */
|
||||||
#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6)
|
#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6)
|
||||||
|
|
||||||
|
typedef struct masks_labels_t {
|
||||||
|
const char *labels;
|
||||||
|
const int masks[];
|
||||||
|
} masks_labels_t;
|
||||||
|
|
||||||
|
int print_flags_separated(const int *masks, const char *labels,
|
||||||
|
int flags, const char *separator);
|
||||||
|
extern int print_flags(const masks_labels_t *ml, int flags);
|
||||||
|
|
||||||
#if ENABLE_FEATURE_DEVFS
|
#if ENABLE_FEATURE_DEVFS
|
||||||
# define CURRENT_VC "/dev/vc/0"
|
# define CURRENT_VC "/dev/vc/0"
|
||||||
|
@ -68,6 +68,7 @@ lib-y += perror_nomsg.o
|
|||||||
lib-y += perror_nomsg_and_die.o
|
lib-y += perror_nomsg_and_die.o
|
||||||
lib-y += pidfile.o
|
lib-y += pidfile.o
|
||||||
lib-y += printable.o
|
lib-y += printable.o
|
||||||
|
lib-y += print_flags.o
|
||||||
lib-y += process_escape_sequence.o
|
lib-y += process_escape_sequence.o
|
||||||
lib-y += procps.o
|
lib-y += procps.o
|
||||||
lib-y += ptr_to_globals.o
|
lib-y += ptr_to_globals.o
|
||||||
|
@ -1228,54 +1228,46 @@ static void dump_identity(const struct hd_driveid *id)
|
|||||||
if (id->tPIO >= 2) printf("pio2 ");
|
if (id->tPIO >= 2) printf("pio2 ");
|
||||||
}
|
}
|
||||||
if (id->field_valid & 2) {
|
if (id->field_valid & 2) {
|
||||||
if (id->eide_pio_modes & 1) printf("pio3 ");
|
static const masks_labels_t pio_modes = {
|
||||||
if (id->eide_pio_modes & 2) printf("pio4 ");
|
.masks = { 1, 2, ~3 },
|
||||||
if (id->eide_pio_modes &~3) printf("pio? ");
|
.labels = "pio3 \0""pio4 \0""pio? \0",
|
||||||
|
};
|
||||||
|
print_flags(&pio_modes, id->eide_pio_modes);
|
||||||
}
|
}
|
||||||
if (id->capability & 1) {
|
if (id->capability & 1) {
|
||||||
if (id->dma_1word | id->dma_mword) {
|
if (id->dma_1word | id->dma_mword) {
|
||||||
|
static const int dma_wmode_masks[] = { 0x100, 1, 0x200, 2, 0x400, 4, 0xf800, 0xf8 };
|
||||||
printf("\n DMA modes: ");
|
printf("\n DMA modes: ");
|
||||||
if (id->dma_1word & 0x100) bb_putchar('*');
|
print_flags_separated(dma_wmode_masks,
|
||||||
if (id->dma_1word & 1) printf("sdma0 ");
|
"*\0""sdma0 \0""*\0""sdma1 \0""*\0""sdma2 \0""*\0""sdma? \0",
|
||||||
if (id->dma_1word & 0x200) bb_putchar('*');
|
id->dma_1word, NULL);
|
||||||
if (id->dma_1word & 2) printf("sdma1 ");
|
print_flags_separated(dma_wmode_masks,
|
||||||
if (id->dma_1word & 0x400) bb_putchar('*');
|
"*\0""mdma0\0""*\0""mdma1\0""*\0""mdma2\0""*\0""mdma?\0",
|
||||||
if (id->dma_1word & 4) printf("sdma2 ");
|
id->dma_mword, NULL);
|
||||||
if (id->dma_1word & 0xf800) bb_putchar('*');
|
|
||||||
if (id->dma_1word & 0xf8) printf("sdma? ");
|
|
||||||
if (id->dma_mword & 0x100) bb_putchar('*');
|
|
||||||
if (id->dma_mword & 1) printf("mdma0 ");
|
|
||||||
if (id->dma_mword & 0x200) bb_putchar('*');
|
|
||||||
if (id->dma_mword & 2) printf("mdma1 ");
|
|
||||||
if (id->dma_mword & 0x400) bb_putchar('*');
|
|
||||||
if (id->dma_mword & 4) printf("mdma2 ");
|
|
||||||
if (id->dma_mword & 0xf800) bb_putchar('*');
|
|
||||||
if (id->dma_mword & 0xf8) printf("mdma? ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (((id->capability & 8) || (id->field_valid & 2)) && id->field_valid & 4) {
|
if (((id->capability & 8) || (id->field_valid & 2)) && id->field_valid & 4) {
|
||||||
|
static const masks_labels_t ultra_modes1 = {
|
||||||
|
.masks = { 0x100, 0x001, 0x200, 0x002, 0x400, 0x004 },
|
||||||
|
.labels = "*\0""udma0 \0""*\0""udma1 \0""*\0""udma2 \0",
|
||||||
|
};
|
||||||
|
|
||||||
printf("\n UDMA modes: ");
|
printf("\n UDMA modes: ");
|
||||||
if (id->dma_ultra & 0x100) bb_putchar('*');
|
print_flags(&ultra_modes1, id->dma_ultra);
|
||||||
if (id->dma_ultra & 0x001) printf("udma0 ");
|
|
||||||
if (id->dma_ultra & 0x200) bb_putchar('*');
|
|
||||||
if (id->dma_ultra & 0x002) printf("udma1 ");
|
|
||||||
if (id->dma_ultra & 0x400) bb_putchar('*');
|
|
||||||
if (id->dma_ultra & 0x004) printf("udma2 ");
|
|
||||||
#ifdef __NEW_HD_DRIVE_ID
|
#ifdef __NEW_HD_DRIVE_ID
|
||||||
if (id->hw_config & 0x2000) {
|
if (id->hw_config & 0x2000) {
|
||||||
#else /* !__NEW_HD_DRIVE_ID */
|
#else /* !__NEW_HD_DRIVE_ID */
|
||||||
if (id->word93 & 0x2000) {
|
if (id->word93 & 0x2000) {
|
||||||
#endif /* __NEW_HD_DRIVE_ID */
|
#endif /* __NEW_HD_DRIVE_ID */
|
||||||
if (id->dma_ultra & 0x0800) bb_putchar('*');
|
static const masks_labels_t ultra_modes2 = {
|
||||||
if (id->dma_ultra & 0x0008) printf("udma3 ");
|
.masks = { 0x0800, 0x0008, 0x1000, 0x0010,
|
||||||
if (id->dma_ultra & 0x1000) bb_putchar('*');
|
0x2000, 0x0020, 0x4000, 0x0040,
|
||||||
if (id->dma_ultra & 0x0010) printf("udma4 ");
|
0x8000, 0x0080 },
|
||||||
if (id->dma_ultra & 0x2000) bb_putchar('*');
|
.labels = "*\0""udma3 \0""*\0""udma4 \0"
|
||||||
if (id->dma_ultra & 0x0020) printf("udma5 ");
|
"*\0""udma5 \0""*\0""udma6 \0"
|
||||||
if (id->dma_ultra & 0x4000) bb_putchar('*');
|
"*\0""udma7 \0"
|
||||||
if (id->dma_ultra & 0x0040) printf("udma6 ");
|
};
|
||||||
if (id->dma_ultra & 0x8000) bb_putchar('*');
|
print_flags(&ultra_modes2, id->dma_ultra);
|
||||||
if (id->dma_ultra & 0x0080) printf("udma7 ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("\n AdvancedPM=%s", (!(id_regs[83] & 8)) ? "no" : "yes");
|
printf("\n AdvancedPM=%s", (!(id_regs[83] & 8)) ? "no" : "yes");
|
||||||
|
@ -313,6 +313,26 @@ static void
|
|||||||
arp_disp(const char *name, char *ip, int type, int arp_flags,
|
arp_disp(const char *name, char *ip, int type, int arp_flags,
|
||||||
char *hwa, char *mask, char *dev)
|
char *hwa, char *mask, char *dev)
|
||||||
{
|
{
|
||||||
|
static const int arp_masks[] = {
|
||||||
|
ATF_PERM, ATF_PUBL,
|
||||||
|
#ifdef HAVE_ATF_MAGIC
|
||||||
|
ATF_MAGIC,
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_ATF_DONTPUB
|
||||||
|
ATF_DONTPUB,
|
||||||
|
#endif
|
||||||
|
ATF_USETRAILERS,
|
||||||
|
};
|
||||||
|
static const char arp_labels[] ALIGN1 = "PERM\0""PUP\0"
|
||||||
|
#ifdef HAVE_ATF_MAGIC
|
||||||
|
"AUTO\0"
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_ATF_DONTPUB
|
||||||
|
"DONTPUB\0"
|
||||||
|
#endif
|
||||||
|
"TRAIL\0"
|
||||||
|
;
|
||||||
|
|
||||||
const struct hwtype *xhw;
|
const struct hwtype *xhw;
|
||||||
|
|
||||||
xhw = get_hwntype(type);
|
xhw = get_hwntype(type);
|
||||||
@ -333,22 +353,8 @@ arp_disp(const char *name, char *ip, int type, int arp_flags,
|
|||||||
if (arp_flags & ATF_NETMASK)
|
if (arp_flags & ATF_NETMASK)
|
||||||
printf("netmask %s ", mask);
|
printf("netmask %s ", mask);
|
||||||
|
|
||||||
if (arp_flags & ATF_PERM)
|
print_flags_separated(arp_masks, arp_labels, arp_flags, " ");
|
||||||
printf("PERM ");
|
printf(" on %s\n", dev);
|
||||||
if (arp_flags & ATF_PUBL)
|
|
||||||
printf("PUP ");
|
|
||||||
#ifdef HAVE_ATF_MAGIC
|
|
||||||
if (arp_flags & ATF_MAGIC)
|
|
||||||
printf("AUTO ");
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ATF_DONTPUB
|
|
||||||
if (arp_flags & ATF_DONTPUB)
|
|
||||||
printf("DONTPUB ");
|
|
||||||
#endif
|
|
||||||
if (arp_flags & ATF_USETRAILERS)
|
|
||||||
printf("TRAIL ");
|
|
||||||
|
|
||||||
printf("on %s\n", dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Display the contents of the ARP cache in the kernel. */
|
/* Display the contents of the ARP cache in the kernel. */
|
||||||
|
@ -45,16 +45,15 @@ typedef struct filter_t {
|
|||||||
|
|
||||||
static void print_link_flags(unsigned flags, unsigned mdown)
|
static void print_link_flags(unsigned flags, unsigned mdown)
|
||||||
{
|
{
|
||||||
|
static const int flag_masks[] = {
|
||||||
|
IFF_LOOPBACK, IFF_BROADCAST, IFF_POINTOPOINT,
|
||||||
|
IFF_MULTICAST, IFF_NOARP, IFF_UP, IFF_LOWER_UP };
|
||||||
|
static const char flag_labels[] ALIGN1 =
|
||||||
|
"LOOPBACK\0""BROADCAST\0""POINTOPOINT\0"
|
||||||
|
"MULTICAST\0""NOARP\0""UP\0""LOWER_UP\0";
|
||||||
|
|
||||||
bb_putchar('<');
|
bb_putchar('<');
|
||||||
flags &= ~IFF_RUNNING;
|
flags &= ~IFF_RUNNING;
|
||||||
#define _PF(f) if (flags & IFF_##f) { \
|
|
||||||
flags &= ~IFF_##f; \
|
|
||||||
printf(#f "%s", flags ? "," : ""); }
|
|
||||||
_PF(LOOPBACK);
|
|
||||||
_PF(BROADCAST);
|
|
||||||
_PF(POINTOPOINT);
|
|
||||||
_PF(MULTICAST);
|
|
||||||
_PF(NOARP);
|
|
||||||
#if 0
|
#if 0
|
||||||
_PF(ALLMULTI);
|
_PF(ALLMULTI);
|
||||||
_PF(PROMISC);
|
_PF(PROMISC);
|
||||||
@ -66,9 +65,7 @@ static void print_link_flags(unsigned flags, unsigned mdown)
|
|||||||
_PF(PORTSEL);
|
_PF(PORTSEL);
|
||||||
_PF(NOTRAILERS);
|
_PF(NOTRAILERS);
|
||||||
#endif
|
#endif
|
||||||
_PF(UP);
|
flags = print_flags_separated(flag_masks, flag_labels, flags, ",");
|
||||||
_PF(LOWER_UP);
|
|
||||||
#undef _PF
|
|
||||||
if (flags)
|
if (flags)
|
||||||
printf("%x", flags);
|
printf("%x", flags);
|
||||||
if (mdown)
|
if (mdown)
|
||||||
|
@ -502,6 +502,8 @@ xbsd_print_disklabel(int show_all)
|
|||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
if (show_all) {
|
if (show_all) {
|
||||||
|
static const int d_masks[] = { BSD_D_REMOVABLE, BSD_D_ECC, BSD_D_BADSECT };
|
||||||
|
|
||||||
#if defined(__alpha__)
|
#if defined(__alpha__)
|
||||||
printf("# %s:\n", disk_device);
|
printf("# %s:\n", disk_device);
|
||||||
#else
|
#else
|
||||||
@ -513,13 +515,8 @@ xbsd_print_disklabel(int show_all)
|
|||||||
printf("type: %d\n", lp->d_type);
|
printf("type: %d\n", lp->d_type);
|
||||||
printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename);
|
printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename);
|
||||||
printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname);
|
printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname);
|
||||||
printf("flags:");
|
printf("flags: ");
|
||||||
if (lp->d_flags & BSD_D_REMOVABLE)
|
print_flags_separated(d_masks, "removable\0""ecc\0""badsect\0", lp->d_flags, " ");
|
||||||
printf(" removable");
|
|
||||||
if (lp->d_flags & BSD_D_ECC)
|
|
||||||
printf(" ecc");
|
|
||||||
if (lp->d_flags & BSD_D_BADSECT)
|
|
||||||
printf(" badsect");
|
|
||||||
bb_putchar('\n');
|
bb_putchar('\n');
|
||||||
/* On various machines the fields of *lp are short/int/long */
|
/* On various machines the fields of *lp are short/int/long */
|
||||||
/* In order to avoid problems, we cast them all to long. */
|
/* In order to avoid problems, we cast them all to long. */
|
||||||
|
Loading…
Reference in New Issue
Block a user