From 6907f5200ad5b26a1e45c5244a6e8c87e45eb417 Mon Sep 17 00:00:00 2001 From: Tomas 'ZeXx86' Jedrzejek Date: Sun, 1 Feb 2009 16:11:11 +0100 Subject: [PATCH] Kernel 0.6.3; ZNFS filesystem is able to create file, directories, change directory and read files - file write support still missing; updated INSTALL file; fixed default config - VGA should be disabled / VESA enabled; fixed bug in VFS - vfs_mkdir () assign to VFS flag VFS_FILEATTR_MOUNTED, what is wrong, should be when physical device is mounted; clean up in drive.c code - debug messages; irc client /os command was updated --- INSTALL | 2 +- apps/irc/commands.c | 3 +- build.sh | 2 +- kernel/.config | 9 ++- kernel/Makefile | 2 +- kernel/core/commands.c | 14 +++-- kernel/core/vfs.c | 4 +- kernel/drivers/Kconfig | 8 +-- kernel/drivers/block/drive.c | 2 +- kernel/drivers/fs/znfs.c | 139 ++++++++++++++++++++++++++++++++++++------- tools/znfsd/proto.c | 70 +++++++++++++++++++--- 11 files changed, 204 insertions(+), 51 deletions(-) diff --git a/INSTALL b/INSTALL index 3b8aad2..0f9f8d7 100644 --- a/INSTALL +++ b/INSTALL @@ -8,7 +8,7 @@ 1. You need to get some burning program 2. In menu select something like 'burn image cd' -3. Find file zexos-X.X.X-i386.iso (http://sf.net/projects/zexos) and check it +3. Find file zexos-*-i386.iso (http://zexos.org/package/) and check it 4. Burn ZeX/OS image 5. Reboot your computer (need to set in BIOS booting from cd) 6. When you see on the screen ZeX/OS title, press enter diff --git a/apps/irc/commands.c b/apps/irc/commands.c index 7aaab2b..f78c1b8 100644 --- a/apps/irc/commands.c +++ b/apps/irc/commands.c @@ -1,6 +1,7 @@ /* * ZeX/OS * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) + * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -186,7 +187,7 @@ int commands_handler (char *buffer, unsigned len) if (!msg) return 0; - memcpy (buffer, "is running on ZeX/OS - operating system created by ZeXx86 - www.zexos.net", 73); + memcpy (buffer, "is running on ZeX/OS - operating system created by ZeXx86 - www.zexos.org", 73); memcpy (msg, "PRIVMSG ", 8); memcpy (msg+8, config.channel, config.channel_len); diff --git a/build.sh b/build.sh index e298b07..38e99bd 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -VERSION="0.6.2" +VERSION="0.6.3" ARCHITECTURE="i386" diff --git a/kernel/.config b/kernel/.config index e0dabde..290254a 100644 --- a/kernel/.config +++ b/kernel/.config @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # ZeX/OS version: .. -# Fri Jan 30 19:52:08 2009 +# Sun Feb 1 16:10:13 2009 # # @@ -42,14 +42,13 @@ CONFIG_DRV_PCNET32=y # CONFIG_DRV_RTL8029 is not set CONFIG_DRV_RTL8139=y CONFIG_DRV_RTL8169=y -CONFIG_DRV_VGA=y +# CONFIG_DRV_VGA is not set CONFIG_DRV_VESA=y -CONFIG_DRV_VGA_RES="320x200" CONFIG_DRV_FAT12=y # CONFIG_DRV_FAT16 is not set # CONFIG_DRV_EXT2 is not set -CONFIG_DRV_ZEXFS=y -# CONFIG_DRV_ZNFS is not set +# CONFIG_DRV_ZEXFS is not set +CONFIG_DRV_ZNFS=y # CONFIG_DRV_ISOFS is not set CONFIG_DRV_SPEAKER=y CONFIG_DRV_FLOPPY=y diff --git a/kernel/Makefile b/kernel/Makefile index b539515..3aebbc1 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -20,7 +20,7 @@ ZEXOS_VERSION = 0 ZEXOS_PATCHLEVEL = 6 -ZEXOS_SUBLEVEL = 1 +ZEXOS_SUBLEVEL = 3 ZEXOS_EXTRAVERSION = ZEXOS_CODENAME = diff --git a/kernel/core/commands.c b/kernel/core/commands.c index 0ffe5e0..bd536a3 100644 --- a/kernel/core/commands.c +++ b/kernel/core/commands.c @@ -826,14 +826,13 @@ unsigned command_test (char *command, unsigned len) { //vfs_dirent (); - partition_t *p = partition_find ("/dev/hda0"); + /*partition_t *p = partition_find ("/dev/hda0"); if (p) mount (p, "", "/mnt/hdd/"); else printf ("WARNING -> partition /dev/hda0 does not exists\n"); - - cd ((char *) "/mnt/hdd"); +*/ //char *t = (char *) 0x400000+0x1; //*t = 0x1; @@ -897,9 +896,16 @@ unsigned command_test (char *command, unsigned len) #ifdef ARCH_i386 dev_t *dev = (dev_t *) dev_register ("vbd", "Virtual Block Device", DEV_ATTR_BLOCK, (dev_handler_t *) &ide_acthandler); - partition_add (dev, 0); + partition_t *p = partition_add (dev, fs_supported ("znfs")); znfs_init (partition_add (dev, fs_supported ("znfs")), "192.168.1.2"); // small HACK + + if (p) + mount (p, "", "/mnt/hdd/"); + else + printf ("WARNING -> partition /dev/hda0 does not exists\n"); + + cd ((char *) "/mnt/hdd"); #endif //printf ("Je to na 0x%x\n", vesafb); return 1; diff --git a/kernel/core/vfs.c b/kernel/core/vfs.c index eaa70a0..41c2b07 100644 --- a/kernel/core/vfs.c +++ b/kernel/core/vfs.c @@ -549,10 +549,10 @@ bool vfs_mkdir (char *file, unsigned file_len) partition_t *p = mount_find ((char *) pwd); if (p) { - vfs_list_add (file, VFS_FILEATTR_DIR | VFS_FILEATTR_READ, (char *) pwd); + vfs_list_add (file, VFS_FILEATTR_DIR | VFS_FILEATTR_READ | VFS_FILEATTR_MOUNTED, (char *) pwd); p->fs->handler (FS_ACT_MKDIR, file, 0, file_len); } else { - vfs_list_add (file, VFS_FILEATTR_DIR | VFS_FILEATTR_READ | VFS_FILEATTR_MOUNTED, (char *) pwd); + vfs_list_add (file, VFS_FILEATTR_DIR | VFS_FILEATTR_READ, (char *) pwd); DPRINT ("NOTE -> this directory is created only in virtual file system\n"); } diff --git a/kernel/drivers/Kconfig b/kernel/drivers/Kconfig index 43fabd2..b2cceb4 100644 --- a/kernel/drivers/Kconfig +++ b/kernel/drivers/Kconfig @@ -57,15 +57,15 @@ config DRV_RTL8169 config DRV_VGA bool "VGA graphics driver" - default y + default n help Enable the VGA graphics driver (max resolution is 640x480 in 16 colors) config DRV_VESA - bool "VESA graphics driver (EXPERIMENTAL)" - default n + bool "VESA graphics driver" + default y help - Enable the VESA v3 graphics driver + Enable the VESA graphics driver config DRV_VGA_RES string "Resolution" diff --git a/kernel/drivers/block/drive.c b/kernel/drivers/block/drive.c index dc1746f..a12f0dd 100644 --- a/kernel/drivers/block/drive.c +++ b/kernel/drivers/block/drive.c @@ -308,7 +308,7 @@ bool ide_acthandler (unsigned act, partition_t *p, char *block, char *more, int return p->fs->handler (FS_ACT_CHDIR, more, 1, l); while (strlen (dir[f].name)) { - printf ("drive__: '%s' : %d | '%s'\n", dir[f].name, f, more); + //printf ("drive__: '%s' : %d | '%s'\n", dir[f].name, f, more); if (!strncmp (dir[f].name, more, l)) { if (!p->fs->handler (FS_ACT_CHDIR, more, f, l)) return 0; diff --git a/kernel/drivers/fs/znfs.c b/kernel/drivers/fs/znfs.c index 993698d..f38bac7 100644 --- a/kernel/drivers/fs/znfs.c +++ b/kernel/drivers/fs/znfs.c @@ -43,19 +43,12 @@ unsigned char znfs_dir_id; /* clear and pre-set dir[] structure */ void znfs_dir_flush (unsigned n) { - unsigned i = 2; - - if (n != 0) { - printf ("eyk\n"); - strcpy (dir[0].name, "."); - strcpy (dir[1].name, ".."); - } else { - strcpy (dir[0].name, "."); - strcpy (dir[1].name, ".."); - } - + strcpy (dir[0].name, "."); + strcpy (dir[1].name, ".."); + + znfs_dir_id = 2; - znfs_dir_id = i; + unsigned i = znfs_dir_id; for (; i < 223; i ++) memset (dir[i].name, 0, 10); @@ -96,19 +89,39 @@ unsigned znfs_read (partition_t *p, unsigned char *name) data[0] = l; memcpy (data+1, name, l); + // Set socket to blocking mode + int oldFlag = fcntl (sock, F_GETFL, 0); + oldFlag &= ~O_NONBLOCK; + + if (fcntl (sock, F_SETFL, oldFlag) == -1) { + printf ("Cant set socket to nonblocking mode\n"); + } + znfs_send (sock, PROTO_READ, data, l+1); + int r = 0; + + file_cache = (char *) 0x35000; + file_cache_id = 0; + char *s = (char *) file_cache; while (1) { - znfs_recv (sock, s, 1024); + r = znfs_recv (sock, s, 1024); - unsigned p = (unsigned) *s; + s += r; - if (p == 0xf9da1e9) + if (r != 1024) break; + } - s += 1024; + file_cache[r] = '\0'; + file_cache_id = r; + + // Set socket to non-blocking mode + oldFlag = fcntl (sock, F_GETFL, 0); + if (fcntl (sock, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + printf ("Cant set socket to nonblocking mode\n"); } return 1; @@ -168,12 +181,12 @@ unsigned znfs_create_file (partition_t *p, unsigned char *name) /* go to next directory placed in current directory */ void znfs_cd (partition_t *p, unsigned char *name) { - unsigned char l = strlen (name); + unsigned short l = strlen (name); - if (l > 254) - l = 254; + if (l > 1023) + l = 1023; - char data[256]; + char data[1024]; data[0] = l; memcpy (data+1, name, l); @@ -181,19 +194,98 @@ void znfs_cd (partition_t *p, unsigned char *name) znfs_send (sock, PROTO_CHDIR, data, l+1); znfs_dir_flush (1); + + // Set socket to blocking mode + int oldFlag = fcntl (sock, F_GETFL, 0); + oldFlag &= ~O_NONBLOCK; + + if (fcntl (sock, F_SETFL, oldFlag) == -1) { + printf ("Cant set socket to nonblocking mode\n"); + } + + int r = znfs_recv (sock, data, 1024); + + // Set socket to non-blocking mode + oldFlag = fcntl (sock, F_GETFL, 0); + if (fcntl (sock, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + printf ("Cant set socket to nonblocking mode\n"); + } + + if (r < 1) { + kprintf ("ZNFS -> error in receiving directory list\n"); + return; + } + + unsigned char n = r/13; + + struct dent { + unsigned char type; + char name[12]; + } __attribute__ ((__packed__)); + + struct dent *d = (struct dent *) data; + + for (l = 0; l < n; l ++) { + memcpy (dir[l].name, d[l].name, 12); + + if (d[l].type == 0x4) + dir[l].dir = 1; + else + dir[l].dir = 0; + } } /* go to root '/' directory on partition */ void znfs_cd_root (partition_t *p) { - znfs_dir_flush (0); - - char data[12]; + char data[1024]; data[0] = 1; data[1] = '/'; znfs_send (sock, PROTO_CHDIR, data, 2); + + znfs_dir_flush (1); + + // Set socket to blocking mode + int oldFlag = fcntl (sock, F_GETFL, 0); + oldFlag &= ~O_NONBLOCK; + + if (fcntl (sock, F_SETFL, oldFlag) == -1) { + printf ("Cant set socket to nonblocking mode\n"); + } + + int r = znfs_recv (sock, data, 1024); + + // Set socket to non-blocking mode + oldFlag = fcntl (sock, F_GETFL, 0); + if (fcntl (sock, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + printf ("Cant set socket to nonblocking mode\n"); + } + + if (r < 1) { + kprintf ("ZNFS -> error in receiving directory list\n"); + return; + } + + unsigned char n = r/13; + unsigned char l; + + struct dent { + unsigned char type; + char name[12]; + } __attribute__ ((__packed__)); + + struct dent *d = (struct dent *) data; + + for (l = 0; l < n; l ++) { + memcpy (dir[l].name, d[l].name, 12); + + if (d[l].type == 0x4) + dir[l].dir = 1; + else + dir[l].dir = 0; + } } /* zexos filesystem initialization function */ @@ -244,6 +336,7 @@ unsigned znfs_init (partition_t *p, char *addr) timer_wait (100); + #endif return 1; } diff --git a/tools/znfsd/proto.c b/tools/znfsd/proto.c index 9c8812e..73be6c3 100644 --- a/tools/znfsd/proto.c +++ b/tools/znfsd/proto.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "client.h" @@ -14,7 +15,7 @@ int proto_handle (client_t *c, char *data, unsigned len) { - char name[256]; + char name[1024]; unsigned char l = 0; int r = -1; @@ -70,8 +71,20 @@ int proto_handle (client_t *c, char *data, unsigned len) printf ("creat (%s, %x) = %d\n", name, 0x0777, r); break; case PROTO_RM: + if (len < 3) + return 0; + + l = data[1]; + + if (l > len-2) + return 0; - printf ("rm (%s) = %d\n", "", r); + memcpy (name, data+2, l); + name[l] = '\0'; + + r = remove (name); + + printf ("remove (%s) = %d\n", name, r); break; case PROTO_CHDIR: if (len < 3) @@ -88,6 +101,44 @@ int proto_handle (client_t *c, char *data, unsigned len) r = chdir (name); printf ("chdir (%s) = %d\n", name, r); + + struct dent { + unsigned char type; + char name[12]; + } __attribute__ ((__packed__)); + + struct dirent **namelist; + struct dent *d = (struct dent *) name; + + int n = scandir (".", &namelist, 0, alphasort); + + if (n * 13 > 1024) { + printf ("scandir () : too big namelist\n"); + break; + } + + if (n < 0) + perror ("scandir"); + else { + for (r = 0; r < n; r ++) { + printf ("%s : 0x%x\n", namelist[r]->d_name, namelist[r]->d_type); + l = strlen (namelist[r]->d_name); + + if (l > 12) + l = 12; + + memcpy (d[r].name, namelist[r]->d_name, l); + d[r].name[l] = '\0'; + d[r].type = namelist[r]->d_type; + + free (namelist[r]); + } + + free (namelist); + + client_send (c, (char *) name, n * 13); + } + break; case PROTO_READ: if (len < 3) @@ -107,19 +158,22 @@ int proto_handle (client_t *c, char *data, unsigned len) fr = fopen (name, "r"); if (!fr) { + printf ("fopen (%s) == 0\n", name); goto done; } - while (fgets (s, sizeof (s), fr) != NULL) { - client_send (c, s, 1024); - usleep (10); + while (1) { + int r = fread (s, sizeof (char), 1024, fr); + + if (!r) + break; + + client_send (c, s, r); + usleep (1); } fclose (fr); - unsigned p = 0xf9da1e9; // some kind of magic .. eh it is match for EOF - client_send (c, (char *) &p, 4); - r = 0; done: -- 2.11.4.GIT