Skip to content
Snippets Groups Projects
Commit 227f64c7 authored by Thierno souleymane Bah's avatar Thierno souleymane Bah
Browse files

feat(mkvol programm upgrade, restrictions on sectors and cylinders added)

parent b18dbfdf
Branches
Tags
No related merge requests found
...@@ -3,14 +3,55 @@ ...@@ -3,14 +3,55 @@
#include "hardware.h" #include "hardware.h"
#include "vol.h" #include "vol.h"
#include "drive.h"
void create_vol(unsigned int nb_blocs, unsigned int cylinder, unsigned int sector, vol_t *volume) void create_vol(unsigned int nb_blocs, unsigned int cylinder, unsigned int sector)
{ {
if (cylinder + sector == 0) int i, abs_nbloc, remaining_blocs;
vol_t *volume;
if (mbr.nb_vols == VOLS_MAX)
{
fprintf(stderr, "Le nombre de volumes maximal est atteint \n");
return;
}
if (cylinder + sector == 0 ||
cylinder >= HDA_MAXCYLINDER ||
sector >= HDA_MAXSECTOR)
{ {
printf("Impossible d'ecrire à cet endroit\n"); fprintf(stderr, "Impossible d'ecrire à cet endroit \n");
return; return;
} }
abs_nbloc = cylinder * HDA_MAXSECTOR + sector;
remaining_blocs = HDA_MAXSECTOR * HDA_MAXCYLINDER - abs_nbloc;
if (abs_nbloc > remaining_blocs)
nb_blocs = remaining_blocs;
for (i = 0; i < mbr.nb_vols; i++)
{
vol_t vol = mbr.vols[i];
int vol_abs_nbloc = vol.cylinder * HDA_MAXSECTOR + vol.sector;
/*
* Les deux commencent sur le même bloc
* Les deux se terminent sur le même bloc
* Si le debut de l'un se trouve entre le debut et la fin de l'autre
*/
printf("%d %d %d %d\n", abs_nbloc, abs_nbloc + nb_blocs, vol_abs_nbloc, vol_abs_nbloc + vol.nb_blocs);
if (abs_nbloc == vol_abs_nbloc ||
(abs_nbloc + nb_blocs) == (vol_abs_nbloc + vol.nb_blocs) ||
((abs_nbloc < vol_abs_nbloc) && (vol_abs_nbloc < abs_nbloc + nb_blocs)) ||
((vol_abs_nbloc < abs_nbloc) && (abs_nbloc < vol_abs_nbloc + vol.nb_blocs)))
{
fprintf(stderr, "Le volume %d occupe déjà cet emplacement \n", i);
return;
}
}
volume = mbr.vols + (mbr.nb_vols++);
volume->nb_blocs = nb_blocs; volume->nb_blocs = nb_blocs;
volume->cylinder = cylinder; volume->cylinder = cylinder;
volume->sector = sector; volume->sector = sector;
...@@ -47,14 +88,8 @@ int main(int argc, char const *argv[]) ...@@ -47,14 +88,8 @@ int main(int argc, char const *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (mbr.nb_vols == VOLS_MAX)
{
fprintf(stderr, "Le nombre de volumes maximal est atteint \n");
exit(EXIT_FAILURE);
}
load_mbr(); load_mbr();
create_vol(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), mbr.vols + (mbr.nb_vols++)); create_vol(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
save_mbr(); save_mbr();
/* and exit! */ /* and exit! */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment