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

Prints 1

The document discusses mounting and unmounting file systems using system calls in C++. It demonstrates mounting one directory to another to share files between them, and later unmounting the target. It also covers implementing a bitmap to represent free block allocation in a file system.

Uploaded by

ks_kshk
Copyright
© Attribution Non-Commercial (BY-NC)
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)
35 views4 pages

Prints 1

The document discusses mounting and unmounting file systems using system calls in C++. It demonstrates mounting one directory to another to share files between them, and later unmounting the target. It also covers implementing a bitmap to represent free block allocation in a file system.

Uploaded by

ks_kshk
Copyright
© Attribution Non-Commercial (BY-NC)
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

/*File system mounting using system calls

Name: Abhinand K R
USN: 1PI07IS002
Class: 5th sem ISE 'A'
*/

#include <iostream>
#include <cstring>
#include <sys/mount.h>
#include <errno.h>

using namespace std;

inline void errorExit( const char * error )


{
perror( error );
exit( 1 );
}

// Prototypes found in sys/mount.h

// int mount( const char * source , const char * target ,


// const char * filesystemtype , unsigned long mountflags ,
// const void * data );

// int unmount( const char * target );

int main( int argc , char ** argv )


{
if( argc != 3 )
{
cerr << "Usage: " << argv[0] << " [-U | source] target" << endl;
exit( 1 );
}

if( strcmp( argv[1] , "-U" ) )


{
if( mount( argv[1] , argv[2] , NULL , MS_BIND , NULL ) == -1 )
errorExit( "mount() error\n" );
}

else
{
if( umount( argv[2] ) == -1 )
errorExit( "umount() error\n" );
}

return 0;
}
/*
[abhinand@localhost src]$ su
Password:
[root@localhost src]# g++ mounting.cpp
root@localhost src]# mkdir h1 h2
[root@localhost src]# touch h1/f1.txt
[root@localhost src]# ./a.out h1 h2
[root@localhost src]# ls h1
f1.txt
[root@localhost src]# ls h2
f1.txt
[root@localhost src]# ./a.out -U h2
[root@localhost src]# ls h2

[root@localhost src]#
*/
/*9) Free space management using bitmap.
Name: Abhinand K R
USN: 1PI07IS002
Class: 5th sem ISE 'A'
*/

#include<iostream>
#define BITMAP_SIZE 20

using namespace std;

void sort( int * , int );

int main()
{
cout << "Bitmap size is " << BITMAP_SIZE << endl;
int i , data[BITMAP_SIZE] , bmp[BITMAP_SIZE] , a[BITMAP_SIZE] , blocks , max , j;

cout << "Enter the no of free blocks: ";


cin >> blocks;

cout << "Enter the free block's number (less than " << BITMAP_SIZE << ") : ";
for(i = 0 ; i < blocks ; i++)
cin >> data[i];

sort( data , blocks );

cout << "Sorted list: ";


for(i = 0 ; i < blocks ; i++)
cout << data[i] << ' ';
cout << endl;

max = data[0];
for(i = 0 ; i < blocks ; i++)
{
if(data[i] > max)
max = data[i];
}

for( i = 0 ; i < BITMAP_SIZE ; i++ )


bmp[i] = 0;

for( i = 0 , j = 0 ; i < max + 1 && j < blocks ; i++)


{
if( data[j] == i )
{
bmp[i] = 1;
j++;
}
else
bmp[i] = 0;
}
cout << endl << "Bit map vector is: ";

for(i = 0 ; i < BITMAP_SIZE ; i++ )


cout << bmp[i];
cout << endl;

return 0;
}

void sort( int * data , int size )


{
void swap( int * , int * );
for( int i = 1 ; i < size ; i++ )
for( int j = 0 ; j < size - 1 ; j++ )
if( data[j] > data[j+1] )
swap( &data[j] , &data[j+1] );
}

void swap( int * a , int * b )


{
int temp = *a;
*a = *b;
*b = temp;
}

/*OUTPUT
Bitmap size is 20
Enter the no of free blocks: 12
Enter the free block's number (less than 20) : 12 19 10 3 13 14 16 15 4 5 9 1
Sorted list: 1 3 4 5 9 10 12 13 14 15 16 19

Bit map vector is: 01011100011011111001


*/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy