Skip to content

Commit 0f651d2

Browse files
Coded umount, tried aesthetic theme, cleaned up sh, cleaned up mount code.
1 parent e043d80 commit 0f651d2

File tree

10 files changed

+169
-26
lines changed

10 files changed

+169
-26
lines changed

disk.img

0 Bytes
Binary file not shown.

source/includes/commands/commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ int cmd_clear(int argc, char** argv);
3636
int cmd_lsblk(int argc, char** argv);
3737
int cmd_mount(int argc, char** argv);
3838
int cmd_mv(int argc, char** argv);
39+
int cmd_umount(int argc, char** argv);
3940

4041
#endif

source/includes/graphics.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
#define green_color "\x1b[32m"
2828
#define orange_color "\x1b[38;5;208m"
2929

30+
// #define reset_color "\x1b[38;5;248m"
31+
// #define red_color "\x1b[38;5;167m"
32+
// #define yellow_color "\x1b[38;5;179m"
33+
// #define blue_color "\x1b[38;5;75m"
34+
// #define green_color "\x1b[38;5;71m"
35+
// #define orange_color "\x1b[38;5;172m"
36+
37+
3038
extern string last_filename;
3139
extern string last_filename; // for warn, info, err, done
3240
extern string last_print_file;

source/kernel/C/ahci.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ mount_entry_t* add_mount(const char* mount_point, const char* part_name, partiti
189189
return NULL;
190190
}
191191

192-
mount_entry_t* new_mount = kmalloc(sizeof(mount_entry_t));
192+
mount_entry_t* new_mount = &mounted_partitions[mounted_partition_count];
193193
if(!new_mount) return NULL;
194194

195195
new_mount->mount_point = strdup(mount_point);
@@ -205,6 +205,42 @@ mount_entry_t* add_mount(const char* mount_point, const char* part_name, partiti
205205
return new_mount;
206206
}
207207

