static void DISKSIM_GLOBAL_STAT_DEFINITION_FILE_loader(int result, char *s) { char *path = lp_search_path(lp_cwd, s); if(!path) { ddbg_assert2(0, "Couldn't find statdefs file in path"); } else { statdeffile = fopen(path, "r"); ddbg_assert2(statdeffile != 0, "failed to open statdefs file!"); } }
static int layout_g2_loadmap(struct dm_layout_g2 *l) { FILE *fd; char junk[1024]; char countstr[16]; char *mapfile; int extentguess; int extents_ct = 0; struct dm_pbn pbn; int64_t lbn; int c,h,s,count; int lastc, lasth; int cyls, heads; int i, j; // index [cyl][head], number of extents for that track int **track_ext_counts; struct dm_layout_g2_node *curr; struct dm_layout_g2_node *track_extents; struct dm_pbn *currdefect; mapfile = lp_search_path(lp_cwd, l->mapfile); fd = fopen(mapfile, "r"); ddbg_assert3(fd != 0, ("failed to open layout mappings file %s", l->mapfile)); // ignore first 2 lines fgets(junk, sizeof(junk), fd); fgets(junk, sizeof(junk), fd); if(fscanf(fd, "%d cylinders, %*d rot, %d heads\n", &cyls, &heads) != 2) { ddbg_assert2(0, "*** error: layout_g2_loadmap: need <cyls> ... <heads>\n"); } // printf("*** layout_g2: %s %s\n", vendor, model); // printf("*** layout_g2: %d %d\n", cyls, heads); extentguess = cyls * heads * 2; // 0t tracks extentguess += extentguess/4; // if there are a lot of defects l->ltop_map = calloc(extentguess, sizeof(struct dm_layout_g2_node)); curr = &l->ltop_map[0]; l->ptol_map = calloc(cyls, sizeof(struct dm_layout_g2_cyl)); for(i = 0; i < cyls; i++) { l->ptol_map[i].surfaces = calloc(heads, sizeof(struct dm_layout_g2_surf)); } track_ext_counts = calloc(cyls, sizeof(int *)); for(i = 0; i < cyls; i++) { track_ext_counts[i] = calloc(heads, sizeof(int)); } curr = &l->ltop_map[0]; // ltop map while(fscanf(fd, "lbn %d --> cyl %d, head %d, sect %d, %s %d\n", &curr->lbn, &curr->loc.cyl, &curr->loc.head, &curr->loc.sector, countstr, &curr->len) == 6) { if(!strcmp(countstr, "seqcnt")) { curr->len++; } track_ext_counts[curr->loc.cyl][curr->loc.head]++; curr++; extents_ct++; l->ltop_map_len++; } // copy the ltop map and sort it by track track_extents = calloc(extents_ct, sizeof(struct dm_layout_g2_node)); memcpy(track_extents, l->ltop_map, extents_ct * sizeof(struct dm_layout_g2_node)); qsort(track_extents, extents_ct, sizeof(struct dm_layout_g2_node), trackcmp); // ptol map curr = &track_extents[0]; for(i = 0; i < cyls; i++) { for(j = 0; j < heads; j++) { int k; int extents_len = track_ext_counts[i][j]; l->ptol_map[i].surfaces[j].extents = calloc(extents_len, sizeof(struct dm_layout_g2_node)); l->ptol_map[i].surfaces[j].extents_len = extents_len; for(k = 0; k < extents_len; k++) { l->ptol_map[i].surfaces[j].extents[k] = *curr; curr++; } } } // free the extra extent list free(track_extents); // ddbg_assert2(extents_ct > (cyls * heads), "EOF on layout mappings file??"); // l->extents_len = extents_ct; // populate the defect list defects = calloc(extents_ct >> 3, sizeof(struct dm_pbn)); currdefect = &defects[0]; while(fscanf(fd, "Defect at cyl %d, head %d, sect %d\n", &currdefect->cyl, &currdefect->head, &currdefect->sector) == 3) { currdefect++; defects_len++; } fclose(fd); return 0; }
void dm_mech_g1_read_extracted_seek_curve (char *filename, int *cntptr, int **distsptr, dm_time_t **timesptr) { int rv, mat; int lineflag = 1; int count = 0, buflen = 128; int *dists; dm_time_t *times; FILE *seekfile = NULL; char linebuf[1024]; char *pathname = lp_search_path(lp_cwd, filename); if(pathname) { seekfile = fopen(pathname, "r"); } else { ddbg_assert2(0, "Seek file not found in path!"); } ddbg_assert3(seekfile != 0, ("fopen seekfile (%s) failed: %s", filename, strerror(errno))); rv = (fgets(linebuf, sizeof(linebuf), seekfile) != 0); mat = sscanf(linebuf, "Seek distances measured: %d\n", &count); if(mat == 1) { buflen = count; lineflag = 0; } dists = calloc(buflen, sizeof(*dists)); times = calloc(buflen, sizeof(*times)); do { double time, stdev; int dist; if(!lineflag) { rv = (fgets(linebuf, sizeof(linebuf), seekfile) != 0); } else { lineflag = 0; } if(rv) { mat = sscanf(linebuf, "%d, %lf, %lf\n", &dist, &time, &stdev); if(mat == 2 || mat == 3) { if(count >= buflen-1) { buflen *= 2; dists = realloc(dists, buflen * sizeof(*dists)); times = realloc(times, buflen * sizeof(*times)); } dists[count] = dist; times[count] = dm_time_dtoi(time); count++; } else { fprintf(stderr, "*** bogus line in seek curve (%s:%d): %s\n", __FILE__, __LINE__, linebuf); } } } while(rv); fclose(seekfile); *cntptr = count; *distsptr = dists; *timesptr = times; }