Skip to content

Commit 077d874

Browse files
VFS supports passing errors to STDERR
1 parent e85aad7 commit 077d874

File tree

1 file changed

+16
-22
lines changed
  • source/kernel/C/filesystems

1 file changed

+16
-22
lines changed

source/kernel/C/filesystems/vfs.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static int path_matches_mount(const char* path, const char* mount) {
3535

3636
static int vfs_resolve_mount(const char* path, vfs_mount_res_t* out) {
3737
if (!path || !out) {
38-
printf("resolve_mount: invalid arguments");
38+
eprintf("resolve_mount: invalid arguments");
3939
return -1;
4040
}
4141

@@ -56,9 +56,9 @@ static int vfs_resolve_mount(const char* path, vfs_mount_res_t* out) {
5656

5757
if (!best) {
5858
if(path)
59-
printf("resolve_mount: no mount matches path: %s", path);
59+
eprintf("resolve_mount: no mount matches path: %s", path);
6060
else
61-
printf("resolve_mount: no mount matches the given path.");
61+
eprintf("resolve_mount: no mount matches the given path.");
6262
return -2;
6363
}
6464

@@ -113,39 +113,37 @@ static void vfs_normalize_path(const char* in, char* out) {
113113

114114
if (oi == 0) out[oi++] = '/';
115115
out[oi] = '\0';
116-
117-
debug_printf("[vfs] normalized path: %s\n", out);
118116
}
119117

120118
int vfs_read(vfs_file_t* file, uint8_t* buf, uint32_t size) {
121119
if (!file || !file->mnt || !buf){
122-
printf("read: invalid parameters passed");
120+
eprintf("read: invalid parameters passed");
123121
return -1;
124122
}
125123

126124
if (file->mnt->type == FS_FAT16)
127125
return fat16_read(&file->f, buf, size);
128126

129-
printf("read: unknown filesystem");
127+
eprintf("read: unknown filesystem");
130128
return -2;
131129
}
132130

133131
int vfs_write(vfs_file_t* file, const uint8_t* buf, uint32_t size) {
134132
if (!file || !file->mnt || !buf){
135-
printf("write: invalid parameters passed");
133+
eprintf("write: invalid parameters passed");
136134
return -1;
137135
}
138136

139137
if (file->mnt->type == FS_FAT16)
140138
return fat16_write(&file->f, buf, size);
141139

142-
printf("write: unknown filesystem");
140+
eprintf("write: unknown filesystem");
143141
return -2;
144142
}
145143

146144
void vfs_close(vfs_file_t* file) {
147145
if (!file || !file->mnt) {
148-
printf("close: invalid file pointer");
146+
eprintf("close: invalid file pointer");
149147
return;
150148
}
151149

@@ -156,7 +154,7 @@ void vfs_close(vfs_file_t* file) {
156154
int vfs_ls(const char* path)
157155
{
158156
if (!path) {
159-
printf("ls: invalid path");
157+
eprintf("ls: invalid path");
160158
return -1;
161159
}
162160

@@ -210,7 +208,7 @@ int vfs_ls(const char* path)
210208

211209
int vfs_open(const char* path, vfs_file_t* out) {
212210
if (!path || !out) {
213-
printf("open: invalid parameters passed");
211+
eprintf("open: invalid parameters passed");
214212
return -1;
215213
}
216214

@@ -229,13 +227,13 @@ int vfs_open(const char* path, vfs_file_t* out) {
229227
return 0;
230228
}
231229

232-
printf("open: unknown filesystem");
230+
eprintf("open: unknown filesystem");
233231
return -3;
234232
}
235233

236234
int vfs_mkdir(const char* path) {
237235
if (!path){
238-
printf("mkdir: path is null or undefined");
236+
eprintf("mkdir: path is null or undefined");
239237
return -1;
240238
}
241239

@@ -257,8 +255,6 @@ int vfs_mkdir(const char* path) {
257255

258256
int vfs_rm_recursive(const char* path)
259257
{
260-
debug_printf("[VFS] rm -r '%s'\n", path);
261-
262258
char norm[256];
263259
vfs_normalize_path(path, norm);
264260

@@ -315,7 +311,7 @@ int vfs_rm_recursive(const char* path)
315311
int vfs_cd(const char* path)
316312
{
317313
if (!path || !*path) {
318-
printf("cd: path is null or undefined");
314+
eprintf("cd: path is null or undefined");
319315
return -1;
320316
}
321317

@@ -327,7 +323,7 @@ int vfs_cd(const char* path)
327323
return -1;
328324

329325
if (res.mnt->type != FS_FAT16) {
330-
printf("cd: unknown filesystem");
326+
eprintf("cd: unknown filesystem");
331327
return -2;
332328
}
333329

@@ -350,15 +346,13 @@ int vfs_cd(const char* path)
350346
vfs_cwd_cluster = new_cluster;
351347
strncpy(vfs_cwd, norm, sizeof(vfs_cwd));
352348
vfs_cwd[sizeof(vfs_cwd) - 1] = 0;
353-
354-
debug_printf("[vfs] cd -> %s (cluster=%u)\n", vfs_cwd, vfs_cwd_cluster);
355349
return 0;
356350
}
357351

358352

359353
int vfs_create_path(const char* path, uint8_t attr) {
360354
if (!path || !*path) {
361-
printf("create_path: path is null or undefined");
355+
eprintf("create_path: path is null or undefined");
362356
return -1;
363357
}
364358

@@ -379,7 +373,7 @@ int vfs_create_path(const char* path, uint8_t attr) {
379373
int vfs_unlink(const char* path)
380374
{
381375
if (!path || !*path) {
382-
printf("unlink:: path is null or undefined");
376+
eprintf("unlink:: path is null or undefined");
383377
return -1;
384378
}
385379
/* Normalize */

0 commit comments

Comments
 (0)