From 3a2d1bdb494a5d68581617b1392f665f6625e3d7 Mon Sep 17 00:00:00 2001
From: Bah Thierno-Souleymane <thiernosouleymane.bah.etu@univ-lille.fr>
Date: Fri, 19 Mar 2021 10:29:46 +0100
Subject: [PATCH] feat(mkvol programm done, we can now create a volume)

---
 tpfs/Makefile |  3 ++-
 tpfs/mkvol.c  | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 tpfs/mkvol.c

diff --git a/tpfs/Makefile b/tpfs/Makefile
index 9d177ab..393143b 100644
--- a/tpfs/Makefile
+++ b/tpfs/Makefile
@@ -13,7 +13,7 @@ LIBS    = -L$(LIBDIR) -lhardware
 ###------------------------------
 ### Main targets 
 ###------------------------------------------------------------
-BINARIES= mkhd display_sector format_sector write_sector
+BINARIES= mkhd display_sector format_sector write_sector mkvol
 
 all: $(BINARIES) $(OBJECTS)
 
@@ -31,6 +31,7 @@ mkhd: mkhd.o
 display_sector: display_sector.o drive.o
 format_sector: format_sector.o drive.o
 write_sector: write_sector.o drive.o
+mkvol: mkvol.o vol.o drive.o
 
 ###------------------------------
 ### Misc.
diff --git a/tpfs/mkvol.c b/tpfs/mkvol.c
new file mode 100644
index 0000000..ad8831b
--- /dev/null
+++ b/tpfs/mkvol.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "hardware.h"
+#include "vol.h"
+
+void create_vol(unsigned int nb_blocs, unsigned int cylinder, unsigned int sector, vol_t *volume)
+{
+    if (cylinder + sector == 0)
+    {
+        printf("Impossible d'ecrire à cet endroit\n");
+        return;
+    }
+    volume->nb_blocs = nb_blocs;
+    volume->cylinder = cylinder;
+    volume->sector = sector;
+    volume->type = BASE;
+}
+
+static void
+empty_it()
+{
+    return;
+}
+
+int main(int argc, char const *argv[])
+{
+    unsigned int i;
+
+    /* init hardware */
+    if (init_hardware("hwconfig.ini") == 0)
+    {
+        fprintf(stderr, "Error in hardware initialization\n");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Interreupt handlers */
+    for (i = 0; i < 16; i++)
+        IRQVECTOR[i] = empty_it;
+
+    /* Allows all IT */
+    _mask(1);
+
+    if (argc != 4)
+    {
+        fprintf(stderr, "Usage: %s <number of blocs> <cylinder> <sector> \n", argv[0]);
+        exit(EXIT_FAILURE);
+    }
+
+    if (mbr.nb_vols == VOLS_MAX)
+    {
+        fprintf(stderr, "Le nombre de volumes maximal est atteint \n");
+        exit(EXIT_FAILURE);
+    }
+
+    load_mbr();
+    create_vol(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), mbr.vols + (mbr.nb_vols++));
+    save_mbr();
+
+    /* and exit! */
+    exit(EXIT_SUCCESS);
+}
-- 
GitLab