/** * @author Ivan Gualandri * @param char* path percorso del file da aprire * @return DIR* puntatore alla cartella aperta se esiste, NULL altrimenti * * Dato un path contenente una cartella viene aperta se presente, e si torna il puntatore a DIR* */ DIR *opendir(const char *path){ int mpoint_id = 0; //char tmp_path[CURPATH_LEN]; char* rel_path; DIR* pdir; #ifdef DEBUG int error = get_abs_path((char*)path); printf("AbsPath in opendir: %s len: %d\nError code: %d\n", path, strlen(path), error); #else get_abs_path((char*)path); #endif //printf("%s\n", path); mpoint_id = get_mountpoint_id((char*)path); rel_path = get_rel_path(mpoint_id, path); //printf("Rel Path len%d - %s\n", strlen(rel_path), rel_path); if(mountpoint_list[mpoint_id].dir_op.opendir_f!=NULL) { pdir = mountpoint_list[mpoint_id].dir_op.opendir_f(rel_path); pdir->handle = mpoint_id; return pdir; } else { //printf("Could not open_dir no function found\n"); return NULL; } return NULL; }
/** * @author Ivan Gualandri * @param char* path percorso del file da aprire * @param int oflags parametri di apertura * * Dato un path viene aperto se presente, e si torna il numero di descrittore che lo contiene * @todo Inserire gestione flags */ int open(const char *path, int oflags, ...){ int prova; int mpid; int ret_fd; int error = 0; char *newpath; va_list ap; va_start(ap, oflags); ret_fd = 0; //printf("Path: %s\n", path); prova = va_arg(ap, int); newpath = kmalloc(CURPATH_LEN * sizeof(char)); memset(newpath, '\0', CURPATH_LEN); cur_fd=0; if(cur_fd == _SC_OPEN_MAX) cur_fd = 0; while(fd_list[cur_fd].mountpoint_id != -1 && cur_fd < _SC_OPEN_MAX){ //printf("%d %d\n", cur_fd, fd_list[cur_fd].mountpoint_id); cur_fd++; } if(cur_fd == _SC_OPEN_MAX) { printf("No more file descriptors available\n"); return -1; } strcpy(newpath, path); error = get_abs_path((char*) newpath); //printf("After get_abs: %s %s\n", newpath, current_user.cur_path); mpid = get_mountpoint_id((char*) newpath); //printf("Cur_fd: %d\n",cur_fd); if(mpid >-1) { fd_list[cur_fd].mountpoint_id = mpid; newpath = get_rel_path(mpid, (char *)newpath); } else { printf("That path doesn't exist\n"); va_end(ap); return -1; } if( mpid > -1 && mountpoint_list[fd_list[cur_fd].mountpoint_id].operations.open != NULL){ fd_list[cur_fd].fs_spec_id = (int) mountpoint_list[fd_list[cur_fd].mountpoint_id].operations.open(newpath, oflags); if(fd_list[cur_fd].fs_spec_id == -1){ printf("No file's Found\n"); va_end(ap); return -1; } } else { if(mpid>-1) printf("No OPEN services found here\n"); va_end(ap); return -1; } va_end(ap) fd_list[cur_fd].offset = 0; fd_list[cur_fd].flags_mask = oflags; ret_fd = cur_fd; cur_fd++; free(newpath); return ret_fd; }