Skip to content

Commit b13cf34

Browse files
Fixes bug in some places where \n used twice.
1 parent 1e31d60 commit b13cf34

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

disk.img

0 Bytes
Binary file not shown.

source/includes/filesystems/fat16.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ typedef enum {
101101
partition_fs_type_t detect_fat_type_enum(const int8* buf);
102102
int fat16_mount(int portno, uint32_t partition_lba, fat16_fs_t* fs) ;
103103
uint16_t fat16_read_fat_fs(fat16_fs_t* fs, uint16_t cluster);
104-
void fat16_list_root(fat16_fs_t* fs);
104+
int fat16_list_root(fat16_fs_t* fs);
105105
int fat16_find_path(fat16_fs_t* fs, const char* path, fat16_dir_entry_t* out);
106106
int fat16_match_name(fat16_dir_entry_t* e, const char* name);
107107
int fat16_find_in_dir(fat16_fs_t* fs, uint16_t current_cluster, const char* name, fat16_dir_entry_t* out);
108-
void fat16_list_dir_cluster(fat16_fs_t* fs, uint16_t start_cluster);
108+
int fat16_list_dir_cluster(fat16_fs_t* fs, uint16_t start_cluster);
109109
void fat16_format_name(const char* input, char out[11]);
110110
int fat16_find_file(fat16_fs_t* fs, const char* name, fat16_dir_entry_t* out);
111111

source/kernel/C/filesystems/fat16.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

source/kernel/C/filesystems/vfs.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,25 @@ int vfs_ls(const char* path)
167167
if (vfs_resolve_mount(norm, &res) != 0)
168168
return -1;
169169

170-
int listed_anything = 0;
171-
172-
for (int i = 0; i < mounted_partition_count; i++) {
170+
bool entries = false;
171+
172+
for (int i = 1; i < mounted_partition_count; i++) { // i = 1; to ignore the root mount
173173
mount_entry_t* m = &mounted_partitions[i];
174174

175175
if (vfs_is_direct_child_mount(norm, m)) {
176176
const char* name = vfs_basename(m->mount_point);
177177
printfnoln(yellow_color "%s " reset_color, name);
178+
entries = true;
178179
}
179180
}
180181

181182
if (res.mnt->type == FS_FAT16) {
182183
fat16_fs_t* fs = (fat16_fs_t*)res.mnt->fs;
183184

184185
if (*res.rel_path == '\0') {
185-
fat16_list_root(fs);
186+
if (fat16_list_root(fs) != 0)
187+
entries = true;
188+
186189
} else {
187190
fat16_dir_entry_t e;
188191
if (fat16_find_path(fs, res.rel_path, &e) != 0) {
@@ -195,10 +198,13 @@ int vfs_ls(const char* path)
195198
return -4;
196199
}
197200

198-
fat16_list_dir_cluster(fs, e.first_cluster);
201+
if (fat16_list_dir_cluster(fs, e.first_cluster) != 0)
202+
entries = true;
199203
}
200204
}
201205

206+
if(entries)
207+
print("\n");
202208
return 0;
203209
}
204210

0 commit comments

Comments
 (0)