Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Projet_Pico_ordi_B6
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Man hing Ling
Projet_Pico_ordi_B6
Commits
9cbc6286
Commit
9cbc6286
authored
1 year ago
by
pifou
Browse files
Options
Downloads
Patches
Plain Diff
RM corrigé, TYPE buggé pour fichier
parent
f827e94f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
SD/picofs.c
+98
-82
98 additions, 82 deletions
SD/picofs.c
with
98 additions
and
82 deletions
SD/picofs.c
+
98
−
82
View file @
9cbc6286
...
@@ -32,7 +32,7 @@ void readBlock(SD_info *sd, unsigned int numBlock, int offset, char *storage, in
...
@@ -32,7 +32,7 @@ void readBlock(SD_info *sd, unsigned int numBlock, int offset, char *storage, in
void
writeBlock
(
SD_info
*
sd
,
unsigned
int
numBlock
,
int
offset
,
char
*
source
,
int
size
)
{
void
writeBlock
(
SD_info
*
sd
,
unsigned
int
numBlock
,
int
offset
,
char
*
source
,
int
size
)
{
char
buffer_write
[
BLOCK_SIZE
/
2
];
char
buffer_write
[
BLOCK_SIZE
];
readData
(
sd
,
numBlock
,
0
,
size
,
(
uint8_t
*
)
buffer_write
);
readData
(
sd
,
numBlock
,
0
,
size
,
(
uint8_t
*
)
buffer_write
);
if
(
offset
+
size
>
512
)
if
(
offset
+
size
>
512
)
{
{
...
@@ -51,11 +51,25 @@ void writeBlock(SD_info *sd, unsigned int numBlock, int offset, char *source, in
...
@@ -51,11 +51,25 @@ void writeBlock(SD_info *sd, unsigned int numBlock, int offset, char *source, in
}
}
// void eraseSD(SD_info *sd){ //met des 0 partout dans la carte SD
// char zeros[BLOCK_SIZE];
// for(int i = 0; i< BLOCK_SIZE-1;i++){
// zeros[i] = '0';
// }
// zeros[BLOCK_SIZE-1] = '\0';
//
// for (int blockNum = 0; blockNum < 5000; blockNum ++){
// //printf("erase\n");
// writeBlockSD(sd,blockNum,zeros);
// }
// return;
// }
void
LS
(
SD_info
*
sd
)
{
void
LS
(
SD_info
*
sd
)
{
char
buffer
[
MAX_FILENAME_LENGTH
];
char
buffer
[
MAX_FILENAME_LENGTH
];
int
fileCount
=
0
;
int
fileCount
=
0
;
printf
(
"
\n
"
);
printf
(
"
\n
"
);
// Parcourir les blocs multiples de 16 à partir de 0 jusqu'à MAX_BLOCKS_IN_SUPERBLOCK
//
//
Parcourir les blocs multiples de 16 à partir de 0 jusqu'à MAX_BLOCKS_IN_SUPERBLOCK
for
(
int
blockNum
=
0
;
blockNum
<
MAX_BLOCKS_IN_SUPERBLOCK
;
blockNum
+=
16
)
{
for
(
int
blockNum
=
0
;
blockNum
<
MAX_BLOCKS_IN_SUPERBLOCK
;
blockNum
+=
16
)
{
readBlock
(
sd
,
blockNum
,
0
,
buffer
,
MAX_FILENAME_LENGTH
);
readBlock
(
sd
,
blockNum
,
0
,
buffer
,
MAX_FILENAME_LENGTH
);
...
@@ -66,7 +80,6 @@ void LS(SD_info *sd) {
...
@@ -66,7 +80,6 @@ void LS(SD_info *sd) {
fileCount
++
;
fileCount
++
;
}
}
}
}
if
(
fileCount
==
0
)
{
if
(
fileCount
==
0
)
{
printf
(
"
\n
Aucun fichier trouvé.
\n
"
);
printf
(
"
\n
Aucun fichier trouvé.
\n
"
);
}
}
...
@@ -105,10 +118,18 @@ int min(int a, int b) {
...
@@ -105,10 +118,18 @@ int min(int a, int b) {
return
a
<
b
?
a
:
b
;
return
a
<
b
?
a
:
b
;
}
}
// Fonction qui reconstitue le numéro de bloc à partir du tableau
int
reconstituteNumber
(
char
blockNumberBuffer
[
2
])
{
char
octet1
=
blockNumberBuffer
[
0
];
char
octet2
=
blockNumberBuffer
[
1
];
int
dataBlockNum
=
(
octet1
<<
8
)
|
octet2
;
return
dataBlockNum
;
}
void
RM
(
SD_info
*
sd
,
char
*
filename
)
{
void
RM
(
SD_info
*
sd
,
char
*
filename
)
{
int
fileFound
=
-
1
;
int
fileFound
=
-
1
;
int
offset
;
int
offset
;
char
fileBuffer
[
BLOC
K_SIZE
];
char
fileBuffer
[
CHUN
K_SIZE
];
// Parcourir les blocs réservés pour la description des fichiers (superbloc)
// Parcourir les blocs réservés pour la description des fichiers (superbloc)
for
(
int
blockNum
=
0
;
blockNum
<
MAX_BLOCKS_IN_SUPERBLOCK
;
blockNum
+=
16
)
{
for
(
int
blockNum
=
0
;
blockNum
<
MAX_BLOCKS_IN_SUPERBLOCK
;
blockNum
+=
16
)
{
...
@@ -139,25 +160,26 @@ void RM(SD_info *sd, char *filename) {
...
@@ -139,25 +160,26 @@ void RM(SD_info *sd, char *filename) {
startOffset
=
MAX_FILENAME_LENGTH
;
startOffset
=
MAX_FILENAME_LENGTH
;
}
}
for
(
int
chunkStart
=
startOffset
;
chunkStart
<
BLOCK_SIZE
/
2
;
chunkStart
+=
CHUNK_SIZE
)
{
//for (int chunkStart = startOffset; chunkStart < BLOCK_SIZE/2; chunkStart += CHUNK_SIZE) {
int
chunkSize
=
min
(
CHUNK_SIZE
,
BLOCK_SIZE
/
2
-
chunkStart
);
// int chunkSize = min(CHUNK_SIZE, BLOCK_SIZE/2 - chunkStart);
readBlock
(
sd
,
blockNum
,
chunkStart
,
fileBuffer
,
chunkSize
);
int
chunkSize
=
0
;
int
chunkStart
=
0
;
for
(
int
i
=
0
;
i
<
chunkSize
;
i
+=
2
)
{
readBlock
(
sd
,
blockNum
,
0
,
fileBuffer
,
chunkSize
);
int
blockNumData
=
(
fileBuffer
[
i
]
<<
8
)
|
fileBuffer
[
i
+
1
];
//for (int i = 0; i < chunkSize; i += 2) {
// int blockNumData = (fileBuffer[i] << 8) | fileBuffer[i + 1];
int
blockNumData
=
reconstituteNumber
(
fileBuffer
);
if
(
blockNumData
==
0
)
{
if
(
blockNumData
==
0
)
{
writeBlock
(
sd
,
blockNum
,
chunkStart
,
fileBuffer
,
chunkSize
);
writeBlock
(
sd
,
blockNum
,
chunkStart
,
fileBuffer
,
chunkSize
);
printf
(
"
\n
Le fichier
\"
%s
\"
a été supprimé avec succès.
\n
"
,
filename
);
printf
(
"
\n
Le fichier
\"
%s
\"
a été supprimé avec succès.
\n
"
,
filename
);
return
;
// Sortir des boucles
return
;
// Sortir des boucles
}
}
setBlockAvailability
(
sd
,
blockNumData
,
0
);
// Marquer le bloc comme disponible
else
setBlockAvailability
(
sd
,
blockNumData
,
0
);
// Marquer le bloc comme disponible
fileBuffer
[
i
]
=
0
;
//fileBuffer[i] = 0;
fileBuffer
[
i
+
1
]
=
0
;
//fileBuffer[i + 1] = 0;
}
//}
writeBlock
(
sd
,
blockNum
,
chunkStart
,
fileBuffer
,
chunkSize
);
writeBlock
(
sd
,
blockNum
,
chunkStart
,
fileBuffer
,
chunkSize
);
}
//
}
}
}
printf
(
"
\n
Le fichier
\"
%s
\"
a été supprimé avec succès.
\n
"
,
filename
);
printf
(
"
\n
Le fichier
\"
%s
\"
a été supprimé avec succès.
\n
"
,
filename
);
...
@@ -171,7 +193,7 @@ void MV(SD_info *sd, char *old_filename, char *new_filename) {
...
@@ -171,7 +193,7 @@ void MV(SD_info *sd, char *old_filename, char *new_filename) {
int
fileFound
=
0
;
int
fileFound
=
0
;
// Parcourir les blocs réservés pour la description des fichiers (superbloc)
// Parcourir les blocs réservés pour la description des fichiers (superbloc)
for
(
int
blockNum
=
0
;
blockNum
<
MAX_BLOCKS_IN_SUPERBLOCK
;
blockNum
+=
1
6
)
{
for
(
int
blockNum
=
0
;
blockNum
<
MAX_BLOCKS_IN_SUPERBLOCK
;
blockNum
+=
1
)
{
readBlock
(
sd
,
blockNum
,
0
,
filenameBuffer
,
MAX_FILENAME_LENGTH
);
readBlock
(
sd
,
blockNum
,
0
,
filenameBuffer
,
MAX_FILENAME_LENGTH
);
...
@@ -189,6 +211,7 @@ void MV(SD_info *sd, char *old_filename, char *new_filename) {
...
@@ -189,6 +211,7 @@ void MV(SD_info *sd, char *old_filename, char *new_filename) {
break
;
// Nom modifié, sortir de la boucle
break
;
// Nom modifié, sortir de la boucle
}
}
}
}
if
(
fileFound
==
1
)
{
if
(
fileFound
==
1
)
{
printf
(
"
\n
Le nom du fichier
\"
%s
\"
a été renommé avec succès.
\n
"
,
old_filename
);
printf
(
"
\n
Le nom du fichier
\"
%s
\"
a été renommé avec succès.
\n
"
,
old_filename
);
...
@@ -232,13 +255,7 @@ int findAvailableBlock(SD_info *sd) {
...
@@ -232,13 +255,7 @@ int findAvailableBlock(SD_info *sd) {
return
-
1
;
return
-
1
;
}
}
// Fonction qui reconstitue le numéro de bloc à partir du tableau
int
reconsituteNumber
(
char
blockNumberBuffer
[
2
])
{
char
octet1
=
blockNumberBuffer
[
0
];
char
octet2
=
blockNumberBuffer
[
1
];
int
dataBlockNum
=
(
octet1
<<
8
)
|
octet2
;
return
dataBlockNum
;
}
// Fonction qui réparti un numéro de bloc sur deux octets
// Fonction qui réparti un numéro de bloc sur deux octets
...
@@ -321,7 +338,6 @@ void TYPE(SD_info *sd, char *filename, char *data) {
...
@@ -321,7 +338,6 @@ void TYPE(SD_info *sd, char *filename, char *data) {
return
;
return
;
}
}
break
;
// Fichier créé, sortir de la boucle
break
;
// Fichier créé, sortir de la boucle
}
}
}
}
...
@@ -361,9 +377,9 @@ void CAT(SD_info *sd, char *filename) {
...
@@ -361,9 +377,9 @@ void CAT(SD_info *sd, char *filename) {
// Lecture des octets deux par deux
// Lecture des octets deux par deux
for
(
int
i
=
0
;
i
<
BLOCK_SIZE
;
i
+=
2
)
{
for
(
int
i
=
0
;
i
<
BLOCK_SIZE
;
i
+=
2
)
{
readBlock
(
sd
,
descrBlockNum
+
blockNum
,
offset
+
i
,
byteBuffer
,
2
);
readBlock
(
sd
,
descrBlockNum
+
blockNum
,
offset
+
i
,
byteBuffer
,
2
);
printf
(
"
\n
Byte buffer: %s
\n
"
,
byteBuffer
);
// Lire les numéros de blocs associés à ce fichier depuis les blocs de description
// Lire les numéros de blocs associés à ce fichier depuis les blocs de description
int
dataBlockNum
=
reconsituteNumber
(
byteBuffer
);
int
dataBlockNum
=
recons
t
ituteNumber
(
byteBuffer
);
// Vérifier si le numéro de bloc est valide (non nul)
// Vérifier si le numéro de bloc est valide (non nul)
if
(
dataBlockNum
==
0
)
{
if
(
dataBlockNum
==
0
)
{
return
;
// Fin du fichier
return
;
// Fin du fichier
...
@@ -445,7 +461,7 @@ void CP(SD_info *sd, char *source_filename, char *destination_filename) {
...
@@ -445,7 +461,7 @@ void CP(SD_info *sd, char *source_filename, char *destination_filename) {
readBlock
(
sd
,
source_offset
+
i
,
offset
+
byteNum
,
numBuffer
,
2
);
readBlock
(
sd
,
source_offset
+
i
,
offset
+
byteNum
,
numBuffer
,
2
);
numDataBlock
=
reconsituteNumber
(
numBuffer
);
numDataBlock
=
recons
t
ituteNumber
(
numBuffer
);
if
(
numDataBlock
==
0
)
{
if
(
numDataBlock
==
0
)
{
printf
(
"
\n
La copie de
\"
%s
\"
sous le nom
\"
%s
\"
a été créée avec succès.
\n
"
,
source_filename
,
destination_filename
);
printf
(
"
\n
La copie de
\"
%s
\"
sous le nom
\"
%s
\"
a été créée avec succès.
\n
"
,
source_filename
,
destination_filename
);
return
;
return
;
...
@@ -496,7 +512,7 @@ int main(int argc, char *argv[]) {
...
@@ -496,7 +512,7 @@ int main(int argc, char *argv[]) {
erase
(
&
sd
,
0
,
15000
);
erase
(
&
sd
,
0
,
15000
);
current_cmd
[
0
]
=
'\0'
;
// Initialise la chaîne vide
current_cmd
[
0
]
=
'\0'
;
// Initialise la chaîne vide
printf
(
"PicoOrdi>"
);
printf
(
"PicoOrdi>"
);
//eraseSD(&sd);
while
(
1
)
{
while
(
1
)
{
_delay_ms
(
10
);
_delay_ms
(
10
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment