0% found this document useful (0 votes)
53 views5 pages

Sequential File Allocation Code

The document discusses two file allocation techniques: 1) Sequential file allocation, which allocates files sequentially to available blocks starting from the given starting block. 2) Linked file allocation, which links available blocks and allocates files across non-sequential blocks, checking for available space. The code samples provided implement these two allocation techniques.

Uploaded by

Hehe Bro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views5 pages

Sequential File Allocation Code

The document discusses two file allocation techniques: 1) Sequential file allocation, which allocates files sequentially to available blocks starting from the given starting block. 2) Linked file allocation, which links available blocks and allocates files across non-sequential blocks, checking for available space. The code samples provided implement these two allocation techniques.

Uploaded by

Hehe Bro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: Shashank Satish Adsule

MIS: 112015004

File allocation
(1) Sequential file allocation

Code:

#include <bits/stdc++.h>

#define ll long long int

#define fr(a,b) for(int I=a;I<b;I++)

#define Vi vector<int>

using namespace std;

ll i,j;

int main()

Vi F(100,0);

static int SB,len;

char ch;

int I;

cout<<"file allocated are:"<<endl;

do

int c=0;

cout<<"enter the starting block & length of file: ";

cin>>SB>>len;
fr(SB,(SB+len)) {if(F[I]==0) c++;}

if(len==c)

for(I=SB;I<(SB+len);I++)

if(F[I]==0)

F[I]=1;

cout<<I<<" "<<F[I]<<endl;

if(I!=(SB+len-1)) cout<<" The file is allocated to disk\n";

else cout<<" The file is not allocated to disk\n";

cout<<"Do you want to enter more file(y/n): ";cin>>ch;

}while(ch=='y' || ch=='Y');

return 0;

Output:
(2) Linked file allocation

Code:

#include <bits/stdc++.h>

#define ll long long int

#define fr(a,b) for(int I=a;I<b;I++)

#define Vi vector<int>

/*array ip/op*/

#define inA(A,n); for(int J=0;J<n;J++) cin>>A[J];

#define outA(A,n); for(int J=0;J<n;J++) cout<<A[J]<<" ";

using namespace std;

ll i,j;

int main()

{
Vi F(100,0);

static int SB,len,n;

char ch;

cout<<"enter the blocks already allocated: ";cin>>n;

Vi a(n);cout<<"Enter blocks already allocated: ";inA(a,n);

fr(0,n) F[a[I]]=1;

do

cout<<"enter the starting block & length: ";cin>>SB>>len;

if(F[SB]==0)

for(i=SB;i<(SB+len);i++)

if(F[i]==0)

F[i]=1;

cout<<i<<" ---> "<<F[i]<<endl;

else

cout<<i<<" Block is already allocated\n";

len++;

}
else cout<<"The file is not allocated to disk\n";

cout<<"Do you want to enter more file(y/n): ";cin>>ch;

}while(ch=='y' || ch=='Y');

return 0;

Output:

You might also like