This article, which is a part of the series on Linux device drivers, takes the next step towards developing a file system module by exploring how to write a formatting application for your real pen drive.
Thanks, friends, for your confidence in Shweta, and not trying to help her figure out the issues with her code. She indeed figured out and fixed the following issues on her own: sfs_read() and sfs_write() need to check for the read and write file permissions before proceeding to read and write, respectively. sfs_write() should free any previously allocated blocks, as write is always over-write. Moreover, the earlier written sfs_remove() also now needs to free up the allocated blocks.
fprintf(stderr, "Error formatting %s: %s\n", argv[1], strerror(errno));
return 2; } if (ioctl(sfs_handle, BLKGETSIZE64, &size) == -1) {
fprintf(stderr, "Error getting size of %s: %s\n", argv[1], strerror(errno));
return 3; } sb.partition_size = size / SIMULA_FS_BLOCK_SIZE;
As per the above code, various additional header files would be needed, as follows: #include <errno.h> /* For errno */ #include <string.h> /* For strerror() */ #include <sys/ioctl.h> /* For ioctl() */ #include <linux/fs.h> /* For BLKGETSIZE64 */
With all the above changes compiled into format_sfs, Pugs plugged in his pen drive, the partition of which was auto-mounted. Then, he took a backup of its contents, and unmounted it, ready for a real SFS formatting of the partition.