Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
abinade2
kernel
Commits
7ac2068f
Commit
7ac2068f
authored
7 years ago
by
abinade2
Browse files
Options
Downloads
Patches
Plain Diff
added more comments
parent
7546e54a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
student-distrib/filesys.c
+12
-14
12 additions, 14 deletions
student-distrib/filesys.c
student-distrib/syscall.c
+8
-7
8 additions, 7 deletions
student-distrib/syscall.c
with
20 additions
and
21 deletions
student-distrib/filesys.c
+
12
−
14
View file @
7ac2068f
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
/*
/*
*init_filesys
*init_filesys
*
*
*D
I
SCRIPTION: initialize file system
*D
E
SCRIPTION: initialize file system
*INPUT: filesys_start -- the starting address of the file system
*INPUT: filesys_start -- the starting address of the file system
*RETURN: void
*RETURN: void
*/
*/
...
@@ -22,7 +22,7 @@ void init_filesys(const uint32_t filesys_start){
...
@@ -22,7 +22,7 @@ void init_filesys(const uint32_t filesys_start){
/*
/*
*read_dentry_by_name
*read_dentry_by_name
*
*
*D
I
SCRIPTION: this function fill in the dentry_t block passed as their second argument with the file name, file
*D
E
SCRIPTION: this function fill in the dentry_t block passed as their second argument with the file name, file
* type, and inode number for the file.
* type, and inode number for the file.
*INPUT: fname -- the name of the file, might be > 32 char
*INPUT: fname -- the name of the file, might be > 32 char
* dentry -- directory entry
* dentry -- directory entry
...
@@ -51,7 +51,7 @@ int32_t read_dentry_by_name(const uint8_t* fname, dentry_t* dentry){
...
@@ -51,7 +51,7 @@ int32_t read_dentry_by_name(const uint8_t* fname, dentry_t* dentry){
/*
/*
*read_dentry_by_index
*read_dentry_by_index
*
*
*D
I
SCRIPTION: this function fill in the dentry t block passed as their second argument with the file name, file
*D
E
SCRIPTION: this function fill in the dentry t block passed as their second argument with the file name, file
* type, and inode number for the file, then return 0.
* type, and inode number for the file, then return 0.
*INPUT: index -- index into the dentry block in boot block
*INPUT: index -- index into the dentry block in boot block
* dentry -- directory entry to be filled in
* dentry -- directory entry to be filled in
...
@@ -71,7 +71,7 @@ int32_t read_dentry_by_index(uint32_t index, dentry_t* dentry){
...
@@ -71,7 +71,7 @@ int32_t read_dentry_by_index(uint32_t index, dentry_t* dentry){
/*
/*
*read_data
*read_data
*
*
*D
I
SCRIPTION: this function works much like the read system call, reading up to
*D
E
SCRIPTION: this function works much like the read system call, reading up to
* length bytes starting from position offset in the file with inode number
* length bytes starting from position offset in the file with inode number
* inode and returning the number of bytes read and placed in the buffer.
* inode and returning the number of bytes read and placed in the buffer.
*
*
...
@@ -125,7 +125,7 @@ int32_t read_data(uint32_t inode, uint32_t offset, uint8_t* buf, uint32_t length
...
@@ -125,7 +125,7 @@ int32_t read_data(uint32_t inode, uint32_t offset, uint8_t* buf, uint32_t length
/*
/*
*Read File
*Read File
*
*
*D
I
SCRIPTION:
*D
E
SCRIPTION:
reads the number of bytes data into buffer
*INPUT: fd -- file discriptor
*INPUT: fd -- file discriptor
* buf -- buffer that store the file
* buf -- buffer that store the file
* nbytes -- the number of bytes that need to read
* nbytes -- the number of bytes that need to read
...
@@ -150,7 +150,7 @@ int32_t read_file(int32_t fd_n, void* buf, int32_t nbytes){
...
@@ -150,7 +150,7 @@ int32_t read_file(int32_t fd_n, void* buf, int32_t nbytes){
/*
/*
*Write File
*Write File
*
*
*D
I
SCRIPTION:
*D
E
SCRIPTION:
returns -1 (do nothing since it is read-only)
*INPUT: fd -- file discriptor
*INPUT: fd -- file discriptor
* buf -- buffer that store the file
* buf -- buffer that store the file
* nbytes -- the number of bytes that need to read
* nbytes -- the number of bytes that need to read
...
@@ -163,19 +163,18 @@ int32_t write_file(int32_t fd, const void* buf, int32_t nbytes){
...
@@ -163,19 +163,18 @@ int32_t write_file(int32_t fd, const void* buf, int32_t nbytes){
/*
/*
*Open File
*Open File
*
*
*D
I
SCRIPTION: use filename to fill in dentry
*D
E
SCRIPTION: use filename to fill in dentry
*INPUT: filename -- file name
*INPUT: filename -- file name
*RETURN: 0 success, -1 fail
*RETURN: 0 success, -1 fail
*/
*/
int32_t
open_file
(
const
uint8_t
*
filename
){
int32_t
open_file
(
const
uint8_t
*
filename
){
return
0
;
return
0
;
// return (read_dentry_by_name(filename, &global_dentry));
}
}
/*
/*
*Close File
*Close File
*
*
*D
I
SCRIPTION:
*D
E
SCRIPTION:
do nothing
*INPUT: fd -- file discriptor
*INPUT: fd -- file discriptor
*RETURN:0 success, -1 fail
*RETURN:0 success, -1 fail
*/
*/
...
@@ -188,7 +187,7 @@ int32_t close_file(int32_t fd){
...
@@ -188,7 +187,7 @@ int32_t close_file(int32_t fd){
/*
/*
*Read Directory
*Read Directory
*
*
*D
I
SCRIPTION:
*D
E
SCRIPTION:
read next file in current directory
*INPUT: fd -- file discriptor
*INPUT: fd -- file discriptor
* buf -- buffer that store the file
* buf -- buffer that store the file
* nbytes -- the number of bytes that need to read
* nbytes -- the number of bytes that need to read
...
@@ -221,7 +220,7 @@ int32_t read_dir(int32_t fd_n, void* buf, int32_t nbytes){
...
@@ -221,7 +220,7 @@ int32_t read_dir(int32_t fd_n, void* buf, int32_t nbytes){
/*
/*
*Write Directory
*Write Directory
*
*
*D
I
SCRIPTION:
*D
E
SCRIPTION:
does nothing
*INPUT: fd -- file discriptor
*INPUT: fd -- file discriptor
* buf -- buffer that store the file
* buf -- buffer that store the file
* nbytes -- the number of bytes that need to read
* nbytes -- the number of bytes that need to read
...
@@ -234,19 +233,18 @@ int32_t write_dir(int32_t fd, const void* buf, int32_t nbytes){
...
@@ -234,19 +233,18 @@ int32_t write_dir(int32_t fd, const void* buf, int32_t nbytes){
/*
/*
*Open Directory
*Open Directory
*
*
*D
I
SCRIPTION:
*D
E
SCRIPTION:
does nothing
*INPUT: filename -- file name
*INPUT: filename -- file name
*RETURN:0 success, -1 fail
*RETURN:0 success, -1 fail
*/
*/
int32_t
open_dir
(
const
uint8_t
*
filename
){
int32_t
open_dir
(
const
uint8_t
*
filename
){
return
0
;
return
0
;
// return (read_dentry_by_name(filename, &global_dentry));
}
}
/*
/*
*Close Directory
*Close Directory
*
*
*D
I
SCRIPTION:
*D
E
SCRIPTION:
does nothing
*INPUT: fd -- file discriptor
*INPUT: fd -- file discriptor
*RETURN:0 success, -1 fail
*RETURN:0 success, -1 fail
*/
*/
...
...
This diff is collapsed.
Click to expand it.
student-distrib/syscall.c
+
8
−
7
View file @
7ac2068f
...
@@ -147,7 +147,7 @@ int32_t execute(const uint8_t* command)
...
@@ -147,7 +147,7 @@ int32_t execute(const uint8_t* command)
total_prog_count
++
;
total_prog_count
++
;
terminal
[
running_terminal
].
terminal_prog_count
++
;
terminal
[
running_terminal
].
terminal_prog_count
++
;
//get entry point from bytes 24 to 27 in exe file
//get entry point from bytes 24 to 27 in
each
exe file
read_data
(
dentry
.
inode_index
,
ENTRY_POINT
,
buf
,
4
);
read_data
(
dentry
.
inode_index
,
ENTRY_POINT
,
buf
,
4
);
entry_point
=
*
((
uint32_t
*
)
buf
);
entry_point
=
*
((
uint32_t
*
)
buf
);
...
@@ -158,20 +158,20 @@ int32_t execute(const uint8_t* command)
...
@@ -158,20 +158,20 @@ int32_t execute(const uint8_t* command)
//-------------------- 4: User-level Program Loader ------------------------
//-------------------- 4: User-level Program Loader ------------------------
read_data
(
dentry
.
inode_index
,
0
,
(
uint8_t
*
)
PROGRAM_START
,
get_file_size
(
dentry
.
inode_index
));
//load 1Mb
// loading executable
read_data
(
dentry
.
inode_index
,
0
,
(
uint8_t
*
)
PROGRAM_START
,
get_file_size
(
dentry
.
inode_index
));
//-------------------- 5: set up pcb----------------------------------------
//-------------------- 5: set up pcb----------------------------------------
uint32_t
temp_esp
,
temp_ebp
;
uint32_t
temp_esp
,
temp_ebp
;
// checks if we're running shell for first time on terminal (if so, gets ebp and esp from scheduler)
if
(
terminal
[
running_terminal
].
pcb
!=
NULL
&&
terminal
[
running_terminal
].
pcb
->
scheduler_flag
)
if
(
terminal
[
running_terminal
].
pcb
!=
NULL
&&
terminal
[
running_terminal
].
pcb
->
scheduler_flag
)
{
{
temp_esp
=
terminal
[
running_terminal
].
pcb
->
current_esp
;
temp_esp
=
terminal
[
running_terminal
].
pcb
->
current_esp
;
temp_ebp
=
terminal
[
running_terminal
].
pcb
->
current_ebp
;
temp_ebp
=
terminal
[
running_terminal
].
pcb
->
current_ebp
;
terminal
[
running_terminal
].
pcb
->
scheduler_flag
=
0
;
terminal
[
running_terminal
].
pcb
->
scheduler_flag
=
0
;
}
}
else
{
else
{
temp_esp
=
0
;
temp_esp
=
0
;
temp_ebp
=
0
;
temp_ebp
=
0
;
}
}
...
@@ -194,6 +194,7 @@ int32_t execute(const uint8_t* command)
...
@@ -194,6 +194,7 @@ int32_t execute(const uint8_t* command)
terminal
[
running_terminal
].
pcb
=
pcb_ptr
;
terminal
[
running_terminal
].
pcb
=
pcb_ptr
;
// checks if command is shell
if
(
strncmp
(
"shell"
,
(
int8_t
*
)
parsed_cmd
,
5
)
==
0
){
if
(
strncmp
(
"shell"
,
(
int8_t
*
)
parsed_cmd
,
5
)
==
0
){
terminal
[
running_terminal
].
pcb
->
shell_flag
=
1
;
terminal
[
running_terminal
].
pcb
->
shell_flag
=
1
;
}
}
...
@@ -263,7 +264,7 @@ int32_t read(int32_t fd_n, void* buf, int32_t nbytes)
...
@@ -263,7 +264,7 @@ int32_t read(int32_t fd_n, void* buf, int32_t nbytes)
/*
/*
*The write system call
*The write system call
*
*
*D
I
SCRIPTION: This function writes data to the terminal or to a device (RTC).
*D
E
SCRIPTION: This function writes data to the terminal or to a device (RTC).
*
*
* case 1 - terminal: all data should be displayed to the screen immediately.
* case 1 - terminal: all data should be displayed to the screen immediately.
*
*
...
@@ -297,7 +298,7 @@ int32_t write (int32_t fd, const void* buf, int32_t nbytes){
...
@@ -297,7 +298,7 @@ int32_t write (int32_t fd, const void* buf, int32_t nbytes){
/*
/*
*The open system call
*The open system call
*
*
*D
I
SCRIPTION: This function provides access to the file system, find the directory entry corresponding
*D
E
SCRIPTION: This function provides access to the file system, find the directory entry corresponding
* to the named file, allocate an unused file descriptor, and set up any data necessary
* to the named file, allocate an unused file descriptor, and set up any data necessary
* to handle the given type of file (directory, RTC device, or regular file).
* to handle the given type of file (directory, RTC device, or regular file).
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment