Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views4 pages

Week 12

The document outlines a C programming assignment focused on simulating three file allocation strategies: Sequential, Linked, and Indexed. Each strategy is described in terms of its organization and access methods, followed by sample C code implementations for each. The document also includes input and output examples for each file allocation method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Week 12

The document outlines a C programming assignment focused on simulating three file allocation strategies: Sequential, Linked, and Indexed. Each strategy is described in terms of its organization and access methods, followed by sample C code implementations for each. The document also includes input and output examples for each file allocation method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

WEEK 12

12.1 OBJECTIVE
Write a C program to simulate the following file allocation strategies.
a) Sequential b) Linked c) ) Indexed

12.2 DESCRIPTION
A file is a collection of data, usually stored on disk. As a logical entity, a file enables to divide data into
meaningful groups. As a physical entity, a file should be considered in terms of its organization. The term "file
organization" refers to the way in which data is stored in a file and, consequently, the method(s) by which it can
be accessed.

12.2.1 SEQUENTIAL FILE ALLOCATION


In this file organization, the records of the file are stored one after another both physically and logically. That is,
record with sequence number 16 is located just after the 15th record. A record of a sequential file can only be
accessed by reading all the previous records.

12.2.2 LINKED FILE ALLOCATION


With linked allocation, each file is a linked list of disk blocks; the disk blocks may be scattered anywhere on the
disk. The directory contains a pointer to the first and last blocks of the file. Each block contains a pointer to the
next block.

12.2.3 INDEXED FILE ALLOCATION


Indexed file allocation strategy brings all the pointers together into one location: an index block. Each file has its
own index block, which is an array of disk-block addresses. The ith entry in the index block points to the ith block
of the file. The directory contains the address of the index block. To find and read the i th block, the pointer in the
ith index-block entry is used.

12.3 PROGRAM

12.3.1 SEQUENTIAL FILE ALLOCATION


#include<stdio.h>
#include<conio.h>

struct fileTable
{
char name[20];
int sb, nob;
}ft[30];

void main()
{
int i, j, n;
char s[20];
clrscr();
printf("Enter no of files :");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("\nEnter file name %d :",i+1);
scanf("%s",ft[i].name);
printf("Enter starting block of file %d :",i+1);
scanf("%d",&ft[i].sb);
printf("Enter no of blocks in file %d :",i+1);
scanf("%d",&ft[i].nob);
}
printf("\nEnter the file name to be searched -- ");
scanf("%s",s);
for(i=0;i<n;i++)
if(strcmp(s, ft[i].name)==0)
9
break;
if(i==n)
printf("\nFile Not Found");
else
{
printf("\nFILE NAME START BLOCK NO OF BLOCKS BLOCKS OCCUPIED\n");
printf("\n%s\t\t%d\t\t%d\t",ft[i].name,ft[i].sb,ft[i].nob);
for(j=0;j<ft[i].nob;j++)
printf("%d, ",ft[i].sb+j);
}
getch();
}

INPUT:
Enter no of files :3

Enter file name 1 :A


Enter starting block of file 1 :85
Enter no of blocks in file 1 :6

Enter file name 2 :B


Enter starting block of file 2 :102
Enter no of blocks in file 2 :4

Enter file name 3 :C


Enter starting block of file 3 :60
Enter no of blocks in file 3 :4
Enter the file name to be searched -- B

OUTPUT:
FILE NAME START BLOCK NO OF BLOCKS BLOCKS OCCUPIED
B 102 4 102, 103, 104, 105

12.3.2 LINKED FILE ALLOCATION


#include<stdio.h>
#include<conio.h>
Type your text
struct fileTable
{
char name[20];
int nob;
struct block *sb;
}ft[30];

struct block
{
int bno;
struct block *next;
};

void main()
{
int i, j, n;
char s[20];
struct block *temp;
clrscr();
printf("Enter no of files :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter file name %d :",i+1);
scanf("%s",ft[i].name);
10
printf("Enter no of blocks in file %d :",i+1);
scanf("%d",&ft[i].nob);
ft[i].sb=(struct block*)malloc(sizeof(struct block));
temp = ft[i].sb;
printf("Enter the blocks of the file :");
scanf("%d",&temp->bno);
temp->next=NULL;

for(j=1;j<ft[i].nob;j++)
{
temp->next = (struct block*)malloc(sizeof(struct block));
temp = temp->next;
scanf("%d",&temp->bno);
}
temp->next = NULL;
}
printf("\nEnter the file name to be searched -- ");
scanf("%s",s);
for(i=0;i<n;i++)
if(strcmp(s, ft[i].name)==0)
break;
if(i==n)
printf("\nFile Not Found");
else
{
printf("\nFILE NAME NO OF BLOCKS BLOCKS OCCUPIED");
printf("\n %s\t\t%d\t",ft[i].name,ft[i].nob);
temp=ft[i].sb;
for(j=0;j<ft[i].nob;j++)
{
printf("%d  ",temp->bno);
temp = temp->next;
}
}
getch();
}

INPUT:
Enter no of files 2

Enter file 1 : A
Enter no of blocks in file 1 4
Enter the blocks of the file 1 : 12 23 9 4

Enter file 2 : G
Enter no of blocks in file 2 5
Enter the blocks of the file 2 88 77 66 55 44

Enter the file to be searched : G

OUTPUT:
FILE NAME NO OF BLOCKS BLOCKS OCCUPIED
G 5 88  77 66 55 44

12.3.3 INDEXED FILE ALLOCATION


#include<stdio.h>
#include<conio.h>

struct fileTable
{
char name[20];
int nob, blocks[30];
11
}ft[30];

void main()
{
int i, j, n;
char s[20];
clrscr();
printf("Enter no of files :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter file name %d :",i+1);
scanf("%s",ft[i].name);
printf("Enter no of blocks in file %d :",i+1);
scanf("%d",&ft[i].nob);
printf("Enter the blocks of the file :");
for(j=0;j<ft[i].nob;j++)
scanf("%d",&ft[i].blocks[j]);
}

printf("\nEnter the file name to be searched -- ");


scanf("%s",s);
for(i=0;i<n;i++)
if(strcmp(s, ft[i].name)==0)
break;
if(i==n)
printf("\nFile Not Found");
else
{
printf("\nFILE NAME NO OF BLOCKS BLOCKS OCCUPIED");
printf("\n %s\t\t%d\t",ft[i].name,ft[i].nob);
for(j=0;j<ft[i].nob;j++)
printf("%d, ",ft[i].blocks[j]);
}
getch();
}

INPUT:
Enter no of files 2

Enter file 1 : A
Enter no of blocks in file 1 4
Enter the blocks of the file 1 : 12 23 9 4

Enter file 2 : G
Enter no of blocks in file 2 5
Enter the blocks of the file 2 88 77 66 55 44
Enter the file to be searched : G

OUTPUT:
FILE NAME NO OF BLOCKS BLOCKS OCCUPIED
G 5 88, 77, 66, 55, 44

12

You might also like