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

fix(volume programms reorganized in library)

parent 40b87926
No related branches found
No related tags found
No related merge requests found
...@@ -4,30 +4,6 @@ ...@@ -4,30 +4,6 @@
#include "hardware.h" #include "hardware.h"
#include "vol.h" #include "vol.h"
void display_vol()
{
int vol;
char *vtype_names[3] = {"BASE", "ANNEXE", "OTHER"};
vol_t volume;
if (mbr.nb_vols == 0)
{
printf("Il n'y aucun volume.\n");
return;
}
printf("--------------------------\n");
for (vol = 0; vol < mbr.nb_vols; vol++)
{
volume = mbr.vols[vol];
printf("Volume: %d (%s)\n", vol, vtype_names[volume.type]);
printf("> Sector: %d \n", volume.sector);
printf("> Cylinder: %d \n", volume.cylinder);
printf("> Nb blocs: %d \n", volume.nb_blocs);
printf("--------------------------\n");
}
}
static void static void
empty_it() empty_it()
{ {
...@@ -53,7 +29,7 @@ int main(int argc, char const *argv[]) ...@@ -53,7 +29,7 @@ int main(int argc, char const *argv[])
_mask(1); _mask(1);
load_mbr(); load_mbr();
display_vol(); display_vols();
/* and exit! */ /* and exit! */
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
......
...@@ -3,60 +3,6 @@ ...@@ -3,60 +3,6 @@
#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)
{
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)
{
fprintf(stderr, "Impossible d'ecrire à cet endroit \n");
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->cylinder = cylinder;
volume->sector = sector;
volume->type = BASE;
}
static void static void
empty_it() empty_it()
......
...@@ -4,16 +4,6 @@ ...@@ -4,16 +4,6 @@
#include "hardware.h" #include "hardware.h"
#include "vol.h" #include "vol.h"
void display_vol()
{
if (mbr.nb_vols == 0)
{
fprintf(stderr, "Vous ne disposez d'aucun volume \n");
return;
}
mbr.nb_vols--;
}
static void static void
empty_it() empty_it()
{ {
...@@ -39,7 +29,7 @@ int main(int argc, char const *argv[]) ...@@ -39,7 +29,7 @@ int main(int argc, char const *argv[])
_mask(1); _mask(1);
load_mbr(); load_mbr();
display_vol(); remove_vol();
save_mbr(); save_mbr();
/* and exit! */ /* and exit! */
......
...@@ -91,3 +91,90 @@ void format_vol(unsigned int vol) ...@@ -91,3 +91,90 @@ void format_vol(unsigned int vol)
format_sector(sector_cylinder[1], sector_cylinder[1], FMT_SIZE, FMT_DATA); format_sector(sector_cylinder[1], sector_cylinder[1], FMT_SIZE, FMT_DATA);
} }
} }
void create_vol(unsigned int nb_blocs, unsigned int cylinder, unsigned int sector)
{
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)
{
fprintf(stderr, "Impossible d'ecrire à cet endroit \n");
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->cylinder = cylinder;
volume->sector = sector;
volume->type = BASE;
}
void display_vols()
{
int vol;
char *vtype_names[3] = {"BASE", "ANNEXE", "OTHER"};
vol_t volume;
if (mbr.nb_vols == 0)
{
printf("Il n'y aucun volume.\n");
return;
}
printf("--------------------------\n");
for (vol = 0; vol < mbr.nb_vols; vol++)
{
volume = mbr.vols[vol];
printf("Volume: %d (%s)\n", vol, vtype_names[volume.type]);
printf("> Sector: %d \n", volume.sector);
printf("> Cylinder: %d \n", volume.cylinder);
printf("> Nb blocs: %d \n", volume.nb_blocs);
printf("--------------------------\n");
}
}
void remove_vol()
{
if (mbr.nb_vols == 0)
{
fprintf(stderr, "Vous ne disposez d'aucun volume \n");
return;
}
mbr.nb_vols--;
}
\ No newline at end of file
...@@ -33,9 +33,13 @@ mbr_t mbr; ...@@ -33,9 +33,13 @@ mbr_t mbr;
void load_mbr(void); void load_mbr(void);
void save_mbr(void); void save_mbr(void);
void get_sector_cylinder(unsigned int vol, unsigned int nbloc, unsigned int *sector_cylinder); void get_sector_cylinder(unsigned int vol, unsigned int nbloc, unsigned int *sector_cylinder);
void read_bloc(unsigned int vol, unsigned int nbloc, unsigned char *buffer); void read_bloc(unsigned int vol, unsigned int nbloc, unsigned char *buffer);
void write_bloc(unsigned int vol, unsigned int nbloc, unsigned char *buffer); void write_bloc(unsigned int vol, unsigned int nbloc, unsigned char *buffer);
void format_vol(unsigned int vol);
void read_sector_n(unsigned char *buf, int cylinder, int sector, int size); void create_vol(unsigned int nb_blocs, unsigned int cylinder, unsigned int sector);
void display_vols();
void remove_vol();
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment