Skip to content

Commit 99b2412

Browse files
authored
fix Track0 sector size in formatting Hard Drive. (#29)
1 parent 71348dd commit 99b2412

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

os9/os9format.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ int os9format(int argc, char **argv)
274274
i = 0;
275275
}
276276
}
277+
278+
sectorsTrack0 = sectorsPerTrack;
277279
}
278280

279281
/* walk command line for pathnames */

unittest/librbftest.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void test_os9_format()
1616
// test format of a non-existent disk image
1717
unsigned int totalSectors, totalBytes;
1818
int clusterSize = 0;
19+
1920
ec = _os9_format("test.dsk", 0, 35, 18, 18, 1, 256, &clusterSize, "Test Disk", 8, 8,
2021
1, 1, 0, 0, &totalSectors, &totalBytes);
2122
ASSERT_EQUALS(0, ec);
@@ -27,6 +28,65 @@ void test_os9_format()
2728
8, 8, 1, 1, 0, 0, &totalSectors, &totalBytes);
2829
ASSERT_EQUALS(0, ec);
2930

31+
32+
// Test format of a hard drive with 65000 sectors.
33+
// Getting the parameters for _os9_format:
34+
// $ gdb os9/os9
35+
// (gdb) b _os9_format
36+
// (gdb) run format test.dsk -l65000
37+
// Breakpoint 1, _os9_format (pathname=0x7fffffffe0ad "test.dsk", os968k=0,
38+
// tracks=125, sectorsPerTrack=4, sectorsTrack0=4, heads=130, sectorSize=256,
39+
// clusterSize=0x7fffffffdae8, diskName=0x5555555761df "CoCo Disk",
40+
// sectorAllocationSize=8, tpi=0, density=0, formatEntire=0, isDragon=0, isHDD=1,
41+
// totalSectors=0x7fffffffdaec, totalBytes=0x7fffffffdaf0) at ../../../librbf/librbfformat.c:25
42+
// (gdb) cont
43+
// Continuing.
44+
// Format Summary
45+
// --------------
46+
// Geometry Data:
47+
// Cylinders: 125
48+
// Heads: 130
49+
// Sectors/track: 4
50+
// Sector size: 256
51+
//
52+
// Logical Data:
53+
// Total sectors: 65000
54+
// Size in bytes: 16640000
55+
// Cluster size: 1
56+
57+
ec = _os9_format("test.dsk", /*68k=*/0,
58+
/*tracks=*/125, /*sPT=*/4, /*sT0=*/4, /*heads=*/130, /*sSize=*/256, &clusterSize,
59+
"HD-Test",
60+
/*sas=*/8, /*tpi=*/0, /*density=*/0, /*fE=*/1, /*isD=*/0, /*isHDD=*/1,
61+
&totalSectors, &totalBytes);
62+
ASSERT_EQUALS(0, ec);
63+
ASSERT_EQUALS(65000, totalSectors);
64+
ASSERT_EQUALS(65000 * 256, totalBytes);
65+
66+
#ifdef unix
67+
// In order to demonstrate the bug described in
68+
// https://github.com/nitros9project/toolshed/issues/28
69+
// we have to execute the `os9 format` command.
70+
// The bug is not in _os9_format, but in preparing its parameters.
71+
ec = system("rm -f test.dsk; ../os9/os9 format test.dsk -l65000");
72+
ASSERT_EQUALS(0, ec);
73+
// When `os9 format` was broken, it would succeed, but later
74+
// operations would fail, like `os9 makdir`:
75+
ec = _os9_makdir("test.dsk,/CMDS");
76+
ASSERT_EQUALS(0, ec);
77+
/*
78+
// ... But if `os9format` were in the tinytest linkage, this could work,
79+
// instead of using system():
80+
char* argv[] = {
81+
"os9", "format", "test.dsk", "-l65000", NULL
82+
};
83+
ec = os9format(4, argv);
84+
ASSERT_EQUALS(0, ec);
85+
ec = _os9_makdir("test.dsk,/CMDS");
86+
ASSERT_EQUALS(0, ec);
87+
*/
88+
#endif
89+
3090
// TODO: test format with oddball parameters to make sure it can survive
3191
}
3292

0 commit comments

Comments
 (0)