static int do_cd(void) { int ret = -1; char name[MAX_FILE_NAME_LENGTH + 1]; char *path; struct directory *dir; if (read_all(STDIN, name, MAX_FILE_NAME_LENGTH) != MAX_FILE_NAME_LENGTH) return -1; name[MAX_FILE_NAME_LENGTH] = '\0'; if ((path = get_path_from_dir(&vfs, pwd)) == NULL) return -1; if ((path = append_to_path(path, name)) == NULL) goto free_path; if ((dir = lookup_dir(&vfs, path, 1)) == NULL) goto free_path; pwd = dir; ret = 0; free_path: free(path); return ret; }
void look_thread (int type) { int status; /* Execute until cancelled. */ while ( 1 ) { /* Lock the condition variable mutex. */ status = pthread_mutex_lock ( &name_mutex ); THRCHK ( status ); /* Flag that one access has been completed. */ name_ready_p--; /* If all accesses have been completed, broadcast a signal. */ if ( name_ready_p == 0 ) { status = pthread_cond_broadcast ( &name_ready ); THRCHK ( status ); } /* Wait on condition variable until there is a new name. */ do { status = pthread_cond_wait ( &name_ready, &name_mutex ); } while ( name_ready_p <= 1 ); /* Release the condition variable mutex. */ status = pthread_mutex_unlock ( &name_mutex ); THRCHK ( status ); if ( name_ready_p == APP_EXIT ) break; /* Perform a lookup selecting the correct server through its handle. */ if (type == 1) { lookup_dir ( phon_bh, name, phone ); } else { lookup_dir ( addr_bh, name, address ); } } }
// TODO lock! static errno_t add_mount( const char* path, const char *name, uufs_t *fs ) { if( *path == '/' ) path++; // NB! path must finish with / if( strlen( path ) >= FS_MAX_MOUNT_PATH-1 ) return E2BIG; if( strlen( name ) >= FS_MAX_MOUNT_PATH-1 ) return E2BIG; hal_mutex_lock( &mm ); int i; for( i = 0; i < FS_MAX_MOUNT; i++ ) { // unused if( mount[i].fs != 0 ) continue; goto found; } hal_mutex_unlock( &mm ); return ENFILE; found: mount[i].fs = fs; strlcpy( mount[i].path, path, FS_MAX_MOUNT_PATH ); strlcpy( mount[i].name, name, FS_MAX_MOUNT_PATH ); //if( mount[i].path[strlen(mount[i].path) - 1] != '/' ) // strcat(mount[i].path, "/" ); // Kill final slash int rlen = strlen(mount[i].path); if( mount[i].path[rlen - 1] == '/' ) mount[i].path[rlen - 1] = 0; lookup_dir( &root_root, mount[i].path, 1, create_dir ); hal_mutex_unlock( &mm ); return 0; }