diff --git a/tpfs/vol.c b/tpfs/vol.c index 70f97f93fc1aaa1856ad7e5ed17b9a3493478892..6d181226da5176388a0ba727053c0f7a33177a29 100644 --- a/tpfs/vol.c +++ b/tpfs/vol.c @@ -47,6 +47,7 @@ void read_bloc(unsigned int vol, unsigned int nbloc, unsigned char *buffer) { unsigned int sector_cylinder[2]; 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]); } @@ -160,23 +161,32 @@ void remove_vol(int vol) mbr.nb_vols--; } -void init_volume(unsigned int vol) +void init_volume(unsigned int vol, char name[32]) { int i; vsuper_t super; + vol_t volume; + unsigned char buffer[sizeof(vsuper_t)]; super.magic = MAGIC; super.serie = vol; - sprintf(super.name, "volume %i", vol); + strcpy(super.name, name); super.id = vol; super.first_free = 1; - write_bloc(vol, SUPER_BLOC, &super); + super.nb_free_blocs = HDA_SECTORSIZE - 1; - for (int i = 1; i < HDA_SECTORSIZE; i++) + memcpy(buffer, &super, sizeof(vsuper_t)); + write_bloc(vol, SUPER_BLOC, buffer); + + volume = mbr.vols[vol]; + for (i = 1; i < volume.nb_blocs; i++) { vblockchain_t blockchain; - blockchain.next = (i + 1) % HDA_SECTORSIZE; - write_bloc(vol, i, &blockchain); + unsigned char buf[sizeof(vblockchain_t)]; + + 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) read_bloc(vol, SUPER_BLOC, buffer); 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() @@ -215,6 +227,7 @@ unsigned int new_bloc() new_bloc = super.first_free; super.first_free = blockchain.next; + super.nb_free_blocs--; return new_bloc; } @@ -225,8 +238,9 @@ void free_bloc(unsigned int bloc) vblockchain_t blockchain; blockchain.next = super.first_free; - super.first_free = bloc; - memcpy(buffer, &blockchain, sizeof(vblockchain_t)); write_bloc(super.id, bloc, buffer); + + super.first_free = bloc; + super.nb_free_blocs++; } \ No newline at end of file diff --git a/tpfs/vol.h b/tpfs/vol.h index 8dd80e135f7494646ce6ba59396c3a66324f0453..f934dd07ad566495308963af6acc4a4c7a3a7ba2 100644 --- a/tpfs/vol.h +++ b/tpfs/vol.h @@ -35,9 +35,10 @@ typedef struct vsuper_s { unsigned int magic; unsigned int serie; - unsigned char *name; + char name[32]; unsigned int id; unsigned int first_free; + unsigned int nb_free_blocs; } vsuper_t; vsuper_t super; @@ -59,7 +60,7 @@ void create_vol(unsigned int nb_blocs, unsigned int cylinder, unsigned int secto void display_vols(); void remove_vol(); -void init_volume(unsigned int vol); +void init_volume(unsigned int vol, char *name); int load_super(unsigned int vol); void save_super(); unsigned int new_bloc();