XML

kent logo

CO527 Anonymous Questions and Answers

This page lists the various questions and answers. To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

We have taken the liberty of making some minor typographical corrections to some of the questions as originally put. Although most of the questions here will have been submitted anonymously, this page also serves to answer some questions of general interest to those on the course.


Question 61:

Submission reference: IN844

Hi, My code successfully prints out the correct block summary information for the test and exact dsk files, but I obtain this output for the large.dsk file:

   Block Summary   : 21212 unused, 803 reserved, 1 used, 3584 invalid

I've placed a print statement on the second block of the bitmap and it reads:

   Block Summary   : 9216 unused, 0 reserved, 0 used, 3584 invalid"=

Which means that 3,584 of the "unused" are being read as "invalid". Are there some numbers at the end of block 2 that are causing this to occur?

Answer 61:

Presumably yes -- but consider whether the values you're reading represent blocks which are actually present on the file-system (i.e. not beyond the total number of blocks).

Keywords: coursework


Question 62:

Submission reference: IN848

Hi, could you please tell me the actual results for the large and the exact disks, as I just need to know what they are to see if i am correct, as it looks like I am from the test one, but knowing what my coding is like....

Answer 62:

The correct outputs for the 3 disk images (well, I'm pretty sure they're correct..) are at the bottom of the assessment description.

Keywords: coursework


Question 63:

Submission reference: IN849

Hi, I've managed to get my code working correctly (kind of anyway). I get this:

  Block Summary	: 238 unused, 18 reserved, 0 used, 0 invalid

I've also checked the other 2 files you gave us and my problem is the same there too. It seems to be that the 1 used block is being recorded as unused. Any ideas why? Thanks. This is my code:

  [snip code]

Answer 63:

The problem lies in the way that you're reading the bits out of the bitmap. Each disk block is represented using 2 bits in the block bitmap. So if we looked at the first byte of the block bitmap (8 bits worth) we'd see 0x55 (hex), giving the status for 4 disk blocks. In binary, and divided up for block status:

   bit7                 bit0

    0  1  0  1  0  1  0  1
          

So block 0 has status 01 (binary), meaning it's reserved, and so are blocks 1, 2 and 3. Using the BM stuff, and assuming the block bitmap data is in an array 'bitmap', the status for the first two blocks could be extracted with:

    int s0 = BM.read_ubits (bitmap, 0, 2);   /* bits 0 and 1 */
    int s1 = BM.read_ubits (bitmap, 2, 2);   /* bits 2 and 3 */

This isn't quite the same as what your code is doing..

Keywords: coursework

Referrers: Question 77 (2006)


Question 64:

Submission reference: IN850

Hi, I am just a bit confussed by this (from 'sfstypes.h'):

  typedef enum {
    SFSB_UNUSED = 0x00,
    SFSB_RESERVED = 0x01,
    SFSB_USED = 0x02,
    SFSB_DAMAGED = 0x03
  } sfs_bitmap_e;

Any help would be great thanks.

Answer 64:

This is an enumerated type. Java has these sorts of things too now. Essentially it's just defining constants for the 4 different bitmap status values; the values of those constants being 0, 1, 2 and 3. (or 00, 01, 10, 11 in binary).

It's similar to just defining integer constants for these things, except that in C, when you 'switch()' on an enumerated type, the gcc compiler checks that all cases are handled (and warns if some are not). Better coding practice basically, and logically more correct (not all integers are valid bitmap-block-status values), but not something I'm bothered about for the assessment.

Keywords: coursework

Referrers: Question 71 (2006)


Question 65:

Submission reference: IN853

For the 3 assesemnt. The invalid block is always set as 0?

Answer 65:

I don't quite understand the question.. But invalid entries in the bitmap have a value of 3 (or 11 in binary). Unused entries have a value of 0 (00 in binary).

Keywords: coursework


Question 66:

Submission reference: IN855

Hi I am just trying to figure out how to do the third assessment. Am I correct in thinking that the bitmap is not located within the superblock ?

Answer 66:

Yes, that would be correct. What the superblock does contain, however, is the disk block number (offset) where the block bitmap starts.

Keywords: coursework


Question 67:

Submission reference: IN856

Hi, I was wondering do we need to use BM.tohexbuf() to compare the result from reading the bits from the bitmap ?

Answer 67:

Nope; you should only need to use BM.read_ubits() -- to read the bits out of the bitmap. To compare, just use normal integer comparison!

