masterclass le dementor
This commit is contained in:
parent
4f8a0bb720
commit
a09cf2de17
1 changed files with 11 additions and 8 deletions
|
|
@ -41,8 +41,10 @@ int find_free_block(struct bucket *buck)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t num_blocks_in_page = (PAGE_SIZE - sizeof(struct bucket)) / buck->block_size;
|
size_t num_blocks_in_page =
|
||||||
size_t maplength = (num_blocks_in_page + 7) / 8; // +7 for ceiling division (oui c'est moche mais ça marche)
|
(PAGE_SIZE - sizeof(struct bucket)) / buck->block_size;
|
||||||
|
size_t maplength = (num_blocks_in_page + 7)
|
||||||
|
/ 8; // +7 for ceiling division (oui c'est moche mais ça marche)
|
||||||
|
|
||||||
// Foreach byte
|
// Foreach byte
|
||||||
for (unsigned i = 0; i < maplength; i++)
|
for (unsigned i = 0; i < maplength; i++)
|
||||||
|
|
@ -52,8 +54,9 @@ int find_free_block(struct bucket *buck)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (unsigned j = 0; j < 8; j++)
|
for (unsigned j = 0; j < 8; j++)
|
||||||
{
|
{
|
||||||
if ((i * 8 + j) < num_blocks_in_page && !(map_byte & (1 << j))) // Check if free
|
if ((i * 8 + j) < num_blocks_in_page
|
||||||
|
&& !(map_byte & (1 << j))) // Check if free
|
||||||
return i * 8 + j;
|
return i * 8 + j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +81,8 @@ int get_block_number(struct bucket *biquette, void *block)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
char *block_nul = block;
|
char *block_nul = block;
|
||||||
char* bibiche = get_data_begin(biquette); // Célèbre bar Capcinois, venez à l'occasion
|
char *bibiche =
|
||||||
|
get_data_begin(biquette); // Célèbre bar Capcinois, venez à l'occasion
|
||||||
|
|
||||||
return (block_nul - bibiche) / biquette->block_size;
|
return (block_nul - bibiche) / biquette->block_size;
|
||||||
|
|
||||||
|
|
@ -91,7 +95,6 @@ int get_block_number(struct bucket *biquette, void *block)
|
||||||
|
|
||||||
// return (block_nul - biquette_cherie - sizeof(struct bucket))
|
// return (block_nul - biquette_cherie - sizeof(struct bucket))
|
||||||
// / biquette->block_size;
|
// / biquette->block_size;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets a bucket with at least a block_size of size
|
// Gets a bucket with at least a block_size of size
|
||||||
|
|
@ -112,8 +115,8 @@ struct bucket *get_bucket(struct bucket *head, size_t size)
|
||||||
// Computes the buckets first block address
|
// Computes the buckets first block address
|
||||||
void *get_data_begin(struct bucket *biquette)
|
void *get_data_begin(struct bucket *biquette)
|
||||||
{
|
{
|
||||||
void* maisqueltrucdemerde = biquette;
|
void *maisqueltrucdemerde = biquette;
|
||||||
char* biquettas = maisqueltrucdemerde;
|
char *biquettas = maisqueltrucdemerde;
|
||||||
return biquettas + sizeof(struct bucket);
|
return biquettas + sizeof(struct bucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue