Report blocking ,management of files in secondry memory , static vs dynamic allocation
375 views
48 slides
Sep 18, 2019
Slide 1 of 48
1
2
3
4
5
6
7
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
About This Presentation
Report blocking ,management of files in Secondry memory , static vs dynamic allocation
Size: 1.91 MB
Language: en
Added: Sep 18, 2019
Slides: 48 pages
Slide Content
Topics 1-Record blocking 2-File Management of Secondary Memory 3-Reallocation and Dynamic allocations By: Noor Mustafa Soomro
1 Record Blocking
Record: It is the collection of related data values and items. It describes the entities and attributes. e.g : Employee records, Files , Folders etc. Add a footer 3
Add a footer 4 Block: A block sometimes called a physical record. It is the sequence of bytes or bits , usually containing whole numbers of records, having max length, a block size. Data thus structures are said to be blocked. The Process of putting data into blocks is called blocking. While deblocking is the process of extracting data from blocks. Blocked Data is normally stored in a data buffer and read written a whole at a time.
Add a footer 7 Three methods of blocking: Fixed blocking Variable-length spanned blocking Variable length un-spanned blocking
Add a footer 8 Fixed Blocking Fixed length records are used and an integral number of records are stored in a block There may be unused space at the end of each block (internal fragmentation).
Add a footer 9 Variable Length Spanned Blocking Variable length records are used and are packed into blocks with no unused space Two records may span across two blocks with the continuation indicated by a pointer to the successor block Wastes space only at the end of the file
Add a footer 10 Variable Length Un-spanned Blocking Variable length records are used, but spanning is not employed. There is wasted space inmost blocks because of the inability to use the remainder of a block if the next record is larger than the remaining unused space
2 File Management of Secondary Memory
A file is sequence of logical records i.e. a sequence of bits and bytes. What is File? Add a footer 12 File Attributes: A file has various attributes like name, type, location, size, protection, time and data of creation, user information etc.
File naming=File name + File extension Example : Student.doc In this example the Student is the file name and doc is the file extension File Naming Add a footer 13
Some Common File extensions Add a footer 14
Add a footer 15 File Attributes A file has a name and data. Other than this, it contains information like date and time of file creation, file’s current size etc. with a file . These are known as attributes of a file.
Add a footer 16 Operations that can be performed on files are: CREATE: A blank file is created. DELETE: The purpose of this system call is to delete this file OPEN: Open a file either for reading or writing. CLOSE: When a file is no longer accessed. =============================================================== READ: When a file is only to be read. Write: To write some data on file. Append: To add some data to the end of the file. Rename: To rename the file. Note: A file can be made read-only, hidden, system-file, and so-on by setting its read only flag to 1, its hidden flag to 1, its system flag to 1 and so on.
Add a footer 17 File Access Methods Sequential Access: in this access method, data records are retrieved in the same order in which they have been stored on the disk. E.g data stored on magnetic disk. Random Access : In case of random access the record is searched from the disk based on its direct address information. The technique used is Hashing. In hashing every record is associated with a key number to preprocess the address calculation. Hash function is used to obtain absolute address of a particular record.
Add a footer 18 Sequential Access Random Access
Add a footer 19 Index Access method: Indexed file approach is helpful with multiple attribute fields like in database files. In these files, every field is associated with an index key. While querying data the index key is kept in the memory and related records are fetched from the disk.
Add a footer 20 Index Access Method
Add a footer 21 Directory Structure A directory contains information about files. A directory is used as a means to group the files owned by a user. Hierarchical Directory Systems
Add a footer 22 Access paths Two possible methods for access path are: It is a listing of the directories and files from the root directory to the intended file. For example, the path ‘c:/windows/programs/spss.exe’ means that the root directory contains a subdirectory ‘windows’, which further contains a subdirectory ‘programs’, that contains an executable “spss.exe”. 1. Absolute path name:
Add a footer 23 2. Relative path name: This uses the concept of current directory (also known as working directory). A user can specify a particular directory as his current working directory and all the path names instead of being specified from the root directory are specified relative to the working directory. For example, if the current working directory is ‘\user\ curr ’, then the file whose absolute path is ‘\user\ curr \student’ can be referred simply as ‘student’.
Add a footer 24 Directory Operations CREATE : A directory is created. DELETE : A directory is deleted. OPENDIR : Directories can be opened for reading it. CLOSEDIR : When a directory has been read, it should be closed to free up internal table space in main memory. RENAME : Directories can be renamed just like files.
Add a footer 25 File Protection File systems often contain information that is highly valuable to their users. Protecting this information against unauthorized usage is therefore, a major concern of all the file systems.
Add a footer 26 1. File protection through Access Control Following are the few file operations that can be controlled: Read Write Append Delete List R ename Edit Copy Read a file Write the file Append a file Delete a file List the name and attributes of a file Rename a file Changing the contents of a file Make a copy of a file.
Add a footer 27 Access control list This list may contain the user name and the types of access allowed for each user. The operating system checks this access control list (associated with a file) whenever a user requests an access to a particular file. But one limitation of Access control list is their length, so we create groups.
Add a footer 28 Classify the users of a file into three types: Owner - The user who created the file. Group - A set of users who are sharing the file and need similar access. Universe - All remaining users in the system constitute universe
Add a footer 29 2. File protection through password Files can be protected by a password . The owner of a file can control its access by assigning a password. Thus, only those users who know the password, can access a particular file.
Add a footer 30 File System Implementation There are 3 ways of File system implementation. They are the following: Contiguous allocation Linked list allocation Linked list allocation using an index
Add a footer 31 1. Contiguous allocation The simplest allocation scheme is to store each file as a contiguous block of data on the disk. Thus, on a disk having blocks size 1k, a 25k file would be allocated 25 consecutive blocks.
Add a footer 32 2. Linked list allocation The second method for storing files is to keep each one as a li n k ed l i st of dis k block s , as sh o wn i n F igu r e bel o w . The first word of each block is used as a pointer to the next one . The rest of the block is used for storing data.
Add a footer 33 In this technique instead of having a pointer, an index is maintained. 3. Linked list allocation using an index
Add a footer 34 Free Space Management Free space management is used to reuse the disk space created after deleting the files. We have 4 techniques for Free space management, Which are the following: Bit map Linked list Grouping Counting
Add a footer 35 1. Bit map The free space list is implemented as a bit map. Every bit represents a block on the disk. The bit for a block is 1 if it is free and it is if the block is allocated.
Add a footer 36 2. Linked list This approach maintains a linked list of all the free disk blocks. The first free block in the list can be pointed out by a head pointer, which is kept in a special location on the disk.
Add a footer 37 3. Grouping Another approach is to store the addresses of n free blocks in the first free block. The last block contains the addresses of other n free blocks and so on. 4. Counting In this technique, instead of keeping a list of addresses of n free blocks, it is more convenient to keep the address of the first free blocks and the number n of free contiguous blocks that follow the first block.
3 Static allocation and Dynamic allocations
Memory allocation The placement of blocks of information in a memory system is called memory allocation. To allocate memory it is necessary to keep in information of available memory in the system If sufficient memory is not available, swapping of blocks is done. Add a footer 39
Types of memory allocation There are two (2) types of memory allocation Static memory allocation Dynamic memory allocation Add a footer 40
Static memory allocation In static memory allocation, size of the memory is required for the calculation that must be required for the calculation that must be define before loading and executing the program Add a footer 41
Example: int[] arr =new int[6];
Dynamic Memory Allocation In static memory allocation, size of the memory is required for the calculation that must be required for the calculation that must be define before loading and executing the program Add a footer 43
Dynamic Memory Allocation Dynamic Memory Management/Allocation Dynamic Memory Allocation is sometimes called as Manual Memory Management In DMA the memory is allocated at run time. It is allocated whenever program, application, data, variable demands with required amount of bytes. We are going present, manual memory allocation using ‘C’ programming language because it will very easy to show allocation and de-allocation. The programmer has direct access to memory at run time to control over memory using DMA
Dynamic Memory Allocations Functions It is mostly explicit call to heap management functions. ‘C’ programming language has supports malloc(), calloc () and realloc () functions to allocate memory for our program or applications. These functions are called dynamic memory allocation functions. The two key dynamic memory functions are malloc() and free(). It returns a pointer to the allocated memory. If the allocation fails, it returns NULL. The prototype for the standard library function is like this: void *malloc( size_t size);
Dynamic Memory Allocations Functions The free() function takes the pointer returned by malloc() and de-allocates the memory. No indication of success or failure is returned. The function prototype is like this: void free(void *pointer); There are two other variants of the malloc() function: calloc () and realloc (). The allocated memory is also initialized to zeros. Here is the prototype: void * calloc ( size_t nelements , size_t elementSize );
Dynamic Memory Allocations Functions The realloc () function resizes a memory allocation previously made by malloc(). It takes as parameters a pointer to the memory area and the new size that is required. If the size is reduced, data may be lost. If the size is increased and the function is unable to extend the existing allocation, it will automatically allocate a new memory area and copy data across. In any case, it returns a pointer to the allocated memory. Here is the prototype: void * realloc (void *pointer, size_t size);