Errcode pic_save(Popot path, Popot screen) /***************************************************************************** * save a picture. ****************************************************************************/ { Errcode err; if (pdr == NULL) { if (Success > (err = pdr_find_load(path))) return err; } if (path.pt == NULL) return builtin_err = Err_null_ref; if (screen.pt == NULL) screen.pt = GetPicScreen(); if (Success > (err = create_ifile(path.pt, screen.pt))) return err; err = save_frame(screen.pt); close_ifile(); return err; }
int add_entry(int inumber, const char* name, enum file_type_e type) { file_desc_t fd; if(strcmp(name, "") == 0) { return -1; } if(open_ifile(&fd, inumber) != RETURN_FAILURE) { struct entry_s entry; if(find_entry(&fd, name) != -1) { return -1; } unsigned int index = new_entry(&fd); seek2_ifile(&fd, index*sizeof(struct entry_s)); entry.inumber = create_ifile(type); strncpy(entry.name, name, MAX_FILE_LENGTH); write_ifile(&fd, &entry, sizeof(struct entry_s)); close_ifile(&fd); //add .. & . if(type == FILE_DIRECTORY) { file_desc_t fd_child; struct entry_s entry_child; if(open_ifile(&fd_child, entry.inumber) != RETURN_FAILURE) { entry_child.inumber = entry.inumber; strcpy(entry_child.name, "."); write_ifile(&fd_child, &entry_child, sizeof(struct entry_s)); entry_child.inumber = inumber; strcpy(entry_child.name, ".."); write_ifile(&fd_child, &entry_child, sizeof(struct entry_s)); close_ifile(&fd_child); } } return entry.inumber; } else return -1; }
int main(int argc, char**argv){ unsigned int i; unsigned int inumber; /* gestion des arguments */ if(argc != 1){ usage(); exit(EXIT_SUCCESS); } /* init hardware */ if(!init_hardware(HW_CONFIG)) { fprintf(stderr, "Initialization error\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<NB_EMPTY_FUNCTION; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); /* chargement du mbr */ if(!load_mbr()){ fprintf(stderr, "Erreur lors du chargement du Master Boot Record.\n"); exit(EXIT_FAILURE); } /* initialise le super du premier volume */ init_super(CURRENT_VOLUME); /* charge le super du premier volume dans la variable globale */ load_super(CURRENT_VOLUME); /* création du fichier */ inumber = create_ifile(IT_FILE); if(!inumber){ fprintf(stderr, "Erreur lors de la creation du fichier\n"); exit(EXIT_FAILURE); } printf("Création d'un fichier:\n"); printf("\tinumber: %d.\n", inumber); exit(inumber); }
int mmkdir(int argc, char** argv) { unsigned status = 0; unsigned inumber; char* dir_path; if(argc < 1) { fprintf(stderr, "ERROR: il manque le nom du dossier à créer\n"); return 0; } /* future chaine contenant le chemin absolu du nouveau dossier */ dir_path = malloc(sizeof(char) * MAX_PATH); /* on met la racine dans dir path */ strcpy(dir_path, current_path); /* chemin different si on est a la racine */ if(strcmp(dir_path, "/") == 0) { sprintf(dir_path, "/%s", argv[1]); } else { sprintf(dir_path, "%s/%s", dir_path, argv[1]); } inumber = create_ifile(IT_DIR); if(inumber == RETURN_FAILURE){ fprintf(stderr, "ERROR: échec creation de dossier avec mkdir\n"); return RETURN_FAILURE; } status = add_entry(get_iroot(), inumber, argv[1]); if(status == RETURN_FAILURE){ fprintf(stderr, "ERROR: échec ajout du dossier dans la racine\n"); return RETURN_FAILURE; } save_current_super(); return RETURN_SUCCESS; }
static void cfile(unsigned int sinumber) { file_desc_t sfd, dfd; unsigned int dinumber; int status; int c; dinumber = create_ifile(FT_STD); ffatal(dinumber, "erreur creation fichier"); printf("%d\n", dinumber); status = open_ifile(&dfd, dinumber); ffatal(!status, "erreur ouverture fichier %d", dinumber); status = open_ifile(&sfd, sinumber); ffatal(!status, "erreur ouverture fichier %d", sinumber); while((c=readc_ifile(&sfd)) != READ_EOF) writec_ifile(&dfd, c); close_ifile(&dfd); close_ifile(&sfd); }