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

issue(mknfs does not work, infinty loop to be fixed)

parent aa5b2f58
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ void read_bloc(unsigned int vol, unsigned int nbloc, unsigned char *buffer) ...@@ -47,6 +47,7 @@ void read_bloc(unsigned int vol, unsigned int nbloc, unsigned char *buffer)
{ {
unsigned int sector_cylinder[2]; unsigned int sector_cylinder[2];
get_sector_cylinder(vol, nbloc, sector_cylinder); /* [sector, cylinder] */ get_sector_cylinder(vol, nbloc, sector_cylinder); /* [sector, cylinder] */
printf("%d %d\n", sector_cylinder[0], sector_cylinder[1]);
read_sector(buffer, sector_cylinder[1], sector_cylinder[0]); read_sector(buffer, sector_cylinder[1], sector_cylinder[0]);
} }
...@@ -160,23 +161,32 @@ void remove_vol(int vol) ...@@ -160,23 +161,32 @@ void remove_vol(int vol)
mbr.nb_vols--; mbr.nb_vols--;
} }
void init_volume(unsigned int vol) void init_volume(unsigned int vol, char name[32])
{ {
int i; int i;
vsuper_t super; vsuper_t super;
vol_t volume;
unsigned char buffer[sizeof(vsuper_t)];
super.magic = MAGIC; super.magic = MAGIC;
super.serie = vol; super.serie = vol;
sprintf(super.name, "volume %i", vol); strcpy(super.name, name);
super.id = vol; super.id = vol;
super.first_free = 1; super.first_free = 1;
write_bloc(vol, SUPER_BLOC, &super); super.nb_free_blocs = HDA_SECTORSIZE - 1;
memcpy(buffer, &super, sizeof(vsuper_t));
write_bloc(vol, SUPER_BLOC, buffer);
for (int i = 1; i < HDA_SECTORSIZE; i++) volume = mbr.vols[vol];
for (i = 1; i < volume.nb_blocs; i++)
{ {
vblockchain_t blockchain; vblockchain_t blockchain;
blockchain.next = (i + 1) % HDA_SECTORSIZE; unsigned char buf[sizeof(vblockchain_t)];
write_bloc(vol, i, &blockchain);
blockchain.next = (i + 1) % volume.nb_blocs;
memcpy(buf, &blockchain, sizeof(vblockchain_t));
write_bloc(vol, i, buf);
} }
} }
...@@ -187,7 +197,9 @@ int load_super(unsigned int vol) ...@@ -187,7 +197,9 @@ int load_super(unsigned int vol)
read_bloc(vol, SUPER_BLOC, buffer); read_bloc(vol, SUPER_BLOC, buffer);
memcpy(&super, buffer, sizeof(vsuper_t)); memcpy(&super, buffer, sizeof(vsuper_t));
assert(super.magic == MAGIC); /* printf("%d %d %d %d %d %s\n", super.id, super.first_free, super.magic, super.nb_free_blocs, super.serie, super.name); */
/* assert(super.magic == MAGIC); */
return 0;
} }
void save_super() void save_super()
...@@ -215,6 +227,7 @@ unsigned int new_bloc() ...@@ -215,6 +227,7 @@ unsigned int new_bloc()
new_bloc = super.first_free; new_bloc = super.first_free;
super.first_free = blockchain.next; super.first_free = blockchain.next;
super.nb_free_blocs--;
return new_bloc; return new_bloc;
} }
...@@ -225,8 +238,9 @@ void free_bloc(unsigned int bloc) ...@@ -225,8 +238,9 @@ void free_bloc(unsigned int bloc)
vblockchain_t blockchain; vblockchain_t blockchain;
blockchain.next = super.first_free; blockchain.next = super.first_free;
super.first_free = bloc;
memcpy(buffer, &blockchain, sizeof(vblockchain_t)); memcpy(buffer, &blockchain, sizeof(vblockchain_t));
write_bloc(super.id, bloc, buffer); write_bloc(super.id, bloc, buffer);
super.first_free = bloc;
super.nb_free_blocs++;
} }
\ No newline at end of file
...@@ -35,9 +35,10 @@ typedef struct vsuper_s ...@@ -35,9 +35,10 @@ typedef struct vsuper_s
{ {
unsigned int magic; unsigned int magic;
unsigned int serie; unsigned int serie;
unsigned char *name; char name[32];
unsigned int id; unsigned int id;
unsigned int first_free; unsigned int first_free;
unsigned int nb_free_blocs;
} vsuper_t; } vsuper_t;
vsuper_t super; vsuper_t super;
...@@ -59,7 +60,7 @@ void create_vol(unsigned int nb_blocs, unsigned int cylinder, unsigned int secto ...@@ -59,7 +60,7 @@ void create_vol(unsigned int nb_blocs, unsigned int cylinder, unsigned int secto
void display_vols(); void display_vols();
void remove_vol(); void remove_vol();
void init_volume(unsigned int vol); void init_volume(unsigned int vol, char *name);
int load_super(unsigned int vol); int load_super(unsigned int vol);
void save_super(); void save_super();
unsigned int new_bloc(); unsigned int new_bloc();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment