22mkfs.ffs binary implementation for Linux.
33*/
44
5+ #include <dirent.h>
56#include <fuzzy/fs/ffs.h>
67#include <stdio.h>
78#include <string.h>
8- #include <dirent.h>
99#include <sys/stat.h>
1010
11- #define FILEENTRY_LOCATION (file_id ) (FS_FFS_FIRST_BLOCK_SIZE+FS_FFS_FILEENTRY_SIZE*(file_id))
11+ #define FILEENTRY_LOCATION (file_id ) \
12+ (FS_FFS_FIRST_BLOCK_SIZE + FS_FFS_FILEENTRY_SIZE * (file_id))
1213
1314void write_first_block (FILE * out ) {
1415 union FFSMetaData block ;
15- strncpy (block .content .signature , FS_FFS_SIGNATURE , sizeof (block .content .signature ));
16+ strncpy (block .content .signature , FS_FFS_SIGNATURE ,
17+ sizeof (block .content .signature ));
1618
1719 rewind (out );
1820 fwrite (block .bytes , 1 , sizeof (block .bytes ), out );
1921}
2022
2123void write_file (int file_id , FILE * outfile , int * outfile_nextdata_block ,
22- const char * filename , FILE * srcfile ,
23- int is_executable ) {
24+ const char * filename , FILE * srcfile , int is_executable ) {
2425 fseek (srcfile , 0L , SEEK_END );
2526 int file_size = ftell (srcfile );
2627 rewind (srcfile );
@@ -42,9 +43,9 @@ void write_file(int file_id, FILE *outfile, int *outfile_nextdata_block,
4243 char buffer [512 ];
4344 size_t bytes_read ;
4445 printf ("Writting context at %d\n" , ((* outfile_nextdata_block )));
45- fseek (outfile , (* outfile_nextdata_block )* FS_BLOCK_SIZE , SEEK_SET );
46- (* outfile_nextdata_block ) += ( file_size + FS_BLOCK_SIZE - 1 )/ FS_BLOCK_SIZE ;
47-
46+ fseek (outfile , (* outfile_nextdata_block ) * FS_BLOCK_SIZE , SEEK_SET );
47+ (* outfile_nextdata_block ) +=
48+ ( file_size + FS_BLOCK_SIZE - 1 ) / FS_BLOCK_SIZE ;
4849
4950 while ((bytes_read = fread (buffer , 1 , sizeof (buffer ), srcfile )) > 0 ) {
5051 fwrite (buffer , 1 , bytes_read , outfile );
@@ -60,7 +61,6 @@ void write_nofile(int file_id, FILE *out) {
6061 fwrite (entry .bytes , 1 , sizeof (entry .bytes ), out );
6162}
6263
63-
6464int create_partition (char * src_dir , char * out_filepath ) {
6565 printf ("dir:%s partition: %s\n" , src_dir , out_filepath );
6666 FILE * src = opendir (src_dir );
@@ -85,19 +85,22 @@ int create_partition(char *src_dir, char *out_filepath) {
8585 strncat (buffer_filename , "/" , sizeof (buffer_filename ));
8686 strncat (buffer_filename , de -> d_name , sizeof (buffer_filename ));
8787 if (file_id >= FS_FFS_FILEENTRY_COUNT ) {
88- fprintf ("reached max supported files, ignoring file '%s'" , buffer_filename );
88+ fprintf ("reached max supported files, ignoring file '%s'" ,
89+ buffer_filename );
8990 continue ;
9091 }
9192 struct stat file_stat ;
9293 stat (buffer_filename , & file_stat );
9394 if (!S_ISREG (file_stat .st_mode )) {
94- fprintf ("skipping non-regular file '%s': %d" , buffer_filename , file_stat .st_mode );
95+ fprintf ("skipping non-regular file '%s': %d" , buffer_filename ,
96+ file_stat .st_mode );
9597 continue ;
9698 }
9799 int is_executable = file_stat .st_mode & S_IXUSR ;
98100
99101 FILE * file_src = fopen (buffer_filename , "rb" );
100- write_file (file_id ++ , out , & outfile_nextdata_block , de -> d_name , file_src , is_executable );
102+ write_file (file_id ++ , out , & outfile_nextdata_block , de -> d_name ,
103+ file_src , is_executable );
101104 fclose (file_src );
102105 }
103106 while (file_id < FS_FFS_FILEENTRY_COUNT ) {
0 commit comments