summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2008-04-11 11:27:40 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2008-04-11 11:27:40 +0200
commit12da0317f4046ed9425571d9752080d7f62d1f6e (patch)
tree8c2edb1376e2721259cd068b801428bc96432153 /src
parentc6ffc1812d87fb555b704cf26bb1f3d883cade72 (diff)
Partition type modification: only use number for Intel and Sun, otherwise select in a list.
Diffstat (limited to 'src')
-rw-r--r--src/chgtype.c122
1 files changed, 121 insertions, 1 deletions
diff --git a/src/chgtype.c b/src/chgtype.c
index c5e5bc6..17722ef 100644
--- a/src/chgtype.c
+++ b/src/chgtype.c
@@ -41,6 +41,8 @@
extern const arch_fnct_t arch_gpt;
extern const arch_fnct_t arch_none;
+extern const arch_fnct_t arch_i386;
+extern const arch_fnct_t arch_sun;
struct part_name_struct
{
@@ -118,6 +120,121 @@ static void change_part_type_ncurses(const disk_t *disk_car,partition_t *partiti
partition->arch->set_part_type(partition,tmp_val);
}
}
+#define INTER_CHGTYPE 15
+#define INTER_CHGTYPE_X 0
+#define INTER_CHGTYPE_Y 23
+
+static void change_part_type_ncurses2(const disk_t *disk_car, partition_t *partition)
+{
+ partition_t *new_partition;
+ unsigned int intr_nbr_line=0;
+ unsigned int offset=0;
+ unsigned int i;
+ unsigned int current_element_num=0;
+ struct part_name_struct part_name[0x100];
+ aff_copy(stdscr);
+ wmove(stdscr,4,0);
+ aff_part(stdscr, AFF_PART_ORDER|AFF_PART_STATUS, disk_car, partition);
+ wmove(stdscr,INTER_CHGTYPE_Y, INTER_CHGTYPE_X);
+ wattrset(stdscr, A_REVERSE);
+ wprintw(stdscr, "[ Proceed ]");
+ wattroff(stdscr, A_REVERSE);
+ /* Create an index of all partition type except Intel extended */
+ new_partition=partition_new(NULL);
+ dup_partition_t(new_partition,partition);
+ for(i=0;i<=0xFF;i++)
+ {
+ if(partition->arch->set_part_type(new_partition,i)==0)
+ {
+ part_name[intr_nbr_line].name=new_partition->arch->get_partition_typename(new_partition);
+ if(part_name[intr_nbr_line].name!=NULL)
+ {
+ if(partition->arch->get_part_type(partition)==i)
+ current_element_num=intr_nbr_line;
+ part_name[intr_nbr_line++].index=i;
+ }
+ }
+ }
+ free(new_partition);
+ while(1)
+ {
+ wmove(stdscr,5,0);
+ wprintw(stdscr, "Please choose the partition type, press Enter when done.");
+ wmove(stdscr,5+1,1);
+ wclrtoeol(stdscr);
+ if(offset>0)
+ wprintw(stdscr, "Previous");
+ for(i=offset;i<intr_nbr_line && (i-offset)<3*INTER_CHGTYPE;i++)
+ {
+ if(i-offset<INTER_CHGTYPE)
+ wmove(stdscr,5+2+i-offset,0);
+ else if(i-offset<2*INTER_CHGTYPE)
+ wmove(stdscr,5+2+i-offset-INTER_CHGTYPE,26);
+ else
+ wmove(stdscr,5+2+i-offset-2*INTER_CHGTYPE,52);
+ wclrtoeol(stdscr); /* before addstr for BSD compatibility */
+ if(i==current_element_num)
+ {
+ wattrset(stdscr, A_REVERSE);
+ wprintw(stdscr,"%s", part_name[i].name);
+ wattroff(stdscr, A_REVERSE);
+ } else
+ {
+ wprintw(stdscr,"%s", part_name[i].name);
+ }
+ }
+ if(i-offset<INTER_CHGTYPE)
+ wmove(stdscr,5+2+i-offset,1);
+ else if(i-offset<2*INTER_CHGTYPE)
+ wmove(stdscr,5+2+i-offset-INTER_CHGTYPE,27);
+ else
+ wmove(stdscr,5+2+i-offset-2*INTER_CHGTYPE,53);
+ wclrtoeol(stdscr);
+ if(i<intr_nbr_line)
+ wprintw(stdscr, "Next");
+ switch(wgetch(stdscr))
+ {
+ case 'p':
+ case 'P':
+ case KEY_UP:
+ if(current_element_num>0)
+ current_element_num--;
+ if(current_element_num<offset)
+ offset=current_element_num;
+ break;
+ case 'n':
+ case 'N':
+ case KEY_DOWN:
+ if(current_element_num < intr_nbr_line-1)
+ current_element_num++;
+ if(current_element_num >= offset+3*INTER_CHGTYPE)
+ offset++;
+ break;
+ case KEY_LEFT:
+ case KEY_PPAGE:
+ if(current_element_num > 3*INTER_CHGTYPE-1)
+ current_element_num-=3*INTER_CHGTYPE-1;
+ else
+ current_element_num=0;
+ if(current_element_num < offset)
+ offset=current_element_num;
+ break;
+ case KEY_RIGHT:
+ case KEY_NPAGE:
+ if(current_element_num+3*INTER_CHGTYPE-1 < intr_nbr_line-1)
+ current_element_num+=3*INTER_CHGTYPE-1;
+ else
+ current_element_num=intr_nbr_line-1;
+ if(current_element_num >= offset+3*INTER_CHGTYPE)
+ offset=current_element_num-1*INTER_CHGTYPE+1;
+ break;
+ case 'Q':
+ case 'q':
+ partition->arch->set_part_type(partition, part_name[current_element_num].index);
+ return;
+ }
+ }
+}
#endif
void change_part_type(const disk_t *disk_car,partition_t *partition, char **current_cmd)
@@ -141,7 +258,10 @@ void change_part_type(const disk_t *disk_car,partition_t *partition, char **curr
else
{
#ifdef HAVE_NCURSES
- change_part_type_ncurses(disk_car, partition);
+ if(partition->arch==&arch_i386 || partition->arch==&arch_sun)
+ change_part_type_ncurses(disk_car, partition);
+ else
+ change_part_type_ncurses2(disk_car, partition);
#endif
}
if(arch==&arch_gpt)