diff options
Diffstat (limited to 'v4.0/src/CMD/FDISK/DISKOUT.C')
| -rw-r--r-- | v4.0/src/CMD/FDISK/DISKOUT.C | 354 |
1 files changed, 354 insertions, 0 deletions
diff --git a/v4.0/src/CMD/FDISK/DISKOUT.C b/v4.0/src/CMD/FDISK/DISKOUT.C new file mode 100644 index 0000000..189795e --- /dev/null +++ b/v4.0/src/CMD/FDISK/DISKOUT.C | |||
| @@ -0,0 +1,354 @@ | |||
| 1 | |||
| 2 | #include "dos.h" /* AN000 */ | ||
| 3 | #include "fdisk.h" /* AN000 */ | ||
| 4 | #include "subtype.h" /* AN000 */ | ||
| 5 | #include "extern.h" /* AN000 */ | ||
| 6 | |||
| 7 | |||
| 8 | /* */ | ||
| 9 | void write_info_to_disk() | ||
| 10 | |||
| 11 | BEGIN | ||
| 12 | |||
| 13 | char i; | ||
| 14 | unsigned char j; | ||
| 15 | unsigned extended_location; | ||
| 16 | char extended_index; | ||
| 17 | char temp; | ||
| 18 | char first_found; | ||
| 19 | char changed_flag; | ||
| 20 | char temp_disk; | ||
| 21 | |||
| 22 | |||
| 23 | temp = c(NUL); /* AN009 */ | ||
| 24 | temp_disk = cur_disk; | ||
| 25 | /* See if need to update the master boot record */ | ||
| 26 | for (j = uc(0); j < number_of_drives; j++) /* AC000 */ | ||
| 27 | BEGIN | ||
| 28 | |||
| 29 | /* Save disk number */ | ||
| 30 | cur_disk = ((char)(j)); | ||
| 31 | |||
| 32 | /* See if there were any errors on that drive */ | ||
| 33 | if (good_disk[j]) | ||
| 34 | BEGIN | ||
| 35 | for (i=c(0); i < c(4); i++) /* AC000 */ | ||
| 36 | BEGIN | ||
| 37 | if (part_table[j][i].changed) | ||
| 38 | BEGIN | ||
| 39 | write_master_boot_to_disk(j); | ||
| 40 | break; | ||
| 41 | END | ||
| 42 | END | ||
| 43 | /* See if the extended partition exists - if not, don't fool with the logical*/ | ||
| 44 | /* drives - there is nothing to point to thier structures. Otherwise you get into */ | ||
| 45 | /* a chicken and the egg situation, where you are trying to write out 'deletes' of */ | ||
| 46 | /* the logical drive based on the start of the extended partition, but there isn't one */ | ||
| 47 | /* because it has already been deleted already. Bad things happen - PTM P941 */ | ||
| 48 | |||
| 49 | if (find_partition_type(uc(EXTENDED))); /* AC000 */ | ||
| 50 | BEGIN | ||
| 51 | /* See if any extended partitions need to be updated */ | ||
| 52 | changed_flag = FALSE; | ||
| 53 | |||
| 54 | for (i=c(0);i <c(23); i++) /* AC000 */ | ||
| 55 | BEGIN | ||
| 56 | if (ext_table[j][i].changed) | ||
| 57 | BEGIN | ||
| 58 | changed_flag = TRUE; | ||
| 59 | break; | ||
| 60 | END | ||
| 61 | END | ||
| 62 | if (changed_flag) | ||
| 63 | BEGIN | ||
| 64 | /* First,get them in order - drive letters are assigned in the order */ | ||
| 65 | /* that they exist on the disk */ | ||
| 66 | sort_ext_table(c(23)); /* AC000 */ | ||
| 67 | |||
| 68 | for (i=c(0);i < c(23); i++) /* AC000 */ | ||
| 69 | |||
| 70 | BEGIN | ||
| 71 | /* If there is a valid drive existing, write it out */ | ||
| 72 | if (ext_table[j][sort[i]].sys_id != uc(0)) /* AC000 */ | ||
| 73 | BEGIN | ||
| 74 | write_ext_boot_to_disk(i,j); | ||
| 75 | END | ||
| 76 | END | ||
| 77 | |||
| 78 | /* Find start of extended partition */ | ||
| 79 | extended_index = find_partition_location(uc(EXTENDED)); /* AC000 */ | ||
| 80 | extended_location = part_table[j][extended_index].start_cyl; | ||
| 81 | |||
| 82 | /* See if the first entry in EXTENDED DOS partition will be written out */ | ||
| 83 | /* Need to find the first drive in the sorted list */ | ||
| 84 | for (i=c(0);i < c(23); i++) /* AC000 */ | ||
| 85 | BEGIN | ||
| 86 | if (ext_table[j][sort[i]].sys_id != uc(0)) /* AC000 */ | ||
| 87 | BEGIN | ||
| 88 | temp = sort[i]; | ||
| 89 | break; | ||
| 90 | END | ||
| 91 | END | ||
| 92 | /* See if drive written out */ | ||
| 93 | if ((temp != c(NUL)) && | ||
| 94 | (extended_location != ext_table[j][temp].start_cyl)) /* AC009 */ | ||
| 95 | BEGIN | ||
| 96 | /* If not, make a special case and go do it */ | ||
| 97 | /* Use the 24 entry in the array to set up a dummy entry */ | ||
| 98 | /* This one isn't used for anything else */ | ||
| 99 | /* Indicate this is special by passing along a deleted entry - the subroutine will catch it and handle correctly */ | ||
| 100 | ext_table[j][23].sys_id = uc(0); /* AC000 */ | ||
| 101 | ext_table[j][23].start_cyl = part_table[j][extended_index].start_cyl; | ||
| 102 | ext_table[j][23].start_head = uc(0); /* AC000 */ | ||
| 103 | ext_table[j][23].start_sector = uc(1); /* AC000 */ | ||
| 104 | |||
| 105 | /* Write out our modified first location - only pointer info will be sent to the disk*/ | ||
| 106 | write_ext_boot_to_disk(c(23),j); /* AC000 */ | ||
| 107 | END | ||
| 108 | END | ||
| 109 | END | ||
| 110 | END | ||
| 111 | END | ||
| 112 | cur_disk = temp_disk; | ||
| 113 | return; | ||
| 114 | END | ||
| 115 | |||
| 116 | /* */ | ||
| 117 | char write_master_boot_to_disk(disk) | ||
| 118 | |||
| 119 | unsigned char disk; | ||
| 120 | |||
| 121 | BEGIN | ||
| 122 | |||
| 123 | unsigned char i; | ||
| 124 | unsigned j; | ||
| 125 | unsigned x; | ||
| 126 | unsigned temp; | ||
| 127 | unsigned long long_temp; | ||
| 128 | unsigned index; | ||
| 129 | char location; | ||
| 130 | unsigned byte_temp; | ||
| 131 | |||
| 132 | /* Clean out the boot_record */ | ||
| 133 | for (j=u(0);j < u(BYTES_PER_SECTOR); j++) /* AC000 */ | ||
| 134 | BEGIN | ||
| 135 | boot_record[j] = uc(0); /* AC000 */ | ||
| 136 | END | ||
| 137 | |||
| 138 | /* Copy the master boot record to boot_record */ | ||
| 139 | for (j=u(0); j < u(BYTES_PER_SECTOR); j++) /* AC000 */ | ||
| 140 | BEGIN | ||
| 141 | boot_record[j] = master_boot_record[disk][j]; | ||
| 142 | END | ||
| 143 | |||
| 144 | /* Copy the partition tables over - only bother with the changed ones */ | ||
| 145 | for (i=uc(0); i < uc(4); i++) /* AC000 */ | ||
| 146 | BEGIN | ||
| 147 | index = ((unsigned)i)*16; | ||
| 148 | if (part_table[disk][i].changed) | ||
| 149 | BEGIN | ||
| 150 | /* Get boot ind */ | ||
| 151 | boot_record[0x1BE+(index)] = part_table[disk][i].boot_ind; | ||
| 152 | |||
| 153 | /* Start head */ | ||
| 154 | boot_record[0x1BF+(index)] = part_table[disk][i].start_head; | ||
| 155 | |||
| 156 | /* Start sector - scramble it to INT 13 format*/ | ||
| 157 | boot_record[0x1C0+(index)] = (part_table[disk][i].start_sector & 0x3F) | | ||
| 158 | ((unsigned char)((part_table[disk][i].start_cyl/256) << 6)); | ||
| 159 | |||
| 160 | /* Start cyl - scramble it to INT 13 format*/ | ||
| 161 | boot_record[0x1C1+(index)] = ((unsigned char)(part_table[disk][i].start_cyl%256)); | ||
| 162 | |||
| 163 | /* System id */ | ||
| 164 | boot_record[0x1C2+(index)]= part_table[disk][i].sys_id; | ||
| 165 | |||
| 166 | /* End head */ | ||
| 167 | boot_record[0x1C3+(index)] = part_table[disk][i].end_head; | ||
| 168 | |||
| 169 | /* End sector - scramble it to INT 13 format*/ | ||
| 170 | boot_record[0x1C4+(index)] = (part_table[disk][i].end_sector & 0x3F) | | ||
| 171 | ((unsigned char)((part_table[disk][i].end_cyl/256) << 6)); | ||
| 172 | |||
| 173 | /* End cyl - scramble it to INT 13 format*/ | ||
| 174 | boot_record[0x1C5+(index)] = ((unsigned char)(part_table[disk][i].end_cyl%256)); | ||
| 175 | |||
| 176 | /* Relative sectors */ | ||
| 177 | long_temp = part_table[disk][i].rel_sec; | ||
| 178 | boot_record[0x1C9+(index)] = uc((long_temp >> 24)); /* AC000 */ | ||
| 179 | boot_record[0x1C8+(index)] = uc(((long_temp & 0x00FF0000l) >> 16)); /* AC000 */ | ||
| 180 | boot_record[0x1C7+(index)] = uc(((long_temp & 0x0000FF00l) >> 8)); /* AC000 */ | ||
| 181 | boot_record[0x1C6+(index)] = uc((long_temp & 0x000000FFl)); /* AC000 */ | ||
| 182 | |||
| 183 | |||
| 184 | /* Number of sectors */ | ||
| 185 | long_temp = part_table[disk][i].num_sec; | ||
| 186 | boot_record[0x1CD+(index)] = uc(long_temp >> 24); /* AC000 */ | ||
| 187 | boot_record[0x1CC+(index)] = uc((long_temp & 0x00FF0000l) >> 16); /* AC000 */ | ||
| 188 | boot_record[0x1CB+(index)] = uc((long_temp & 0x0000FF00l) >> 8); /* AC000 */ | ||
| 189 | boot_record[0x1CA+(index)] = uc(long_temp & 0x000000FFl); /* AC000 */ | ||
| 190 | END | ||
| 191 | END | ||
| 192 | boot_record[510] = uc(0x55); /* AC000 */ | ||
| 193 | boot_record[511] = uc(0xAA); /* AC000 */ | ||
| 194 | |||
| 195 | return(write_boot_record(u(0),disk)); /* AC000 */ | ||
| 196 | END | ||
| 197 | |||
| 198 | /* */ | ||
| 199 | char write_ext_boot_to_disk(entry,disk) | ||
| 200 | |||
| 201 | char entry; | ||
| 202 | unsigned char disk; | ||
| 203 | BEGIN | ||
| 204 | |||
| 205 | char i; | ||
| 206 | unsigned j; | ||
| 207 | unsigned long long_temp; | ||
| 208 | unsigned index; | ||
| 209 | char location; | ||
| 210 | char next_drive; | ||
| 211 | char pointer; | ||
| 212 | char write; | ||
| 213 | |||
| 214 | /* Clean out the boot_record */ | ||
| 215 | for (j=u(0);j < u(BYTES_PER_SECTOR); j++) /* AC000 */ | ||
| 216 | BEGIN | ||
| 217 | boot_record[j] = uc(0); /* AC000 */ | ||
| 218 | END | ||
| 219 | |||
| 220 | /* First - setup the logical devices */ | ||
| 221 | /* See if it has been deleted - if so, leave entries as zero */ | ||
| 222 | /* Otherwise - go unscramble everything out of the arrays */ | ||
| 223 | |||
| 224 | if (ext_table[disk][sort[entry]].sys_id != uc(0)) /* AC000 */ | ||
| 225 | BEGIN | ||
| 226 | /* Get boot ind */ | ||
| 227 | boot_record[0x1BE] = ext_table[disk][sort[entry]].boot_ind; | ||
| 228 | |||
| 229 | /* Start head */ | ||
| 230 | boot_record[0x1BF] = ext_table[disk][sort[entry]].start_head; | ||
| 231 | |||
| 232 | /* Start sector - scramble it to INT 13 format*/ | ||
| 233 | boot_record[0x1C0] = (ext_table[disk][sort[entry]].start_sector & 0x3F) | | ||
| 234 | ((ext_table[disk][sort[entry]].start_cyl/256) << 6); | ||
| 235 | |||
| 236 | /* Start cyl - scramble it to INT 13 format*/ | ||
| 237 | boot_record[0x1C1] = ((unsigned char)(ext_table[disk][sort[entry]].start_cyl%256)); | ||
| 238 | |||
| 239 | /* System id */ | ||
| 240 | boot_record[0x1C2]= ext_table[disk][sort[entry]].sys_id; | ||
| 241 | |||
| 242 | /* End head */ | ||
| 243 | boot_record[0x1C3] = ext_table[disk][sort[entry]].end_head; | ||
| 244 | |||
| 245 | /* End sector - scramble it to INT 13 format*/ | ||
| 246 | boot_record[0x1C4] = (ext_table[disk][sort[entry]].end_sector & 0x3F) | | ||
| 247 | ((ext_table[disk][sort[entry]].end_cyl/256) << 6); | ||
| 248 | |||
| 249 | /* End cyl - scramble it to INT 13 format*/ | ||
| 250 | boot_record[0x1C5] = ((unsigned char)(ext_table[disk][sort[entry]].end_cyl%256)); | ||
| 251 | |||
| 252 | /* Relative sectors */ | ||
| 253 | long_temp = ext_table[disk][sort[entry]].rel_sec; | ||
| 254 | boot_record[0x1C9] = uc((long_temp >> 24)); /* AC000 */ | ||
| 255 | boot_record[0x1C8] = uc(((long_temp & 0x00FF0000l) >> 16)); /* AC000 */ | ||
| 256 | boot_record[0x1C7] = uc(((long_temp & 0x0000FF00l) >> 8)); /* AC000 */ | ||
| 257 | boot_record[0x1C6] = uc((long_temp & 0x000000FFl)); /* AC000 */ | ||
| 258 | |||
| 259 | /* Number of sectors */ | ||
| 260 | long_temp = ext_table[disk][sort[entry]].num_sec; | ||
| 261 | boot_record[0x1CD] = uc((long_temp >> 24)); /* AC000 */ | ||
| 262 | boot_record[0x1CC] = uc(((long_temp & 0x00FF0000l) >> 16)); /* AC000 */ | ||
| 263 | boot_record[0x1CB] = uc(((long_temp & 0x0000FF00l) >> 8)); /* AC000 */ | ||
| 264 | boot_record[0x1CA] = uc((long_temp & 0x000000FFl)); /* AC000 */ | ||
| 265 | END | ||
| 266 | |||
| 267 | /* set up pointer to next logical drive unless this is # 23 */ | ||
| 268 | if (entry != c(22)) /* AC000 */ | ||
| 269 | BEGIN | ||
| 270 | /* Find the drive to be pointed to */ | ||
| 271 | pointer = entry+1; | ||
| 272 | |||
| 273 | /* Handle the special case of a deleted or empty first entry in partition*/ | ||
| 274 | if (entry == c(23)) /* AC000 */ | ||
| 275 | BEGIN | ||
| 276 | pointer = c(0); /* AC000 */ | ||
| 277 | END | ||
| 278 | for (i = pointer; i <c(23); i++) /* AC000 */ | ||
| 279 | BEGIN | ||
| 280 | next_drive = ((char)(INVALID)); | ||
| 281 | |||
| 282 | /* Go look for the next valid drive */ | ||
| 283 | if (ext_table[disk][sort[i]].sys_id != uc(0)) /* AC000 */ | ||
| 284 | BEGIN | ||
| 285 | next_drive = sort[i]; | ||
| 286 | break; | ||
| 287 | END | ||
| 288 | END | ||
| 289 | if (next_drive != ((char)(INVALID))) | ||
| 290 | BEGIN | ||
| 291 | /* Get boot ind */ | ||
| 292 | boot_record[0x1CE] = uc(0); /* AC000 */ | ||
| 293 | |||
| 294 | /* Start head */ | ||
| 295 | boot_record[0x1CF] = uc(0); /* AC000 */ | ||
| 296 | |||
| 297 | /* Start sector - scramble it to INT 13 format*/ | ||
| 298 | boot_record[0x1D0] = uc(0x01) | ((ext_table[disk][next_drive].start_cyl/256) << 6); /* AC000 */ | ||
| 299 | |||
| 300 | |||
| 301 | /* System id */ | ||
| 302 | boot_record[0x1D2]= uc(EXTENDED); /* AC000 */ | ||
| 303 | |||
| 304 | /* End head */ | ||
| 305 | boot_record[0x1D3] = uc(max_head[disk] -1); /* AC004 */ | ||
| 306 | |||
| 307 | /* End sector - scramble it to INT 13 format*/ | ||
| 308 | boot_record[0x1D4] =(max_sector[disk] & 0x3F) | ((ext_table[disk][next_drive].end_cyl/256) << 6); | ||
| 309 | |||
| 310 | |||
| 311 | /* Start cyl - scramble it to INT 13 format*/ | ||
| 312 | boot_record[0x1D1] = ((unsigned char)(ext_table[disk][next_drive].start_cyl%256)); | ||
| 313 | |||
| 314 | /* End cyl - scramble it to INT 13 format*/ | ||
| 315 | boot_record[0x1D5] = ((unsigned char)(ext_table[disk][next_drive].end_cyl%256)); | ||
| 316 | |||
| 317 | /* Relative sectors - this is from the front of the extended volume */ | ||
| 318 | /* Find the extended partition */ | ||
| 319 | location = find_partition_location(uc(EXTENDED)); | ||
| 320 | long_temp = ((unsigned long)(ext_table[disk][next_drive].start_cyl - part_table[disk][location].start_cyl)) | ||
| 321 | * max_head[disk] * max_sector[disk]; | ||
| 322 | boot_record[0x1D9] = uc((long_temp >> 24)); /* AC000 */ | ||
| 323 | boot_record[0x1D8] = uc(((long_temp & 0x00FF0000l) >> 16)); /* AC000 */ | ||
| 324 | boot_record[0x1D7] = uc(((long_temp & 0x0000FF00l) >> 8)); /* AC000 */ | ||
| 325 | boot_record[0x1D6] = uc((long_temp & 0x000000FFl)); /* AC000 */ | ||
| 326 | |||
| 327 | /* Number of sectors in the next volume*/ | ||
| 328 | long_temp = ((unsigned long)(ext_table[disk][next_drive].end_cyl - ext_table[disk][next_drive].start_cyl+1)) | ||
| 329 | * max_head[disk] * max_sector[disk]; | ||
| 330 | boot_record[0x1DD] = uc((long_temp >> 24)); /* AC000 */ | ||
| 331 | boot_record[0x1DC] = uc(((long_temp & 0x00FF0000l) >> 16)); /* AC000 */ | ||
| 332 | boot_record[0x1DB] = uc(((long_temp & 0x0000FF00l) >> 8)); /* AC000 */ | ||
| 333 | boot_record[0x1DA] = uc((long_temp & 0x000000FFl)); /* AC000 */ | ||
| 334 | END | ||
| 335 | END | ||
| 336 | boot_record[510] = uc(0x55); /* AC000 */ | ||
| 337 | boot_record[511] = uc(0xAA); /* AC000 */ | ||
| 338 | |||
| 339 | /* Write the boot record out */ | ||
| 340 | if (entry != c(23)) /* AC000 */ | ||
| 341 | BEGIN | ||
| 342 | write = write_boot_record(ext_table[disk][sort[entry]].start_cyl,disk); | ||
| 343 | END | ||
| 344 | else | ||
| 345 | BEGIN | ||
| 346 | /* Write the special case of the first entry only having a pointer */ | ||
| 347 | write = write_boot_record(ext_table[disk][23].start_cyl,disk); | ||
| 348 | END | ||
| 349 | return(write); | ||
| 350 | END | ||
| 351 | |||
| 352 | |||
| 353 | |||
| 354 | |||