208+
int remove_mount(const char* mount_point)
209+
{
210+
if (!mount_point)
211+
return -1;
212+
213+
for (int i = 0; i < mounted_partition_count; i++) {
214+
mount_entry_t* m = &mounted_partitions[i];
215+
216+
if (strcmp(m->mount_point, mount_point) == 0) {
217+
218+
/* Free allocated strings */
219+
if (m->mount_point)
220+
kfree(m->mount_point);
221+
if (m->part_name)
222+
kfree(m->part_name);
223+
224+
/* Shift remaining mounts left */
225+
for (int j = i; j < mounted_partition_count - 1; j++) {
226+
mounted_partitions[j] = mounted_partitions[j + 1];
227+
}
228+
229+
mounted_partition_count--;
230+
231+
/* Clear last slot (debug safety) */
232+
memset(&mounted_partitions[mounted_partition_count], 0,
233+
sizeof(mount_entry_t));
234+
235+
return 0;
236+
}
237+
}
238+
239+
printf("umount: %s: not mounted", mount_point);
240+
return -2;
241+
}
242+
243+
208244
mount_entry_t* find_mount_by_point(const char* mount_point)
209245
{
210246
for(int i = 0; i < mounted_partition_count; i++){

source/kernel/C/filesystems/fat16.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ int fat16_mount(int portno, uint32_t partition_lba, fat16_fs_t* fs) {
6262
return FAT_OK;
6363
}
6464

65+
void fat16_unmount(fat16_fs_t* fs)
66+
{
67+
if (!fs)
68+
return;
69+
70+
/*
71+
* FAT16 has no runtime state that must be flushed
72+
* because:
73+
* - FAT updates are written immediately
74+
* - directory entries are written immediately
75+
* - no write-back cache exists
76+
*/
77+
78+
/* Clear sensitive fields (debug-friendly) */
79+
fs->portno = 0;
80+
fs->partition_lba = 0;
81+
fs->fat_start = 0;
82+
fs->root_dir_start = 0;
83+
fs->data_start = 0;
84+
fs->root_dir_sectors = 0;
85+
86+
memset(&fs->bs, 0, sizeof(fs->bs));
87+
88+
/* NOTE:
89+
* fs memory is freed by umount(), not here
90+
*/
91+
}
92+
6593
uint16_t fat16_read_fat_fs(fat16_fs_t* fs, uint16_t cluster) {
6694
uint8_t buf[512];
6795
uint32_t offset = cluster * 2;

source/kernel/C/filesystems/layers/proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int proc_heap_read(
6262

6363
char tmp[128];
6464
int len = snprintf(tmp, sizeof(tmp),
65-
"HeapTotal: %u bytes\nHeapUsed: %u bytes\nHeapFree: %u bytes\nAllocCount: %u",
65+
"HeapTotal: %u bytes\nHeapUsed: %u bytes\nHeapFree: %u bytes\nAllocCount: %d",
6666
(heap_end - heap_begin),
6767
(memory_used),
6868
(heap_end - last_alloc),

source/kernel/C/filesystems/vfs.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int path_matches_mount(const char* path, const char* mount) {
3333
return path[mlen] == '\0' || path[mlen] == '/';
3434
}
3535

36-
static int vfs_resolve_mount(const char* path, vfs_mount_res_t* out) {
36+
int vfs_resolve_mount(const char* path, vfs_mount_res_t* out) {
3737
if (!path || !out) {
3838
eprintf("resolve_mount: invalid arguments");
3939
return -1;
@@ -191,6 +191,13 @@ int vfs_ls(const char* path)
191191
}
192192
}
193193

194+
if(res.mnt->type == FS_PROC) {
195+
if (res.rel_path[0] == '\0') {
196+
procfs_ls();
197+
entries = true;
198+
}
199+
}
200+
194201
if (res.mnt->type == FS_FAT16) {
195202
fat16_fs_t* fs = (fat16_fs_t*)res.mnt->fs;
196203

@@ -215,13 +222,6 @@ int vfs_ls(const char* path)
215222
}
216223
}
217224

218-
if(res.mnt->type == FS_PROC) {
219-
if (res.rel_path[0] == '\0') {
220-
procfs_ls();
221-
entries = true;
222-
}
223-
}
224-
225225
if(entries)
226226
print("\n");
227227
return 0;

source/kernel/C/shell/commands/mount.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ int cmd_mount(int argc, char** argv)
2929
const char* device = argv[1];
3030
const char* mount_point = argv[2];
3131

32+
if(strcmp(mount_point, "/") != 0) {
33+
vfs_mount_res_t res;
34+
if (vfs_resolve_mount("/", &res) != 0){
35+
eprintf("mount: cannot mount block device, root (/) is not mounted.");
36+
return -2;
37+
}
38+
}
39+
3240
if(strcmp(device, "proc") == 0){
3341
mount_entry_t* new_mount = add_mount(mount_point, device, FS_PROC, NULL);
3442
if (!new_mount)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @file umount.c
3+
* @author Pradosh ([email protected])
4+
* @brief
5+
* @version 0.1
6+
* @date 2026-01-06
7+
*
8+
* @copyright Copyright (c) Pradosh 2026
9+
*
10+
*/
11+
12+
#include <commands/commands.h>
13+
#include <ahci.h>
14+
#include <filesystems/fat16.h>
15+
#include <strings.h>
16+
17+
int cmd_umount(int argc, char** argv)
18+
{
19+
if (argc < 2) {
20+
printf("Usage: umount <mount_point>");
21+
return 1;
22+
}
23+
24+
const char* mount_point = argv[1];
25+
26+
/* Never allow root unmount */
27+
if (strcmp(mount_point, "/") == 0)
28+
printf("umount: warn unmounting root filesystem");
29+
30+
mount_entry_t* m = find_mount_by_point(mount_point);
31+
if (!m) {
32+
printf("umount: %s: not mounted", mount_point);
33+
return 1;
34+
}
35+
36+
/* Filesystem-specific cleanup */
37+
switch (m->type) {
38+
case FS_FAT16:
39+
if (m->fs) {
40+
fat16_unmount((fat16_fs_t*)m->fs);
41+
kfree(m->fs);
42+
}
43+
break;
44+
45+
case FS_PROC:
46+
// procfs_shutdown(); /* or procfs_unmount() */
47+
break;
48+
49+
default:
50+
printf("umount: unsupported filesystem");
51+
return 1;
52+
}
53+
54+
if (remove_mount(mount_point) != 0) {
55+
printf("umount: failed to remove mount");
56+
return 1;
57+
}
58+
59+
printf("umount: %s unmounted", mount_point);
60+
return 0;
61+
}

source/kernel/C/shell/sh.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,24 @@ void push_command_to_list(command_list* lst, const char* value, size_t length)
6767
bool running = true;
6868

6969
void welcome_message(){
70-
print("\e[1;34m ______ _ _ _____ _ _ _ \n");
71-
printf("| ____| | | | |/ ____| | | | |");
72-
printf("| |__ _ __ ___ ___| |_ ___ __| | (___ | |__ ___| | |");
73-
printf("| __| '__/ _ \\/ __| __/ _ \\/ _` |\\___ \\| '_ \\ / _ \\ | |");
74-
printf("| | | | | (_) \\__ \\ || __/ (_| |____) | | | | __/ | |");
75-
print("|_| |_| \\___/|___/\\__\\___|\\__,_|_____/|_| |_|\\___|_|_|\e[0m\n\n");
76-
77-
print("\033[1;32mWelcome to frosted shell!\033[0m This is an implementation of \033[0;34msh\033[0m.\n");
78-
print("We as the developers try to make this shell as similar as \033[0;34msh\033[0m.\n\n");
79-
80-
print("Website : \e[1;34mhttps://prad.digital\033[0m\n");
81-
print("Wiki : \e[1;34mhttps://github.com/Frost-Wing/osdev/wiki\033[0m\n");
82-
print("Github : \e[1;34mhttps://github.com/Frost-Wing\033[0m\n\n");
83-
70+
printf(blue_color " ______ _ _ _____ _ _ _ ");
71+
printf(blue_color "| ____| | | | |/ ____| | | | |");
72+
printf(blue_color "| |__ _ __ ___ ___| |_ ___ __| | (___ | |__ ___| | |");
73+
printf(blue_color "| __| '__/ _ \\/ __| __/ _ \\/ _` |\\___ \\| '_ \\ / _ \\ | |");
74+
printf(blue_color "| | | | | (_) \\__ \\ || __/ (_| |____) | | | | __/ | |");
75+
printf(blue_color "|_| |_| \\___/|___/\\__\\___|\\__,_|_____/|_| |_|\\___|_|_|" reset_color "\n");
76+
77+
printf(green_color "Welcome to frosted shell!" reset_color " This is an implementation of " blue_color "sh" reset_color ".");
78+
printf("We as the developers try to make this shell as similar as " blue_color "sh" reset_color ".\n");
79+
80+
printf("Wiki : " blue_color "https://github.com/Frost-Wing/osdev/wiki" reset_color "");
81+
printf("Github : " blue_color "https://github.com/Frost-Wing" reset_color "\n");
82+
8483
uint8_t second, minute, hour, day, month, year;
8584
update_system_time(&second, &minute, &hour, &day, &month, &year);
8685

87-
printf("Time : %d:%d:%d %d/%d/%d", hour, minute, second, day, month, year);
86+
printf("Time : %02d:%02d:%02d %02d/%02d/%02d",
87+
hour, minute, second, day, month, year);
8888
}
8989

9090
extern int64* wm_addr;
@@ -393,7 +393,8 @@ static command_t commands[] = {
393393
{ "lspci", cmd_lspci },
394394
{ "lsblk", cmd_lsblk },
395395
{ "mount", cmd_mount },
396-
{ "mv", cmd_mv }
396+
{ "mv", cmd_mv },
397+
{ "umount", cmd_umount }
397398
// { "fwfetch", cmd_fwfetch },
398399
// { "help", cmd_help },
399400
};

0 commit comments

Comments
 (0)