Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simple Linux File System Implementation using C. a) write the first inode structure (for the root) to the file (sfs.bin), b) jump to the beginning

Simple Linux File System Implementation using C.

a) write the first inode structure (for the root) to the file (sfs.bin),

b) jump to the beginning of the data block to write the two directory entries (dot and dotdot) the first data block,

c) close the file (sfs.bin)

d) open the file (sfs.bin) and read the directory entries dot and dotdot, print their names.

The code I wrote is below. May you please help me to fix mistakes for these parts?

#include #include #include

const int REG_FILE = 0; const int DIRECTORY = 1;

struct super_block{ int inode_bitmap; int data_bitmap[10]; }; struct inode_st{ int type; int size; int data_block_indices[10]; };

struct dir_ent{ char name [28]; unsigned int inode_no; }; void initialize_sb(struct super_block sb){ sb.inode_bitmap = 0; for(int i = 0; i < 10; i++) sb.data_bitmap[i] = 0; } int main() { struct super_block sb; initialize_sb(sb);

struct inode_st root; root.type = DIRECTORY; root.size = sizeof(struct dir_ent)*2; for(int i = 0; i < 10; i++) root.data_block_indices[i] = 0;

sb.inode_bitmap = 1; sb.data_bitmap[0] = 1;

printf("size of dir. entry: %lu ",sizeof(struct dir_ent));

struct dir_ent dot; strcpy(dot.name, "."); dot.inode_no = 0; struct dir_ent dotdot; strcpy(dotdot.name, ".."); dotdot.inode_no = 0;

FILE *sfs = fopen("sfs.bin", "w+"); fwrite(&sb,sizeof(sb),1, sfs); fwrite(&root, sizeof(root.size), 1, sfs); //first inode structure (for the root) to the file fseek(sfs, 0, SEEK_SET); //jump to the beginning of the file fwrite(&dot, sizeof(dot), 1, sfs); //write dot to the first data block fwrite(&dotdot, sizeof(dotdot), 1, sfs); //write dotdot to the first data block fclose(sfs); //close the file fopen("sfs.bin","r+"); //open the existing file again char buff[500]; while(!feof(sfs)) //while it's not the end of the file fgets(buff, 500, sfs); //read the directory entries dot and dotdot puts(buff); //print their names

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

/connect.html $2,180 Exercise 9-5 Computing payroll taxes LO P2, P3

Answered: 1 week ago