Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learning xv6 #184

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.16299.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ UPROGS=\
_usertests\
_wc\
_zombie\
_rm2\
_sh1\

fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)
Expand Down Expand Up @@ -250,7 +252,7 @@ qemu-nox-gdb: fs.img xv6.img .gdbinit
EXTRA=\
mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\
ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\
printf.c umalloc.c\
printf.c umalloc.c rm2.c sh1.c\
README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
.gdbinit.tmpl gdbutil\

Expand Down
23 changes: 23 additions & 0 deletions rm2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "types.h"
#include "stat.h"
#include "user.h"

int
main(int argc, char *argv[])
{
int i;

if(argc < 2){
printf(2, "Usage: rm files...\n");
exit();
}

for(i = 1; i < argc; i++){
if(unlink(argv[i]) < 0){
printf(2, "rm: %s failed to delete\n", argv[i]);
break;
}
}

exit();
}
29 changes: 27 additions & 2 deletions sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,27 @@ main(void)
{
static char buf[100];
int fd;

// added this one
int fp;
int n=1;
n=n+1;
// Ensure that three file descriptors are open.
while((fd = open("console", O_RDWR)) >= 0){
if(fd >= 3){
close(fd);
break;
}
}

//important to open
fp = open("commands",O_WRONLY|O_CREATE);
if (fp == 0)
{
// Error opening the file
printf(2, "Error opening file");
return 1;
}
char command[256];
//printf(2,"Sucessfully opened!");
// Read and run input commands.
while(getcmd(buf, sizeof(buf)) >= 0){
if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
Expand All @@ -165,9 +177,22 @@ main(void)
continue;
}
if(fork1() == 0)
{
//To check if this is where process is going
//printf(1,"at least this is working ??\n");
strcpy(command,buf);
// Append the command to the file
write(fd, command, strlen(command));
//printf(2,"we are here", buf);
runcmd(parsecmd(buf));


}

wait();
}
//close the file?
close(fp);
exit();
}

Expand Down
Loading