Keywords: coursework


Question 68:

Submission reference: IN857

I'm having trouble understanding how there should be 24796 unused blocks for the 100MB file. The block bitmap is at location 1 and I can see that there are 7388 unused, 803 reserved, 1 used and 0 invalid. I understand that because the block can only contain details of 16384 disk blocks that I also have to look at the next bitmap block aswell. To get to the next bitmap block by doing: [code] (adding 1 to the bitmap location). The thing I can't understand is block 2 just has 8192 unused blocks - which would make my answer different to your sample output.

Answer 68:

Double-check your math. If a single block of bitmap-data can hold the status of 16384 blocks, then the sum of all the counters for that block of bitmap-data (7388 + 803 + 1 + 0) should equal this.

Keywords: coursework

Referrers: Question 69 (2006) , Question 80 (2006)


Question 69:

Submission reference: IN859

In reference to Question 68 (2006):

I do understand that if you add all the states up in the bitmap block, it should come to 16384, but in the 2nd bitmap block in the 100MB file, I can only see 8192 unused blocks. I'm pretty sure that I'm getting the location for the 2nd bitmap block wrong, but I'm stuck as to what else to do. Is the 2nd bitmap block next to the 1st bitmap block? - So if the 1st bitmap block is at position 1, the 2nd bitmap block will be at position 2?

Answer 69:

Yes, the second part of the block bitmap is in disk block 2. However, there are more than 8192 unused block entries in that block: look at the data in a hex editor if you're unconvinced!

Keywords: coursework

Referrers: Question 80 (2006)


Question 70:

Submission reference: IN863

Hi there, I was wondering, once we have a solution that gives the correct output for the test.dsk, is reasonable to assume that the correct output will be obtained for the other disk files? I say this because I am having problems in accessing the other disk files.

Answer 70:

Without any insight, that's probably not a safe assumption to make.. But you should be able to read and understand your code to the extent of knowing what it would do for the other disk images. There's a zip-file in the same directory as the images which you can download, or see the answer to Question 45 (2006).

Keywords: coursework


Question 71:

Submission reference: IN866

Hi, I have read the bitmap block, but I don't understand how you get the values for reserved, unused. etc. Could you point me to the right direction please. thanks.

Answer 71:

See Question 64 (2006).

Keywords: coursework


Question 72:

Submission reference: IN867

Hi Fred, Just wondering, in respects to the material you are teaching on this module, whether we 'have to find out more about each of the things in the lectures. For example, if I understand all the material in the lectures and can answer all the self-test Q's at the end of the lectures. In theory can I get 100% in the exam for your material. Or do I need to have an in depth knowledge of everything (from the further reading) ? Thanks.

Answer 72:

There's no simple answer to this one, really. In theory, yes, you could get 100% on the exam from understanding all the material, but in practice it's extremely rare. The key point here is understanding: just knowing the material is not enough - you have to have the knowledge in order to build an understanding. Exam answers which demonstrate an understanding of the underlying concepts of operating-systems and architecture will typically attract more marks than answers which simply regurgitate the lecture-slides. The self-test questions I've included in the slides test mainly knowledge, though a few do test understanding as well. Original thinking is also a good thing to demonstrate in an exam.

Keywords: coursework


Question 73:

Submission reference: IN870

Hi Fred, I'm having a problem where I can never seem to count the 1 used block. I've tested my solution on all 3 disk images and it counts the unused, reserved and invalid blocks fine and I get the same results as your sample outputs except that for each disk image it counts 0 used blocks. Here is my code if it helps:

 [snip code]

Thanks.

Answer 73:

I am not a debugger :-). Hint: the read_ubits(...,2) function can only read two bits, so it always returns something between 0 and 3.

Keywords: coursework


Question 74:

Submission reference: IN868

When you talk about virtual memory and real memory, is the virtual memory loaded-from/stored-to the hard disk and mapped between the hard disk and the real memory?

Answer 74:

Not exactly; virtual-memory is an abstract memory, not a mapping between the hard-disk and real-memory. A correct way of expressing what virtual-memory is could be: "a virtual-machine's (e.g. a program's) view of memory, where parts of the virtual memory may be: saved in the swap-file or swap-partition on the hard-disk; mapped to real-memory; non-existent; or invalid". The choices here are generally mutually exclusive.

