WKern
Loading...
Searching...
No Matches
filecmds.c
Go to the documentation of this file.
1/*
2WKern - A Bare Metal OS / Kernel I am maKing (For Fun)
3Copyright (C) 2025 Wdboyes13
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18#include <fileio/fileio.h>
19#include <io/kio.h>
20#include <mem/kmem.h>
21
31void Rm(const char *argv[], int argc) { // rm [filename] [ext]
32 if (argc < 3) {
33 Kprintf("Not enough args\nUsage: rm [filename] [ext]");
34 return;
35 }
36 Fat16RemoveFile(argv[1], argv[2]);
37}
38
48void Mkf(const char *argv[], int argc) { // mKfile [filename] [ext]
49 if (argc < 3) {
50 Kprintf("Not enough args\nUsage: mKfile [filename] [ext]");
51 return;
52 }
53 Mkfile(argv[1], argv[2]);
54}
55
68void Writef(const char *argv[], int argc) { // write [filename] [ext]
69 if (argc < 3) {
70 Kprintf("Not enough args\nUsage: write [filename] [ext]");
71 return;
72 }
73 char *data = (char *)Kmalloc(512, 8);
74 if (!data) {
75 Kprintf("\nMalloc Failed!\n");
76 Kfree(data);
77 return;
78 }
79 Kprintf("Start Writing Data:\n");
80 Kgetstr(data, 500); // only read 500 max
81 Kflush();
82
83 int len = 0;
84 while (len < 500 && data[len] != '\0') {
85 len++;
86 }
87
88 // Add EOF marKer
89 if (len + 5 < 512) {
90 data[len] = 0x1A;
91 len++;
92 data[len] = '\0'; // Optional if your writer handles C-strings
93 }
94
95 Writefile(argv[1], argv[2], data, len + 1); // Use actual size
96 Kfree(data);
97}
98
108void Readf(const char *argv[], int argc) { // read [filename] [ext]
109 if (argc < 3) {
110 Kprintf("Not enough args\nUsage: read [filename] [ext]");
111 return;
112 }
113 Fileconts(argv[1], argv[2]);
114}
void * Kmalloc(size_t size, size_t align)
Allocate memory.
Definition alloc.c:48
void Kfree(void *ptr)
Free allocated memory.
Definition alloc.c:75
void Readf(const char *argv[], int argc)
Read and display contents of a file from the FAT16 filesystem.
Definition filecmds.c:108
void Rm(const char *argv[], int argc)
Delete a file from the FAT16 filesystem.
Definition filecmds.c:31
void Writef(const char *argv[], int argc)
Write data to a file in the FAT16 filesystem from user input.
Definition filecmds.c:68
void Mkf(const char *argv[], int argc)
Create a new empty file on the FAT16 filesystem.
Definition filecmds.c:48
Definitions and declarations for FAT16 filesystem and ATA I/O.
void Fileconts(const char *filename, const char *ext)
Prints contents of a FAT16 file.
Definition printconts.c:40
void Mkfile(const char *filename, const char *ext)
Creates a new empty file in the FAT16 root directory.
Definition mkfile.c:41
void Writefile(const char *filename, const char *ext, const char *data, u32 size)
Writes data to a FAT16 file, replacing its contents.
Definition write.c:41
void Fat16RemoveFile(const char *filename, const char *ext)
Removes a file from the FAT16 root directory and frees clusters.
Definition rmfile.c:38
void Kgetstr(char *str, int length)
Reads a line of input from the keyboard (blocking).
Definition keyin.c:186
void Kflush()
Flushes the keyboard controller input buffer.
Definition keyin.c:219
void Kprintf(const char *fmt,...)
Formatted output to the screen.
Definition printer.c:152