Typical information contained within each information structure includes the

Typical information contained within each information

This preview shows page 8 - 12 out of 23 pages.

Typical information contained within each information structure includes: the file’s type (plain file, directory, etc), the file’s size, in bytes and/or blocks, any limits set on the file’s size, the primary owner of the file, information about other potential users of this file, access constraints on the owner and other users, dates and times of creation, last access and last modification, dates and times of last backup and recovery, and asynchronous event triggers when the file changes. As a directory consequence, multiple file names (even from different directories) may refer to the same file. These are termed file-system links. 8
Image of page 8
Reading a File’s Information Structure Under both Unix and Windows-NT, library routines again simplify access to a file’s information structure: Under Unix: #include <sys/stat.h> struct stat statbuf; stat("filename", &statbuf); printf("inode = %d\n", (int)statbuf.st_ino); printf("owner’s userid = %d\n", (int)statbuf.st_uid); printf("size in bytes = %d\n", (int)statbuf.st_size); printf("size in blocks = %d\n", (int)statbuf.st_blocks); Under Windows-NT: #include <windows.h> HANDLE filehandle; DWORD sizeLo, sizeHi; BY_HANDLE_FILE_INFORMATION info; filehandle = CreateFile("filename", GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); GetFileInformationByHandle(filehandle, &info); sizeLo = GetFileSize(filehandle, &sizeHi); printf("number of links = %d\n", (int)info.nNumberOfLinks); printf("size in bytes ( low 32bits) = %u\n", sizeLo); printf("size in bytes (high 32bits) = %u\n", sizeHi); CloseFile(filehandle); 9
Image of page 9
File Allocation Methods — Contiguous Of particular interest is the method that the basic file system uses to place the logical file blocks onto the physical medium (for example, into the disk’s tracks and sectors). 0 1 2 3 4 5 6 7 File A File Allocation Table Figure 12.7 Contiguous File Allocation File B File C File E File D 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 File Name File A File B File C File D File E 2 9 18 30 26 3 5 8 2 3 Start Block Length The simplest policy (akin to memory partitioning in process management) is the use of a fixed or contiguous allocation. This requires that a file’s maximum (ever) size be determined when the file is created, and that the file cannot grow beyond this limit (Figure 12.7). The file allocation table stores, for each file, its starting block and length. Like simple memory allocation schemes, this method suffers from both internal fragmentation (if the initial allocation is too large) and external fragmentation (as files are deleted over time). Again, as with memory allocation, a compaction scheme is required to reduce fragmentation (“defragging” your disk). 10
Image of page 10
File Allocation Methods — Chained The opposite extreme to contiguous allocation is chained allocation. Here, the blocks allocated to a file form a linked list (or chain), and as a file’s length is extended (by appending to the file), a new block is allocated and linked to the last block in the file (Figure 12.9). 0
Image of page 11
Image of page 12

You've reached the end of your free preview.

Want to read all 23 pages?

  • One '20

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes