⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layout_g1.c

📁 目前最精确的磁盘模拟器的第3版
💻 C
📖 第 1 页 / 共 4 页
字号:
	*first_lbn = max(((*first_lbn) - lbnadd), temp_lbn);	break;      }    }    if (p->sector == b->blkspertrack) {      *first_lbn = DM_SLIPPED;    }  }  if (last_lbn) {    // was 1, want the last block on this track rather than    // the first of the next.  bucy 200208    lbnadd = 0;    /* use brute force -- back translate each pbn to figure out endlbn */    for (p->sector = (b->blkspertrack-1); p->sector >= 0; p->sector--) {      int remapsector = 0;      *last_lbn = g1_ptol_sectpercylspare(d, p, &remapsector);      if ((*last_lbn) == DM_REMAPPED) {	lbnadd++;      }      if (remapsector) {      	*last_lbn = DM_SLIPPED;      }      if ((*last_lbn) >= 0) {	*last_lbn = (*last_lbn) + lbnadd;	break;      }    }    if (p->sector == DM_SLIPPED) {      *last_lbn = DM_SLIPPED;    }  }  p->head = g1_surfno_on_cyl(l, b, p);  p->sector = (((p->cyl - b->startcyl) * d->dm_surfaces) + p->head) * b->blkspertrack;  for (i = 0; i < b->numdefects; i++) {    if ((blkno <= b->defect[i]) && 	((blkno + b->blkspertrack) > b->defect[i])) {      // XXX global/remapsetor      if(remapsector) *remapsector = 1;    }  }}static voidg1_track_boundaries_sectperrangespare(struct dm_disk_if *d,				      struct dm_pbn *p,				      int *first_lbn,				      int *last_lbn,				      int *remapsector){  /* lbn equals first block in band */  int i;  int blkno;  int lbnadd;  struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout;  struct dm_layout_g1_band *b = find_band_pbn(l, p);  int lbn = l->band_blknos[b->num];  int temp_lbn = lbn;  int lbnspertrack = b->blkspertrack - b->sparecnt;  struct dm_pbn pbn = *p;  p = &pbn;  if (first_lbn) {    lbnadd = 0;    /* use brute force -- back translate each pbn to figure out startlbn */    for (blkno = 0; blkno < b->blkspertrack; blkno++) {      int remapsector = 0;      p->sector = blkno;      *first_lbn = g1_ptol_sectperrangespare(d,p,&remapsector);      if ((*first_lbn) == DM_REMAPPED) {	lbnadd++;      }      if (remapsector) {      	*first_lbn = DM_SLIPPED;      }      if ((*first_lbn) >= 0) {	*first_lbn = max(((*first_lbn) - lbnadd), temp_lbn);	break;      }    }    if (blkno == b->blkspertrack) {      *first_lbn = DM_SLIPPED;    }  }  if (last_lbn) {    // was 1, want the last block on this track rather than    // the first of the next.  bucy 200208    lbnadd = 0;    /* use brute force -- back translate each pbn to figure out endlbn */    for (p->sector = (b->blkspertrack-1); p->sector >= 0; p->sector--) {      int remapsector = 0;      *last_lbn = g1_ptol_sectperrangespare(d,p,&remapsector);					          if ((*last_lbn) == DM_REMAPPED) {	lbnadd++;      }      if (remapsector) {      	*last_lbn = DM_SLIPPED;      }      if ((*last_lbn) >= 0) {	*last_lbn = (*last_lbn) + lbnadd;	break;      }    }    if (blkno == DM_SLIPPED) {      *last_lbn = DM_SLIPPED;    }  }  p->head = g1_surfno_on_cyl(l, b, p);  p->sector = (((p->cyl - b->startcyl) * d->dm_surfaces) + p->head) * b->blkspertrack;  for (i = 0; i < b->numdefects; i++) {    if ((p->sector <= b->defect[i]) && ((p->sector + b->blkspertrack) > b->defect[i])) {      if(remapsector) *remapsector = 1;    }  }}static voidg1_track_boundaries_sectperzonespare(struct dm_disk_if *d,				     struct dm_pbn *p,				     int *first_lbn,				     int *last_lbn,				     int *remapsector){  /* lbn equals first block in band */  int i;  int blkno;  int lbnadd;  struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout;  struct dm_layout_g1_band *b = find_band_pbn(l, p);  int lbn = l->band_blknos[b->num];  int temp_lbn = lbn;  int lbnspertrack = b->blkspertrack - b->sparecnt;  struct dm_pbn pbn = *p;  p = &pbn;  if (first_lbn) {    lbnadd = 0;    /* use brute force -- back translate each pbn to figure out startlbn */    for (p->sector = 0; p->sector < b->blkspertrack; p->sector++) {      int remapsector = 0;      *first_lbn = g1_ptol_sectperzonespare(d, p, &remapsector);      if ((*first_lbn) == DM_REMAPPED) {	lbnadd++;      }      if (remapsector) {      	*first_lbn = DM_SLIPPED;      }      if ((*first_lbn) >= 0) {	*first_lbn = max(((*first_lbn) - lbnadd), temp_lbn);	break;      }    }    if(p->sector == b->blkspertrack) {      *first_lbn = DM_SLIPPED;    }  }  if (last_lbn) {    // was 1, want the last block on this track rather than    // the first of the next.  bucy 200208    lbnadd = 0;    /* use brute force -- back translate each pbn to figure out endlbn */    for (p->sector = (b->blkspertrack - 1); p->sector >= 0; p->sector--)       {	// XXX global/remapsector	int remapsector = 0;	*last_lbn = g1_ptol_sectperzonespare(d,p,&remapsector);	if ((*last_lbn) == DM_REMAPPED) {	  lbnadd++;	}	if (remapsector) {	  *last_lbn = DM_SLIPPED;	}	if ((*last_lbn) >= 0) {	  *last_lbn = (*last_lbn) + lbnadd;	  break;	}      }    //    if (blkno == DM_SLIPPED) {    //      *last_lbn = DM_SLIPPED;    //    }  }  p->head = g1_surfno_on_cyl(l,b,p);  p->sector = (((p->cyl - b->startcyl) * d->dm_surfaces) + p->head) * b->blkspertrack;  for (i = 0; i < b->numdefects; i++) {    if ((p->sector <= b->defect[i]) && 	((p->sector + b->blkspertrack) > b->defect[i]))       {	if(remapsector) *remapsector = 1;      }  }}static voidg1_track_boundaries_trackspare(struct dm_disk_if *d,			       struct dm_pbn *p,			       int *first_lbn,			       int *last_lbn,			       int *remapsector){  int i;  int trackno;  int lasttrack;  int blkno;  struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout;  struct dm_layout_g1_band *b = find_band_pbn(l, p);  int lbn = l->band_blknos[b->num];  int lbnspertrack = b->blkspertrack - b->sparecnt;  struct dm_pbn pbn = *p;  p = &pbn;  p->head = g1_surfno_on_cyl(l,b,p);  trackno = ((p->cyl - b->startcyl) * d->dm_surfaces) + p->head;  for(i = (b->numdefects - 1); i >= 0; i--) {    if(trackno == b->defect[i]) {   /* Remapped bad track */      lbn = DM_REMAPPED;    }    if(trackno == b->remap[i]) {      trackno = b->defect[i];      break;    }  }  for(i = (b->numslips-1); i >= 0; i--) {    if(trackno == b->slip[i]) {     /* Slipped bad track */      lbn = DM_SLIPPED;    }    if(trackno > b->slip[i]) {      trackno--;    }  }  lasttrack = (b->blksinband + b->deadspace) / b->blkspertrack;  if(trackno > lasttrack) {                 /* Unused spare track */    lbn = DM_SLIPPED;  }  p->sector = lbn + (trackno * b->blkspertrack) - b->deadspace;  if(first_lbn) {    if(lbn < 0) {      *first_lbn = lbn;    }    else {      *first_lbn = ((p->sector + b->blkspertrack) <= lbn) 	? DM_SLIPPED 	: max(p->sector, lbn);    }  }  if(last_lbn) {    p->sector += (b->blkspertrack - 1);    if(lbn < 0) {      *last_lbn = lbn;    }    else {      *last_lbn = (p->sector <= lbn) 	? DM_SLIPPED 	: p->sector;    }  }}static dm_ptol_result_tg1_ltop_0t(struct dm_disk_if *d, 		  int lbn, 		  dm_layout_maptype maptype,		  struct dm_pbn *result,		  int *remapsector){  long long max = (long long)1 << 32;  dm_angle_t a;  struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout;  struct dm_layout_g1_band *b = find_band_lbn(l, lbn);    d->layout->dm_translate_ltop(d,lbn,maptype,result,remapsector);  a = d->layout->dm_pbn_skew(d,result);  result->sector = (a / b->sector_width) % b->blkspertrack;  return DM_OK;}/* * The next several functions compute the physical media location to * which a given lbn (blkno) is mapped for different sparing/mapping * schemes.  The returned value is a proper lbn, or DM_REMAPPED if the * sector is a remapped defect, or DM_SLIPPED if the sector is a slipped * defect or an unused spare. *//* * NOTE: No slipping beyond the end of a track is allowed.  The * following code will produce incorrect results if this rule is * violated.  To fix this, trackno needs to be recomputed after slips * and slips on immediately previous tracks need to be accounted for. * Low Priority.   */static dm_ptol_result_tg1_ltop_nosparing(struct dm_disk_if *d, 		  int lbn, 		  dm_layout_maptype maptype,		  struct dm_pbn *result,		  int *remapsector){  int blkspertrack;  struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout;  struct dm_layout_g1_band *b = find_band_lbn(l, lbn);  struct dm_pbn pbn = *result;  result = &pbn;  lbn -= l->band_blknos[b->num];  lbn += b->deadspace;  blkspertrack = b->blkspertrack;  result->cyl = lbn / (blkspertrack * d->dm_surfaces) + b->startcyl;  result->cyl = (lbn / blkspertrack) % d->dm_surfaces;  result->cyl = g1_surfno_on_cyl(l,b,result);  result->sector = lbn % blkspertrack;  return DM_OK;}static dm_ptol_result_tg1_ltop_sectpertrackspare(struct dm_disk_if *d, 		  int lbn, 			  dm_layout_maptype maptype,			  struct dm_pbn *result,			  int *remapsector){  int i, trackno;  int firstblkontrack = -1;    struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout;  struct dm_layout_g1_band *b = find_band_lbn(l, lbn);  int blkspertrack = b->blkspertrack;  int lbnspertrack = blkspertrack - b->sparecnt;  lbn -= l->band_blknos[b->num];  lbn += b->deadspace;  trackno = lbn / lbnspertrack;  lbn %= lbnspertrack;  if ((maptype == MAP_ADDSLIPS) || (maptype == MAP_FULL)) {    firstblkontrack = blkspertrack * trackno;    for (i=0; i<b->numslips; i++) {      if ((b->slip[i] >= firstblkontrack) && 	  ((b->slip[i] - firstblkontrack) <= lbn)) 	{	  lbn++;	}    }  }  if(maptype == MAP_FULL) {    for(i = 0; i < b->numdefects; i++) {      if(b->defect[i] == (firstblkontrack + lbn)) {	if(remapsector) *remapsector = 1;	trackno = b->remap[i] / blkspertrack;	firstblkontrack = blkspertrack * trackno;	lbn = b->remap[i] % blkspertrack;      }    }  }  result->cyl = trackno/d->dm_surfaces + b->startcyl;  result->head = trackno % d->dm_surfaces;  result->head = g1_surfno_on_cyl(l,b,result);      if(lbn >= blkspertrack) {    //printf("Somehow computed a blkno that crosses to another track\n");    //printf("This could be the result of too many slips, or of a bug\n");    //printf("in the defect-related computations...\n");    ddbg_assert(0);  }  else {    result->sector = lbn;  }  return DM_OK;}static dm_ptol_result_tg1_ltop_sectpercylspare(struct dm_disk_if *d, 			int lbn, 			dm_layout_maptype maptype,			struct dm_pbn *result,			int *remapsector){  int i;  int blkspertrack;  int blkspercyl;  int lbnspercyl;  int firstblkoncyl = 0;  int cyl;  int slips = 0;  struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout;  struct dm_layout_g1_band *b = find_band_lbn(l, lbn);  lbn -= l->band_blknos[b->num];  lbn += b->deadspace;  blkspertrack = b->blkspertrack;  blkspercyl = blkspertrack * d->dm_surfaces;  lbnspercyl = blkspercyl - b->sparecnt;  cyl = lbn / lbnspercyl;  lbn = lbn % lbnspercyl;  if ((maptype == MAP_ADDSLIPS) || (maptype == MAP_FULL)) {    firstblkoncyl = cyl * blkspertrack * d->dm_surfaces;    for (i=0; i<b->numslips; i++) {      if (((issliptoend(l)) && 	   ((b->slip[i]/blkspercyl) < cyl)) || 	  ((b->slip[i] >= firstblkoncyl) && 	   ((b->slip[i] - firstblkoncyl) <= (lbn+slips)))) 	{	  slips++;	}    }  }  lbn += slips;  if (maptype == MAP_FULL) {    for (i=0; i<b->numdefects; i++) {      if ((b->defect[i] == (firstblkoncyl + lbn)) && 	  (b->remap[i] != b->defect[i])) 	{	  if(remapsector) *remapsector = 1;	  lbn = b->remap[i];	  cyl = lbn / blkspercyl;	  lbn = lbn % blkspercyl;	  goto g1_ltop_sectpercylspare_done;	}    }  }     cyl += lbn / lbnspercyl;  lbn = lbn % lbnspercyl; g1_ltop_sectpercylspare_done:    result->cyl = cyl + b->startcyl;  result->head = lbn / blkspertrack;  result->head = g1_surfno_on_cyl(l,b,result);  result->sector = lbn % blkspertrack;  return DM_OK;}/* Assume no remapping/slipping out of a range. */static dm_ptol_result_tg1_ltop_sectperrangespare(struct dm_disk_if *d, 			  int lbn, 			  dm_layout_maptype maptype,			  struct dm_pbn *result,			  int *remapsector){  int i;  int blksperrange;  int blkspercyl;  int lbnsperrange;  int firstblkinrange = 0;  int rangeno;  int slips = 0;  struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout;  struct dm_layout_g1_band *b = find_band_lbn(l, lbn);  lbn -= l->band_blknos[b->num];  lbn += b->deadspace;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -