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

Add test command to user space #52

Open
nestrada2 opened this issue Sep 8, 2024 · 2 comments
Open

Add test command to user space #52

nestrada2 opened this issue Sep 8, 2024 · 2 comments

Comments

@nestrada2
Copy link

nestrada2 commented Sep 8, 2024

test

The "test" command evaluates a conditional expression. It is an if statement that will return zero (true) or 1 (false), or greater than 1 (error).

Approach

The "test" command will check if any flags were inputted and, based on the expression, will return a truthy or falsy value. For example,test -e myfile.txt will return 0 if that file exists. Will have to use the sys_fstat to obtain information about the specified file.

Files to be Modified/Added

user:

  • user.h (add test)
  • test.c (new: call sys_open, pass a path to that and that will give us a file descriptor. With the file descriptor we call sys_fstat, and pass in an file descriptor, and a pointer to an empty stat struct which is an output, it is going to modify it)

Subcommands Implemented in Test

Command Description
-d file True if file exists and is a directory.
-e file True if file exists (regardless of type).
-f file True if file exists and is a regular file.
file1 -ef file2 True if file1 and file2 exist and refer to the same file.
s1 = s2 True if the strings s1 and s2 are identical.
s1 != s2 True if the strings s1 and s2 are not identical.
n1 -gt n2 True if the integer n1 is algebraically greater than the integer n2.
n1 -lt n2 True if the integer n1 is algebraically less than the integer n2.

Future Development

Add functionality for more flags
Add logical operators for combining expressions
Edit sh so that test can be incorporated in shell scripting

References

man test

@malensek
Copy link
Contributor

This sounds like a good project, although I don't think there is any reason to modify kernel space. The stat system call should already be enough for getting file system information. When you get a chance, can you specify the exact test features you plan to implement?

@nestrada2
Copy link
Author

nestrada2 commented Sep 13, 2024

Hello Mr. Malensek (@malensek), I updated the project specifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants