开发者

File System in Linux [closed]

开发者 https://www.devze.com 2023-02-25 05:50 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I've got a lab work relating to Linux's File System. The thing is that I need to retrieve all directories and files in a floppy image.It is required using C language to get directories and filenames of an FAT12 formatted floppy image.

Below is what I've done by now:

  1. I had created a floppy.img using linux dd command and add some files into it;
  2. I had gathered some information about FAT12 file system and known how data arranged in a floppy disk;

Below is what I开发者_如何学Python completely have no idea about:

  1. I know little linux system call

Now I need your help for showing me the entry of solving this problem. Some hints or documents also do great help to me!


What you will need to do is to open your copied image in C. You will need to read this data in, understanding the FAT12 format, modify it, then write it back out.

Look at fopen, fread, fclose using "man". You will probably need to make an array of FAT structures, read in each FAT entry using fread, then modify your array with new entries and write it back out using fwrite. You will probably want to use fseek to jump around. I expect you want to write a new entry to the disk FAT table (sic) and also knowing where the free space is, write the actual file there.

1) fopen 2) fread FAT into arrays (using fseek as needed) 3) modify arrays with new entries 4) fwrite new files' data to the appropriate free area of the image 5) fwrite the updated array back to the FAT 6) fclose 7) test the image

You can test the image by something like this:

mkdir /mnt/test -p mount -o loop -t vfat test.img /mnt/test

If this fails, then you messed up somewhere. Use hexdump to examine your file. If it works, make sure to umount it before modifying the file again.


From what I understand you should read data from a disk image in a pure user-space program. In other words: you're not required to write any kernel code or driver.

This task is possible using only standard C API, no Linux-specific calls should be necessary.


I've written a complete implementation of this for a previous employer. Fortunately FAT is VERY well supported as binary formats and filesystems go.

The canonical reference for this is the Microsoft specification (FAT was conceived by Bill Gates in 1976), which covers FAT12, FAT16, and FAT32, which are all very similar.

As you are working in user space, the C stdio library will meet all your needs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号