It is not an error to format an already formatted disk, but of course any data previously written to the disk is lost. The format operation also sets the current working directory to be the root directory.
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 returning a copy of x in which bit positions corresponing to zero bits in mask are cleared (set to zero) and bit positions where mask has a one are unchanged.
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.
cd /tmp ln -s /tmp/bad bad cd bad rm badYou will get a message like "bad: Too many levels of symbolic links." or "bad: Number of symbolic links encountered during path name traversal exceeds MAXSYMLINKS." Your implementation of namei should check the depth of recursion of calls to namei and fail if it exceeds some arbitrary bound. Unix generally limits the number of levels of links to 128.
The only exceptions to this rule are readlink, mkdir, rmdir, create, and delete. Clearly readlink would be useless if it dereferenced a symlink argument. In fact, that is the only difference between read and readlink. However, it should still follow “internal” symlinks as in case of /a/b above.
As for mkdir, rmdir, create, and delete, you can think of the pathname argument as a pair of arguments, a pathname for a directory and a simple name. For example,
create("/a/b/c/d")looks for a directory named /a/b/c and inserts a new entry for d. As before, /a/b/c many be either a directory or a symlink designating a directory.