summaryrefslogtreecommitdiffstats
path: root/src/pblocksize.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2008-08-25 23:15:17 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2008-08-25 23:15:17 +0200
commitd5d0a9a74f20ab8288f81ec96be48636dd6e0686 (patch)
treed9ca34d754825448472b3670afaef7a8d43f38e6 /src/pblocksize.c
parentc943ebd716ad2f71d2f73abc821e266be552a36f (diff)
Split the interface in several files, part 2
Text interface needs 24 lines instead of 25
Diffstat (limited to 'src/pblocksize.c')
-rw-r--r--src/pblocksize.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/pblocksize.c b/src/pblocksize.c
new file mode 100644
index 0000000..9c9a4af
--- /dev/null
+++ b/src/pblocksize.c
@@ -0,0 +1,142 @@
+/*
+
+ File: pblocksize.c
+
+ Copyright (C) 1998-2008 Christophe GRENIER <grenier@cgsecurity.org>
+
+ This software is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write the Free Software Foundation, Inc., 51
+ Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "types.h"
+#include "common.h"
+#include "intrf.h"
+#ifdef HAVE_NCURSES
+#include "intrfn.h"
+#else
+#include <stdio.h>
+#endif
+#include "log.h"
+#include "pblocksize.h"
+
+#ifdef HAVE_NCURSES
+unsigned int menu_choose_blocksize(unsigned int blocksize, const unsigned int sector_size, uint64_t *offset)
+{
+ int command;
+ unsigned int menu=0;
+ const char *optionsBlocksize="S51248736";
+ static const struct MenuItem menuBlocksize[]=
+ {
+ {'S',"256",""},
+ {'5',"512",""},
+ {'1',"1024",""},
+ {'2',"2048",""},
+ {'4',"4096",""},
+ {'8',"8192",""},
+ {'7',"16384",""},
+ {'3',"32768",""},
+ {'6',"65536",""},
+ {0,NULL,NULL}
+ };
+ switch(sector_size)
+ {
+ case 512: optionsBlocksize+=1; break;
+ case 1024: optionsBlocksize+=2; break;
+ case 2048: optionsBlocksize+=3; break;
+ case 4096: optionsBlocksize+=4; break;
+ case 8192: optionsBlocksize+=5; break;
+ case 16384: optionsBlocksize+=6;break;
+ case 32768: optionsBlocksize+=7; break;
+ case 65536: optionsBlocksize+=8; break;
+ }
+ switch(blocksize)
+ {
+ case 256: menu=0; break;
+ case 512: menu=1; break;
+ case 1024: menu=2; break;
+ case 2048: menu=3; break;
+ case 4096: menu=4; break;
+ case 8192: menu=5; break;
+ case 16384: menu=6; break;
+ case 32768: menu=7; break;
+ case 65536: menu=8; break;
+ }
+ aff_copy(stdscr);
+ wmove(stdscr,INTER_PARTITION_Y-1,0);
+ wprintw(stdscr,"Please select the block size, press Enter when done.");
+ command = wmenuSelect_ext(stdscr, 23, INTER_PARTITION_Y, INTER_PARTITION_X, menuBlocksize, 7,
+ optionsBlocksize, MENU_VERT| MENU_BUTTON|MENU_VERT_WARN, &menu,NULL);
+ switch(command)
+ {
+ case 'S': blocksize=256; break;
+ case '5': blocksize=512; break;
+ case '1': blocksize=1024; break;
+ case '2': blocksize=2048; break;
+ case '4': blocksize=4096; break;
+ case '8': blocksize=8192; break;
+ case '7': blocksize=16384; break;
+ case '3': blocksize=32768; break;
+ case '6': blocksize=65536; break;
+ }
+ if(*offset%sector_size!=0 || *offset>=blocksize)
+ *offset=0;
+ if(sector_size < blocksize)
+ {
+ unsigned int quit=0;
+ aff_copy(stdscr);
+ wmove(stdscr,INTER_PARTITION_Y-2,0);
+ wprintw(stdscr,"Please select the offset (0 - %u). Press Up/Down to increase/decrease it,",blocksize-sector_size);
+ wmove(stdscr,INTER_PARTITION_Y-1,0);
+ wprintw(stdscr,"Enter when done.");
+ do
+ {
+ wmove(stdscr,INTER_PARTITION_Y,0);
+ wclrtoeol(stdscr);
+ wprintw(stdscr,"Offset %u",(unsigned int)(*offset));
+ switch(wgetch(stdscr))
+ {
+ case KEY_ENTER:
+#ifdef PADENTER
+ case PADENTER:
+#endif
+ case '\n':
+ case '\r':
+ quit=1;
+ break;
+ case KEY_PPAGE:
+ case KEY_UP:
+ case KEY_RIGHT:
+ case '+':
+ if(*offset + sector_size < blocksize)
+ *offset+=sector_size;
+ break;
+ case KEY_NPAGE:
+ case KEY_DOWN:
+ case KEY_LEFT:
+ case '-':
+ if(*offset >= sector_size)
+ *offset-=sector_size;
+ break;
+ }
+ } while(quit==0);
+ }
+ log_info("blocksize=%u,offset=%u\n",blocksize,(unsigned int)*offset);
+ return blocksize;
+}
+#endif