diff --git a/include/command.h b/include/command.h index f480033..afe6b03 100644 --- a/include/command.h +++ b/include/command.h @@ -13,6 +13,7 @@ #include #include + #define HELP_HELP "Shows this help function" #define HELP_RESTART "Restarts the OS" @@ -314,4 +315,8 @@ void testHeap(); int DMTest2(int argc, char **argv); +int processInfo_cmd(int argc, char **argv); + +int sudo_cmd(int argc, char **argv); + #endif diff --git a/include/defs.h b/include/defs.h index 1c4ee75..1a29e06 100644 --- a/include/defs.h +++ b/include/defs.h @@ -54,6 +54,7 @@ typedef void* type_t; #define SYSTEM_OPEN 5 #define SYSTEM_YIELD 6 #define SYSTEM_CLOSE 7 +#define SYSTEM_ADDSTACK 8 #define SYSTEM_USERLIST 9 #define SYSTEM_USERADD 10 @@ -86,6 +87,7 @@ typedef void* type_t; #define E_FILE_NOT_EXISTS -8 #define E_DIR_NOT_EXISTS -9 #define E_MAX_FD_REACHED -10 +#define E_FILE_IS_DIR -11 #define MAX_NAME_LENGTH 24 diff --git a/include/interrupts/interrupts.h b/include/interrupts/interrupts.h index c0b58c3..9867852 100644 --- a/include/interrupts/interrupts.h +++ b/include/interrupts/interrupts.h @@ -2,13 +2,12 @@ #define INTERRUPTS_H #include -#include -#include -#include #include -#include -#include +#include +#include #include +#include + void initBasicHandlers(); diff --git a/include/lib/unistd.h b/include/lib/unistd.h index bd4625c..ca686f4 100644 --- a/include/lib/unistd.h +++ b/include/lib/unistd.h @@ -45,4 +45,11 @@ int lseek(int fildes, int offset, int oflag); **/ int mkfifo(char *name, int mode); +/* growStack +* +* No recibe parámetros +* +* Aumenta el stack del proceso actual +**/ +int growStack(); #endif diff --git a/include/session.h b/include/session.h index a7840a6..6b482b7 100644 --- a/include/session.h +++ b/include/session.h @@ -21,4 +21,8 @@ PUBLIC int session_getEuid(); PUBLIC int session_getEgid(); +PUBLIC void session_sudoEnd(); + +PUBLIC void session_sudoStart(); + #endif diff --git a/include/shell.h b/include/shell.h index 585f557..57633ef 100644 --- a/include/shell.h +++ b/include/shell.h @@ -28,5 +28,9 @@ cmd_table_entry* shell_getCmdsTable(); int shell_getCmdIndex(char * cmdName); +void excecuteCmd(int cmd, char* buffer); + +int parse_cmd(char* buffer); + #endif diff --git a/include/tty.h b/include/tty.h index 03d5609..5edd195 100644 --- a/include/tty.h +++ b/include/tty.h @@ -16,10 +16,10 @@ typedef struct { int id; int pid; char* screen; + int screenOffset; int offset; c_buffer_t input_buffer; char buffer[TTY_BUFFER_SIZE]; - int bufferOffset; u32int currDirectory; char currPath[64]; int currPathOffset; diff --git a/src/access/user.c b/src/access/user.c index 0e015ad..fae4c25 100644 --- a/src/access/user.c +++ b/src/access/user.c @@ -12,7 +12,7 @@ PRIVATE boolean user_add(int uid); PRIVATE boolean user_del(int uid); PRIVATE boolean user_isValidFormat(char *token); PRIVATE boolean createUserDir(int uid); -PRIVATE boolean deleteUserDir(int uid); +//PRIVATE boolean deleteUserDir(int uid); PRIVATE void flushList(); PRIVATE void loadList(); @@ -217,9 +217,11 @@ PRIVATE void flushList() { char userstring[128]; for (int i = 0; i < USER_MAX; ++i) { user_string(i, userstring); - write_fs(passwd, offset, strlen(userstring) + 1, (u8int*) userstring); - offset += strlen(userstring) + 1; - write_fs(passwd, offset++, 1, (u8int*)"\n"); + if (strlen(userstring)) { + write_fs(passwd, offset, strlen(userstring), (u8int*) userstring); + offset += strlen(userstring); + write_fs(passwd, offset++, 1, (u8int*)"\n"); + } } } @@ -313,9 +315,9 @@ PRIVATE boolean createUserDir(int uid) { } } -PRIVATE boolean deleteUserDir(int uid) { - return false; -} +//PRIVATE boolean deleteUserDir(int uid) { +// return false; +//} PUBLIC boolean do_useradd(char *userName, char *password) { boolean addOk = true; diff --git a/src/command.c b/src/command.c index 9eeb8b9..aa20478 100644 --- a/src/command.c +++ b/src/command.c @@ -169,10 +169,10 @@ int kill_cmd(int argc, char**argv) { if (err == NULL) { // No error kill(pid); } else { - printf("Could not kill %d: %s", pid, err); + printf("Could not kill %d: %s\n", pid, err); } } else { - printf("Usage:\nkill PID"); + printf("Usage:\nkill PID\n"); } return 0; } @@ -452,6 +452,7 @@ int touch_cmd(int argc, char **argv) { } if (errno != 0) { printf("touch: cannot create file %s: %s\n", argv[0], err); + return -1; } if (argc == 2) { TTY* tty = tty_getCurrentTTY(); @@ -693,18 +694,26 @@ int cp_cmd(int argc, char **argv) { case E_FILE_EXISTS: err = "file already exists"; break; + case E_FILE_IS_DIR: + err = "File is a directory! (use -r)"; + break; default: err = "no se que paso!"; log(L_ERROR, "no se q paso: %d", errno); } if (err != NULL) { - printf("cp: could not copy %s: %s", source, err); + printf("cp: could not copy %s: %s\n", source, err); return -1; } return 0; } else { printf("cp: Source file: %s does not exists\n", source); } + } else { + tty_setFormatToCurrTTY(video_getFormattedColor(RED, BLACK)); + printf("cp: This feature does not come with Gat O.S. free trial edition.\n"); + tty_setFormatToCurrTTY(video_getFormattedColor(MAGENTA, BLACK)); + printf("\t\t\tConsider Purchasing it - Ask for teacher discounts!!\n"); } return -1; } @@ -715,6 +724,8 @@ int mv_cmd(int argc, char **argv) { if (copied == 0) { rm_cmd(1, &argv[0]); } + } else { + cp_cmd(4, NULL); } return 0; } @@ -751,3 +762,23 @@ int nice_cmd(int argc, char **argv) { } return -1; } + +int sudo_cmd(int argc, char **argv) { + session_sudoStart(); + int i; + char buffer[128]; + int totalLen = 0; + for(i = 0; i < argc; i++) { + int len = strlen(argv[i]); + strcpy(buffer + totalLen, argv[i]); + strcpy(buffer + totalLen + 1, " "); + totalLen += len + 1; + } + int cmd = parse_cmd(argv[0]); + if (cmd != -1) { + log(L_DEBUG, "parsed command: %d - %s", cmd, argv[0]); + excecuteCmd(cmd, buffer); + } + session_sudoEnd(); + return 0; +} diff --git a/src/fs/fs.c b/src/fs/fs.c index 1cc1ea0..b4f4817 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c @@ -117,7 +117,8 @@ PRIVATE void fs_create() { fs_node_t root; fs_getRoot(&root); fs_createdir(&root, "dev", FS_DIRECTORY); - fs_createdir(&root, "home", FS_DIRECTORY); + u32int home = fs_createdir(&root, "home", FS_DIRECTORY); + fs_setFileMode(home, 0x777); fs_createdir(&root, "etc", FS_DIRECTORY); } @@ -395,8 +396,8 @@ PUBLIC void fs_setFileGid(u32int inode, int gid) { } PUBLIC void fs_clone(fs_node_t *folder, fs_node_t *node, char *name) { - if (FILE_TYPE(folder->mask) != FS_DIRECTORY) { - errno = E_INVALID_ARG; + if (FILE_TYPE(node->mask) == FS_DIRECTORY) { + errno = E_FILE_IS_DIR; return; } int created = fs_createdir(folder, name, FILE_TYPE(node->mask)); diff --git a/src/interrupts/handlers.c b/src/interrupts/handlers.c index 89b759a..bc7e94c 100644 --- a/src/interrupts/handlers.c +++ b/src/interrupts/handlers.c @@ -1,5 +1,9 @@ #include +#include +#include +#include +extern PUBLIC void _expandStack(); extern void switchProcess(void); int taskSwitch = true; static int ticksSinceLasfFlush = 0; @@ -104,8 +108,10 @@ void *systemCallHandler(int sysCallNumber, void ** args) { case SYSTEM_CLOSE: ret = (void*)sysClose((char*)args[0], (int)args[1], (int)args[2]); break; + case SYSTEM_ADDSTACK: + _expandStack(); + break; } - return ret; } // This gets called from our ASM interrupt handler stub. diff --git a/src/lib/fifo.c b/src/lib/fifo.c index f600b96..b03ed98 100644 --- a/src/lib/fifo.c +++ b/src/lib/fifo.c @@ -2,7 +2,7 @@ #include #include -#define MAX_FIFOS 1 +#define MAX_FIFOS 3 PRIVATE fifo_t fifos[MAX_FIFOS]; @@ -99,9 +99,9 @@ u32int fifo_write(fs_node_t *node, u32int offset, u32int size, u8int *buffer) { while(fifo->offset < size) ; // FIXME: The writer should be set to BLOCKED here... sem_signal(&fifo->writers); // notify waiting writers the fifo is ready - // TODO: close pipe.... if (fifo->writers.count == 1) { // If last writer... fifo->offset = 0; + fifo->inode = -1; } return size; } diff --git a/src/lib/unistd.c b/src/lib/unistd.c index 595b1de..537b2e5 100644 --- a/src/lib/unistd.c +++ b/src/lib/unistd.c @@ -3,6 +3,11 @@ #include #include +int growStack() { + _SysCall(SYSTEM_ADDSTACK); + return 0; +} + int open(const char *path, int oflags, ...) { int create_flags = -1; if (oflags & O_CREAT) { diff --git a/src/memory/paging.c b/src/memory/paging.c index 8f79e2e..b0496f1 100644 --- a/src/memory/paging.c +++ b/src/memory/paging.c @@ -71,7 +71,7 @@ void paging_init() { } void _logPage(page_t page, int i, int j) { - log(L_INFO, "%d:%d (0x%x): f:0x%x ( %s%s%s%s) r:0x%x", + log(L_TRACE, "%d:%d (0x%x): f:0x%x ( %s%s%s%s) r:0x%x", i, j, (i<<22)|(j<<12), @@ -156,7 +156,6 @@ PRIVATE u32int create_stack(void *new_stack_start, u32int size) { for (i = (u32int) new_stack_start; i >= ((u32int) new_stack_start - size -1); i -= PAGE_SIZE) { // General-purpose stack is in user-mode. - log(L_DEBUG, "alloc 0x%x", i); alloc_frame(get_page(i, 1, current_directory), 1 /* User mode */, 1 /* Is writable */ ); } @@ -169,7 +168,7 @@ PRIVATE u32int create_stack(void *new_stack_start, u32int size) { for (i = (u32int) new_stack_start; i >= ((u32int) new_stack_start - size -1); i -= PAGE_SIZE) { _logPage(*get_page(i, 0, current_directory), 0, 0); - } + } return i+PAGE_SIZE; } @@ -180,7 +179,6 @@ PUBLIC int paging_dropStack(int stack_startaddr, int stacksize) { PUBLIC int paging_reserveStack(int size) { static int OLD = 0x11FFF000; static int inc = 0x00100000; - log(L_DEBUG, "????? 0x%x p:%d", OLD, size/PAGE_SIZE); int a = create_stack((void*)OLD, size); OLD -= inc; return a; diff --git a/src/process/scheduler.c b/src/process/scheduler.c index 6d859a9..f95a92e 100644 --- a/src/process/scheduler.c +++ b/src/process/scheduler.c @@ -6,9 +6,6 @@ PRIVATE PROCESS* _nextTask(int withPriority); PRIVATE void saveESP(int oldESP); PRIVATE void killChildren(int pid); -PRIVATE void showPages(PROCESS *process); -PRIVATE void showAllProcessInfo(); -PRIVATE void showStackInfo(PROCESS *process); void downPages(PROCESS *p); void upPages(PROCESS *p); /* @@ -27,13 +24,9 @@ PRIVATE int firstTime = true; extern page_directory_t *current_directory; extern u32int initial_esp; -PRIVATE void move_stack(void *new_stack_start, u32int size); PRIVATE int idle_cmd(int argc, char **argv); void scheduler_init(int withPriority) { - log(L_DEBUG, "PRE. ESP:0x%x, EBP:0x%x", _ESP, _EBP); - //move_stack((void*)0xE0000000, 0x2000); - log(L_DEBUG, "POST. ESP:0x%x, EBP:0x%x", _ESP, _EBP); count100 = 0; usePriority = withPriority; for (int i = 0; i < MAX_PROCESSES; i++) { @@ -115,11 +108,7 @@ int getNextProcess(int oldESP) { next->lastCalled = 0; if (!firstTime) { saveESP(oldESP); // en el oldESP esta el stack pointer del proceso - if (current->pid > MAX_TTYs) - log(L_INFO, "%s: ESPa: 0x%x", current->name, current->ESP); process_checkStack(); - if (current->pid > MAX_TTYs) - log(L_INFO, "%s: ESPb: 0x%x", current->name, current->ESP); } else { firstTime = false; } @@ -216,44 +205,9 @@ void scheduler_setCurrent(PROCESS* p) { } current = p; upPages(current); - //showAllProcessInfo(); } } -PRIVATE void showPages(PROCESS *process) { - page_t* page; - int pages = process->stacksize / PAGE_SIZE; // cuantas paginas tiene ese proceso - int up = 0, down = 0; - //direccion de memoria donde comienza el stack ( operacion inversa de create process ) - int mem_dir = process->stack; - for (int p = 0; p < pages; ++p) { - page = get_page(mem_dir, 0, current_directory); - if (page->present) { - up++; - } else { - down++; - } - mem_dir += PAGE_SIZE; // 4kb step! - } - log(L_INFO, "Paging: %d pages %d/%d (up/down)", pages, up, down); -} - -PRIVATE void showStackInfo(PROCESS *process) { - log(L_INFO, "Stack: start: 0x%x end: 0x%x size: 0x%x ESP: 0x%x", process->stack, process->stack + process->stacksize - 1, process->stacksize, process->ESP); -} - -PRIVATE void showAllProcessInfo() { - log(L_INFO, "-------------------------SHOWING ALL PROCESSES PAGES-------------------------"); - for (int i = 0; i < MAX_PROCESSES; i++) { - if (allProcess[i] != NULL) { - log(L_INFO, "%s %s Info:", (current == allProcess[i] ? "Current process" : "Process"), allProcess[i]->name); - showPages(allProcess[i]); - showStackInfo(allProcess[i]); - } - } - log(L_INFO, "--------------------FINISHED SHOWING ALL PROCESSES PAGES---------------------"); -} - void kill(int pid) { for (int i = 0; i < MAX_PROCESSES; i++) { if (allProcess[i] != NULL && allProcess[i]->pid == pid) { @@ -300,62 +254,10 @@ u32int scheduler_activeProcesses() { return active; } -PRIVATE void move_stack(void *new_stack_start, u32int size) -{ - u32int i; - // Allocate some space for the new stack. - for( i = (u32int)new_stack_start; - i >= ((u32int)new_stack_start-size); - i -= 0x1000) - { - // General-purpose stack is in user-mode. - alloc_frame( get_page(i, 1, current_directory), 0 /* User mode */, 1 /* Is writable */ ); - } - - // Flush the TLB by reading and writing the page directory address again. - u32int pd_addr; - __asm volatile("mov %%cr3, %0" : "=r" (pd_addr)); - __asm volatile("mov %0, %%cr3" : : "r" (pd_addr)); - - // Old ESP and EBP, read from registers. - u32int old_stack_pointer; __asm volatile("mov %%esp, %0" : "=r" (old_stack_pointer)); - u32int old_base_pointer; __asm volatile("mov %%ebp, %0" : "=r" (old_base_pointer)); - - // Offset to add to old stack addresses to get a new stack address. - u32int offset = (u32int)new_stack_start - initial_esp; - - // New ESP and EBP. - u32int new_stack_pointer = old_stack_pointer + offset; - u32int new_base_pointer = old_base_pointer + offset; - - // Copy the stack. - memcpy((void*)new_stack_pointer, (void*)old_stack_pointer, initial_esp-old_stack_pointer); - - // Backtrace through the original stack, copying new values into - // the new stack. - for(i = (u32int)new_stack_start; i > (u32int)new_stack_start-size; i -= 4) - { - u32int tmp = * (u32int*)i; - // If the value of tmp is inside the range of the old stack, assume it is a base pointer - // and remap it. This will unfortunately remap ANY value in this range, whether they are - // base pointers or not. - if (( old_stack_pointer < tmp) && (tmp < initial_esp)) - { - tmp = tmp + offset; - u32int *tmp2 = (u32int*)i; - *tmp2 = tmp; - } - } - - // Change stacks. - __asm volatile("mov %0, %%esp" : : "r" (new_stack_pointer)); - __asm volatile("mov %0, %%ebp" : : "r" (new_base_pointer)); -} - // a partir de un proceso dado setea como presentes o ausentes todas las paginas de un proceso ademas // de las paginas de sus ancestros -void flushPages (PROCESS *process , int action) { +void flushPages(PROCESS *process , int action) { PROCESS *proc_parent; int pages, mem_dir, p; page_t *page; diff --git a/src/session.c b/src/session.c index 7b895d6..92ffc62 100644 --- a/src/session.c +++ b/src/session.c @@ -7,6 +7,7 @@ #include PRIVATE user_t *currentUser = NULL; +PRIVATE user_t *sudoUser = NULL; void prntWelcomeMsg(); @@ -94,3 +95,18 @@ void prntWelcomeMsg() { currTty->fgColor = video_getFGcolor(format); printf("\n\n"); } + +PUBLIC void session_sudoStart() { + if (sudoUser == NULL) { + sudoUser = currentUser; + currentUser = user_get(SUPER_USER); + } +} + +PUBLIC void session_sudoEnd() { + if (sudoUser != NULL) { + currentUser = sudoUser; + sudoUser = NULL; + } +} + diff --git a/src/shell.c b/src/shell.c index 1eb4fda..8a4f523 100644 --- a/src/shell.c +++ b/src/shell.c @@ -16,8 +16,6 @@ tty_getTTY(tty)->currPath); int shell_readCommand(TTY* tty); -void excecuteCmd(int cmd, TTY* tty); -int parse_cmd(char* buffer); char** getArguments(char* buffer, int* argc, int *background); void cleanBuffer(TTY* tty); void printShellLabel(TTY* tty); @@ -36,53 +34,57 @@ cmd_table_entry cmd_table[] = { {"clear", HELP_CLEAR, clear_cmd}, {"getCPUspeed", HELP_GETCPUSPEED, getCPUspeed_cmd}, {"echo", HELP_ECHO, echo_cmd}, - {"cd", "switch current directory", cd_cmd}, - {"ls", "List information about the FILEs (the current directory by default).", ls_cmd}, - {"mkdir", "Create the DIRECTORY(ies), if they do not already exist.", mkdir_cmd}, - {"mkfifo", "Create named pipes (FIFOs) with the given NAMEs.", mkfifo_cmd}, + {"cd", "switch current directory: cd DIRECTORY", cd_cmd}, + {"ls", "List information about the FILEs (the current directory by default). Use -a modifier to show hidden files", ls_cmd}, + {"mkdir", "Create the DIRECTORY(ies), if they do not already exist: mkdir DIRECTORY", mkdir_cmd}, + {"mkfifo", "Create named pipes (FIFOs) with the given NAMEs: mkfifo FIFO", mkfifo_cmd}, {"pwd", "Show current user path", pwd_cmd}, - {"touch", "Creates a new empty file", touch_cmd}, - {"cat", "Shows the content for a specified filename", cat_cmd}, - {"ln", "make links between files", ln_cmd}, - {"rm", "Removes the file specified by the parameter", rm_cmd}, - {"cp", "Copy SOURCE to DEST", cp_cmd}, - {"mv", "Rename SOURCE to DEST", mv_cmd}, + {"touch", "Creates a new empty file: touch FILE CONTENT", touch_cmd}, + {"cat", "Shows the content for a specified filename: cat FILE", cat_cmd}, + {"ln", "make links between files: ln SOURCE TARGET", ln_cmd}, + {"rm", "Removes the file specified by the parameter: rm TARGET", rm_cmd}, + {"cp", "Copy SOURCE to DEST: cp SOURCE DEST", cp_cmd}, + {"mv", "Rename SOURCE to DEST: mv SOURCE DEST", mv_cmd}, {"logout", "Logout current user\n", logout}, {"top", "Shows the current running processes", top_cmd}, - {"kill", "Kills process with given PID", kill_cmd}, + {"kill", "Kills process with given PID: kill PID", kill_cmd}, {"infWhile", "Process that loops till the end of time!", eternumWhile_cmd}, - {"useradd", "usage: useradd USERNAME PASSWORD", shell_useradd}, - {"userdel", "usage: userdel USERNAME", shell_userdel}, - {"userlist", "usage: userlist", shell_userlist}, - {"usersetgid", "usage: usersetgid USERNAME GID", shell_usersetgid}, - {"groupadd", "usage: groupadd GROUP PASSWORD", shell_groupadd}, - {"groupdel", "usage: groupdel GROUP", shell_groupdel}, - {"grouplist", "usage: grouplist", shell_grouplist}, - {"chmod", "usage: OCTALMODE FILE", chmod_cmd}, - {"chown", "usage: USERNAME FILE", chown_cmd}, - {"chgrp", "usage: GROUPNAME FILE", chgrp_cmd}, - {"cache", "prints the fs cache status", cacheStatus_cmd}, + {"useradd", "Adds a user: useradd USERNAME PASSWORD", shell_useradd}, + {"userdel", "Deletes a user: userdel USERNAME", shell_userdel}, + {"userlist", "Lists all available users: userlist", shell_userlist}, + {"usersetgid", "Set's user group id: usersetgid USERNAME GID", shell_usersetgid}, + {"groupadd", "Adds a group: groupadd GROUP PASSWORD", shell_groupadd}, + {"groupdel", "Deletes a group: groupdel GROUP", shell_groupdel}, + {"grouplist", "Lists all available groups: grouplist", shell_grouplist}, + {"chmod", "Changes file permissions: chmod OCTALMODE FILE", chmod_cmd}, + {"chown", "Changes file owner: chown USERNAME FILE", chown_cmd}, + {"chgrp", "Changes file group: chgrp GROUPNAME FILE", chgrp_cmd}, + {"cache", "Prints the fs cache status", cacheStatus_cmd}, {"random", HELP_RANDOM, random_cmd}, - {"nice", "Run COMMAND with an adjusted niceness, which affects process scheduling", nice_cmd}, + {"sudo", "sudo", sudo_cmd}, + {"nice", "Run COMMAND with an adjusted niceness, which affects process scheduling: nice PID PRIORITY", nice_cmd}, // TESTS ==================================================================== - {"pfiles", "prints the files opened by the current process", pfiles}, - {"DMtest", "disk manager test", diskManagerTest}, - {"pitest", "pipes test", pipeTest_cmd}, - {"pageFault", "pageFault test", pageFault_cmd}, - {"infRec", "infinite recursion test", infRecursion_cmd}, - {"expStack", "expand stack test", testExpandStack_cmd}, - {"getchar", "getchar test", getchar_cmd}, + {"pfiles", "Prints the files opened by the specified process: pfiles PID", pfiles}, + {"DMtest", "Disk manager test, creates a very big file", diskManagerTest}, + {"pitest", "Pipe test: pitest r/w", pipeTest_cmd}, + {"pageFault", "Page fault test", pageFault_cmd}, + {"infRec", "Infinite recursion test", infRecursion_cmd}, + {"expStack", "Stack expand test", testExpandStack_cmd}, + {"getchar", "Getchar test", getchar_cmd}, + {"pInfo", "Shows all running processes stack and paging information", processInfo_cmd}, {"", "", NULL} }; void shell_update() { - // FIXME: not really nice... TTY* tty = tty_getTTY(scheduler_getCurrentProcess()->tty); if (!session_isLoggedIn()) { session_login(); } int cmd = shell_readCommand(tty); - excecuteCmd(cmd, tty); + if (cmd != -1) { + tty_setFormatToCurrTTY(video_getFormattedColor(LIGHT_BLUE, BLACK)); + excecuteCmd(cmd, tty->buffer); + } cleanBuffer(tty); } @@ -112,14 +114,14 @@ void shell_cleanScreen() { video_write(tty->screen, TOTAL_VIDEO_SIZE); } -void excecuteCmd(int cmd, TTY* tty) { +void excecuteCmd(int cmd, char* buffer) { + log(L_DEBUG, "buffer: %s", buffer); int cmdLen, argc; char **argv; if (cmd != -1) { - tty_setFormatToCurrTTY(video_getFormattedColor(LIGHT_BLUE, BLACK)); cmdLen = strlen(cmd_table[cmd].name); int background; - argv = getArguments(tty->buffer + cmdLen, &argc, &background); + argv = getArguments(buffer + cmdLen, &argc, &background); // log(L_DEBUG, "Running %s in %s", cmd_table[cmd].name, (background == true ? "background" : "foreground")); scheduler_schedule(cmd_table[cmd].name, cmd_table[cmd].func, argc, argv, DEFAULT_STACK_SIZE, tty_getCurrent(), (background == true ? BACKGROUND : FOREGROUND), READY, NORMAL); @@ -169,7 +171,7 @@ char** getArguments(char* buffer, int* argc, int *background) { } void cleanBuffer(TTY *tty) { - tty->bufferOffset = 0; + tty->screenOffset = 0; tty->buffer[0] = '\0'; } diff --git a/src/signal.c b/src/signal.c index 2277fdd..65d8329 100644 --- a/src/signal.c +++ b/src/signal.c @@ -8,14 +8,11 @@ void checkReset(); void checkTTY(); -void checkKill(char c) ; static int newTTY = -1; void signal_keyPressed(char c) { - checkKill(c); TTY* tty = tty_getCurrentTTY(); - PROCESS* tty_process = scheduler_getProcess(tty ->pid); PROCESS** allProc = scheduler_getAllProcesses(); if (tty_process->status == BLOCKED) { @@ -25,9 +22,13 @@ void signal_keyPressed(char c) { PROCESS* p = allProc[i]; if (p != NULL && p->tty == tty->id && p->status == BLOCKED && p->waitingFlags == W_INPUT) { - circularBuffer_add(&tty->input_buffer , c); - scheduler_setStatus(p->pid, READY); - log(L_DEBUG, "Sending input to process: %s", p->name); + if (IS_CTRL() && c == 'c') { + kill(p->pid); + } else { + circularBuffer_add(&tty->input_buffer , c); + scheduler_setStatus(p->pid, READY); + log(L_DEBUG, "Sending input to process: %s", p->name); + } return; } } @@ -71,12 +72,6 @@ void checkTTY() { } } -void checkKill(char c) { - if (IS_CTRL() && c == 'c') { - killCurrent(); - } -} - int signal(int signum) { PROCESS **processes = scheduler_getAllProcesses(); for(int i = 0; i < MAX_PROCESSES; i++) { diff --git a/src/test/test.c b/src/test/test.c index 4e7a110..164df1e 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -1,4 +1,7 @@ #include +#include + +extern page_directory_t *current_directory; int getchar_cmd(int argc, char **argv) { printf("Please type in a character\n"); @@ -111,7 +114,7 @@ extern PUBLIC void _expandStack(); int testExpandStack_cmd(int argc, char **argv) { log(L_INFO, "Expanding stack... Current ESP is 0x%x", _ESP); - _expandStack(); + growStack(); log(L_INFO, "Stack expanded... Current ESP is 0x%x", _ESP); printf("Stack expanded...\n"); return 0; @@ -139,9 +142,45 @@ int DMTest2(int argc, char **argv) { return 0; } +PRIVATE void showPages(PROCESS *process) { + page_t* page; + int pages = process->stacksize / PAGE_SIZE; // cuantas paginas tiene ese proceso + int up = 0, down = 0; + //direccion de memoria donde comienza el stack ( operacion inversa de create process ) + int mem_dir = process->stack; + for (int p = 0; p < pages; ++p) { + page = get_page(mem_dir, 0, current_directory); + if (page->present) { + up++; + } else { + down++; + } + mem_dir += PAGE_SIZE; // 4kb step! + } + printf("Paging: %d pages %d/%d (up/down)\n", pages, up, down); +} +PRIVATE void showStackInfo(PROCESS *process) { + printf("Stack: start: 0x%x end: 0x%x size: 0x%x ESP: 0x%x\n", process->stack, process->stack + process->stacksize - 1, process->stacksize, process->ESP); +} +PRIVATE void showAllProcessInfo() { + PROCESS **process = scheduler_getAllProcesses(); + PROCESS *current = scheduler_getCurrentProcess(); + + for (int i = 0; i < MAX_PROCESSES; i++) { + if (process[i] != NULL) { + printf("%s %s Info:\n", (current == process[i] ? "Current process" : "Process"), process[i]->name); + showPages(process[i]); + showStackInfo(process[i]); + } + } +} +int processInfo_cmd(int argc, char **argv) { + showAllProcessInfo(); + return 0; +} /////////////////// WAAAAARRRNINNNNGGGG!!!!! //////////////////////////// diff --git a/src/tty.c b/src/tty.c index 087c5f5..32736a8 100644 --- a/src/tty.c +++ b/src/tty.c @@ -30,7 +30,7 @@ void initTTY(int pid) { tty[index].screen[i + 1] = 0; } tty[index].offset = 0; - tty[index].bufferOffset = 0; + tty[index].screenOffset = 0; tty[index].bgColor = BLACK; tty[index].fgColor = WHITE; tty[index].pid = pid; diff --git a/testScript.txt b/testScript.txt new file mode 100644 index 0000000..f7170dc --- /dev/null +++ b/testScript.txt @@ -0,0 +1,102 @@ +Available commands: + help | restart + clear | getCPUspeed + echo | cd + ls | mkdir + mkfifo | pwd + touch | cat + ln | rm + cp | mv + logout | top + kill | infWhile + useradd | userdel + userlist | usersetgid + groupadd | groupdel + grouplist | chmod + chown | chgrp + cache | random + nice | pfiles + DMtest | pitest + pageFault | infRec + expStack | getchar + pInfo | + +Script +log with qcho (contraseña incorrecta y después correcta) +help +clear +ls +cd \ +ls +cd home +cd a +mkdir test +touch file1 +ls +cd test +ls +touch file2 +ls +reset +(back to start and show that files still exist) + + +PROCESOS +top +infWhile +top +nice (infWhile) 5 +top +(switch tty) +kill (infWhile pid) +infWhile () + +getchar (Blocked process) +(switch shell) +top (see that it's blocked) +(switch shell back) + + +PIPES +pitest w +pfiles +top +(change shell 2) +pitest r +(change shell 3) + +USERS & GROUPS +useradd pepe asd +logout +log with pepe +touch x a +ls (see that the owner is the new dude) + +FILES AND CACHE (REMEMBER TO TEST CACHE AFTER ANY "touch" or "ln") +touch b +cache (very quick to see dirty cache) +DMtest +cat "archivo de DMtest" +touch pepe kljrglekrjger;lkg +cat pepe +copy pepe pepe2 +cat pepe2 +mv pepe pepito +rm pepito +ls +touch .hidden wfwef +ls +ls -a +touch linked TestText +ln linked link +cat link +rm linked +cat link +rm link + +PAGING & STACK +pageFault +expStack +infRec (dejar que expanda) (opcional: varios infRec corriendo) +(Switch tty) +pInfo (Notar que el proceso infRec tiene su stack más grande) \ No newline at end of file