FYP Update 09/02/2009
Some ground was made today. Had a meeting with Paul Kelly on friday 6th feb – first after the christmas and exam break – and it went well. As seen in previous blog entries i had started to code some parts of the ESAD tool in fragments, i.e. picking out what i thought were difficult bits to code and trying to solve them.
At the meeting with Paul he set goals for me to hit and they were to start with a simple interface and work on drawing out a hardcoded superblock for EXT2. I have to admit i was a bit worried about the superblock part of this project as i thought it would be the most difficult to draw – famous last words – but after getting used to the cairo drawing library it doesn’t seem as daunting of a task. knowing me saying that though it will come back to bite me in the arse royally.
For my next meeting with Paul i need to have a hardcoded superblock displaying and i’m half way there. I’m having problems randomly generating the block numbers for the free blocks in the superblock. the image below shows how far i’ve gotten at of the time of this post. the text box is so that a user can enter in how many bytes they want to allocate although for the meeting next friday (13th feb) i may only have time to code it in terms of blocks so that 1 block is equal to 1 byte.
window before clicking go:

image after clicking go (note the 1024’s are hardcoded in for the time being to get positioning correct):

here is some of the code used to create the above.
[code lang="c"]
//function the draw a simple rectangle.
void drawSB(GtkWidget *widget, gpointer darea)
{
GtkWidget *boxwidget;
g_return_if_fail(GTK_IS_WIDGET(darea));
boxwidget = GTK_WIDGET(darea);
cairo_t *cr;
cr = gdk_cairo_create(GDK_DRAWABLE(boxwidget->window));
cairo_set_line_width(cr, 2);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
//superblock
cairo_select_font_face(cr, "Courier", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr, 13);
int i;
gchar* colour = "red";
for(i = 30 ; i <= 190 ; i += 40)
{
//rectangle to draw
cairo_rectangle(cr, i, 60, 40, 30);
//set the first block to be red, and the rest green.
if( strcmp(colour, "red") == 0 )
{
cairo_set_source_rgb(cr, 1.0, 0, 0);
cairo_fill(cr);
colour = "green";
}
else
{
cairo_set_source_rgb(cr, 0, 1.0, 0);
cairo_fill(cr);
}
//black outline of each data block.
cairo_set_source_rgb(cr, 0.1, 0, 0);
cairo_rectangle(cr, i, 60, 40, 30);
cairo_stroke(cr);
}
//loop to add in the text for the blocks
for(i = 35 ; i <= 195 ; i += 40)
{
cairo_move_to(cr, i, 80);
//cairo_show_text(cr, "1024");
char* text = gen_random();
g_print(text);
cairo_show_text(cr, text);
}
cairo_move_to(cr,30,55);
cairo_show_text(cr, "SuperBlock");
cairo_destroy(cr);
}
[/code]
[code lang="c"]
//function to return a string of a random number.
gchar* gen_random()
{
int n;
n = rand()%10000;
char text[10];
gchar* textreturn;
sprintf(text, "%d", n);
textreturn = (gchar*)text;
g_print("%s\n", textreturn);
return textreturn;
}
[/code]
the above code has a bug in it, the gen_random() function doesn’t return the string properly so the numbers do not get put inside the data blocks as of yet.
overall i’m happy with the progress that i have made today, but i still have a long way to go with this project but i’m feeling somewhat happier about it now that i’ve stuck my teeth in a little.