#include #include #include #include #include #include #include #include #include static void emptyIT() { return; } static void hddIT() { return; } int main(int argc, char *argv[]) { unsigned int i; /* init hardware */ if(initHardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<16; i++) IRQVECTOR[i] = emptyIT; IRQVECTOR[HDA_IRQ] = hddIT; /* Allows all IT */ _mask(1); struct superblock_desc_t sblock; int before; load_super(0, &sblock); before = sblock.free_space; printf("Création du sfile...\n"); create_sfile(0, FILET_REG); struct file_desc_t fd; printf("Ouverture du sfile...\n"); if ( open_sfile(0, &fd) != OPEN_SUCCESS ) { printf("Erreur d'ouverture!\n"); return EXIT_FAILURE; } printf("File length : %u\n", fd.filesize); printf("Ecrire du caractère 'a'..."); if ( writec_sfile(&fd, 'a') > 0 ) printf("ok\n"); else { printf("failed!\n"); return EXIT_FAILURE; } printf("Ecrire du caractère 'b'..."); if ( writec_sfile(&fd, 'b') > 0 ) printf("ok\n"); else { printf("failed!\n"); return EXIT_FAILURE; } char blub[100]; FILE *f = fopen("libfs/inode.c", "r"); if ( f == NULL ) { perror("Erreur"); return EXIT_FAILURE; } while ( ! feof(f) ) { int c = fread(blub, sizeof(char), 99, f); write_sfile(&fd, blub, c); } fclose(f); printf("Deplacement au début...\n"); seek2_sfile(&fd, 0); close_sfile(&fd); printf("Ouverture du sfile...\n"); if ( open_sfile(0, &fd) != OPEN_SUCCESS ) { printf("Erreur d'ouverture!\n"); return EXIT_FAILURE; } printf("File length : %u\n", fd.filesize); printf("Lecture d'un caractère..."); int a = readc_sfile(&fd); if ( a == READ_EOF ) printf("EOF!\n"); else printf("Lu : %c\n", a); printf("Lecture d'un caractère..."); int b = readc_sfile(&fd); if ( b == READ_EOF ) printf("EOF!\n"); else printf("Lu : %c\n", b); int x; do { x = read_sfile(&fd, blub, 99); blub[x] = '\0'; printf("%s", blub); } while ( x == 99 ); printf("Fermeture du sfile...\n"); close_sfile(&fd); printf("Suppression du sfile...\n"); delete_sfile(0); printf("Tentative d'ouverture du sfile..."); if ( open_sfile(0, &fd) != OPEN_SUCCESS ) printf("failed! (test réussi)\n"); else { printf("ok! (test échoué)\n"); return EXIT_FAILURE; } return EXIT_SUCCESS; }