Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gcastigl/SO2C2011TP2
Browse files Browse the repository at this point in the history
  • Loading branch information
horacio.gomez committed Nov 29, 2011
2 parents dde057f + c860ae8 commit 668a000
Show file tree
Hide file tree
Showing 21 changed files with 297 additions and 177 deletions.
5 changes: 5 additions & 0 deletions include/command.h
Expand Up @@ -13,6 +13,7 @@
#include <lib/unistd.h>
#include <lib/file.h>


#define HELP_HELP "Shows this help function"

#define HELP_RESTART "Restarts the OS"
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions include/defs.h
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 4 additions & 5 deletions include/interrupts/interrupts.h
Expand Up @@ -2,13 +2,12 @@
#define INTERRUPTS_H

#include <defs.h>
#include <io.h>
#include <asm/interrupts.h>
#include <util/logger.h>
#include <interrupts/defs.h>
#include <process/scheduler.h>
#include <access/user.h>
#include <util/logger.h>
#include <asm/interrupts.h>
#include <lib/file.h>
#include <io.h>


void initBasicHandlers();

Expand Down
7 changes: 7 additions & 0 deletions include/lib/unistd.h
Expand Up @@ -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
4 changes: 4 additions & 0 deletions include/session.h
Expand Up @@ -21,4 +21,8 @@ PUBLIC int session_getEuid();

PUBLIC int session_getEgid();

PUBLIC void session_sudoEnd();

PUBLIC void session_sudoStart();

#endif
4 changes: 4 additions & 0 deletions include/shell.h
Expand Up @@ -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

2 changes: 1 addition & 1 deletion include/tty.h
Expand Up @@ -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;
Expand Down
16 changes: 9 additions & 7 deletions src/access/user.c
Expand Up @@ -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();

Expand Down Expand Up @@ -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");
}
}
}

Expand Down Expand Up @@ -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;
Expand Down
37 changes: 34 additions & 3 deletions src/command.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
7 changes: 4 additions & 3 deletions src/fs/fs.c
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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));
Expand Down
8 changes: 7 additions & 1 deletion src/interrupts/handlers.c
@@ -1,5 +1,9 @@
#include <interrupts/interrupts.h>
#include <process/scheduler.h>
#include <access/user.h>
#include <session.h>

extern PUBLIC void _expandStack();
extern void switchProcess(void);
int taskSwitch = true;
static int ticksSinceLasfFlush = 0;
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/fifo.c
Expand Up @@ -2,7 +2,7 @@
#include <lib/file.h>
#include <util/logger.h>

#define MAX_FIFOS 1
#define MAX_FIFOS 3

PRIVATE fifo_t fifos[MAX_FIFOS];

Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib/unistd.c
Expand Up @@ -3,6 +3,11 @@
#include <fs/fs.h>
#include <tty.h>

int growStack() {
_SysCall(SYSTEM_ADDSTACK);
return 0;
}

int open(const char *path, int oflags, ...) {
int create_flags = -1;
if (oflags & O_CREAT) {
Expand Down
6 changes: 2 additions & 4 deletions src/memory/paging.c
Expand Up @@ -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),
Expand Down Expand Up @@ -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 */
);
}
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down

0 comments on commit 668a000

Please sign in to comment.