Skip to content

Commit

Permalink
add file_clean()
Browse files Browse the repository at this point in the history
  • Loading branch information
GandelXIV committed May 30, 2021
1 parent b9e0111 commit 25f29c3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions fs/fscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ int file_write(char* filename, char* data, uint32_t depth)
return OK;
}

void file_clean(char* filename)
{
if (!file_exists(filename)) return FILE_NOT_FOUND;
File* fp = find_file(filename);
Sector* fs = fp->first_sector;
do {
for (int i = 0; i < FS_SECTOR_DATA_SIZE; ++i)
{
fs->data[i] = 0;
}
Sector* next_fs = fs->next;
fs = next_fs;
} while(fs != 0);
return OK;
}

int file_writes(char* filename, char* text)
{
return file_write(filename, text, strlen(text));
Expand Down
1 change: 1 addition & 0 deletions fs/fscore.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ int file_size(char* name);
int file_read(char* filename, char* output);
int file_write(char* filename, char* data, uint32_t depth);
int file_writes(char* filename, char* text);
void file_clean(char* filename);
1 change: 1 addition & 0 deletions kernel/advanced_cmds/write_to_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void ksh_write_to_file()
kprints("Enter data: ");
kinputs(data);

file_clean(filename);
file_writes(filename, data);

kfree(filename);
Expand Down

0 comments on commit 25f29c3

Please sign in to comment.