From 61e7641cfbad3c1b1647b28f018a0aee5ad2cabe Mon Sep 17 00:00:00 2001 From: Bah Thierno-Souleymane <thiernosouleymane.bah.etu@univ-lille.fr> Date: Fri, 26 Mar 2021 02:04:52 +0100 Subject: [PATCH] feat(new_bloc function added) --- tpfs/vol.c | 21 +++++++++++++++++++++ tpfs/vol.h | 1 + 2 files changed, 22 insertions(+) diff --git a/tpfs/vol.c b/tpfs/vol.c index d61d2fe..f8c8f1d 100644 --- a/tpfs/vol.c +++ b/tpfs/vol.c @@ -196,4 +196,25 @@ void save_super() memcpy(buffer, &super, sizeof(vsuper_t)); write_bloc(super.id, SUPER_BLOC, buffer); +} + +unsigned int new_bloc() +{ + unsigned int new_bloc; + unsigned char buffer[sizeof(vblockchain_t)]; + vblockchain_t blockchain; + + if (!super.first_free) + { + fprintf(stderr, "Il n'y a pas de bloc libre"); + return 0; + } + + read_bloc(super.id, super.first_free, buffer); + memcpy(&blockchain, buffer, sizeof(vblockchain_t)); + + new_bloc = super.first_free; + super.first_free = blockchain.next; + + return new_bloc; } \ No newline at end of file diff --git a/tpfs/vol.h b/tpfs/vol.h index 9dadedc..a090f2c 100644 --- a/tpfs/vol.h +++ b/tpfs/vol.h @@ -62,5 +62,6 @@ void remove_vol(); void init_volume(unsigned int vol); int load_super(unsigned int vol); void save_super(); +unsigned int new_bloc(); #endif -- GitLab