/** * Loads the runtime kernel files stored in /runtime. * These files consist of the compiled Ruby /kernel code in .rbc files, which * are needed to bootstrap the Ruby kernel. * This method is called after the VM has completed bootstrapping, and is * ready to load Ruby code. * * @param root The path to the /runtime directory. All kernel loading is * relative to this path. */ void Environment::load_kernel(std::string root) { // Check that the index file exists; this tells us which sub-directories to // load, and the order in which to load them std::string index = root + "/index"; std::ifstream stream(index.c_str()); if(!stream) { std::string error = "Unable to load kernel index: " + root; throw std::runtime_error(error); } version_ = as<Fixnum>(G(rubinius)->get_const( state, state->symbol("RUBY_LIB_VERSION")))->to_native(); // Load alpha run_file(root + "/alpha.rbc"); while(!stream.eof()) { std::string line; stream >> line; stream.get(); // eat newline // skip empty lines if(line.empty()) continue; load_directory(root + "/" + line); } }
void load_directory(char *param, ID3 *info) { DIR *dir; struct dirent *file= NULL; id3_return rc= ID3_OK; if (!(dir= opendir(param))) { printf("No such directory as %s\n", param); return; } while ((file= readdir(dir))) { char buffer[HUGE_STRING_LEN]; struct stat sbuf; snprintf(buffer, HUGE_STRING_LEN, "%s/%s", param, file->d_name); if (stat(buffer, &sbuf) == 0) { if (S_ISREG(sbuf.st_mode)) { printf("Found file %s\n", file->d_name); if (!(info= create_ID3(info))) { printf("Create Failed\n"); goto error; } if ((rc= parse_file_ID3(info, buffer))) { printf("File: %s\n Failed with code %d\n", buffer, (int)rc); } else { printID3(info, file->d_name); } } else if (S_ISDIR(sbuf.st_mode)) { if (file->d_name[0] != '.') { printf("Recursing into %s\n", file->d_name); load_directory(buffer, info); } } } else { printf("Could not stat %s\n", buffer); } } error: closedir(dir); }
/** * file_open - open a file on given secondary * @secondary: secondary address used in OPEN call * * This function opens the file named in command_buffer on the given * secondary address. All special names and prefixes/suffixed are handled * here, e.g. $/#/@/,S,W */ void file_open(uint8_t secondary) { buffer_t *buf; uint8_t i = 0; uint8_t recordlen = 0; /* If the secondary is already in use, close the existing buffer */ buf = find_buffer(secondary); if (buf != NULL) { /* FIXME: What should we do if an error occurs? */ cleanup_and_free_buffer(buf); } /* Assume everything will go well unless proven otherwise */ set_error(ERROR_OK); /* Strip 0x0d characters from end of name (C2BD-C2CA) */ if (command_length > 1) { if (command_buffer[command_length-1] == 0x0d) command_length -= 1; else if (command_buffer[command_length-2] == 0x0d) command_length -= 2; } /* Clear the remainder of the command buffer, simplifies parsing */ memset(command_buffer+command_length, 0, sizeof(command_buffer)-command_length); uart_trace(command_buffer,0,command_length); /* Direct access? */ if (command_buffer[0] == '#') { open_buffer(secondary); return; } /* Parse type+mode suffixes */ uint8_t *ptr = command_buffer; enum open_modes mode = OPEN_READ; uint8_t filetype = TYPE_DEL; while(i++ < 2 && *ptr && (ptr = ustrchr(ptr, ','))) { *ptr = 0; ptr++; switch (*ptr) { case 0: break; case 'R': /* Read */ mode = OPEN_READ; break; case 'W': /* Write */ mode = OPEN_WRITE; break; case 'A': /* Append */ mode = OPEN_APPEND; break; case 'M': /* Modify */ mode = OPEN_MODIFY; break; case 'D': /* DEL */ filetype = TYPE_DEL; break; case 'S': /* SEQ */ filetype = TYPE_SEQ; break; case 'P': /* PRG */ filetype = TYPE_PRG; break; case 'U': /* USR */ filetype = TYPE_USR; break; case 'L': /* REL */ filetype = TYPE_REL; mode = OPEN_WRITE; if((ptr = ustrchr(ptr, ','))) recordlen = *(++ptr); i = 2; // stop the scan break; } } /* Load directory? */ if (command_buffer[0] == '$') { load_directory(secondary); return; } /* Parse path+partition numbers */ uint8_t *fname; int8_t res; cbmdirent_t dent; path_t path; /* Parse path and file name */ if (parse_path(command_buffer, &path, &fname, 0)) return; #ifdef CONFIG_M2I /* For M2I only: Remove trailing spaces from name */ if (partition[path.part].fop == &m2iops) { res = ustrlen(fname); while (--res && fname[res] == ' ') fname[res] = 0; } #endif /* Filename matching */ if (opendir(&matchdh, &path)) return; do { res = next_match(&matchdh, fname, NULL, NULL, FLAG_HIDDEN, &dent); if (res > 0) /* Error, abort */ return; /* Don't match on DEL or DIR */ if ((dent.typeflags & TYPE_MASK) != TYPE_DEL && (dent.typeflags & TYPE_MASK) != TYPE_DIR) break; /* But do match if it's for writing */ if (mode == OPEN_WRITE || secondary == 1) break; } while (res == 0); if(res && filetype == TYPE_REL && !recordlen) { set_error(ERROR_SYNTAX_UNABLE); return; } /* If match found is a REL... */ if(!res && (dent.typeflags & TYPE_MASK) == TYPE_REL) { /* requested type must be REL or DEL */ if(filetype != TYPE_REL && filetype != TYPE_DEL) { set_error(ERROR_FILE_TYPE_MISMATCH); return; } filetype = TYPE_REL; mode = OPEN_MODIFY; } /* Force mode+type for secondaries 0/1 */ switch (secondary) { case 0: mode = OPEN_READ; if (filetype == TYPE_DEL) filetype = TYPE_PRG; break; case 1: mode = OPEN_WRITE; if (filetype == TYPE_DEL) filetype = TYPE_PRG; break; default: if (filetype == TYPE_DEL) filetype = TYPE_SEQ; } if (mode == OPEN_WRITE) { if (res == 0) { /* Match found */ if (command_buffer[0] == '@') { /* Make sure there is a free buffer to open the new file later */ if (!check_free_buffers()) { set_error(ERROR_NO_CHANNEL); return; } /* Copy dent because file_delete may change it */ cbmdirent_t dentcopy = dent; /* Rewrite existing file: Delete the old one */ if (file_delete(&path, &dentcopy) == 255) return; /* Force fatops to create a new name based on the (long) CBM- */ /* name instead of creating one with the old SFN and no LFN. */ if (dent.opstype == OPSTYPE_FAT || dent.opstype == OPSTYPE_FAT_X00) dent.pvt.fat.realname[0] = 0; } else { /* Write existing file without replacement: Raise error */ set_error(ERROR_FILE_EXISTS); return; } } else { /* Normal write or non-existing rewrite */ /* Doesn't exist: Copy name to dent */ memset(&dent, 0, sizeof(dent)); ustrncpy(dent.name, fname, CBM_NAME_LENGTH); set_error(ERROR_OK); // because first_match has set FNF } } else if (res != 0) { /* File not found */ set_error(ERROR_FILE_NOT_FOUND); return; } /* Grab a buffer */ buf = alloc_buffer(); if (!buf) return; buf->secondary = secondary; if(filetype == TYPE_REL) { display_filename_write(path.part,CBM_NAME_LENGTH,dent.name); open_rel(&path, &dent, buf, recordlen, (mode == OPEN_MODIFY)); return; } switch (mode) { case OPEN_MODIFY: case OPEN_READ: /* Modify is the same as read, but allows reading *ed files. */ /* FAT doesn't have anything equivalent, so both are mapped to READ */ display_filename_read(path.part,CBM_NAME_LENGTH,dent.name); open_read(&path, &dent, buf); break; case OPEN_WRITE: case OPEN_APPEND: display_filename_write(path.part,CBM_NAME_LENGTH,dent.name); open_write(&path, &dent, filetype, buf, (mode == OPEN_APPEND)); break; } }
/* * transfer_single_new_db() * * create links for mappings stored in "maps" array. */ static void transfer_single_new_db(pageCnvCtx *pageConverter, FileNameMap *maps, int size) { char old_dir[MAXPGPATH]; struct dirent **namelist = NULL; int numFiles = 0; int mapnum; int fileno; bool vm_crashsafe_change = false; old_dir[0] = '\0'; /* Do not copy non-crashsafe vm files for binaries that assume crashsafety */ if (old_cluster.controldata.cat_ver < VISIBILITY_MAP_CRASHSAFE_CAT_VER && new_cluster.controldata.cat_ver >= VISIBILITY_MAP_CRASHSAFE_CAT_VER) vm_crashsafe_change = true; for (mapnum = 0; mapnum < size; mapnum++) { char old_file[MAXPGPATH]; char new_file[MAXPGPATH]; /* Changed tablespaces? Need a new directory scan? */ if (strcmp(maps[mapnum].old_dir, old_dir) != 0) { if (numFiles > 0) { for (fileno = 0; fileno < numFiles; fileno++) pg_free(namelist[fileno]); pg_free(namelist); } snprintf(old_dir, sizeof(old_dir), "%s", maps[mapnum].old_dir); numFiles = load_directory(old_dir, &namelist); } /* Copying files might take some time, so give feedback. */ snprintf(old_file, sizeof(old_file), "%s/%u", maps[mapnum].old_dir, maps[mapnum].old_relfilenode); snprintf(new_file, sizeof(new_file), "%s/%u", maps[mapnum].new_dir, maps[mapnum].new_relfilenode); pg_log(PG_REPORT, OVERWRITE_MESSAGE, old_file); /* * Copy/link the relation file to the new cluster */ unlink(new_file); transfer_relfile(pageConverter, old_file, new_file, maps[mapnum].nspname, maps[mapnum].relname); /* fsm/vm files added in PG 8.4 */ if (GET_MAJOR_VERSION(old_cluster.major_version) >= 804) { /* * Copy/link any fsm and vm files, if they exist */ snprintf(scandir_file_pattern, sizeof(scandir_file_pattern), "%u_", maps[mapnum].old_relfilenode); for (fileno = 0; fileno < numFiles; fileno++) { char *vm_offset = strstr(namelist[fileno]->d_name, "_vm"); bool is_vm_file = false; /* Is a visibility map file? (name ends with _vm) */ if (vm_offset && strlen(vm_offset) == strlen("_vm")) is_vm_file = true; if (strncmp(namelist[fileno]->d_name, scandir_file_pattern, strlen(scandir_file_pattern)) == 0 && (!is_vm_file || !vm_crashsafe_change)) { snprintf(old_file, sizeof(old_file), "%s/%s", maps[mapnum].old_dir, namelist[fileno]->d_name); snprintf(new_file, sizeof(new_file), "%s/%u%s", maps[mapnum].new_dir, maps[mapnum].new_relfilenode, strchr(namelist[fileno]->d_name, '_')); unlink(new_file); transfer_relfile(pageConverter, old_file, new_file, maps[mapnum].nspname, maps[mapnum].relname); } } } /* * Now copy/link any related segments as well. Remember, PG breaks * large files into 1GB segments, the first segment has no extension, * subsequent segments are named relfilenode.1, relfilenode.2, * relfilenode.3, ... 'fsm' and 'vm' files use underscores so are not * copied. */ snprintf(scandir_file_pattern, sizeof(scandir_file_pattern), "%u.", maps[mapnum].old_relfilenode); for (fileno = 0; fileno < numFiles; fileno++) { if (strncmp(namelist[fileno]->d_name, scandir_file_pattern, strlen(scandir_file_pattern)) == 0) { snprintf(old_file, sizeof(old_file), "%s/%s", maps[mapnum].old_dir, namelist[fileno]->d_name); snprintf(new_file, sizeof(new_file), "%s/%u%s", maps[mapnum].new_dir, maps[mapnum].new_relfilenode, strchr(namelist[fileno]->d_name, '.')); unlink(new_file); transfer_relfile(pageConverter, old_file, new_file, maps[mapnum].nspname, maps[mapnum].relname); } } } if (numFiles > 0) { for (fileno = 0; fileno < numFiles; fileno++) pg_free(namelist[fileno]); pg_free(namelist); } }