@@ -96,8 +96,9 @@ int fat16_name_eq(const uint8_t fat_name[11], const char* input)
9696
9797// END =========
9898
99- void fat16_list_root (fat16_fs_t * fs ) {
99+ int fat16_list_root (fat16_fs_t * fs ) {
100100 uint8_t buf [512 ];
101+ int entries_exist = 0 ;
101102
102103 for (uint32_t s = 0 ; s < fs -> root_dir_sectors ; s ++ ) {
103104 ahci_read_sector (fs -> portno , fs -> root_dir_start + s , buf , 1 );
@@ -106,10 +107,7 @@ void fat16_list_root(fat16_fs_t* fs) {
106107
107108 for (int i = 0 ; i < 16 ; i ++ ) {
108109 /* End of directory */
109- if (e [i ].name [0 ] == 0x00 ) {
110- print ("\n" );
111- return ;
112- }
110+ if (e [i ].name [0 ] == 0x00 ) return ;
113111
114112 /* Deleted entry */
115113 if ((uint8_t )e [i ].name [0 ] == 0xE5 )
@@ -152,8 +150,12 @@ void fat16_list_root(fat16_fs_t* fs) {
152150 } else {
153151 printfnoln (blue_color "%s " reset_color , name );
154152 }
153+
154+ entries_exist ++ ;
155155 }
156156 }
157+
158+ return entries_exist ;
157159}
158160
159161
@@ -281,9 +283,10 @@ int fat16_find_in_dir(
281283}
282284
283285
284- void fat16_list_dir_cluster (fat16_fs_t * fs , uint16_t start_cluster ) {
286+ int fat16_list_dir_cluster (fat16_fs_t * fs , uint16_t start_cluster ) {
285287 uint8_t buf [512 ];
286288 uint16_t cluster = start_cluster ;
289+ int entries_exist = 0 ;
287290
288291 while (cluster >= 2 && cluster < 0xFFF8 ) {
289292 uint32_t lba =
@@ -297,10 +300,7 @@ void fat16_list_dir_cluster(fat16_fs_t* fs, uint16_t start_cluster) {
297300
298301 for (int i = 0 ; i < 16 ; i ++ ) {
299302 /* End of directory */
300- if (e [i ].name [0 ] == 0x00 ) {
301- print ("\n" );
302- return ;
303- }
303+ if (e [i ].name [0 ] == 0x00 ) return ;
304304
305305 /* Deleted entry */
306306 if ((uint8_t )e [i ].name [0 ] == 0xE5 )
@@ -343,13 +343,15 @@ void fat16_list_dir_cluster(fat16_fs_t* fs, uint16_t start_cluster) {
343343 } else {
344344 printfnoln (blue_color "%s " reset_color , name );
345345 }
346+
347+ entries_exist ++ ;
346348 }
347349 }
348350
349351 cluster = fat16_read_fat_fs (fs , cluster );
350352 }
351353
352- print ( "\n" ) ;
354+ return entries_exist ;
353355}
354356
355357
@@ -725,7 +727,7 @@ int fat16_create(fat16_fs_t* fs, uint16_t parent_cluster, const char* name, uint
725727 // Check if file already exists
726728 fat16_dir_entry_t tmp ;
727729 if (fat16_find_in_dir (fs , parent_cluster , name , & tmp ) == 0 ) {
728- printf ("create: '%s' already exists\n " , name );
730+ printf ("create: '%s' already exists" , name );
729731 return FAT_ERR_NOT_FOUND ;
730732 }
731733
@@ -797,12 +799,12 @@ int fat16_unlink(fat16_fs_t* fs, uint16_t parent_cluster, const char* name) {
797799 fat16_format_name (name , fatname );
798800
799801 if (fat16_find_in_dir (fs , parent_cluster , name , & e ) != 0 ) {
800- printf ("unlink: '%s' not found\n " , name );
802+ printf ("unlink: '%s' not found" , name );
801803 return FAT_ERR_NOT_FOUND ;
802804 }
803805
804806 if (e .attr & 0x10 ) {
805- printf ("unlink: '%s' is a directory\n " , name );
807+ printf ("unlink: '%s' is a directory" , name );
806808 return FAT_ERR_NOT_FOUND ;
807809 }
808810
@@ -1008,7 +1010,7 @@ int fat16_create_path(fat16_fs_t* fs,
10081010
10091011 /* BLOCK "." and ".." */
10101012 if (fat16_is_reserved_name (part )) {
1011- printf ("create: refusing to create reserved name '%s'\n " , part );
1013+ printf ("create: refusing to create reserved name \ '%s\' " , part );
10121014 return FAT_ERR_NOT_FOUND ;
10131015 }
10141016
@@ -1176,7 +1178,7 @@ int fat16_ls(fat16_fs_t* fs, const char* path) {
11761178 char name [13 ];
11771179 fat16_unformat_name (& e [i ], name );
11781180
1179- printf ("%s%s\n " ,
1181+ printf ("%s%s" ,
11801182 name ,
11811183 (e [i ].attr & 0x10 ) ? "/" : "" );
11821184 }
@@ -1223,7 +1225,7 @@ int fat16_cd(fat16_fs_t* fs, const char* path, uint16_t* pwd_cluster) {
12231225 uint16_t current = * pwd_cluster ;
12241226
12251227 if (fat16_resolve_path (fs , path , current , & new_cluster ) != 0 ) {
1226- printf ("cd: no such directory: %s\n " , path );
1228+ printf ("cd: no such directory: %s" , path );
12271229 return FAT_ERR_NOT_FOUND ;
12281230 }
12291231
0 commit comments