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
Reading a File’s Information StructureUnder both Unix and Windows-NT, library routines again simplify access to afile’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>HANDLEfilehandle;DWORDsizeLo, 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
File Allocation Methods — ContiguousOf particular interest is the method that the basic file system uses to place thelogical file blocks onto the physical medium (for example, into the disk’s tracksand sectors).01234567File AFile Allocation TableFigure 12.7 Contiguous File AllocationFile BFile CFile EFile D8910111213141516171819202122232425262728293031323334File NameFile AFile BFile CFile DFile E2918302635823Start BlockLengthThe simplest policy (akin to memory partitioning in process management) isthe 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 growbeyond this limit (Figure 12.7).Thefile allocation tablestores, for each file, its starting block and length.Like simple memory allocation schemes, this method suffers from both internalfragmentation (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 reducefragmentation (“defragging” your disk).10
File Allocation Methods — ChainedThe 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’slength is extended (by appending to the file), a new block is allocated and linkedto the last block in the file (Figure 12.9).0
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.
Temple University Fox School of Business ‘17, Course Hero Intern
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.
University of Pennsylvania ‘17, Course Hero Intern
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.
Tulane University ‘16, Course Hero Intern
Ask Expert Tutors
You can ask
You can ask ( soon)
You can ask
(will expire )