From 8b495e929ca77f80e2d8074e28aae9166af75600 Mon Sep 17 00:00:00 2001
From: Bah Thierno-Souleymane <thiernosouleymane.bah.etu@univ-lille.fr>
Date: Fri, 19 Mar 2021 08:46:18 +0100
Subject: [PATCH] =?UTF-8?q?fix(get=5Fsector=5Fcylinder=20function=20patche?=
 =?UTF-8?q?d,=20absolute=20bloc=20n=C2=B0=20of=20a=20volume=20is=20now=20?=
 =?UTF-8?q?=20calculated=20by=20cylinder=20and=20sector)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 tpfs/vol.c | 18 +++++++++++-------
 tpfs/vol.h |  2 +-
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/tpfs/vol.c b/tpfs/vol.c
index e1a8f44..8f5f430 100644
--- a/tpfs/vol.c
+++ b/tpfs/vol.c
@@ -50,12 +50,16 @@ void save_mbr()
     write_sector(0, 0, buffer);
 }
 
-unsigned int *get_sector_cylinder(int vol, int nbloc)
+unsigned int *get_sector_cylinder(unsigned int vol, unsigned int nbloc)
 {
-    assert(vol < mbr.nb_vols);
-    assert(nbloc < mbr.vols[vol].nb_sectors);
     int sector_cylinder[2], absolute_nbloc;
-    absolute_nbloc = (mbr.vols[vol].sector + nbloc);
+    vol_t volume;
+
+    assert(vol < mbr.nb_vols);
+    volume = mbr.vols[vol];
+    assert(nbloc < volume.nb_sectors);
+
+    absolute_nbloc = (volume.cylinder * HDA_MAXSECTOR + volume.sector + nbloc);
     sector_cylinder[0] = absolute_nbloc % HDA_MAXSECTOR;
     sector_cylinder[1] = absolute_nbloc / HDA_MAXCYLINDER;
     return sector_cylinder;
@@ -75,10 +79,10 @@ void write_bloc(unsigned int vol, unsigned int nbloc, const unsigned char *buffe
 
 void format_vol(unsigned int vol)
 {
-    int nbloc;
-    vol_t current_vol = mbr.vols[vol];
+    unsigned int nbloc;
+    vol_t volume = mbr.vols[vol];
 
-    for (nbloc = 0; nbloc < current_vol.nb_sectors; nbloc++)
+    for (nbloc = 0; nbloc < volume.nb_sectors; nbloc++)
     {
         int sector_cylinder[2] = get_sector_cylinder(vol, nbloc);
         format_sector(sector_cylinder[1], sector_cylinder[1], FMT_SIZE, FMT_DATA);
diff --git a/tpfs/vol.h b/tpfs/vol.h
index 77abccb..e16cbe8 100644
--- a/tpfs/vol.h
+++ b/tpfs/vol.h
@@ -32,7 +32,7 @@ typedef struct mbr_s
 
 void load_mbr(void);
 void save_mbr(void);
-unsigned int *get_sector_cylinder(int volume, int bloc);
+unsigned int *get_sector_cylinder(unsigned int vol, unsigned int nbloc);
 void read_bloc(unsigned int vol, unsigned int nbloc, unsigned char *buffer);
 void write_bloc(unsigned int vol, unsigned int nbloc, const unsigned char *buffer);
 
-- 
GitLab