aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-11-27 06:13:43 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-11-27 06:13:43 +0100
commit29516ac0e41fc41dd15b7d0c67bd160f03d21bbb (patch)
tree5c5df00c64e1ed9361243540657e3391c69004c2
parent351ab8278e9719cfdc2abb348017b4e5909bcee8 (diff)
downloadbusybox-w32-29516ac0e41fc41dd15b7d0c67bd160f03d21bbb.tar.gz
busybox-w32-29516ac0e41fc41dd15b7d0c67bd160f03d21bbb.tar.bz2
busybox-w32-29516ac0e41fc41dd15b7d0c67bd160f03d21bbb.zip
fdisk: sanitize partition name printing; drop "Code" column; get rid of one static var
function old new delta list_table 2335 2373 +38 fill_bounds 131 128 -3 part_array_len 4 - -4 get_boot 1584 1574 -10 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/2 up/down: 38/-17) Total: 21 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/fdisk.c1
-rw-r--r--util-linux/fdisk_gpt.c56
2 files changed, 42 insertions, 15 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index af8073532..b988e65a9 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -121,6 +121,7 @@
121# define BLKGETSIZE64 _IOR(0x12,114,size_t) 121# define BLKGETSIZE64 _IOR(0x12,114,size_t)
122#endif 122#endif
123#include "libbb.h" 123#include "libbb.h"
124#include "unicode.h"
124 125
125#if BB_LITTLE_ENDIAN 126#if BB_LITTLE_ENDIAN
126# define inline_if_little_endian ALWAYS_INLINE 127# define inline_if_little_endian ALWAYS_INLINE
diff --git a/util-linux/fdisk_gpt.c b/util-linux/fdisk_gpt.c
index 715e227ca..9b17b4a57 100644
--- a/util-linux/fdisk_gpt.c
+++ b/util-linux/fdisk_gpt.c
@@ -36,14 +36,13 @@ typedef struct {
36 uint64_t lba_start; 36 uint64_t lba_start;
37 uint64_t lba_end; 37 uint64_t lba_end;
38 uint64_t flags; 38 uint64_t flags;
39 uint16_t name[36]; 39 uint16_t name36[36];
40} gpt_partition; 40} gpt_partition;
41 41
42static gpt_header *gpt_hdr; 42static gpt_header *gpt_hdr;
43 43
44static char *part_array; 44static char *part_array;
45static unsigned int n_parts; 45static unsigned int n_parts;
46static unsigned int part_array_len;
47static unsigned int part_entry_len; 46static unsigned int part_entry_len;
48 47
49static inline gpt_partition * 48static inline gpt_partition *
@@ -73,18 +72,34 @@ gpt_print_guid(uint8_t *buf)
73 buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); 72 buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
74} 73}
75 74
76/* TODO: real unicode support */
77static void 75static void
78gpt_print_wide(uint16_t *s, int max_len) 76gpt_print_wide36(uint16_t *s)
79{ 77{
78#if ENABLE_UNICODE_SUPPORT
79 char buf[37 * 4];
80 wchar_t wc[37];
80 int i = 0; 81 int i = 0;
81 82 while (i < ARRAY_SIZE(wc)-1) {
82 while (i < max_len) { 83 if (s[i] == 0)
83 if (*s == 0) 84 break;
84 return; 85 wc[i] = s[i];
85 fputc(*s, stdout); 86 i++;
86 s++; 87 }
88 wc[i] = 0;
89 if (wcstombs(buf, wc, sizeof(buf)) <= sizeof(buf)-1)
90 fputs(printable_string(NULL, buf), stdout);
91#else
92 char buf[37];
93 int i = 0;
94 while (i < ARRAY_SIZE(buf)-1) {
95 if (s[i] == 0)
96 break;
97 buf[i] = (s[i] < 0x7f) ? s[i] : '?';
98 i++;
87 } 99 }
100 buf[i] = '\0';
101 fputs(printable_string(NULL, buf), stdout);
102#endif
88} 103}
89 104
90static void 105static void
@@ -106,19 +121,28 @@ gpt_list_table(int xtra UNUSED_PARAM)
106 (unsigned long long)SWAP_LE64(gpt_hdr->first_usable_lba), 121 (unsigned long long)SWAP_LE64(gpt_hdr->first_usable_lba),
107 (unsigned long long)SWAP_LE64(gpt_hdr->last_usable_lba)); 122 (unsigned long long)SWAP_LE64(gpt_hdr->last_usable_lba));
108 123
109 puts("Number Start (sector) End (sector) Size Code Name"); 124/* "GPT fdisk" has a concept of 16-bit extension of the original MBR 8-bit type codes,
125 * which it displays here: its output columns are ... Size Code Name
126 * They are their own invention and are not stored on disk.
127 * Looks like they use them to support "hybrid" GPT: for example, they have
128 * AddType(0x8307, "69DAD710-2CE4-4E3C-B16C-21A1D49ABED3", "Linux ARM32 root (/)");
129 * and then (code>>8) matches what you need to put into MBR's type field for such a partition.
130 * To print those codes, we'd need a GUID lookup table. Lets just drop the "Code" column instead:
131 */
132 puts("Number Start (sector) End (sector) Size Name");
133 // 123456 123456789012345 123456789012345 12345 abc
110 for (i = 0; i < n_parts; i++) { 134 for (i = 0; i < n_parts; i++) {
111 gpt_partition *p = gpt_part(i); 135 gpt_partition *p = gpt_part(i);
112 if (p->lba_start) { 136 if (p->lba_start) {
113 smart_ulltoa5((1 + SWAP_LE64(p->lba_end) - SWAP_LE64(p->lba_start)) * sector_size, 137 smart_ulltoa5((1 + SWAP_LE64(p->lba_end) - SWAP_LE64(p->lba_start)) * sector_size,
114 numstr6, " KMGTPEZY")[0] = '\0'; 138 numstr6, " KMGTPEZY")[0] = '\0';
115 printf("%4u %15llu %15llu %11s %04x ", 139 printf("%6u %15llu %15llu %s ",
116 i + 1, 140 i + 1,
117 (unsigned long long)SWAP_LE64(p->lba_start), 141 (unsigned long long)SWAP_LE64(p->lba_start),
118 (unsigned long long)SWAP_LE64(p->lba_end), 142 (unsigned long long)SWAP_LE64(p->lba_end),
119 numstr6, 143 numstr6
120 0x0700 /* FIXME */); 144 );
121 gpt_print_wide(p->name, 18); 145 gpt_print_wide36(p->name36);
122 bb_putchar('\n'); 146 bb_putchar('\n');
123 } 147 }
124 } 148 }
@@ -127,6 +151,7 @@ gpt_list_table(int xtra UNUSED_PARAM)
127static int 151static int
128check_gpt_label(void) 152check_gpt_label(void)
129{ 153{
154 unsigned part_array_len;
130 struct partition *first = pt_offset(MBRbuffer, 0); 155 struct partition *first = pt_offset(MBRbuffer, 0);
131 struct pte pe; 156 struct pte pe;
132 uint32_t crc; 157 uint32_t crc;
@@ -150,6 +175,7 @@ check_gpt_label(void)
150 return 0; 175 return 0;
151 } 176 }
152 177
178 init_unicode();
153 if (!global_crc32_table) { 179 if (!global_crc32_table) {
154 global_crc32_table = crc32_filltable(NULL, 0); 180 global_crc32_table = crc32_filltable(NULL, 0);
155 } 181 }