#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); unsigned int volume=0; printf("Création du /..."); inode_t root = create_ifile(volume, FILET_DIR); if ( root ) printf("ok\n"); else { printf("failed!\n"); return EXIT_FAILURE; } struct file_desc_t root_fd; printf("Ouverture du rootfile..."); if ( open_ifile(volume, root, &root_fd) != OPEN_SUCCESS ) { printf("failed.\n"); return EXIT_FAILURE; } else printf("ok!\n"); printf("Création d'un fichier plop..."); if ( add_entry(&root_fd, create_ifile(volume, FILET_REG), "plop") < 0 ) { printf("failed!\n"); return EXIT_FAILURE; } else printf("ok!\n"); printf("Fermeture du fichier root.\n"); close_ifile(&root_fd); printf("Réouverture du rootfile..."); if ( open_ifile(volume, root, &root_fd) != OPEN_SUCCESS ) { printf("failed.\n"); return EXIT_FAILURE; } else printf("ok!\n"); seek2_ifile(&root_fd, 0); struct entry_t ent = {0, "blub"}; printf("Listing du rép...\n"); while( read_ifile(&root_fd, &ent, sizeof(struct entry_t)) != 0 ) printf("* %s (%u)\n", ent.ent_basename, ent.ent_inumber); printf("Suppression du fichier plop\n"); inode_t plop_no = find_entry(&root_fd, "plop"); del_entry(&root_fd, plop_no); seek2_ifile(&root_fd, 0); printf("Listing du rép...\n"); while( read_ifile(&root_fd, &ent, sizeof(struct entry_t)) != 0 ) printf("* %s (%u)\n", ent.ent_basename, ent.ent_inumber); printf("Fermeture du fichier\n"); close_ifile(&root_fd); printf("Réouverture du rootfile..."); if ( open_ifile(volume, root, &root_fd) != OPEN_SUCCESS ) { printf("failed.\n"); return EXIT_FAILURE; } else printf("ok!\n"); printf("Recréation du fichier plop\n"); add_entry(&root_fd, create_ifile(volume, FILET_REG), "plop"); printf("Création d'un sous répertoire coin\n"); add_entry(&root_fd, create_ifile(volume, FILET_DIR), "coin"); printf("Création d'un fichier beuh\n"); add_entry(&root_fd, create_ifile(volume, FILET_REG), "beuh"); seek2_ifile(&root_fd, 0); printf("Listing du rép...\n"); while( read_ifile(&root_fd, &ent, sizeof(struct entry_t)) != 0 ) printf("* %s (%u)\n", ent.ent_basename, ent.ent_inumber); close_ifile(&root_fd); printf("Mise de l'inode 'root' en tant que '/' réel\n"); struct superblock_desc_t sblock; load_super(volume, &sblock); sblock.first_inode = root; save_super(volume, &sblock); printf("ouveture...\n"); open_ifile(volume, sblock.first_inode, &root_fd); printf("Listing du rép...\n"); while( read_ifile(&root_fd, &ent, sizeof(struct entry_t)) != 0 ) printf("* %s (%u)\n", ent.ent_basename, ent.ent_inumber); close_ifile(&root_fd); printf("Ajout d'un sous sous fichier au rép /coin (meuh)\n"); struct file_desc_t coin_fd; inode_t meuh_no = inumber_of_basename(volume, sblock.first_inode, "coin"); if ( meuh_no == 0 ) return EXIT_FAILURE; open_ifile(volume, meuh_no, &coin_fd); add_entry(&coin_fd, create_ifile(volume, FILET_REG), "meuh"); close_ifile(&coin_fd); printf("Test des fonctions basename...\n"); printf("Inumber_of_basename(): \n"); printf("plop ds / : %d\n", inumber_of_basename(volume, sblock.first_inode, "plop")); printf("coin ds / : %d\n", inumber_of_basename(volume, root, "coin")); printf("Inumber_of_path(): \n"); printf("/plop : %d\n", inumber_of_path(volume, "/plop")); printf("/coin : %d\n", inumber_of_path(volume, "/coin")); printf("/ : %d\n", inumber_of_path(volume, "/")); printf("/coin/meuh : %d\n", inumber_of_path(volume, "/coin//meuh")); const char *res; printf("Dinumber_of_path(): \n"); printf("/plop : %d\n", dinumber_of_path(volume, "/plop", &res)); printf("Res = %s\n", res); printf("/coin : %d\n", dinumber_of_path(volume, "/coin", &res)); printf("Res = %s\n", res); printf("/ : %d\n", dinumber_of_path(volume, "/", &res)); printf("Res = %s\n", res); printf("/coin/meuh : %d\n", dinumber_of_path(volume, "/coin//meuh", &res)); printf("Res = %s\n", res); return EXIT_SUCCESS; }