\doxysection{src/disk.h File Reference} \hypertarget{disk_8h}{}\label{disk_8h}\index{src/disk.h@{src/disk.h}} {\ttfamily \#include $<$stdio.\+h$>$}\newline {\ttfamily \#include "{}struct.\+h"{}}\newline {\ttfamily \#include $<$string.\+h$>$}\newline {\ttfamily \#include $<$stdlib.\+h$>$}\newline {\ttfamily \#include $<$unistd.\+h$>$}\newline {\ttfamily \#include "{}env.\+h"{}}\newline {\ttfamily \#include "{}const.\+h"{}}\newline {\ttfamily \#include "{}utils.\+h"{}}\newline Include dependency graph for disk.\+h\+: % FIG 0 This graph shows which files directly or indirectly include this file\+: % FIG 1 \doxysubsubsection*{Functions} \begin{DoxyCompactItemize} \item \mbox{\hyperlink{structdisk}{disk}} \mbox{\hyperlink{disk_8h_a7eb10c7006ff648d851b15f24e4305c3}{create\+\_\+disk}} () \begin{DoxyCompactList}\small\item\em Formate et initialise un tout nouveau disque virtuel brut nommé "{}disk"{} sur le support hôte. \end{DoxyCompactList}\item \mbox{\hyperlink{structdisk}{disk}} \mbox{\hyperlink{disk_8h_a0410aa30c92de7cca42080e61d4dcd91}{open\+\_\+disk}} (char \texorpdfstring{$\ast$}{*}filename) \begin{DoxyCompactList}\small\item\em Ouvre un fichier conteneur physique existant sur le système hôte pour charger sa structure logique en mémoire RAM. \end{DoxyCompactList}\item int \mbox{\hyperlink{disk_8h_a9db73bc21d502f4b9231a7366070fcad}{do\+\_\+ls}} (\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}d, char \texorpdfstring{$\ast$}{*}path) \begin{DoxyCompactList}\small\item\em Commande système {\ttfamily ls}. Liste l\textquotesingle{}ensemble des éléments compris dans un répertoire. \end{DoxyCompactList}\item int \mbox{\hyperlink{disk_8h_ae99a488757a20d04370d00dd36dcd605}{do\+\_\+touch}} (\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}d, char \texorpdfstring{$\ast$}{*}filepath) \begin{DoxyCompactList}\small\item\em Commande système {\ttfamily touch}. Crée un nouveau fichier vide à l\textquotesingle{}emplacement indiqué. \end{DoxyCompactList}\item int \mbox{\hyperlink{disk_8h_a69cc37c23ee36cbf476280a13b83276b}{do\+\_\+mkdir}} (\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}d, char \texorpdfstring{$\ast$}{*}dirpath) \begin{DoxyCompactList}\small\item\em Commande système {\ttfamily mkdir}. Génère une arborescence de sous-\/répertoire d\textquotesingle{}après un chemin fourni. \end{DoxyCompactList}\item int \mbox{\hyperlink{disk_8h_a31d16b7fcc1b8c0cfc7651c86d233bd5}{do\+\_\+df}} (\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}d) \begin{DoxyCompactList}\small\item\em Commande système {\ttfamily df}. Affiche les statistiques d\textquotesingle{}utilisation de l\textquotesingle{}espace disque et des inodes. \end{DoxyCompactList}\item int \mbox{\hyperlink{disk_8h_ab892860e63632cdcf960c65b314772b9}{do\+\_\+rm}} (\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}\mbox{\hyperlink{structdisk}{disk}}, char \texorpdfstring{$\ast$}{*}filepath) \begin{DoxyCompactList}\small\item\em Commande système {\ttfamily rm}. Supprime un fichier classique ou un lien symbolique. \end{DoxyCompactList}\item int \mbox{\hyperlink{disk_8h_af10807a70b9341c379973247c446824e}{do\+\_\+rmdir}} (\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}\mbox{\hyperlink{structdisk}{disk}}, char \texorpdfstring{$\ast$}{*}filepath) \begin{DoxyCompactList}\small\item\em Commande système {\ttfamily rmdir}. Supprime un répertoire vide identifié par son chemin absolu. \end{DoxyCompactList}\item int \mbox{\hyperlink{disk_8h_a6715a2ff0198e20d4596d140784d633b}{do\+\_\+cat}} (\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}\mbox{\hyperlink{structdisk}{disk}}, char \texorpdfstring{$\ast$}{*}path\+\_\+to\+\_\+file) \begin{DoxyCompactList}\small\item\em Commande système {\ttfamily cat}. Affiche le contenu d\textquotesingle{}un fichier ou redirige l\textquotesingle{}entrée standard. \end{DoxyCompactList}\item int \mbox{\hyperlink{disk_8h_acaa80df6e40b49030c912453717bc176}{do\+\_\+grep}} (char \texorpdfstring{$\ast$}{*}arg) \item int \mbox{\hyperlink{disk_8h_a6f69e1d7bb5d136f816149887845e9c8}{find\+\_\+dir\+\_\+inode\+\_\+by\+\_\+name}} (char \texorpdfstring{$\ast$}{*}name, int dir\+\_\+index, \mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}d) \begin{DoxyCompactList}\small\item\em Parcourt les entrées d\textquotesingle{}un répertoire pour extraire l\textquotesingle{}ID numérique de l\textquotesingle{}inode correspondant à un nom donné. \end{DoxyCompactList}\item int \mbox{\hyperlink{disk_8h_ae1bed71dffe181556a19024ae600412f}{redirect\+\_\+out}} (\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}d, int mode, char \texorpdfstring{$\ast$}{*}file, int in) \begin{DoxyCompactList}\small\item\em Redirige le flux de données lu depuis un descripteur d\textquotesingle{}entrée vers un fichier spécifié de notre SGF. \end{DoxyCompactList}\item void \mbox{\hyperlink{disk_8h_ad6626984368788d12c01f0dffe24d4ea}{persist\+\_\+on\+\_\+disk}} (\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}d) \begin{DoxyCompactList}\small\item\em Synchronise (sauvegarde) l\textquotesingle{}arborescence logique en mémoire vive dans le conteneur physique "{}disk"{}. \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsection{Function Documentation} \Hypertarget{disk_8h_a7eb10c7006ff648d851b15f24e4305c3}\label{disk_8h_a7eb10c7006ff648d851b15f24e4305c3} \index{disk.h@{disk.h}!create\_disk@{create\_disk}} \index{create\_disk@{create\_disk}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{create\_disk()}{create\_disk()}} {\footnotesize\ttfamily \mbox{\hyperlink{structdisk}{disk}} create\+\_\+disk (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})} Formate et initialise un tout nouveau disque virtuel brut nommé "{}disk"{} sur le support hôte. \begin{DoxyItemize} \item Cette fonction crée la structure logique de base \+: vidage des tables, initialisation de la racine {\ttfamily /}, création automatique des liens auto-\/référencés {\ttfamily .} et {\ttfamily ..} sur le bloc 0, et génération d\textquotesingle{}un fichier de test. \item \begin{DoxyReturn}{Returns} disk La structure de données mémoire représentant le disque nouvellement formaté. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_a6715a2ff0198e20d4596d140784d633b}\label{disk_8h_a6715a2ff0198e20d4596d140784d633b} \index{disk.h@{disk.h}!do\_cat@{do\_cat}} \index{do\_cat@{do\_cat}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{do\_cat()}{do\_cat()}} {\footnotesize\ttfamily int do\+\_\+cat (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{disk, }\item[{char \texorpdfstring{$\ast$}{*}}]{path\+\_\+to\+\_\+file }\end{DoxyParamCaption})} Commande système {\ttfamily cat}. Affiche le contenu d\textquotesingle{}un fichier ou redirige l\textquotesingle{}entrée standard. \begin{DoxyItemize} \item \begin{DoxyParams}{Parameters} {\em disk} & Pointeur vers le disque virtuel. \\ \hline {\em path\+\_\+to\+\_\+file} & Chemin vers le fichier à lire. Si NULL, la fonction affiche en boucle le flux de l\textquotesingle{}entrée standard. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int 1 en cas de succès, -\/1 s\textquotesingle{}il s\textquotesingle{}agit d\textquotesingle{}un répertoire. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_a31d16b7fcc1b8c0cfc7651c86d233bd5}\label{disk_8h_a31d16b7fcc1b8c0cfc7651c86d233bd5} \index{disk.h@{disk.h}!do\_df@{do\_df}} \index{do\_df@{do\_df}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{do\_df()}{do\_df()}} {\footnotesize\ttfamily int do\+\_\+df (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{d }\end{DoxyParamCaption})} Commande système {\ttfamily df}. Affiche les statistiques d\textquotesingle{}utilisation de l\textquotesingle{}espace disque et des inodes. \begin{DoxyItemize} \item \begin{DoxyParams}{Parameters} {\em d} & Pointeur vers le disque virtuel. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int Retourne 0 systématiquement après l\textquotesingle{}affichage sur la sortie standard. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_acaa80df6e40b49030c912453717bc176}\label{disk_8h_acaa80df6e40b49030c912453717bc176} \index{disk.h@{disk.h}!do\_grep@{do\_grep}} \index{do\_grep@{do\_grep}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{do\_grep()}{do\_grep()}} {\footnotesize\ttfamily int do\+\_\+grep (\begin{DoxyParamCaption}\item[{char \texorpdfstring{$\ast$}{*}}]{arg }\end{DoxyParamCaption})} \Hypertarget{disk_8h_a9db73bc21d502f4b9231a7366070fcad}\label{disk_8h_a9db73bc21d502f4b9231a7366070fcad} \index{disk.h@{disk.h}!do\_ls@{do\_ls}} \index{do\_ls@{do\_ls}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{do\_ls()}{do\_ls()}} {\footnotesize\ttfamily int do\+\_\+ls (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{d, }\item[{char \texorpdfstring{$\ast$}{*}}]{path }\end{DoxyParamCaption})} Commande système {\ttfamily ls}. Liste l\textquotesingle{}ensemble des éléments compris dans un répertoire. \begin{DoxyItemize} \item Cette fonction colore la sortie selon le type de fichier rencontré (Vert pour un fichier, Bleu pour un dossier). \item \begin{DoxyParams}{Parameters} {\em d} & Pointeur vers le disque virtuel. \\ \hline {\em path} & Optionnel \+: chemin vers le dossier à lister. Si NULL, utilise la variable d\textquotesingle{}environnement PWD. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int 1 en cas de succès, -\/1 si le répertoire n\textquotesingle{}existe pas ou s\textquotesingle{}il s\textquotesingle{}agit d\textquotesingle{}un fichier classique. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_a69cc37c23ee36cbf476280a13b83276b}\label{disk_8h_a69cc37c23ee36cbf476280a13b83276b} \index{disk.h@{disk.h}!do\_mkdir@{do\_mkdir}} \index{do\_mkdir@{do\_mkdir}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{do\_mkdir()}{do\_mkdir()}} {\footnotesize\ttfamily int do\+\_\+mkdir (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{d, }\item[{char \texorpdfstring{$\ast$}{*}}]{dirpath }\end{DoxyParamCaption})} Commande système {\ttfamily mkdir}. Génère une arborescence de sous-\/répertoire d\textquotesingle{}après un chemin fourni. \begin{DoxyItemize} \item \begin{DoxyParams}{Parameters} {\em d} & Pointeur vers le disque virtuel. \\ \hline {\em dirpath} & Chemin logique qualifiant le nouveau dossier. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int 0 en cas de succès, -\/1 en cas d\textquotesingle{}erreur de cheminement ou si le répertoire est déjà pris. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_ab892860e63632cdcf960c65b314772b9}\label{disk_8h_ab892860e63632cdcf960c65b314772b9} \index{disk.h@{disk.h}!do\_rm@{do\_rm}} \index{do\_rm@{do\_rm}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{do\_rm()}{do\_rm()}} {\footnotesize\ttfamily int do\+\_\+rm (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{disk, }\item[{char \texorpdfstring{$\ast$}{*}}]{filepath }\end{DoxyParamCaption})} Commande système {\ttfamily rm}. Supprime un fichier classique ou un lien symbolique. \begin{DoxyItemize} \item \begin{DoxyParams}{Parameters} {\em disk} & Pointeur vers le disque virtuel. \\ \hline {\em filepath} & Chemin vers le fichier cible à supprimer. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int 0 en cas de succès, -\/1 en cas d\textquotesingle{}erreur d\textquotesingle{}accès ou s\textquotesingle{}il s\textquotesingle{}agit d\textquotesingle{}un répertoire. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_af10807a70b9341c379973247c446824e}\label{disk_8h_af10807a70b9341c379973247c446824e} \index{disk.h@{disk.h}!do\_rmdir@{do\_rmdir}} \index{do\_rmdir@{do\_rmdir}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{do\_rmdir()}{do\_rmdir()}} {\footnotesize\ttfamily int do\+\_\+rmdir (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{disk, }\item[{char \texorpdfstring{$\ast$}{*}}]{filepath }\end{DoxyParamCaption})} Commande système {\ttfamily rmdir}. Supprime un répertoire vide identifié par son chemin absolu. \begin{DoxyItemize} \item \begin{DoxyParams}{Parameters} {\em disk} & Pointeur vers le disque virtuel. \\ \hline {\em filepath} & Chemin absolu menant au répertoire à supprimer. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int 0 en cas de succès, -\/1 en cas d\textquotesingle{}erreur de chemin, si le dossier n\textquotesingle{}est pas vide, ou s\textquotesingle{}il n\textquotesingle{}existe pas. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_ae99a488757a20d04370d00dd36dcd605}\label{disk_8h_ae99a488757a20d04370d00dd36dcd605} \index{disk.h@{disk.h}!do\_touch@{do\_touch}} \index{do\_touch@{do\_touch}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{do\_touch()}{do\_touch()}} {\footnotesize\ttfamily int do\+\_\+touch (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{d, }\item[{char \texorpdfstring{$\ast$}{*}}]{filepath }\end{DoxyParamCaption})} Commande système {\ttfamily touch}. Crée un nouveau fichier vide à l\textquotesingle{}emplacement indiqué. \begin{DoxyItemize} \item \begin{DoxyNote}{Note} Si le nom existe déjà, une erreur est renvoyée (le comportement diffère du touch Unix classique). \end{DoxyNote} \begin{DoxyParams}{Parameters} {\em d} & Pointeur vers le disque virtuel. \\ \hline {\em filepath} & Chemin complet d\textquotesingle{}accès au fichier à générer. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int 0 en cas de succès, -\/1 si le chemin intermédiaire n\textquotesingle{}existe pas ou si le nom est indisponible. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_a6f69e1d7bb5d136f816149887845e9c8}\label{disk_8h_a6f69e1d7bb5d136f816149887845e9c8} \index{disk.h@{disk.h}!find\_dir\_inode\_by\_name@{find\_dir\_inode\_by\_name}} \index{find\_dir\_inode\_by\_name@{find\_dir\_inode\_by\_name}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{find\_dir\_inode\_by\_name()}{find\_dir\_inode\_by\_name()}} {\footnotesize\ttfamily int find\+\_\+dir\+\_\+inode\+\_\+by\+\_\+name (\begin{DoxyParamCaption}\item[{char \texorpdfstring{$\ast$}{*}}]{name, }\item[{int}]{dir\+\_\+index, }\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{d }\end{DoxyParamCaption})} Parcourt les entrées d\textquotesingle{}un répertoire pour extraire l\textquotesingle{}ID numérique de l\textquotesingle{}inode correspondant à un nom donné. \begin{DoxyItemize} \item \begin{DoxyParams}{Parameters} {\em name} & Nom de l\textquotesingle{}élément recherché au sein du dossier. \\ \hline {\em dir\+\_\+index} & Index du nœud d\textquotesingle{}index du répertoire de recherche. \\ \hline {\em d} & Pointeur vers le disque virtuel. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int L\textquotesingle{}index numérique de l\textquotesingle{}inode trouvé, ou -\/1 en cas d\textquotesingle{}erreur ou d\textquotesingle{}absence. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_a0410aa30c92de7cca42080e61d4dcd91}\label{disk_8h_a0410aa30c92de7cca42080e61d4dcd91} \index{disk.h@{disk.h}!open\_disk@{open\_disk}} \index{open\_disk@{open\_disk}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{open\_disk()}{open\_disk()}} {\footnotesize\ttfamily \mbox{\hyperlink{structdisk}{disk}} open\+\_\+disk (\begin{DoxyParamCaption}\item[{char \texorpdfstring{$\ast$}{*}}]{filename }\end{DoxyParamCaption})} Ouvre un fichier conteneur physique existant sur le système hôte pour charger sa structure logique en mémoire RAM. \begin{DoxyItemize} \item \begin{DoxyParams}{Parameters} {\em filename} & Chaîne de caractères qualifiant l\textquotesingle{}emplacement du fichier fichier-\/disque (généralement "{}disk"{}). \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} disk La structure mémoire complétée par la lecture brute sérialisée. \end{DoxyReturn} \end{DoxyItemize}\Hypertarget{disk_8h_ad6626984368788d12c01f0dffe24d4ea}\label{disk_8h_ad6626984368788d12c01f0dffe24d4ea} \index{disk.h@{disk.h}!persist\_on\_disk@{persist\_on\_disk}} \index{persist\_on\_disk@{persist\_on\_disk}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{persist\_on\_disk()}{persist\_on\_disk()}} {\footnotesize\ttfamily void persist\+\_\+on\+\_\+disk (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{d }\end{DoxyParamCaption})} Synchronise (sauvegarde) l\textquotesingle{}arborescence logique en mémoire vive dans le conteneur physique "{}disk"{}. \begin{DoxyItemize} \item \begin{DoxyParams}{Parameters} {\em d} & Pointeur vers la structure mémoire globale à sérialiser sur le disque dur réel. \\ \hline \end{DoxyParams} \end{DoxyItemize}\Hypertarget{disk_8h_ae1bed71dffe181556a19024ae600412f}\label{disk_8h_ae1bed71dffe181556a19024ae600412f} \index{disk.h@{disk.h}!redirect\_out@{redirect\_out}} \index{redirect\_out@{redirect\_out}!disk.h@{disk.h}} \doxysubsubsection{\texorpdfstring{redirect\_out()}{redirect\_out()}} {\footnotesize\ttfamily int redirect\+\_\+out (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structdisk}{disk}} \texorpdfstring{$\ast$}{*}}]{d, }\item[{int}]{mode, }\item[{char \texorpdfstring{$\ast$}{*}}]{file, }\item[{int}]{in }\end{DoxyParamCaption})} Redirige le flux de données lu depuis un descripteur d\textquotesingle{}entrée vers un fichier spécifié de notre SGF. \begin{DoxyItemize} \item Si le fichier existe déjà, le contenu est soit écrasé, soit complété selon la valeur du paramètre {\ttfamily mode}. S\textquotesingle{}il n\textquotesingle{}existe pas, un fichier classique est automatiquement créé dans son répertoire d\textquotesingle{}appartenance. \item \begin{DoxyParams}{Parameters} {\em d} & Pointeur vers le disque virtuel. \\ \hline {\em mode} & Mode d\textquotesingle{}ouverture \+: 0 pour écraser ({\ttfamily \texorpdfstring{$>$}{>}}), 1 pour ajouter à la fin ({\ttfamily \texorpdfstring{$>$}{>}\texorpdfstring{$>$}{>}}). \\ \hline {\em file} & Nom ou chemin du fichier cible devant intercepter le flux. \\ \hline {\em in} & Descripteur d\textquotesingle{}écriture d\textquotesingle{}entrée (Pipe, stdin, etc.) depuis lequel lire les octets. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int 1 après écriture réussie et synchronisation sur le support physique, -\/1 en cas d\textquotesingle{}échec de chemin. \end{DoxyReturn} \end{DoxyItemize}