📄 layout_g1.c
字号:
p = &pbn; ddbg_assert(b); ddbg_assert(p->cyl >= 0); ddbg_assert(p->cyl >= b->startcyl); ddbg_assert(p->cyl < d->dm_cyls); ddbg_assert(p->head >= 0); ddbg_assert(p->head < d->dm_surfaces); ddbg_assert(p->sector >= 0); ddbg_assert(p->sector < b->blkspertrack); p->head = g1_surfno_on_cyl(l, b, p); firstblkoncyl = (p->cyl - b->startcyl) * d->dm_surfaces * b->blkspertrack; p->sector += firstblkoncyl + (p->head * b->blkspertrack); for (i=(b->numdefects-1); i>=0; i--) { if (p->sector == b->defect[i]) { /* Remapped bad block */ return DM_REMAPPED; } if(p->sector == b->remap[i]) { if(remapsector) *remapsector = 1; p->sector = b->defect[i]; break; } } for (i = (b->numslips-1); i >= 0; i--) { if (p->sector == b->slip[i]) { /* Slipped bad block */ return DM_SLIPPED; } if ((p->sector > b->slip[i]) && ((b->slip[i] / (b->blkspertrack * d->dm_surfaces)) == (p->cyl - b->startcyl)) && ((b->slip[i] % (b->blkspertrack * d->dm_surfaces)) == p->head)) { p->sector--; } } if((p->sector % b->blkspertrack) >= (b->blkspertrack - b->sparecnt)) { /* Unused spare block */ return DM_SLIPPED; } /* recompute in case sector was remapped */ p->cyl = p->sector / (b->blkspertrack * d->dm_surfaces); p->head = p->sector % (b->blkspertrack * d->dm_surfaces); p->head = p->head / b->blkspertrack; p->sector = p->sector % b->blkspertrack; lbnspercyl = (b->blkspertrack - b->sparecnt) * d->dm_surfaces; lbn += p->cyl * lbnspercyl; lbn += p->head * (b->blkspertrack - b->sparecnt); lbn += p->sector - b->deadspace; if(lbn < 0) { return DM_SLIPPED; } else { return lbn; }}static dm_ptol_result_tg1_ptol_sectpercylspare(struct dm_disk_if *d, struct dm_pbn *p, int *remapsector){ int i; int lbnspercyl; int blkspercyl; int firstblkoncyl; 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]; struct dm_pbn pbn = *p; p = &pbn; /* ddbg_assert(b); */ /* ddbg_assert(p->cyl >= 0); */ /* ddbg_assert(p->cyl >= b->startcyl); */ /* ddbg_assert(p->cyl < d->numcyls); */ /* ddbg_assert(surfaceno >= 0); */ /* ddbg_assert(surfaceno < d->dm_surfaces); */ /* ddbg_assert(p->sector >= 0); */ /* ddbg_assert(p->sector < b->blkspertrack); */ //printf ("ptol_sectpercylspare: p->cyl %d, surfaceno %d, p->sector %d, lbn %d\n", p->cyl, surfaceno, p->sector, lbn); p->head = g1_surfno_on_cyl(l, b, p); blkspercyl = b->blkspertrack * d->dm_surfaces; lbnspercyl = blkspercyl - b->sparecnt; firstblkoncyl = (p->cyl - b->startcyl) * blkspercyl; p->sector += firstblkoncyl + (p->head * b->blkspertrack); for (i = (b->numdefects - 1); i >= 0; i--) { if (p->sector == b->defect[i]) { /* Remapped bad block */ return DM_REMAPPED; } if (p->sector == b->remap[i]) { if(remapsector) *remapsector = 1; p->sector = b->defect[i]; break; } } for (i = (b->numslips - 1); i >= 0; i--) { if (p->sector == b->slip[i]) { /* Slipped bad block */ return DM_SLIPPED; } if (p->sector > b->slip[i]) { if ((b->slip[i] / blkspercyl) == (p->cyl - b->startcyl)) { p->sector--; } else if (issliptoend(l)) { lbn--; } } } /* check for unused spare blocks */ if (((!isspareatfront(l)) && ((p->sector % blkspercyl) >= lbnspercyl)) || ((isspareatfront(l)) && ((p->sector % blkspercyl) < b->sparecnt))) { return DM_SLIPPED; } /* recompute in case sector was remapped */ p->cyl = p->sector / blkspercyl; p->head = p->sector % blkspercyl; p->head = p->head / b->blkspertrack; p->sector = p->sector % b->blkspertrack; lbn += p->cyl * lbnspercyl; lbn += p->head * b->blkspertrack; lbn += p->sector - b->deadspace; lbn -= (isspareatfront(l)) ? b->sparecnt : 0; if(lbn < 0) { return DM_SLIPPED; } else { return lbn; }}static dm_ptol_result_tg1_ptol_sectperrangespare(struct dm_disk_if *d, struct dm_pbn *p, int *remapsector){ int i; int lbnsperrange; int blksperrange; int blkspercyl; int firstblkoncyl; int rangeno; 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]; struct dm_pbn pbn = *p; p = &pbn; ddbg_assert(b); ddbg_assert(p->cyl >= 0); ddbg_assert(p->cyl >= b->startcyl); ddbg_assert(p->cyl < d->dm_cyls); ddbg_assert(p->head >= 0); ddbg_assert(p->head < d->dm_surfaces); ddbg_assert(p->sector >= 0); ddbg_assert(p->sector < b->blkspertrack); p->head = g1_surfno_on_cyl(l, b, p); blkspercyl = b->blkspertrack * d->dm_surfaces; blksperrange = blkspercyl * l->rangesize; lbnsperrange = blksperrange - b->sparecnt; rangeno = (p->cyl - b->startcyl) / l->rangesize; firstblkoncyl = (p->cyl - b->startcyl) * blkspercyl; p->sector += firstblkoncyl + (p->head * b->blkspertrack); for (i=(b->numdefects-1); i>=0; i--) { if (p->sector == b->defect[i]) { /* Remapped bad block */ return DM_REMAPPED; } if (p->sector == b->remap[i]) { if(remapsector) *remapsector = 1; p->sector = b->defect[i]; break; } } for (i=(b->numslips-1); i>=0; i--) { if (p->sector == b->slip[i]) { /* Slipped bad block */ return DM_SLIPPED; } if (p->sector > b->slip[i]) { if ((b->slip[i] / blksperrange) == rangeno) { p->sector--; } } } p->sector = p->sector % blksperrange; /* check for unused spare blocks */ if (p->sector >= lbnsperrange) { return DM_SLIPPED; } lbn += rangeno * lbnsperrange; lbn += p->sector - b->deadspace; if(lbn < 0) { return DM_SLIPPED; } else { return lbn; }}static dm_ptol_result_tg1_ptol_sectperzonespare(struct dm_disk_if *d, struct dm_pbn *p, int *remapsector){ int i; int blkspercyl; int firstblkoncyl; 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]; struct dm_pbn pbn = *p; p = &pbn; ddbg_assert(b); ddbg_assert(p->cyl >= 0); ddbg_assert(p->cyl >= b->startcyl); ddbg_assert(p->cyl < d->dm_cyls); ddbg_assert(p->head >= 0); ddbg_assert(p->head < d->dm_surfaces); ddbg_assert(p->sector >= 0); ddbg_assert(p->sector < b->blkspertrack); //printf ("ptol_sectperzonespare: p->cyl %d, p->head %d, p->sector %d, lbn %d\n", p->cyl, p->head, p->sector, lbn); /* compute p->sector within zone */ p->head = g1_surfno_on_cyl(l, b, p); blkspercyl = b->blkspertrack * d->dm_surfaces; firstblkoncyl = (p->cyl - b->startcyl) * blkspercyl; p->sector += firstblkoncyl + (p->head * b->blkspertrack); for (i = (b->numdefects - 1); i >= 0; i--) { if (p->sector == b->defect[i]) { /* Remapped bad block */ return DM_REMAPPED; } if (p->sector == b->remap[i]) { if(remapsector) *remapsector = 1; p->sector = b->defect[i]; break; } } for (i=(b->numslips-1); i>=0; i--) { if (p->sector == b->slip[i]) { /* Slipped bad block */ return DM_SLIPPED; } if (p->sector > b->slip[i]) { p->sector--; } } /* check for unused spare blocks */ if (p->sector >= b->blksinband) { return DM_SLIPPED; } lbn += p->sector - b->deadspace; if(lbn < 0) { return DM_SLIPPED; } else { return lbn; }}static dm_ptol_result_tg1_ptol_trackspare(struct dm_disk_if *d, struct dm_pbn *p, int *remapsector){ int i; int trackno; int lasttrack; 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]; struct dm_pbn pbn = *p; p = &pbn; ddbg_assert(b); ddbg_assert(p->cyl >= 0); ddbg_assert(p->cyl >= b->startcyl); ddbg_assert(p->cyl < d->dm_cyls); ddbg_assert(p->head >= 0); ddbg_assert(p->head < d->dm_surfaces); ddbg_assert(p->sector >= 0); ddbg_assert(p->sector < b->blkspertrack); 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 */ return 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 */ return DM_SLIPPED; } if (trackno > b->slip[i]) { trackno--; } } lasttrack = (b->blksinband + b->deadspace) / b->blkspertrack; if (trackno > lasttrack) { /* Unused spare track */ return DM_SLIPPED; } lbn += p->sector + (trackno * b->blkspertrack) - b->deadspace; if(lbn < 0) { return DM_SLIPPED; } else { return lbn; }}/* * * The next several functions compute the lbn boundaries (first and * last) for a given physical track <cyl, surf>, for different * sparing/mapping schemes. The start and end values are proper lbns, * or DM_REMAPPED if the entire track consists of remapped defects, or * DM_SLIPPED if the entire track consists of slipped defects or * unused spare space. Note: the lbns returned account for slippage * but purposefully ignore remapping of sectors to other tracks. * * Note: the per-scheme functions take a pointer to the relevant band * and the first lbn in that band, in addition to the basic * parameters. * * These functions are organized by sparing scheme ... though we could * potentially have the cross-product of sparing and mapping schemes, * normal, cylcswitchonsurf1 and cylswitchonsurf2 all share the per- * sparing-scheme implementations. (bucy 1/02) * *//* Assume that we never slip sectors over track boundaries! */static voidg1_track_boundaries_nosparing(struct dm_disk_if *d, struct dm_pbn *p, int *first_lbn, int *last_lbn, int *remapsector){ 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; // this implementation lived in disk_get_lbn_boundaries_for_track p->head = g1_surfno_on_cyl(l, b, p); lbn += ((((p->cyl - b->startcyl) * d->dm_surfaces) + p->head) * b->blkspertrack) - b->deadspace; if(first_lbn) { *first_lbn = ((lbn + b->blkspertrack) <= temp_lbn) ? DM_SLIPPED : max(lbn, temp_lbn); } if(last_lbn) { lbn += (b->blkspertrack - 1); *last_lbn = (lbn <= temp_lbn) ? DM_SLIPPED : lbn; }}static voidg1_track_boundaries_sectpertrackspare(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; 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; p->head = g1_surfno_on_cyl(l, b, p); lbn += ((((p->cyl - b->startcyl) * d->dm_surfaces) + p->head) * lbnspertrack) - b->deadspace; if (first_lbn) { *first_lbn = ((lbn + lbnspertrack) <= temp_lbn) ? DM_SLIPPED : max(temp_lbn, lbn); } if (last_lbn) { lbn += (lbnspertrack - 1); *last_lbn = (lbn <= temp_lbn) ? DM_SLIPPED : lbn; } 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_sectpercylspare(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 = 0; 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_sectpercylspare(d, p, &remapsector); if ((*first_lbn) == DM_REMAPPED) { lbnadd++; } if (remapsector) { *first_lbn = DM_SLIPPED; } if ((*first_lbn) >= 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -