From 8351f342a046c34caef703beba9b5dc6a1a415b2 Mon Sep 17 00:00:00 2001 From: Tomas 'ZeXx86' Jedrzejek Date: Thu, 12 Nov 2009 19:35:24 +0100 Subject: [PATCH] websrv makefile updated; added support for more web pages to websrv; ZDE improvement of zgui_puts () - better handling of text; added support of terminal to ZDE; fixed ZDE desktop icon's position; fixed compilation of zjab for linux + improvements in zjab; added command "gui" for build.sh script, e.g. "./build.sh iso gui" what is responsible for ZDE installation into CD image; fixed possible sys_write () memory corruption with unwanted '\0' character; added command cmd for sequentional execution of shell commands; small changes in console's gets (); devices can check their name in INIT over flags structure; added ioctl () call IOATAREAD and IOATAWRITE for read/write ATA operations; small changes in TCP implementation + partially fixed bug with random close () when connect (); changes in tty.c + each tty is recognized as character device mapped to /dev/tty*; some fixes in ext2; added file descriptor type FD_TERM for terminal's read/write feature; improvements in read.c, open.c and write.c in kernel lib; added initial GUI installer of ZeX/OS --- apps/websrv/Makefile | 12 +- apps/websrv/a.htm | 16 +++ apps/websrv/client.h | 2 + apps/websrv/http.c | 170 +++++++++++++++++++++--- apps/websrv/{html => i.htm} | 7 +- apps/websrv/net.c | 33 +++-- apps/websrv/{start.asm => start.s} | 0 apps/zde/appcl.c | 34 ++++- apps/zde/dialog.c | 8 +- apps/zde/handler.c | 82 +++++++++--- apps/zde/icon.c | 9 +- apps/zde/zinstall/Makefile | 48 +++++++ apps/zde/zinstall/README | 5 + apps/zde/zinstall/link.ld | 48 +++++++ apps/zde/zinstall/main.c | 66 +++++++++ apps/zde/zinstall/make_img.sh | 29 ++++ apps/{websrv/start.asm => zde/zinstall/start.s} | 0 apps/zjab/Makefile | 2 +- apps/zjab/cmds.c | 7 +- apps/zjab/utils.c | 3 +- build.sh | 8 ++ kernel/arch/i386/syscall.c | 9 +- kernel/core/commands.c | 71 +++++++++- kernel/core/console.c | 22 +-- kernel/core/dev.c | 10 +- kernel/core/ioctl.c | 40 ++++++ kernel/core/mm/usermem.c | 4 +- kernel/core/net/tcp.c | 20 +-- kernel/core/net/tcp6.c | 5 + kernel/core/tty.c | 112 +++++++++++++--- kernel/drivers/fs/ext2.c | 111 +++++++++------- kernel/include/ioctl.h | 8 ++ kernel/include/tty.h | 10 +- kernel/lib/stdio/open.c | 2 +- kernel/lib/stdio/read.c | 3 + kernel/lib/stdio/write.c | 39 ++++++ libc/include/sys/ioctl.h | 8 ++ 37 files changed, 900 insertions(+), 163 deletions(-) create mode 100644 apps/websrv/a.htm rename apps/websrv/{html => i.htm} (79%) copy apps/websrv/{start.asm => start.s} (100%) create mode 100644 apps/zde/zinstall/Makefile create mode 100644 apps/zde/zinstall/README create mode 100644 apps/zde/zinstall/link.ld create mode 100644 apps/zde/zinstall/main.c create mode 100755 apps/zde/zinstall/make_img.sh rename apps/{websrv/start.asm => zde/zinstall/start.s} (100%) diff --git a/apps/websrv/Makefile b/apps/websrv/Makefile index f185463..07bd91a 100644 --- a/apps/websrv/Makefile +++ b/apps/websrv/Makefile @@ -29,22 +29,14 @@ install: websrv rmdir mnt clean: - rm -f *.o websrv websrv.img $(OBJS) + rm -f *.o websrv websrv_linux websrv.img $(OBJS) # implicit rules -.asm.o: +.s.o: $(NASM) -o$@ $< .c.o: $(CC) -c -o$@ $< -#: dependencies -# boot -start.o: start.asm $(MAKEDEP) -# kernel -main.o: main.c $(MAKEDEP) -net.o: net.c $(MAKEDEP) -http.o: http.c $(MAKEDEP) - # explicit rules websrv: $(OBJS) $(LIBC) $(MAKEDEP) $(LD) $(LFLAGS) -o$@ $(OBJS) $(LIBC) \ No newline at end of file diff --git a/apps/websrv/a.htm b/apps/websrv/a.htm new file mode 100644 index 0000000..43661d2 --- /dev/null +++ b/apps/websrv/a.htm @@ -0,0 +1,16 @@ + + + Powered by ZeX/OS + + + +

Powered by ZeX/OS

+
+ Screenshots from ZeX/OS graphical environment
+ + + +
+ + + diff --git a/apps/websrv/client.h b/apps/websrv/client.h index 66fb721..079711c 100644 --- a/apps/websrv/client.h +++ b/apps/websrv/client.h @@ -1,6 +1,7 @@ /* * ZeX/OS * Copyright (C) 2007 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 @@ -32,6 +33,7 @@ typedef struct client_context { int fd; unsigned char state; unsigned ret; + char page[32]; } client_t; #endif diff --git a/apps/websrv/http.c b/apps/websrv/http.c index 8b56073..8169b57 100644 --- a/apps/websrv/http.c +++ b/apps/websrv/http.c @@ -2,6 +2,7 @@ * ZeX/OS * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * 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 @@ -23,20 +24,50 @@ #include #include #include +#ifdef LINUX +# include +# include +# include +# include +#endif + #include "net.h" #include "client.h" +typedef struct { + char *name; + unsigned attrib; + unsigned char next; + unsigned char unused; +} __attribute__ ((__packed__)) dirent_t; -char *http_header; // Buffer s http hlavickou -unsigned http_header_len; // Delka http hlavicky -char *buf; // Buffer -unsigned buf_len; // Delka bufferu -char *page; -unsigned page_len; +#define VFS_FILEATTR_FILE 0x1 -int http_init () +typedef struct web_context { + struct web_context *next, *prev; + + char *name; + char *page; + unsigned page_len; +} web_t; + +web_t web_list; + +web_t *web_find (char *name) { - page = (char *) malloc (sizeof (char) * 80); + web_t *web; + for (web = web_list.next; web != &web_list; web = web->next) + if (!strcmp (web->name, name)) + return web; + + return 0; +} + +web_t *web_register (char *name) +{ + unsigned page_len = 0; + + char *page = (char *) malloc (sizeof (char) * 80); if (!page) return 0; @@ -57,18 +88,18 @@ int http_init () page_len = 63; - FILE *f = fopen ("html", "r"); + FILE *f = fopen (name, "r"); if (!f) { - puts ("error -> file 'html' not found\n"); - return -1; + printf ("error -> file '%s' not found\n", name); + return 0; } fseek (f, 0, SEEK_END); unsigned flen = ftell (f); fseek (f, 0, SEEK_SET); - page = (char *) realloc ((void *) page, sizeof (char) * (flen + page_len)); + page = (char *) realloc ((void *) page, sizeof (char) * (flen + 80)); if (!page) return 0; @@ -81,21 +112,124 @@ int http_init () char num[11]; memset (num, 0, 11); - sprintf (num, "%d", page_len); // convert int to char * + sprintf (num, "%d", page_len-63); // convert int to char * unsigned num_len = strlen (num); memcpy (page+56, num, num_len); fclose (f); + + web_t *web = (web_t *) malloc (sizeof (web_t)); + + if (!web) + return 0; + + web->name = strdup (name); + web->page = page; + web->page_len = page_len; + + /* add into list */ + web->next = &web_list; + web->prev = web_list.prev; + web->prev->next = web; + web->next->prev = web; + + printf ("> adding to cache: '%s'\n", name); + + return web; +} + +dirent_t *getdir () +{ + dirent_t *dirent; + + asm volatile ( + "movl $25, %%eax;" + "int $0x80;" + "movl %%eax, %0;" + : "=g" (dirent) :: "%eax"); + + return dirent; +} + +int http_loadfiles () +{ +#ifndef LINUX + dirent_t *dir = getdir (); + if (!dir) + return 0; + + unsigned id = 0; + + for (;;) { + if (dir[id].attrib & VFS_FILEATTR_FILE) { + if (strstr (dir[id].name, ".htm")) + if (!web_register (dir[id].name)) + return 0; + } + + if (!dir[id].next) + break; + + id ++; + } +#else + struct dirent *entry; /* Only used as a pointer - see dirent.h */ + struct stat statbuf; /* So we can check which files are directories. */ + char *pathname = "."; + + /* Open a directory for directory reads. */ + DIR *directory = opendir (pathname); + + if (!directory) { + printf ("ERROR -> cannot open %s\n", pathname); + return 0; + } + + while ((entry = readdir (directory))) { + /* Skip if . or .. */ + if (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, "..")) + continue; + + /* stat it to see if it is a directory. */ + int retval = stat (entry->d_name, &statbuf); + + if (retval == 0 && statbuf.st_mode & S_IFREG) + if (strstr (entry->d_name, ".htm")) + if (!web_register (entry->d_name)) + return 0; + + } + + closedir (directory); +#endif + return 1; } -extern int client_count; -int http_transfer (client_t *c) +int http_init () { - send_to_socket (c->fd, page, page_len); + web_list.next = &web_list; + web_list.prev = &web_list; + + if (!http_loadfiles ()) + return 0; + + return 1; +} +int http_transfer (client_t *c) +{ + web_t *web = web_find (strlen (c->page) == 0 ? "i.htm" : c->page); + + if (web) { + printf ("> sending '%s' web page\n", web->name); + + send_to_socket (c->fd, web->page, web->page_len); + } else + printf ("> web page '%s' not found\n", c->page); + c->state = CLIENT_STATE_DONE; return 1; @@ -103,7 +237,9 @@ int http_transfer (client_t *c) int http_destroy () { - free (page); + web_t *web; + for (web = web_list.next; web != &web_list; web = web->next) + free (web->page); return 1; } diff --git a/apps/websrv/html b/apps/websrv/i.htm similarity index 79% rename from apps/websrv/html rename to apps/websrv/i.htm index d763273..660939a 100644 --- a/apps/websrv/html +++ b/apps/websrv/i.htm @@ -8,12 +8,16 @@

* Operating system created by ZeXx86 *
web page -
This web is served by websrv +
This web is running websrv - fast, easy and portable web server

Next available apps, which use networking:
+
  • zjab - Jabber/XMPP IM client
  • irc - IRC client for chat
  • nc - Hacking tool, clone of netcat
  • telnetd - Telnetd daemon, telnet server
  • im - Instant messaging client
  • +
  • webcl - Web browser
  • +
    + Some screenshots from ZeX/OS are HERE

    Use OpenSource

    Open source is a set of principles and practices that promote access to the design and production of goods and knowledge. This allows users to create software content through incremental individual effort or through collaboration.

    @@ -21,4 +25,3 @@ - diff --git a/apps/websrv/net.c b/apps/websrv/net.c index 47c98c8..d4a3a7d 100644 --- a/apps/websrv/net.c +++ b/apps/websrv/net.c @@ -2,7 +2,7 @@ * ZeX/OS * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com) - * 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 @@ -73,18 +73,27 @@ int client_get (client_t *c) } buffer[ret] = '\0'; - - //printf ("DATA: "); - //printf (buffer); - if (!strncmp (buffer, "GET / ", 6)) { - //while (ret > 0) - //ret = recv (c->fd, buffer, 1023, 0); +// printf ("DATA: %s\n", buffer); + + if (!strncmp (buffer, "GET /", 5)) { + + int i; + for (i = 4; i < ret; i ++) + if (buffer[i] == ' ') + break; + + if ((i-5) >= 32) + i = 36; + + memcpy (c->page, buffer+5, i-5); + c->page[i-5] = '\0'; c->state = CLIENT_STATE_TRANSFER; return 1; - } + } else + printf ("ERROR -> corrupted http session ..\n"); c->state = CLIENT_STATE_DONE; @@ -252,16 +261,20 @@ int loop () if (!c) close (client); - - usleep (32); } + unsigned i = 0; client_t *c; for (c = client_list.next; c != &client_list; c = c->next) { if (!client_handle (c)) break; + + i ++; } + if (!i) + usleep (64); + return 1; } diff --git a/apps/websrv/start.asm b/apps/websrv/start.s similarity index 100% copy from apps/websrv/start.asm copy to apps/websrv/start.s diff --git a/apps/zde/appcl.c b/apps/zde/appcl.c index 5816500..6c53e2a 100755 --- a/apps/zde/appcl.c +++ b/apps/zde/appcl.c @@ -51,8 +51,38 @@ appcl_t *zgui_window () void zgui_puts (unsigned short x, unsigned short y, char *str, unsigned color) { - if (zappcl) - xtext_puts (zappcl->x+4+x, zappcl->y+21+y, color, str); + if (!zappcl) + return; + + int i = 0; + int j = 0; + int k = 0; + + for (i = 0; str[i]; i ++) { + if (str[i] == '\n') { + j += 6; + k = 0; + continue; + } else + if (str[i] == '\t') { + k += 4*5; + continue; + } + + if (zappcl->sizex < k+15) { + j += 6; + k = 0; + continue; + } + + if (j < zappcl->sizey) + xtext_putch (zappcl->x+4+x+k, zappcl->y+21+y+j, color, str[i]); + + k += 6; + } + + //xtext_puts (zappcl->x+4+x, zappcl->y+21+y, color, str); + } int zgui_cursor (unsigned short *x, unsigned short *y) diff --git a/apps/zde/dialog.c b/apps/zde/dialog.c index c071163..f8fc8a7 100755 --- a/apps/zde/dialog.c +++ b/apps/zde/dialog.c @@ -189,16 +189,20 @@ int draw_dialog_object (zde_win_t *window) if (dobj_text->data[i] == '\n') { j += 6; k = 0; + continue; } else - if (dobj_text->data[i] == '\t') + if (dobj_text->data[i] == '\t') { k += 4*5; + continue; + } if (!dobj_text->sizex && window->sizex < k+15) { j += 6; k = 0; + continue; } - if (!dobj_text->sizey && j < window->sizey) + if (!dobj_text->sizey && j < window->sizey-21) xtext_putch (x+k, y+j, 0, dobj_text->data[i]); k += 6; diff --git a/apps/zde/handler.c b/apps/zde/handler.c index 4351c29..14df52b 100755 --- a/apps/zde/handler.c +++ b/apps/zde/handler.c @@ -138,11 +138,19 @@ void *handler_icon_terminal (void *r) if (!window) return (0); - -/* int fd = open (r, O_RDONLY); + + window->sizex = 6 * 80; + window->sizey = 9 * 65; + + int fd = open ("/dev/tty1", O_RDWR); if (!fd) return 0; + + if (fcntl (fd, F_SETFL, 0x2000) == -1) { + printf ("Cant set fd to terminal mode\n"); + return 0; + } int l = lseek (fd, 0, SEEK_END); @@ -152,36 +160,80 @@ void *handler_icon_terminal (void *r) if (!buf) return 0; + + char *buf2 = (char *) malloc (l+1); - read (fd, buf, l);*/ - + if (!buf2) { + free (buf); + return 0; + } + zde_dobj_text_t dobj_text; - char buf[130]; - dobj_text.sizex = 0; dobj_text.sizey = 0; + dobj_text.data = (char *) "tty"; + dobj_text.len = 3; - create_dialog_object (ZDE_DOBJ_TYPE_TEXT, &dobj_text, 0, 0, window); + zde_dobj_t *dobj = create_dialog_object (ZDE_DOBJ_TYPE_TEXT, &dobj_text, 0, 0, window); + if (!dobj) + return 0; + + zde_dobj_text_t *text = (zde_dobj_text_t *) dobj->arg; + + if (!text) + return 0; + while (!(window->state & WINDOW_STATE_CLOSE)) { schedule (); - - int r = read (1, buf, 128); - - if (r > 0) { - dobj_text.data = (char *) buf; - dobj_text.len = r; - } - + if (window != zde_win_last) continue; + + read (fd, buf, l); + + lseek (fd, 0, SEEK_SET); + + unsigned i = 0; + unsigned j = 0; + unsigned k = 0; + unsigned m = 80 * 65; + unsigned pos = 0; + + while (i < m) { + if (buf[i*2]) + buf2[pos ++] = buf[i*2]; + else + buf2[pos ++] = ' '; + + j ++; + + if (j >= 80) { + j = 0; + k ++; + buf2[pos ++] = '\n'; + } + + i ++; + } + + text->data = (char *) buf2; + text->len = pos; + + char c[2]; + c[0] = kbd_getkey (); + + if (c[0]) + write (fd, c, 1); if (zde_cursor->state == XCURSOR_STATE_LBUTTON) { } } + free (buf2); + free (buf); free (window); return (0); diff --git a/apps/zde/icon.c b/apps/zde/icon.c index 9e88594..06ba971 100755 --- a/apps/zde/icon.c +++ b/apps/zde/icon.c @@ -65,8 +65,8 @@ zde_icon_t *create_icon (char *name, int type, void *(*entry) (void *), void *ar icon->next = &zde_icon_list; icon->prev = zde_icon_list.prev; - icon->x = 14 + (icon->prev->x * 40); - icon->y = 14; + icon->x = 14; + icon->y = icon->prev->y + 54; icon->prev->next = icon; icon->next->prev = icon; @@ -323,7 +323,8 @@ int init_icon () zde_icon_list.prev = &zde_icon_list; zde_icon_list.prev->x = 0; - + zde_icon_list.prev->y = 0; + /* FOLDER bitmap */ bitmap_folder = load_icon ("folder"); @@ -340,7 +341,7 @@ int init_icon () create_icon ("Filesystem", 0, handler_icon_filesystem, ""); /* create test icon */ - //create_icon ("Terminal", 0, handler_icon_terminal, ""); + create_icon ("Terminal", 0, handler_icon_terminal, ""); return 0; } diff --git a/apps/zde/zinstall/Makefile b/apps/zde/zinstall/Makefile new file mode 100644 index 0000000..9410926 --- /dev/null +++ b/apps/zde/zinstall/Makefile @@ -0,0 +1,48 @@ +.SUFFIXES: .asm + +# defines +MAKEFILE=Makefile +MAKEDEP=$(MAKEFILE) +NASM =nasm -f elf +GLIBC =../../../libc +LSCRIPT =./link.ld +LFLAGS =-g -T$(LSCRIPT) +INCDIR =$(GLIBC)/include +LIBXDIR =../../../libx +LIBIDIR =../../../libipc +LIBZDIR =.. +CC =gcc -m32 -g -O2 -Wall -W -c -nostdinc -fno-builtin -fno-stack-protector -I$(INCDIR) -I$(LIBIDIR)/include -I$(LIBXDIR) -I$(LIBZDIR) +#-Wall -W +LD =ld -m elf_i386 -s -nostdlib +LIBC =$(GLIBC)/libc.a +LIBX =$(LIBXDIR)/libx.a +LIBI =$(LIBIDIR)/libipc.a +LIBZ =$(LIBZDIR)/libzde.a +OBJS =start.o main.o + +# targets +all: prepare zinst.x + +prepare: + make -C ../ + + +install: zinst.x + mkdir mnt + mount /dev/fd0 mnt + cp -f zinst ./mnt/zinst + umount mnt + rmdir mnt + +clean: + rm -f *.o zinst.x zinst.img $(OBJS) +# implicit rules +.s.o: + $(NASM) -o$@ $< + +.c.o: + $(CC) -c -o$@ $< + +# explicit rules +zinst.x: $(OBJS) $(LIBI) $(LIBX) $(LIBZ) $(LIBC) $(MAKEDEP) + $(LD) $(LFLAGS) -o$@ $(OBJS) $(LIBZ) $(LIBI) $(LIBX) $(LIBC) \ No newline at end of file diff --git a/apps/zde/zinstall/README b/apps/zde/zinstall/README new file mode 100644 index 0000000..d13554b --- /dev/null +++ b/apps/zde/zinstall/README @@ -0,0 +1,5 @@ +Description: zinstall - GUI installer for ZDE +Info: installer of ZeX/OS for ZDE + +License: GNU/GPL3 +Author: ZeXx86 \ No newline at end of file diff --git a/apps/zde/zinstall/link.ld b/apps/zde/zinstall/link.ld new file mode 100644 index 0000000..eac4bff --- /dev/null +++ b/apps/zde/zinstall/link.ld @@ -0,0 +1,48 @@ +OUTPUT_FORMAT("elf32-i386") +ENTRY(entry) +phys = 0x800000; + +SECTIONS +{ + .text phys + 0x1000 : AT (phys) + { + code = .; _code = .; __code = .; + *(.text) + . = ALIGN(64); + } + .data : AT(phys + (data - code)) + { + data = .; _data = .; __data = .; + *(.data) + . = ALIGN(64); + } + .rodata : AT(phys + (rodata - code)) + { + rodata = .; _rodata = .; __rodata = .; + *(.rodata) + *(.rodata.*) + . = ALIGN(64); + } + .bss : AT(phys + (bss - code)) + { + bss = .; _bss = .; __bss = .; + *(.bss) + *(COMMON) + . = ALIGN(64); + } + .comment : AT(phys + (comment - code)) + { + comment = .; _comment = .; __comment = .; + *(.comment) + *(.comment.*) + . = ALIGN(64); + } + .shstrtab : AT(phys + (shstrtab - code)) + { + shstrtab = .; _shstrtab = .; __shstrtab = .; + *(.shstrtab) + *(.shstrtab.*) + . = ALIGN(64); + } + end = .; _end = .; +} diff --git a/apps/zde/zinstall/main.c b/apps/zde/zinstall/main.c new file mode 100644 index 0000000..17544f9 --- /dev/null +++ b/apps/zde/zinstall/main.c @@ -0,0 +1,66 @@ +/* + * ZeX/OS + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include + +unsigned step; + +void zinstall_draw () +{ + zgui_puts (10, 10, "ZeX/OS Installer\n-=-=-=-=-=-=-=-=-", 0); + + unsigned btn_next = zgui_button (150, 145, "Next"); + + if (!btn_next) + step ++; + + switch (step) { + case 0: + zgui_puts (10, 40, "Welcome my user!\nYou are attempting to install ZeX/OS\nonto your hard-drive, please be sure\nabout your backup because of data loss.\n\nWarning: This version is in the alpha-stage,\nit is possible that some error may occur.\n\nPress button \"Next\" for continue\nin installation process", 0); + break; + case 1: + zgui_puts (10, 40, "First step is focused on hard-drive ID,\nthat mean, you must select\n correct disk for installation.\n\n", 0); + break; + case 2: + zgui_puts (10, 40, "In this step we should setup HDD partition\ntable before installation process begin.\nIt is necessary to choose current partition\ntype, respectively filesystem ID.", 0); + break; + } +} + +int main (int argc, char **argv) +{ + int exit = 0; + step = 0; + + if (zgui_init () == -1) + return -1; + + while (!exit) { + unsigned state = zgui_event (); + + if (state & APPCL_STATE_REDRAW) + zinstall_draw (); + + if (state & APPCL_STATE_EXIT) + exit = 1; + } + + return zgui_exit (); +} + diff --git a/apps/zde/zinstall/make_img.sh b/apps/zde/zinstall/make_img.sh new file mode 100755 index 0000000..65ad89f --- /dev/null +++ b/apps/zde/zinstall/make_img.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +if [ "$USER" = "root" ] ; then + +# Folder name of your application +APPNAME="zinst.x" + +# Compile source +make + +# Optimized for 1,4MB floppy +dd if=/dev/zero of=$APPNAME.img bs=1440k count=1 +mkfs.vfat $APPNAME.img + +mkdir floppy +mount -oloop $APPNAME.img floppy +cp ../zde floppy +cp ../folder floppy +cp ../border floppy +cp ../file floppy +cp $APPNAME floppy +umount floppy +rmdir floppy + +else + +echo "Please start this script as root - it is needed for mount program" + +fi \ No newline at end of file diff --git a/apps/websrv/start.asm b/apps/zde/zinstall/start.s similarity index 100% rename from apps/websrv/start.asm rename to apps/zde/zinstall/start.s diff --git a/apps/zjab/Makefile b/apps/zjab/Makefile index 2da9632..0daad58 100644 --- a/apps/zjab/Makefile +++ b/apps/zjab/Makefile @@ -18,7 +18,7 @@ OBJS =start.o main.o net.o xml.o xmpp.o cmds.o utils.o all: zjab linux: - gcc -O2 -ozjab_linux main.c net.c xml.c xmpp.c cmds.c -DLINUX + gcc -O2 -ozjab_linux main.c net.c xml.c xmpp.c cmds.c utils.c -DLINUX install: zjab mkdir mnt diff --git a/apps/zjab/cmds.c b/apps/zjab/cmds.c index 5e4cbb9..8e36e1f 100644 --- a/apps/zjab/cmds.c +++ b/apps/zjab/cmds.c @@ -80,6 +80,10 @@ int cmds_handler (char *buffer, unsigned len) free (cmd_window); cmd_window = strndup (buffer+4, len-4); + + if (!cmd_window) + return -1; + printf ("> Current chat window: %s\n", cmd_window); return 0; @@ -99,7 +103,8 @@ int cmds_handler (char *buffer, unsigned len) return 0; } - xmpp_message (cmd_window, buffer, len); + if (cmd_window) + xmpp_message (cmd_window, buffer, len); setcolor (14, 0); printf ("> %s\n", buffer); diff --git a/apps/zjab/utils.c b/apps/zjab/utils.c index cb0fc06..a1a019a 100644 --- a/apps/zjab/utils.c +++ b/apps/zjab/utils.c @@ -62,7 +62,6 @@ static void base64_encode (const char *in, unsigned inlen, char *out, unsigned o *out = '\0'; } - char *base64 (const char *input, int length) { char *buff = (char *) malloc (4 * length + 1); @@ -73,4 +72,4 @@ char *base64 (const char *input, int length) base64_encode (input, length, buff, 4 * length + 1); return buff; -} +} diff --git a/build.sh b/build.sh index a49fbf3..87ccdb0 100755 --- a/build.sh +++ b/build.sh @@ -80,6 +80,14 @@ then fi if [ "$1" = "iso" ] ; then + if [ "$2" = "gui" ] ; then + make -C apps/zde && + cp apps/zde/zde iso/ && + cp apps/zde/file iso/ && + cp apps/zde/border iso/ && + cp apps/zde/folder iso/ + fi + cp kernel/kernel.bin iso/boot/kernel.bin && cp README iso/README && mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 50 -boot-info-table -o zexos-$VERSION-$ARCH.iso iso && diff --git a/kernel/arch/i386/syscall.c b/kernel/arch/i386/syscall.c index d9bf288..b96079d 100644 --- a/kernel/arch/i386/syscall.c +++ b/kernel/arch/i386/syscall.c @@ -218,7 +218,7 @@ void sys_write (struct regs *r) break; case 1: proc = proc_find (_curr_task); - + if (!proc) { ret = -1; break; @@ -233,7 +233,7 @@ void sys_write (struct regs *r) for (i = len; i >= 0; i --) setkey (buf[i]); - mem[len] = '\0'; + //mem[len] = '\0'; ret = len; break; @@ -387,11 +387,6 @@ void sys_time (struct regs *r) void sys_system (struct regs *r) { - task_t *task = task_find (0); - - if (!task) - return; - proc_t *proc = proc_find (_curr_task); if (!proc) diff --git a/kernel/core/commands.c b/kernel/core/commands.c index d078dae..f579484 100644 --- a/kernel/core/commands.c +++ b/kernel/core/commands.c @@ -411,6 +411,9 @@ unsigned command_exec (char *command, unsigned len) tty_t *tty = currtty; + if (!tty) + return 0; + /* lock current tty keyboard */ tty_lock (tty); @@ -889,14 +892,14 @@ extern unsigned end; extern bool ide_acthandler (unsigned act, partition_t *p, char *block, char *more, int n); unsigned command_test (char *command, unsigned len) { - partition_t *p = partition_find ("/dev/hdc0"); + partition_t *p = partition_find ("/dev/hda0"); if (p) - mount (p, "", "/mnt/cdrom/"); + mount (p, "", "/mnt/hdd/"); else return 0; - cd ("/mnt/cdrom"); + cd ("/mnt/hdd"); return 1; } @@ -904,6 +907,30 @@ extern char *vgafb; extern char *vgadb; unsigned command_test2 (char *command, unsigned len) { + partition_t *p = partition_find ("/dev/hdc0"); + + if (p) + mount (p, "", "/mnt/cdrom/"); + else + return 0; + + cd ("/mnt/cdrom"); + +/* tty_t *tty = tty_find ("tty0"); + + if (!tty) + return 0; + char str[513]; + int r = tty_read (tty, str, 512); + + if (r > 0) { + printf ("str: r: %d\n", r); + int i; + for (i = 0; i < r; i ++) + tty_putch (str[i]); + } + */ + /* int ret = vfs_read ("wav", 3); if (ret < 0) { @@ -1866,6 +1893,41 @@ unsigned command_ttyctrl (char *command, unsigned len) return 1; } +unsigned command_cmd (char *command, unsigned len) +{ + unsigned s = 0; + unsigned e = 0; + + if (!strlen (argparse (command))) { + printf ("cmd ;;...;\n"); + return 0; + } + + char *cmds = kmalloc (len - 3); + + if (!cmds) + return 0; + + memcpy (cmds, command + 4, len - 4); + cmds[len - 4] = '\0'; + + unsigned i; + for (i = 1; i < len - 4; i ++) { + if (cmds[i] == ';') { + cmds[i] = '\0'; + e = i-1; + + command_parser (cmds+s, e-s+1); + + s = i+1; + } + } + + kfree (cmds); + + return 1; +} + /*************************************************************\ | COMMAND's UTILS | \*************************************************************/ @@ -2040,6 +2102,7 @@ unsigned int init_commands () command_register ("adm", "Automatic Device Mounter", &command_adm, 0); command_register ("ttyctrl", "TTY Console control", &command_ttyctrl, 0); - + command_register ("cmd", "Execute command sequence", &command_cmd, 0); + return 1; } diff --git a/kernel/core/console.c b/kernel/core/console.c index cc61ac1..f230148 100644 --- a/kernel/core/console.c +++ b/kernel/core/console.c @@ -49,12 +49,22 @@ int cstrcmp (char *one, char *two) int gets (void) { +/* tty_t *tty = tty_find ("tty1"); + + if (tty) { + if (tty->task == _curr_task) + tty_write (tty, "je tam\n", 7); + } + if (currtty->task != _curr_task) return 0; - + */ + if (!currtty->active) + return 0; + char key = getkey (); - if (key != 0) { + if (key) { //DPRINT ("currtty->task %s | _curr_task %s\n", currtty->task->name, _curr_task->name); int i = 0; @@ -63,20 +73,17 @@ int gets (void) char c[1]; c[0] = key; - if (key == 8 && currtty->shell_len == 0 || key == 27) return i; if (currtty->shell_len < 64) tty_write (currtty, c, 1); - if (key == '\n') { // we press enter currtty->shell[currtty->shell_len] = '\0'; currtty->shell_len = 0; i = 1; - } - else { + } else { /* if you has wroted some text, and backspace is pressed, lets move cursor back */ if (key == '\b' && currtty->shell_len > 0) { currtty->shell_len --; // first we have to descrease text length @@ -102,9 +109,8 @@ unsigned consolelog_list () { consolelog_t *c; - for (c = clog_list.next; c != &clog_list; c = c->next) { + for (c = clog_list.next; c != &clog_list; c = c->next) printf ("%s\n", c->cmd); - } printf ("-> %d\n", clog_num); diff --git a/kernel/core/dev.c b/kernel/core/dev.c index a3281f7..2889e68 100644 --- a/kernel/core/dev.c +++ b/kernel/core/dev.c @@ -95,6 +95,8 @@ dev_t *dev_register (char *devname, char *desc, unsigned attrib, dev_handler_t * if (dev_find (devname)) return 0; + unsigned l = strlen (devname); + video_color (9, 0); kprintf (":"); @@ -104,6 +106,10 @@ dev_t *dev_register (char *devname, char *desc, unsigned attrib, dev_handler_t * dev_flags_t flags; memset (&flags, 0, sizeof (dev_flags_t)); + /* chance of getting device name on DEV_ACT_INIT */ + flags.iomem = (void *) devname; + flags.iolen = l; + vfs_t *vfs = (vfs_t *) 0; if (handler (DEV_ACT_INIT, (char *) &flags, sizeof (dev_flags_t))) { @@ -116,8 +122,10 @@ dev_t *dev_register (char *devname, char *desc, unsigned attrib, dev_handler_t * /* alloc and init context */ dev_t *dev = (dev_t *) kmalloc (sizeof (dev_t)); + + if (!dev) + return 0; - unsigned l = strlen (devname); memcpy (dev->devname, "/dev/", 5); memcpy (dev->devname+5, devname, l); dev->devname[l+5] = '\0'; diff --git a/kernel/core/ioctl.c b/kernel/core/ioctl.c index 2eeaef6..401abbc 100644 --- a/kernel/core/ioctl.c +++ b/kernel/core/ioctl.c @@ -59,6 +59,46 @@ int ioctl_call (unsigned id, void *buf, int l) return 0; } + case IOATAREAD: + { + struct ioatarq_t *io = buf; + + if (l != sizeof (struct ioatarq_t)) + return -1; + + dev_t *dev = dev_find (io->dev); + + if (!dev) + return -1; + + partition_t p; + p.base_io = 0; + + if (!dev->handler (DEV_ACT_READ, &p, io->data, "", io->sector)) + return -1; + + return 0; + } + case IOATAWRITE: + { + struct ioatarq_t *io = buf; + + if (l != sizeof (struct ioatarq_t)) + return -1; + + dev_t *dev = dev_find (io->dev); + + if (!dev) + return -1; + + partition_t p; + p.base_io = 0; + + if (!dev->handler (DEV_ACT_WRITE, &p, io->data, "", io->sector)) + return -1; + + return 0; + } } return 1; diff --git a/kernel/core/mm/usermem.c b/kernel/core/mm/usermem.c index 9b34f3b..9376f06 100644 --- a/kernel/core/mm/usermem.c +++ b/kernel/core/mm/usermem.c @@ -229,12 +229,12 @@ void *urealloc (proc_t *proc, void *ptr, size_t size) } int s = (int) (malloc->next - ptr) + p; -printf ("s: %d size: %d\n", s, size); + if (s >= size) { ufree (proc, ptr); return 0; } -printf ("err\n"); + char *ptr_new = umalloc (proc, size); if (!ptr_new) { diff --git a/kernel/core/net/tcp.c b/kernel/core/net/tcp.c index 8e84fac..52e1c29 100644 --- a/kernel/core/net/tcp.c +++ b/kernel/core/net/tcp.c @@ -94,7 +94,7 @@ int net_proto_tcp_connect (int fd, sockaddr_in *addr) if (!ret) return -1; - while (1) { + for (;;) { schedule (); /* timeout for 8s */ @@ -228,9 +228,7 @@ int net_proto_tcp_close (int fd) if (conn->state == PROTO_TCP_CONN_STATE_DISCONNECTED) return 0; - int ret = net_proto_tcp_conn_close (conn); - - return ret; + return net_proto_tcp_conn_close (conn); } int net_proto_tcp_fcntl (int fd, int cmd, long arg) @@ -444,13 +442,13 @@ unsigned net_proto_tcp_handler (packet_t *packet, proto_ip_t *ip, char *buf, uns /* another side close connection */ if (tcp->flags & 0x01) { - DPRINT ("TCP -> fd %d connection closed by remote host\n", conn->fd); + DPRINT ("TCP -> fd %d connection closed by remote host", conn->fd); net_proto_tcp_conn_disconnected (conn, ip, tcp); // FIXME: problem in server with hangind the whole program } /* another side close connection */ if (tcp->flags & 0x04) { - DPRINT ("TCP -> fd %d connection reseted by peer\n", conn->fd); + DPRINT ("TCP -> fd %d connection reseted by peer", conn->fd); net_proto_tcp_conn_disconnected (conn, ip, tcp); } @@ -668,7 +666,7 @@ int net_proto_tcp_write_data (proto_tcp_conn_t *conn, char *data, unsigned len) conn->cross = 0; } - //printf ("TCP -> seq: 0x%x | ack: 0x%x | proto_seq: 0x%x\n", tcp->seq, conn->ack, proto_tcp_seq); +// printf ("TCP -> seq: 0x%x | ack: 0x%x | proto_seq: 0x%x\n", tcp->seq, conn->ack, proto_tcp_seq); tcp->res = 0; tcp->data_offset = 5; @@ -814,9 +812,14 @@ int net_proto_tcp_conn_disconnected (proto_tcp_conn_t *conn, proto_ip_t *ip_old, int net_proto_tcp_conn_close (proto_tcp_conn_t *conn) { + return 0; /* FIXME: close () is faster then send () sometime :-B */ + if (!conn) return 0; + if (conn->state == PROTO_TCP_CONN_STATE_CLOSE) + return 0; + proto_tcp_t *tcp = (proto_tcp_t *) kmalloc (sizeof (proto_tcp_t)); if (!tcp) @@ -838,9 +841,8 @@ int net_proto_tcp_conn_close (proto_tcp_conn_t *conn) kfree (tcp); - if (ret) { + if (ret) conn->state = PROTO_TCP_CONN_STATE_CLOSE; - } return ret; } diff --git a/kernel/core/net/tcp6.c b/kernel/core/net/tcp6.c index 75246ce..7a81bff 100644 --- a/kernel/core/net/tcp6.c +++ b/kernel/core/net/tcp6.c @@ -858,9 +858,14 @@ int net_proto_tcp6_conn_disconnected (proto_tcp6_conn_t *conn, proto_ipv6_t *ip_ int net_proto_tcp6_conn_close (proto_tcp6_conn_t *conn) { + return 0; /* FIXME: close () is faster then send () sometime :-B */ + if (!conn) return 0; + if (conn->state == PROTO_TCP_CONN_STATE_CLOSE) + return 0; + proto_tcp_t *tcp = (proto_tcp_t *) kmalloc (sizeof (proto_tcp_t)); if (!tcp) diff --git a/kernel/core/tty.c b/kernel/core/tty.c index 7f95695..48d0e74 100644 --- a/kernel/core/tty.c +++ b/kernel/core/tty.c @@ -80,7 +80,6 @@ bool tty_cls (tty_t *tty) tty->screen_x = 0; tty->screen_y = 0; - tty->read_len = 0; if (tty != currtty) return 1; @@ -241,6 +240,29 @@ void tty_listview () } } +/* enable logging for TTY */ +int tty_log_create (tty_t *tty, unsigned short len) +{ + if (!tty || !len) + return 0; + + tty->log = (tty_log_t *) kmalloc (sizeof (tty_log_t)); + + if (!tty->log) + return 0; + + tty->log->buf = (char *) kmalloc (sizeof (char) * len); + + if (!tty->log->buf) { + kfree (tty->log); + return 0; + } + + tty->log->len = 0; + + return 1; +} + /* main function for print strings into selected tty */ bool tty_write (tty_t *tty, char *str, unsigned len) { @@ -272,27 +294,48 @@ int tty_read (tty_t *tty, char *str, unsigned len) unsigned x = 0; unsigned y = 0; - if (len+tty->read_len > n) - len = n-tty->read_len; - - for (l = 0; l < len; l ++) { - if (p[((l+tty->read_len)*2)+1]) - str[l] = p[((l+tty->read_len)*2)+1]; + //if (tty->read_len > n) + // len = n-tty->read_len; +//printf ("len: %d : %d\n", len, tty->read_len); + unsigned i = 0; + +/* for (l = 0; l < len; l ++) { + if (p[(l+tty->read_len)*2]) + str[i ++] = p[(l+tty->read_len)*2]; x ++; if (x >= tty_char.x) { x = 0; y ++; - str[l] = '\n'; + str[i ++] = '\n'; } + + } - str[l] = '\0'; + str[++ i] = '\0'; - tty->read_len += l; + tty->read_len += l;*/ - return l; + /*if (len > tty->read_len) + len = tty->read_len; + + for (l = 0; l < len; l ++) { + char c = p[((tty->screen_y * tty_char.x) + tty->screen_x - len + l)*2]; + + if (c) + str[i ++] = c; + else + str[i ++] = ' '; + + } + + str[i] = '\0'; + + tty->read_len -= len;*/ + + return i; } /* print character to current tty */ @@ -309,7 +352,7 @@ bool tty_putnch (tty_t *tty, char c) /* we wont null character */ if (!c) return 0; - + switch (c) { case '\n': tty->screen_y ++; @@ -323,9 +366,10 @@ bool tty_putnch (tty_t *tty, char c) tty->screen[(tty->screen_x+(tty->screen_y*tty_char.x))*2] = ' '; /* save character into buffer */ tty->screen[((tty->screen_x+(tty->screen_y*tty_char.x))*2)+1] = attrib; + break; case '\t': - tty->screen_x = (tty->screen_x + 8) & ~(8 - 1); + tty->screen_x = (tty->screen_x + 8) & ~7; break; default: /* save font attributes (colors) */ @@ -350,8 +394,6 @@ bool tty_putnch (tty_t *tty, char c) for (i = 0; i < (tty_char.x * tty_char.y * 2); i ++) tty->screen[i] = con_screen[i]; - tty->read_len += tty_char.x; - tty->screen_y = tty_char.y - 1; } @@ -389,6 +431,36 @@ bool tty_motd () return 1; } +/* virtual terminal (device handler) */ +bool vterm_acthandler (unsigned act, char *block, unsigned block_len) +{ + switch (act) { + case DEV_ACT_INIT: + { + dev_flags_t *flags = (dev_flags_t *) block; + + if (!flags) + return 0; + + if (block_len != sizeof (dev_flags_t)) + return 0; + + tty_t *tty = tty_find ((char *) flags->iomem); + + if (!tty) + return 0; + + flags->iomem = (void *) tty->screen; + flags->iolen = tty_char.x * tty_char.y * 2; + + return 1; + } + break; + } + + return 0; +} + /* create new tty console */ tty_t *tty_create () { @@ -436,7 +508,7 @@ tty_t *tty_create () tty->active = true; - tty->read_len = 0; + tty->log = 0; strcpy (tty->pwd, (char *) env_get ("PWD")); @@ -448,6 +520,9 @@ tty_t *tty_create () tty->prev->next = tty; tty->next->prev = tty; + /* create device which correspnd with current TTY */ + dev_register (name, "Virtual terminal", DEV_ATTR_CHAR, (dev_handler_t *) &vterm_acthandler); + tty_count ++; return tty; @@ -507,7 +582,7 @@ static unsigned task_tty () if (!tty) return 0; - while (1) + for (;;) task_thread (tty); } @@ -597,8 +672,9 @@ unsigned int init_tty () /* then print login messages */ tty_write (tty0, "\nlogin: ", 8); +#ifdef ARCH_i386 tty_write (tty1, "\nlogin: ", 8); - +#endif return 1; } diff --git a/kernel/drivers/fs/ext2.c b/kernel/drivers/fs/ext2.c index c3fce6c..af351e4 100644 --- a/kernel/drivers/fs/ext2.c +++ b/kernel/drivers/fs/ext2.c @@ -226,7 +226,7 @@ unsigned ext2_block_read (partition_t *p, ext2_inode_t *inode, vfs_content_t *co if (!cache) return 0; - while (1) { + for (;;) { /* first 12 address are direct and next are from indirect block */ if (i < 12) address = inode->block[i]; @@ -284,7 +284,7 @@ unsigned ext2_block_write (partition_t *p, ext2_inode_t *inode) return 0; } - while (1) { + for (;;) { /* write 512 bytes block from file_cache */ lba28_drive_write (p, address+i, &cache->data+len); @@ -341,12 +341,22 @@ unsigned ext2_inode_write (partition_t *p, ext2_inode_t *inode, unsigned id) unsigned group_num = (id - 1) / superblock->inodes_per_group; unsigned id_new = (id - 1) % superblock->inodes_per_group; - char *block = (char *) inode; + ext2_inode_t *block = (ext2_inode_t *) kmalloc (1024); + if (!block) { + kfree (group); + return 0; + } + + ext2_sector_read (p, group[group_num].inode_table, (unsigned char *) block); + + memcpy (&block[id_new], inode, sizeof (ext2_inode_t)); + ext2_sector_write (p, group[group_num].inode_table, (unsigned char *) block); //DPRINT ("inode -> %d / %d - 0x%x - %d - %d - %d", superblock->inodes_per_group, id_new, inode[id_new].mode, inode[id_new].ctime, inode[id_new].size, inode[id_new].block[0]); + kfree (block); kfree (group); return 1; @@ -366,12 +376,12 @@ unsigned ext2_dir_scan (partition_t *p, ext2_inode_t *inode) unsigned dir_next = 0; unsigned entry = 0; - while (1) { + for (;;) { ext2_dir_t *dir_new = (ext2_dir_t *) ((void *) ext2dir + dir_next); DPRINT ("dir -> 0x%x : %d - %d - %d - %s - %d", dir_new, dir_new->inode, dir_new->rec_len, dir_new->name_len, dir_new->name, dir_new->file_type); - if (!dir_new->rec_len || !dir_new->inode) + if (!dir_new->rec_len || !dir_new->inode || dir_next >= 1024) break; /* we won't unknown file type */ @@ -409,7 +419,7 @@ unsigned ext2_dir_scan (partition_t *p, ext2_inode_t *inode) return 1; } -unsigned ext2_create_file (partition_t *p, char *name) +unsigned ext2_create_entity (partition_t *p, char *name, unsigned char type) { if (!name) return 0; @@ -419,7 +429,7 @@ unsigned ext2_create_file (partition_t *p, char *name) if (!block) return 0; - DPRINT ("create_file -> %d : %s", inode_curr, name); + DPRINT ("ext2_create_entity -> %d : %s", inode_curr, name); /* read inode structure by current inode id number */ ext2_inode_t *inode = ext2_inode_read (p, block, inode_curr); @@ -441,16 +451,38 @@ unsigned ext2_create_file (partition_t *p, char *name) unsigned dir_next = 0; - while (1) { - ext2_dir_t *dir_new = (ext2_dir_t *) ((void *) ext2dir + dir_next); + for (;;) { + ext2_dir_t *dir_new = (ext2_dir_t *) ((char *) ext2dir + dir_next); - if (dir_new->rec_len || dir_new->inode) { + if (dir_new->rec_len && dir_new->inode) { dir_next += dir_new->rec_len; - continue; + printf ("dir_next: %d | %d | %d\n", dir_next, dir_new->rec_len, dir_new->inode); + + if (dir_next >= 1024) { + if (dir_new->rec_len < 264) { + printf ("ERROR -> out of dirent\n"); + break; + } + + dir_next -= dir_new->rec_len; + dir_new->rec_len = (dir_new->name_len+9) <= 12 ? 12 : 20; + dir_next += dir_new->rec_len; + printf ("dir_new->rec_len: %d dir_next: %d\n", dir_new->rec_len, dir_next); + + int inode = dir_new->inode + 1; + + if (type == EXT2_FT_DIR) + inode += 2000; + + dir_new = (ext2_dir_t *) ((char *) ext2dir + dir_next); + + dir_new->inode = inode; + } else + continue; } /* set the file type */ - dir_new->file_type = EXT2_FT_REG_FILE; + dir_new->file_type = type; unsigned name_len = strlen (name); @@ -460,33 +492,13 @@ unsigned ext2_create_file (partition_t *p, char *name) /* yeah :( .. limit to 10 characters for dir[] entry */ memcpy (dir_new->name, name, name_len); dir_new->name_len = name_len; + dir_new->rec_len = 1024 - dir_next; ext2_inode_t *inode_new = (ext2_inode_t *) kmalloc (sizeof (ext2_inode_t)); if (!inode_new) return 0; -/* - unsigned short mode; - unsigned short uid; - unsigned size; - unsigned atime; - unsigned ctime; - unsigned mtime; - unsigned dtime; - unsigned short gid; - unsigned short links_count; - unsigned blocks; - unsigned flags; - unsigned osd1; - unsigned block[15]; - unsigned generation; - unsigned file_acl; - unsigned dir_acl; - unsigned faddr; - unsigned char osd2[12]; -*/ - tm *t = rtc_getcurrtime (); inode_new->mode = 0; @@ -501,18 +513,25 @@ unsigned ext2_create_file (partition_t *p, char *name) inode_new->blocks = 0; inode_new->flags = 0; inode_new->osd1 = 0; - inode_new->block[0] = block_free; + + if (dir_new->file_type != EXT2_FT_DIR) + inode_new->block[0] = block_free; + else + inode_new->block[0] = 0; - if (!ext2_inode_write (p, inode_new, dir_new->inode+1)) { + if (!ext2_inode_write (p, inode_new, dir_new->inode)) { kfree (ext2dir); kfree (block); return 0; } + + /* write direct block */ + ext2_sector_write (p, inode->block[0], (unsigned char *) ext2dir); block_free += 32; - DPRINT ("dir -> dir_new->inode: %d", dir_new->inode); + DPRINT ("dir -> dir_new->inode: %d | %d | %d", dir_new->inode, dir_new->rec_len, sizeof (ext2_inode_t)); kfree (inode_new); @@ -600,10 +619,10 @@ unsigned ext2_cd (partition_t *p, char *name) unsigned name_len = strlen (name); /* loop for find name of directory, where we want go */ - while (1) { + for (;;) { ext2_dir_t *dir_new = (ext2_dir_t *) ((void *) ext2dir + dir_next); - if (!dir_new->rec_len || !dir_new->inode) + if (!dir_new->rec_len || !dir_new->inode || dir_next >= 1024) break; DPRINT ("dir -> 0x%x : %d - %d - %d - %s", dir_new, dir_new->inode, dir_new->rec_len, dir_new->name_len, dir_new->name); @@ -670,10 +689,10 @@ unsigned ext2_cat (partition_t *p, char *name, vfs_content_t *content) unsigned dir_next = 0; unsigned name_len = strlen (name); - while (1) { + for (;;) { ext2_dir_t *dir_new = (ext2_dir_t *) ((void *) ext2dir + dir_next); - if (!dir_new->rec_len || !dir_new->inode) + if (!dir_new->rec_len || !dir_new->inode || dir_next >= 1024) break; /* check for file type - regular file */ @@ -736,10 +755,10 @@ unsigned ext2_write_file (partition_t *p, char *name) unsigned dir_next = 0; unsigned name_len = strlen (name); - while (1) { + for (;;) { ext2_dir_t *dir_new = (ext2_dir_t *) ((void *) ext2dir + dir_next); - if (!dir_new->rec_len || !dir_new->inode) + if (!dir_new->rec_len || !dir_new->inode || dir_next >= 1024) break; /* check for file type - regular file */ @@ -816,7 +835,7 @@ unsigned mkext2 (partition_t *p) /* read group decriptor */ ext2_sector_write (p, 2, (unsigned char *) group); - DPRINT ("group -> %d - %d - %d\n", group[0].block_bitmap, group[0].inode_bitmap, group[0].inode_table); + DPRINT ("group -> %d - %d - %d", group[0].block_bitmap, group[0].inode_bitmap, group[0].inode_table); /* inode tables */ ext2_inode_t *inode = (ext2_inode_t *) kmalloc (1024); @@ -898,17 +917,17 @@ bool ext2_handler (unsigned act, char *block, unsigned n, unsigned long l) return (bool) ext2_cd_root (curr_part); /* walk to another directory */ - return (bool) ext2_cd (curr_part, dir[n].name); + return (bool) ext2_cd (curr_part, block); } break; case FS_ACT_MKDIR: { - return 0; + return ext2_create_entity (curr_part, block, EXT2_FT_DIR); } break; case FS_ACT_TOUCH: { - return 0; + return ext2_create_entity (curr_part, block, EXT2_FT_REG_FILE); } } diff --git a/kernel/include/ioctl.h b/kernel/include/ioctl.h index 784b743..4c29448 100644 --- a/kernel/include/ioctl.h +++ b/kernel/include/ioctl.h @@ -30,8 +30,16 @@ struct ioifaddr_t { net_ipv6 ipv6; }; +struct ioatarq_t { + unsigned char dev[16]; + unsigned sector; + unsigned char data[512]; +}; + #define IOIFADDRSET 1 #define IOIFADDRGET 2 +#define IOATAREAD 3 +#define IOATAWRITE 4 /* externs */ extern int ioctl_call (unsigned id, void *buf, int l); diff --git a/kernel/include/tty.h b/kernel/include/tty.h index 3ce5f4e..8795552 100644 --- a/kernel/include/tty.h +++ b/kernel/include/tty.h @@ -26,6 +26,8 @@ #include #include +#define FD_TERM 0x2000 + #define TTY_CON_BUF 16000 #define TTY_COUNT_MAX 1024 #define TTY_SCREEN_RES_VGA 4000 @@ -44,6 +46,12 @@ typedef struct { unsigned short y; } tty_char_t; +/* log for read () op purposes */ +typedef struct { + char *buf; + unsigned short len; +} tty_log_t; + /* Device structure */ typedef struct tty_context { struct tty_context *next, *prev; @@ -59,7 +67,7 @@ typedef struct tty_context { bool logged; char pwd[64]; bool active; - unsigned short read_len; + tty_log_t *log; } tty_t; /* externs */ diff --git a/kernel/lib/stdio/open.c b/kernel/lib/stdio/open.c index 47aa201..bc9acd5 100644 --- a/kernel/lib/stdio/open.c +++ b/kernel/lib/stdio/open.c @@ -103,7 +103,7 @@ int open (const char *pathname, int flags) fd->dev = dev_find ((char *) pathname); - if (flags & O_RDONLY) { + if (flags & O_RDONLY || flags & O_RDWR) { vfs_content_t content; int ret = vfs_read ((char *) fd->path, fi_len, &content); diff --git a/kernel/lib/stdio/read.c b/kernel/lib/stdio/read.c index 5e2a3b5..96d1506 100644 --- a/kernel/lib/stdio/read.c +++ b/kernel/lib/stdio/read.c @@ -39,6 +39,9 @@ int read (unsigned fd, void *buf, unsigned len) if (d->flags & O_WRONLY) return 0; + + if (!d->s) + return 0; if (d->flags & FD_PIPE) { pipe_t *p = pipe_get (fd); diff --git a/kernel/lib/stdio/write.c b/kernel/lib/stdio/write.c index aa58288..70ddfe3 100644 --- a/kernel/lib/stdio/write.c +++ b/kernel/lib/stdio/write.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,44 @@ int write (unsigned fd, void *buf, unsigned len) else return 0; } + + if (d->flags & FD_TERM) { + tty_t *ttyold = currtty; + tty_t *tty = 0; + + if (d->dev) + tty = tty_find (d->dev->devname+5); + + if (tty) + tty_change (tty); + else + return -1; + + //task_t *taskold = _curr_task; + //_curr_task = tty->task; + + char *str = (char *) buf; + + int i = 0; + + for (i = len; i >= 0; i --) + setkey (str[i]); + + int id = gets (); + + if (id == 1) { + if (tty->user) { + console (id); + } else + getlogin (id); + } + + //_curr_task = taskold; + + tty_change (ttyold); + + return 1; + } char *file = d->path; diff --git a/libc/include/sys/ioctl.h b/libc/include/sys/ioctl.h index 6098070..d3861f9 100644 --- a/libc/include/sys/ioctl.h +++ b/libc/include/sys/ioctl.h @@ -27,8 +27,16 @@ struct ioifaddr_t { struct in6_addr ipv6; }; +struct ioatarq_t { + unsigned char dev[16]; + unsigned sector; + unsigned char data[512]; +}; + #define IOIFADDRSET 1 #define IOIFADDRGET 2 +#define IOATAREAD 3 +#define IOATAWRITE 4 extern int ioctl (unsigned id, void *buf, int l); -- 2.11.4.GIT