{"id":24030735,"url":"https://github.com/rvk007/recover-fat32-file-system","last_synced_at":"2025-05-07T20:41:15.385Z","repository":{"id":140055798,"uuid":"443957802","full_name":"rvk007/Recover-FAT32-File-System","owner":"rvk007","description":"A FAT32 file recovery tool.","archived":false,"fork":false,"pushed_at":"2022-01-04T06:20:03.000Z","size":29,"stargazers_count":7,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T14:04:00.996Z","etag":null,"topics":["c","fat32","file-recovery","filesystem","recover-files"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rvk007.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-03T06:05:25.000Z","updated_at":"2025-02-14T13:44:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"e12b7c76-a1a0-4aca-889f-423c01d44d54","html_url":"https://github.com/rvk007/Recover-FAT32-File-System","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvk007%2FRecover-FAT32-File-System","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvk007%2FRecover-FAT32-File-System/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvk007%2FRecover-FAT32-File-System/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvk007%2FRecover-FAT32-File-System/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rvk007","download_url":"https://codeload.github.com/rvk007/Recover-FAT32-File-System/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252954128,"owners_count":21830893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","fat32","file-recovery","filesystem","recover-files"],"created_at":"2025-01-08T17:56:43.928Z","updated_at":"2025-05-07T20:41:15.366Z","avatar_url":"https://github.com/rvk007.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Recover FAT32 File System\n\nThis repository is a FAT32 file recovery tool.\n\n_If you have accidentally deleted a file, you can use this tool recover to it, as long as you remember the name of the file!_\n\n## Getting Started\n\n1. Clone the repository\n\n   ```\n   $ git clone https://github.com/rvk007/Recover-FAT32-File-System.git\n   ```\n\n2. Install openssl package\n   ```\n   $ sudo apt install openssl\n   ```\n\nTo compile, run the below command\n\n```\n$ make\n```\n\nTo use this tool you need the binary file of the FAT32 disk. To know how to create a FAT32 disk click [here](https://github.com/rvk007/Recover-FAT32-File-System#create-a-fat32-disk).\n\n## Usage\n\nTo see the meanings of all the flags of the tool just run `./file` command:\n\n```\n$ ./file\nUsage: ./nyufile disk \u003coptions\u003e\n  -i                     Print the file system information.\n  -l                     List the root directory.\n  -r filename [-s sha1]  Recover a contiguous file.\n  -R filename -s sha1    Recover a possibly non-contiguous file.\n```\n\n### Print the file system information\n\n```\n$ ./file \u003cdisk\u003e -i\n```\n\nThe output would look something like this:\n\n```\n$ ./file fat32.disk -i\nNumber of FATs = 2\nNumber of bytes per sector = 512\nNumber of sectors per cluster = 1\nNumber of reserved sectors = 32\n```\n\n### List the root directory\n\n```\n$ ./file \u003cdisk\u003e -l\n```\n\nShows the contents of the root directory along with its size and starting cluster in the file system. It also lists the total number of entries in the root directory.\n\n```\n$ ./file fat32.disk -l\nDIR/ (size = 0, starting cluster = 3)\nEMPTY (size = 0, starting cluster = 0)\nHELLO.TXT (size = 13, starting cluster = 20)\nLARGE.TXT (size = 4129, starting cluster = 7)\nMEDIUM.TXT (size = 1549, starting cluster = 16)\nMELLO.TXT (size = 15, starting cluster = 21)\nMARGE.TXT (size = 0, starting cluster = 0)\nTotal number of entries = 7\n```\n\n### Recover a file\n\nTo recover a file, it must be marked as deleted in the file system. The steps to delete a file are be accessed [here](https://github.com/rvk007/Recover-FAT32-File-System#delete-a-file).\nYou can check if the file is deleted or not using the above command.\n\n```\n$ ./file fat32.disk -l\nDIR/ (size = 0, starting cluster = 3)\nEMPTY (size = 0, starting cluster = 0)\nHELLO.TXT (size = 13, starting cluster = 20)\nLARGE.TXT (size = 4129, starting cluster = 7)\nMELLO.TXT (size = 15, starting cluster = 21)\nMARGE.TXT (size = 0, starting cluster = 0)\nTotal number of entries = 6\n```\n\nAs seen from the above two results `MEDIUM.TXT` file is deleted.\nTo recover a deleted file use the below command. Once the file is recovered it will return `\u003cfilename\u003e: successfully recovered` and you can find the file again in the root directory by running the second command.\n\n```\n$ ./file \u003cdisk\u003e -r \u003cfilename\u003e\n```\n\nFor example, the below command can be used to recover the `MEDIUM.TXT` file:\n\n```\n$ ./file fat32.disk -r MEDIUM.TXT\nMEDIUM.TXT: successfully recovered\n```\n\nTo verify if the file is recovered or not, use the `-l` flag again:\n\n```\n$ ./file fat32.disk -l\nDIR/ (size = 0, starting cluster = 3)\nEMPTY (size = 0, starting cluster = 0)\nHELLO.TXT (size = 13, starting cluster = 20)\nLARGE.TXT (size = 4129, starting cluster = 7)\nMEDIUM.TXT (size = 1549, starting cluster = 16)\nMELLO.TXT (size = 15, starting cluster = 21)\nMARGE.TXT (size = 0, starting cluster = 0)\nTotal number of entries = 7\n```\n\nAs seen from the above output, the number of entries is increased to 7 again and `MEDIUM.TXT` is showing in the root directory.\n\nIf the given filename does not exist the tool will print `\u003cfilename\u003e: file not found`.\n\n```\n$ ./file fat32.disk -r FILE.TXT\nFILE.TXT: file not found\n```\n\n### Handle ambiguous file recovery requests\n\nWhen a file is deleted, its first character is changed to `0xE5`. Now, if there are multiple files with whose filenames differ only by the first character then it becomes tricky for the tool to recover the file. These filenames can be like HELLO.TXT and MELLO.TXT or LARGE.TXT and MARGE.TXT.\nIn that case, the tool will return `\u003cfilename\u003e: multiple candidates found` and even if the file exists it won't be able to recover it.\n\n```\n$ ./file fat32.disk -r LARGE.TXT\nLARGE.TXT: multiple candidates found\n```\n\n### Recover a file with SHA-1 hash\n\nTo avoid this situation we can provide SHA-1 hash of the file. SHA-1 hash is 160-bit fingerprint of a file. It is unique for each file and depends on the file content. To get the SHA-1 hash of your file run the below command:\n\n```\n$ sha1sum \u003cfilename\u003e\n```\n\nFor example, to generate the SHA-1 hash of LARGE.TXT file, run the below command:\n\n```\n$ sha1sum /mnt/disk/LARGE.TXT\n92a18d61b3591abd6db3b01ce75240ac045a15cf  /mnt/disk/LARGE.TXT\n```\n\nWith SHA-1 hash the tool can exactly identify the given file even if there are multiple files with similar names. To recover a file with SHA-1 hash, use the below command:\n\n```\n$ ./file \u003cdisk\u003e -r \u003cfilename\u003e -s \u003cSHA-1\u003e\n```\n\nFor example, to recover LARGE.TXT\n\n```\n$ ./file fat32.disk -r LARGE.TXT -s 92a18d61b3591abd6db3b01ce75240ac045a15cf\nLARGE.TXT: successfully recovered with SHA-1\n```\n\n## Create a FAT32 disk\n\nTo create a FAT32 disk, follow these steps:\n\n### Create an empty file of a certain size\n\nFirstly, create an empty file which contains zeros. Let's create a 256KB file named fat32.disk:\n\n```\n$ dd if=/dev/zero of=fat32.disk bs=256k count=1\n```\n\n### Format the disk with FAT32\n\nUse `mkfs.fat` command to convert the above file to FAT32 file system.\n\n```\n$ mkfs.fat -F 32 -f 2 -S 512 -s 1 -R 32 fat32.disk\n```\n\nMeanings of each of these options:\n\n```\n-F: type of FAT (FAT12, FAT16, or FAT32)\n-f: number of FATs\n-S: number of bytes per sector\n-s: number of sectors per cluster\n-R: number of reserved sectors\n```\n\n### Verify the file system information\n\nUse `fsck.fat` command to check the FAT file system details:\n\n```\n$ fsck.fat -v fat32.disk\nfsck.fat 3.0.20 (12 Jun 2013)\nfsck.fat 3.0.20 (12 Jun 2013)\nChecking we can access the last sector of the filesystem\nWarning: Filesystem is FAT32 according to fat_length and fat32_length fields,\n  but has only 472 clusters, less than the required minimum of 65525.\n  This may lead to problems on some systems.\nBoot sector contents:\nSystem ID \"mkfs.fat\"\nMedia byte 0xf8 (hard disk)\n       512 bytes per logical sector\n       512 bytes per cluster\n        32 reserved sectors\nFirst FAT starts at byte 16384 (sector 32)\n         2 FATs, 32 bit entries\n      2048 bytes per FAT (= 4 sectors)\nRoot directory start at cluster 2 (arbitrary size)\nData area starts at byte 20480 (sector 40)\n       472 data clusters (241664 bytes)\n32 sectors/track, 64 heads\n         0 hidden sectors\n       512 sectors total\nChecking for unused clusters.\nChecking free cluster summary.\nfat32.disk: 0 files, 1/472 clusters\n```\n\n### Mount the file system\n\nThe file system can be mounted to any empty folder. So, let's create a folder `/mnt/disk` and mount `fat32.disk` to that point.\n\n```\n$ sudo mkdir /mnt/disk\n$ sudo mount -o umask=0 fat32.disk /mnt/disk\n```\n\n### Creating files and directory\n\nOnce the file system is mounted, new files and folders can be created, edited and deleted.\nAs not all the OS support long filenames, only 8.3 filename format is considered as anaming convention.\n\nThe filename can be of atmost eight characters which can be only uppercase letters, number and the following special characters `` ! # $ % \u0026 ' ( ) - @ ^ _ ` { } ~ `` . The filename is followed by an optional '.' and at most three characters.\n\n```\n$ echo \"Hello, world.\" \u003e /mnt/disk/HELLO.TXT\n$ mkdir /mnt/disk/DIR\n$ touch /mnt/disk/EMPTY\n```\n\nAfter writing to the disk, make sure to run the below command to _flush the file system cache_:\n\n```\n$ sync\n```\n\n### Unmount the file system\n\nOnce all the changes are made to the disk, you can unmount the disk:\n\n```\n$ sudo umount /mnt/disk\n```\n\n### Examine the file system\n\nTo examine the file system use `xxd` command. To examine the root directory you can give a range using `-s`(starting offset) and `-l`(length) flags.\n\n```\n$ xxd -s 20480 -l 96 fat32.disk\n00005000: 4845 4c4c 4f20 2020 5458 5420 0000 0000  HELLO   TXT ....\n00005010: 6e53 6e53 0000 0000 6e53 0300 0e00 0000  nSnS....nS......\n00005020: 4449 5220 2020 2020 2020 2010 0000 0000  DIR        .....\n00005030: 6e53 6e53 0000 0000 6e53 0400 0000 0000  nSnS....nS......\n00005040: 454d 5054 5920 2020 2020 2020 0000 0000  EMPTY       ....\n00005050: 6e53 6e53 0000 0000 6e53 0000 0000 0000  nSnS....nS......\n```\n\n### Delete a file\n\n```\n$ sudo mount -o umask=0 fat32.disk /mnt/disk\n$ ls /mnt/disk\nDIR  EMPTY  HELLO.TXT  LARGE.TXT  MARGE.TXT  MEDIUM.TXT  MELLO.TXT\n$ rm /mnt/disk2/MEDIUM.TXT\n$ ls /mnt/disk2\nDIR  EMPTY  HELLO.TXT  LARGE.TXT  MARGE.TXT  MELLO.TXT\n$ sudo umount /mnt/disk\n```\n\n## Contact/ Getting Help\n\nIf you need any help or want to report a bug, raise an issue in the repo.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvk007%2Frecover-fat32-file-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frvk007%2Frecover-fat32-file-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvk007%2Frecover-fat32-file-system/lists"}