In practice, some parts of virtual-memory which are mapped to real-memory may also be in the swap-file. This is more likely because that bit of the swap-file is not cleared when the data is loaded into real-memory (in paging, during the "page-in" operation). However, there is no simultaneity of use -- when the program reads/writes virtual addresses, the corresponding operations must happen on real addresses in real-memory; regardless of whether the data hangs around in the swap-file. The advantage is that we may save having to write real-memory back to the swap-file, provided it hadn't change since the last read out of the swap file. Cases where the virtual-memory is exclusively in the swap-file generate a "page-fault" (assuming a paging implementation), which triggers the "page-in" operation. We'll finish looking at this aspect in this coming week's lecture (week 19, lecture 6 notes).

As a final point, and for informational value only, some OSs do in fact use virtual-memory as a mapping between things on the disk and things in real-memory. But it applies largely to regular files on the file-system — not the data in the swap-file (which is essentially saved chunks of real-memory). The technique is known as memory-mapping and enables programs to map whole files into their address space (the API is specified by POSIX, "man mmap" on a UNIX system will give you the details). Linux (and I presume other operating-systems) use this technique in read-only mode to get program data from an executable file or shared library into the virtual-machine's address space. As a result, the executable code is on-demand loaded into real-memory.

Keywords: virtual-memory


Question 75:

Submission reference: IN874

Where are spin locks actually used? Is it (for example) when a thread tries to access a critical part of the system and can't (because of the mutex value) and has to "suspend()"? Or is it for the processor when it hasn't got any processes to run? Thanks.

Answer 75:

Be wary of terminology here. So you understand the answer, here are my assumptions/definitions:

Spin-locks would mostly be used inside operating-system code. They implement mutually exclusive locks (mutex) to control access to critical parts of operating-system data. However, they do not "suspend()" — rather, they keep the processor permanently busy until the lock becomes available, spinning. As such, it only makes sense to use these in multi-processor systems — if one processor ends up spinning trying to acquire a spin-lock, the only thing which can stop the spinning is another processor releasing the same spin-lock. If they are used on single-processor systems, they should only be used in places where it would not result in extended spinning.

When a processor hasn't got any processes to run, it drops into an "idle" state. Typically this involves executing some special hardware instruction that puts the processor into some power-saving mode, which stops things until an interrupt is received. Such interrupts will always be hardware ones; including hardware timers. If handling the interrupt causes some process to become runnable, the OS will context-switch back into it. If not, it goes back to sleep. An operating-system could choose to have no idle task and spin when it has nothing else to do, but you wouldn't use a spin-lock; rather some spinning mechanism that repeatedly checks for things woken up by interrupts or by regular polling — but such implementations would consume a lot of power and generate a lot of heat (processor constantly at 100% usage). In a normal desktop machine which isn't doing much, the OS will spend most of its time sleeping inside the idle task.

Keywords: spinlock


Question 76:

Submission reference: IN877

In my CO527 assessment 2 feedback form, you said, "bad case of mixed DOS/UNIX line-endings -- broken editor possibly". I use SciTE as my default editor, and having just completed assessment 3 i copied my code over from SciTE to notepad to find more of those line endings. Just to be certain the problem wasn't in the copy/pasting between the two, I extracted a fresh SmallFS.java from the assessment zip, and again, after copying/pasting into notepad the bad line endings appear.

what could be the reason for this? there has to be around 100 of them

Answer 76:

Just to be clear, you didn't lose any marks for this, it was an observation :-). But traditionally, DOS systems (and Windows which evolved from it) do text-file line-endings as a sequence of "carriage-return" ('CR', ASCII 0x0d) and "line-feed" ('LF', ASCII 0x0a). When dumped on a DOS terminal ("command prompt" these days), CR moves the cursor to the left-hand margin and LF scrolls the terminal up one line. The result is to put the cursor at the start of the next line.

UNIX systems do things differently: within a text file, line-endings are just "line-feed" ('LF', ASCII 0x0a). When this is dumped to a UNIX teletype terminal (tty), the terminal driver will translate the single 'LF' into a sequence of 'CR' and 'LF'. The advantage is that if we're not using a teletype terminal, the terminal driver can handle the 'LF' in a way that generates the appropriate newline sequence.

