It is not an error to format an already formatted disk, but of course any data previously written to the disk is lost.
You will also need to use the operator &, which performs "bitwise and". Each bit of the result is the logical "and" of corresponding bits of the operands. Thus x & mask has the effect of "clearing" (setting to zero) result bits in positions where mask has zero bits, and returning the bits of x in positions where mask has one bits.
You will find examples of use of these operators in the code for pack and unpackShort.
See also Q6.
byte b = (byte) 128;
int n = (b<<8) + 1;
System.out.println(n);
See also Q5.
((FastDisk) disk).read(blockNumber, buffer)or declare disk to be of type FastDisk and use a cast when initializing it.
See also Q10 and Q11.
od -Ad -td2 DISKThis says to dump the file in two-byte decimal integers (-td2) and show offsets in the file in decimal (-Ad). You might also try -td4 (4-byte decimal integers), or -tc (1-byte characters).
One word of warning however: This will only work on X86 machines (e.g. the tux lab), not SPARC machines (the nova lab) because the "little-endian" byte order specified for this project matches the native byte-order of the X86 but not the SPARC.
// Print out the result of the function call
if (result != 0) {
if (result == -1) {
pl("*** System call failed");
} else {
pl("*** Bad result " + result + " from system call");
}
}
with these lines
// Print out the result of the function call
switch (result) {
case 0:
break;
case -1:
pl("*** System call failed");
break;
default:
pl("*** Result " + result + " from system call");
}