1 #ifndef lint 2 static char sccsid[] = "@(#)util.c 1.3 (Berkeley/CCI) 05/31/88"; 3 #endif 4 5 #include "vdfmt.h" 6 #include "cmd.h" 7 8 /* 9 */ 10 to_track(daddr)11to_track(daddr) 12 dskadr daddr; 13 { 14 return ((daddr.cylinder * lab->d_ntracks) + daddr.track); 15 } 16 17 18 /* 19 */ 20 from_track(trk)21dskadr *from_track(trk) 22 int trk; 23 { 24 static dskadr temp; 25 26 temp.cylinder = trk / lab->d_ntracks; 27 temp.track = trk % lab->d_ntracks; 28 temp.sector = 0; 29 return &temp; 30 } 31 32 33 /* 34 */ 35 to_sector(daddr)36to_sector(daddr) 37 dskadr daddr; 38 { 39 return ((to_track(daddr) * lab->d_nsectors) + daddr.sector); 40 } 41 42 43 /* 44 */ 45 from_sector(sec)46dskadr *from_sector(sec) 47 unsigned int sec; 48 { 49 static dskadr temp; 50 51 temp = *from_track((int)(sec / lab->d_nsectors)); 52 temp.sector = sec % lab->d_nsectors; 53 return &temp; 54 } 55 56 57 /* 58 ** 59 */ 60 print_unix_block(dskaddr)61print_unix_block(dskaddr) 62 dskadr dskaddr; 63 { 64 char fs; 65 int blk; 66 register struct partition *pp; 67 68 indent(); 69 blk = to_sector(dskaddr); 70 print("** Warning - Unable to relocate sector %d:\n",to_sector(dskaddr)); 71 indent(); 72 print("to map out using BADSECT use the following values:\n"); 73 indent(); 74 for(fs = 0; fs < lab->d_npartitions; fs++) { 75 int s, l; 76 77 pp = &lab->d_partitions[fs]; 78 s = pp->p_offset; 79 l = pp->p_size; 80 if (pp->p_fsize == 0) 81 pp->p_fsize = DEV_BSIZE; 82 if((blk < (s+l)) && (blk >= s)) { 83 print("On the `%c' Partition use filesystem block %d.\n", 84 fs+'a', (blk - s) * lab->d_secsize / pp->p_fsize); 85 } 86 } 87 exdent(3); 88 } 89 from_unix(par,block)90dskadr *from_unix(par, block) 91 unsigned char par; 92 unsigned int block; 93 { 94 unsigned int sector; 95 register int fs; 96 register struct partition *pp; 97 static dskadr dskaddr; 98 99 fs = tolower(par) - 'a'; 100 if((fs < lab->d_npartitions) && 101 (block <= (pp = &lab->d_partitions[fs])->p_size)) { 102 if (pp->p_fsize == 0) 103 pp->p_fsize = DEV_BSIZE; 104 dskaddr = *from_sector(pp->p_offset + 105 block * pp->p_fsize / lab->d_secsize); 106 } else { 107 dskaddr.cylinder = -1; 108 dskaddr.track = -1; 109 dskaddr.sector = -1; 110 } 111 return &dskaddr; 112 } 113