As far as editors go, most either do DOS line-endings or UNIX line-endings. Most Windows editors will do DOS line-endings; most UNIX editors will do UNIX line-endings. But the line-endings within a single text file should be consistent — having a mixture is a bad thing. Most sensible editors will detect what the file uses and adjust it to the local default. Some (like vim/gvim) support both. My 'SmallFS.java' file, and other assessment-supplied files, have UNIX line-endings. It sounds like your editor is leaving these as is, but generating DOS line-endings for stuff you add. Sign of a poorly implemented editor in my opinion — file a bug report :-).

Keywords: coursework


Question 77:

Submission reference: IN880

This is a resubmission... on the confirmation page it only showed half my question as submitted, I assume that it's because you don't want the page to print out the whole of a large question but just in case the last question appears to be cut short here it is again (hopefully :D)

Hi, I'm a bit confused about the results my solution is giving. I somehow get a feeling that my fundamental understanding behind what I'm trying to do is wrong :/. I've read the bitmap blocks like this..

  [snip code]

This produces results with higher amount of reserved(19) and used(14) blocks. If I increment the counter by two (i += 2) it produces the correct output for everything except the number of unused blocks, which is much lower (109). I suppose because all the blocks are not being read?

Answer 77:

The fact that you didn't see the whole question on the confirmation page is a slight bug in the script sat behind this all -- it doesn't escape the question for HTML special characters such as '<'. If you were to "view page source" on the page you'd see everything (and in a decent browser like firefox, it'll syntax highlight the broken HTML for you as well :-)).

As far as your code goes, it's nearly correct. Incrementing 'i' by 2 each time is certainly more correct than incrementing it by one, otherwise you'll be reading bit pairs (0,1), (1,2), (2,3), ..., etc. whereas the bitmap has bit pairs (0,1), (2,3), (4,5), ..., etc; see the answer to Question 63 (2006). As to why there's a shortage in the numbers reported is something you'll have to debug for yourself. But it's not hard: run-through your code by hand for a hypothetical 4-block disk, you should be able to see where it goes wrong.

As a final point, your code is reading the block bitmap data multiple times -- this is bad. In a real operating-system, we would want to do this once at most, because of the relative overheads of reading from a slow device like a disk.

Keywords: coursework


Question 78:

Submission reference: IN881

Hi, I know you have been over this numerous times on this questions page, but I'm a bit confused... The way I understand it is that bitmap offset = 1, so we are reading block 1 off the DiskScheduler? and using your line of code (shown below) it should print out 01, 01? But it is only printing 1, 1? Where am I going wrong? Or does it print the value of the binary? i.e. 01 would be 1. 10 would be 2 etc.?

  byte[] bitmap = dsched.readBlock(1);

  int s0 = BM.read_ubits (bitmap, 0, 2);        /* bits 0 and 1 */
  int s1 = BM.read_ubits (bitmap, 2, 2);        /* bits 2 and 3 */
  System.out.println(s0);
  System.out.println(s1);

Answer 78:

You're right in that the numbers printed are decimal. When Java converts an integer to a string, it does it in base-10 representation (decimal), not base-2 representation (binary). So if the "read_ubits()" method returns 11 (binary), you'd expect to see the value 3 (decimal equivalent) displayed on the screen. Incidentally, there doesn't appear to be a method in Java's string formatter for outputting in binary format (it'll do decimal, octal, hexadecimal and decimal floating-point, though..).

Keywords: coursework


Question 79:

Submission reference: IN883

How and where do I test my code using the exact.dsk and the large.dsk, my code works fine with the test.dsk, but just need to check it with the other two, but am not too sure where I get them from!

Answer 79:

See the part of the assessment description which talks about the files — it tells you where to get these images from! :-)

Keywords: coursework


Question 80:

Submission reference: IN885

My code seems to work fine with test.dsk and exact.dsk but if I try it with large.dsk I get an array index out of bounds error:

   java.lang.ArrayIndexOutOfBoundsException: 4096

I'd guess that the large disk perhaps has a different bitmap set up to the others? My loop condition is [snip code], and I'm reading the blocks as [snip code that only reads from block 1]. My best guess is that readBlock() should be changed? Although I'm pretty lost on this one...

Answer 80:

Each block is only 4096 bytes long, so when you try and read index 4096 (the 4097'th byte), it blows up with an array bounds exception. That particular byte is in the next block of the bitmap. See also Question 69 (2006), Question 68 (2006) and Question 56 (2006).

Keywords: coursework

Referrers: Question 81 (2006)

Valid CSS!

Valid XHTML 1.0!

Maintained by Fred Barnes, last modified Thu May 8 12:58:00 2014