6#include <manux/errno.h>
11#include <manux/string.h>
13#define MIN(a, b) (((a) < (b)) ? (a) : (b))
36int supportBlocFermer([[maybe_unused]]
Fichier *f)
45size_t supportBlocEcrire(
Fichier *f,
void *buffer,
size_t nbOctets)
48 void *bufferIntermediaire =
NULL;
49 uint16_t tailleBloc = sb->tailleBloc;
60 if (
position + nbOctets > tailleBloc * sb->nombreBlocs) {
61 nbOctets = tailleBloc * sb->nombreBlocs -
position;
69 bufferIntermediaire =
kmalloc(tailleBloc);
70 if (bufferIntermediaire ==
NULL) {
77 sb->methodes->lire(sb, indiceBloc, 1, bufferIntermediaire);
80 positionDansBloc =
position % tailleBloc;
81 nbOctetsAEcrire =
MIN(nbOctets, tailleBloc - positionDansBloc);
82 memcpy(bufferIntermediaire + positionDansBloc, buffer, nbOctetsAEcrire);
85 sb->methodes->ecrire(sb, indiceBloc, 1, bufferIntermediaire);
88 nbOctets -= nbOctetsAEcrire;
90 buffer += nbOctetsAEcrire;
91 result += nbOctetsAEcrire;
98 nbBlocsEntiers = nbOctets / tailleBloc;
101 if (nbBlocsEntiers > 0) {
105 sb->methodes->ecrire(sb, indiceBloc, nbBlocsEntiers, buffer);
109 nbOctets -= nbBlocsEntiers * tailleBloc;
110 position += nbBlocsEntiers * tailleBloc;
111 buffer += nbBlocsEntiers * tailleBloc;
112 result += nbBlocsEntiers * tailleBloc;
118 assert(nbOctets < tailleBloc);
128 if (bufferIntermediaire ==
NULL) {
129 bufferIntermediaire =
kmalloc(tailleBloc);
131 if (bufferIntermediaire ==
NULL) {
136 sb->methodes->lire(sb, indiceBloc, 1, bufferIntermediaire);
139 memcpy(bufferIntermediaire, buffer, nbOctets);
142 sb->methodes->ecrire(sb, indiceBloc, 1, bufferIntermediaire);
150 if (bufferIntermediaire !=
NULL) {
151 kfree(bufferIntermediaire);
161size_t supportBlocLire(
Fichier *f,
void *buffer,
size_t nbOctets)
164 void *bufferIntermediaire =
NULL;
165 uint16_t tailleBloc = sb->tailleBloc;
176 if (
position + nbOctets > tailleBloc * sb->nombreBlocs) {
177 nbOctets = tailleBloc * sb->nombreBlocs -
position;
185 bufferIntermediaire =
kmalloc(tailleBloc);
186 if (bufferIntermediaire ==
NULL) {
193 sb->methodes->lire(sb, indiceBloc, 1, bufferIntermediaire);
196 positionDansBloc =
position % tailleBloc;
197 nbOctetsALire =
MIN(nbOctets, tailleBloc - positionDansBloc);
198 memcpy(buffer, bufferIntermediaire + positionDansBloc, nbOctetsALire);
201 nbOctets -= nbOctetsALire;
203 buffer += nbOctetsALire;
204 result += nbOctetsALire;
211 nbBlocsEntiers = nbOctets / tailleBloc;
214 if (nbBlocsEntiers > 0) {
218 sb->methodes->lire(sb, indiceBloc, nbBlocsEntiers, buffer);
222 nbOctets -= nbBlocsEntiers * tailleBloc;
223 position += nbBlocsEntiers * tailleBloc;
224 buffer += nbBlocsEntiers * tailleBloc;
225 result += nbBlocsEntiers * tailleBloc;
231 assert(nbOctets < tailleBloc);
241 if (bufferIntermediaire ==
NULL) {
242 bufferIntermediaire =
kmalloc(tailleBloc);
244 if (bufferIntermediaire ==
NULL) {
247 sb->methodes->lire(sb, indiceBloc, 1, bufferIntermediaire);
248 memcpy(buffer, bufferIntermediaire, nbOctets);
256 if (bufferIntermediaire !=
NULL) {
257 kfree(bufferIntermediaire);
267 .ouvrir = supportBlocOuvrir,
268 .fermer = supportBlocFermer,
269 .ecrire = supportBlocEcrire,
270 .lire = supportBlocLire
279 return supportBloc->
methodes->
lire(supportBloc, indice, nombre, buffer);
289 return supportBloc->
methodes->
ecrire(supportBloc, indice, nombre, buffer);
#define O_RDONLY
Les différents fanions.
struct _MethodesFichier MethodesFichier
: Définition des opérations réalisables sur un fichier
struct _Fichier Fichier
: Qu'est-ce qu'un fichier ouvert du point de vue du noyau ?
void position(int ligne, int colonne)
typedef void(Handler(void))
void * memcpy(void *dest, const void *src, size_t n)
struct _INoeud INoeud
: Un INoeud représente un fichier, d'un point de vue statique Il s'agit donc de la description d'un f...
INoeud * iNoeudCreer(void *prive, MethodesFichier *methodesFichier)
: Création d'un INoeud
void * kmalloc(size_t n)
Allocation d'une zone de n octets.
void kfree(void *p)
Libération d'une zone mémoire allouée.
: Ma version des assertions et autres outils de debug.
#define paniqueNoyau(fmt, args...)
#define printk_debug(lvl, fmt, args...)
Définition des supports orientés bloc (C) Manu Chaput 2026 Baptiste Gomez 2026.
struct _SupportBloc SupportBloc
La structure définissant un support bloc.
INoeud * iNoeud
Caractérisation de la structure.
uint32_t(* lire)(SupportBloc *supportBloc, uint32_t indice, uint32_t nombre, void *buffer)
uint32_t(* ecrire)(SupportBloc *supportBloc, uint32_t indice, uint32_t nombre, void *buffer)
SupportBlocMethodes * methodes
MethodesFichier supportBlocMethodesFichier
Les méthodes pour manipuler un support bloc comme un fichier.
void supportBlocEnregistrer(SupportBloc *sb)
Enregistrement dans le système d'un support bloc.
Fichier * supportBlocOuvrirHorsSF(SupportBloc *sb)
Une fonction d'ouverture qui ne passe pas par le système de fichiers WARNING : à supprimer dès que po...
uint32_t supportBlocLireBlocs(SupportBloc *supportBloc, uint32_t indice, uint32_t nombre, void *buffer)
Lecture de blocs depuis un support bloc.
uint32_t supportBlocEcrireBlocs(SupportBloc *supportBloc, uint32_t indice, uint32_t nombre, void *buffer)
Écriture de blocs vers un support bloc.