Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ee2f95e51d | |||
| b617fccee4 | |||
| 14474130ad | |||
| 18504170ec | |||
| 404f4c20f0 | |||
| dea54c7dae | |||
| 44b1acf33c | |||
| 4d4504486d | |||
| f7e53f9b00 | |||
| beacbde52e | |||
| cad4804a95 | |||
| e2e608b073 | |||
| bb1bca458e | |||
| b489df26ba | |||
| 1832c77fdb | |||
| ce98a0d3de | |||
| 89e6d75627 | |||
| 4c6cbc3360 | |||
| c3c2ba824e | |||
| 015768793b |
@@ -0,0 +1,8 @@
|
|||||||
|
SYNOPSIS
|
||||||
|
mkdir DIRECTORY
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
Create the DIRECTORY, if it does not exist.
|
||||||
|
|
||||||
|
OPTIONS
|
||||||
|
--help : shows command help.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
SYNOPSIS
|
||||||
|
rmdir DIRECTORY
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
Remove the DIRECTORY, if it is empty.
|
||||||
|
|
||||||
|
OPTIONS
|
||||||
|
--help : shows command help.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
SYNOPSIS
|
||||||
|
showpid
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
showpid uses getppid() to print the ID of the parent process.
|
||||||
@@ -2,6 +2,6 @@ set timeout=5
|
|||||||
set default=0
|
set default=0
|
||||||
|
|
||||||
menuentry "MentOS" {
|
menuentry "MentOS" {
|
||||||
multiboot /boot/kernel-bootloader.bin
|
multiboot /boot/bootloader.bin
|
||||||
boot
|
boot
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-16
@@ -72,21 +72,7 @@ int execv(const char *path, char *const argv[])
|
|||||||
|
|
||||||
int execvp(const char *file, char *const argv[])
|
int execvp(const char *file, char *const argv[])
|
||||||
{
|
{
|
||||||
if (!file || !argv || !environ) {
|
return execvpe(file, argv, environ);
|
||||||
errno = ENOENT;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (file[0] == '/') {
|
|
||||||
return execve(file, argv, environ);
|
|
||||||
}
|
|
||||||
// Prepare a buffer for the absolute path.
|
|
||||||
char absolute_path[PATH_MAX] = { 0 };
|
|
||||||
// Find the file inside the entries of the PATH variable.
|
|
||||||
if (__find_in_path(file, absolute_path, PATH_MAX) == 0) {
|
|
||||||
return execve(absolute_path, argv, environ);
|
|
||||||
}
|
|
||||||
errno = ENOENT;
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int execvpe(const char *file, char *const argv[], char *const envp[])
|
int execvpe(const char *file, char *const argv[], char *const envp[])
|
||||||
@@ -95,7 +81,7 @@ int execvpe(const char *file, char *const argv[], char *const envp[])
|
|||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (file[0] == '/') {
|
if (strchr(file, '/')) {
|
||||||
return execve(file, argv, envp);
|
return execve(file, argv, envp);
|
||||||
}
|
}
|
||||||
// Prepare a buffer for the absolute path.
|
// Prepare a buffer for the absolute path.
|
||||||
|
|||||||
@@ -1413,8 +1413,6 @@ static int ext2_allocate_inode_block(ext2_filesystem_t *fs, ext2_inode_t *inode,
|
|||||||
if (inode->blocks_count < blocks_count) {
|
if (inode->blocks_count < blocks_count) {
|
||||||
// Set the blocks count.
|
// Set the blocks count.
|
||||||
inode->blocks_count = blocks_count;
|
inode->blocks_count = blocks_count;
|
||||||
// Update the size.
|
|
||||||
inode->size = (blocks_count / fs->blocks_per_block_count) * fs->block_size;
|
|
||||||
pr_debug("Setting the block count for inode `%d` to `%d` blocks.\n", inode_index, blocks_count / fs->blocks_per_block_count);
|
pr_debug("Setting the block count for inode `%d` to `%d` blocks.\n", inode_index, blocks_count / fs->blocks_per_block_count);
|
||||||
}
|
}
|
||||||
// Update the inode.
|
// Update the inode.
|
||||||
@@ -1557,6 +1555,10 @@ static ssize_t ext2_write_inode_data(ext2_filesystem_t *fs, ext2_inode_t *inode,
|
|||||||
uint32_t end = offset + nbyte;
|
uint32_t end = offset + nbyte;
|
||||||
if (end > inode->size) {
|
if (end > inode->size) {
|
||||||
inode->size = end;
|
inode->size = end;
|
||||||
|
if (ext2_write_inode(fs, inode, inode_index) == -1) {
|
||||||
|
pr_err("Failed to write the inode `%d`\n", inode_index);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
uint32_t start_block = offset / fs->block_size;
|
uint32_t start_block = offset / fs->block_size;
|
||||||
uint32_t end_block = end / fs->block_size;
|
uint32_t end_block = end / fs->block_size;
|
||||||
@@ -2267,7 +2269,7 @@ static vfs_file_t *ext2_creat(const char *path, mode_t permission)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// Get the parent VFS node.
|
// Get the parent VFS node.
|
||||||
vfs_file_t *parent = vfs_open(parent_path, O_RDONLY, 0);
|
vfs_file_t *parent = vfs_open(parent_path, O_WRONLY, 0);
|
||||||
if (parent == NULL) {
|
if (parent == NULL) {
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -2587,7 +2589,10 @@ static ssize_t ext2_write(vfs_file_t *file, const void *buffer, off_t offset, si
|
|||||||
pr_err("Failed to read the inode `%s`.\n", file->name);
|
pr_err("Failed to read the inode `%s`.\n", file->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return ext2_write_inode_data(fs, &inode, file->ino, offset, nbyte, (char *)buffer);
|
ssize_t written = ext2_write_inode_data(fs, &inode, file->ino, offset, nbyte, (char *)buffer);
|
||||||
|
// Update the file length
|
||||||
|
file->length = inode.size;
|
||||||
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Repositions the file offset inside a file.
|
/// @brief Repositions the file offset inside a file.
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ int sys_creat(const char *path, mode_t mode)
|
|||||||
|
|
||||||
// Set the file descriptor id.
|
// Set the file descriptor id.
|
||||||
task->fd_list[fd].file_struct = file;
|
task->fd_list[fd].file_struct = file;
|
||||||
|
task->fd_list[fd].flags_mask = O_WRONLY|O_CREAT|O_TRUNC;
|
||||||
|
|
||||||
// Return the file descriptor and increment it.
|
// Return the file descriptor and increment it.
|
||||||
return fd;
|
return fd;
|
||||||
|
|||||||
+7
-3
@@ -18,9 +18,10 @@ static inline void print_content(const char *path, char *buffer, unsigned buflen
|
|||||||
// Open the file.
|
// Open the file.
|
||||||
int fd = open(path, O_RDONLY, 42);
|
int fd = open(path, O_RDONLY, 42);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
|
ssize_t bytes_read = 0;
|
||||||
// Put on the standard output the characters.
|
// Put on the standard output the characters.
|
||||||
while (read(fd, buffer, buflen) > 0) {
|
while ((bytes_read = read(fd, buffer, buflen)) > 0) {
|
||||||
puts(buffer);
|
write(STDOUT_FILENO, buffer, bytes_read);
|
||||||
}
|
}
|
||||||
// Close the file descriptor.
|
// Close the file descriptor.
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -45,6 +46,7 @@ int main(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int status = 0;
|
||||||
// Prepare the buffer for reading.
|
// Prepare the buffer for reading.
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
// Iterate the arguments.
|
// Iterate the arguments.
|
||||||
@@ -60,16 +62,18 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
} else if (S_ISDIR(statbuf.st_mode)) {
|
} else if (S_ISDIR(statbuf.st_mode)) {
|
||||||
printf("cat: %s: Is a directory\n\n", argv[i]);
|
printf("cat: %s: Is a directory\n\n", argv[i]);
|
||||||
|
status = 1;
|
||||||
|
|
||||||
} else if (S_ISLNK(statbuf.st_mode)) {
|
} else if (S_ISLNK(statbuf.st_mode)) {
|
||||||
if (readlink(argv[i], buffer, BUFSIZ)) {
|
if (readlink(argv[i], buffer, BUFSIZ)) {
|
||||||
print_content(buffer, buffer, BUFSIZ);
|
print_content(buffer, buffer, BUFSIZ);
|
||||||
} else {
|
} else {
|
||||||
printf("cat: %s: %s\n\n", argv[i], strerror(errno));
|
printf("cat: %s: %s\n\n", argv[i], strerror(errno));
|
||||||
|
status = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
return 0;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -77,7 +77,7 @@ static inline void print_dir_entry(dirent_t *dirent, const char *path, unsigned
|
|||||||
// Add a space.
|
// Add a space.
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
// Print the rest.
|
// Print the rest.
|
||||||
printf("%4d %4d %11s %2d/%2d %2d:%2d %s\n",
|
printf("%4d %4d %11s %02d/%02d %02d:%02d %s\n",
|
||||||
dstat.st_uid,
|
dstat.st_uid,
|
||||||
dstat.st_gid,
|
dstat.st_gid,
|
||||||
to_human_size(dstat.st_size),
|
to_human_size(dstat.st_size),
|
||||||
|
|||||||
+4
-15
@@ -40,6 +40,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if (argc == 2)
|
else if (argc == 2)
|
||||||
{
|
{
|
||||||
|
char *pager = "cat";
|
||||||
char filepath[PATH_MAX];
|
char filepath[PATH_MAX];
|
||||||
strcpy(filepath, "/usr/share/man/");
|
strcpy(filepath, "/usr/share/man/");
|
||||||
strcat(filepath, argv[1]);
|
strcat(filepath, argv[1]);
|
||||||
@@ -47,23 +48,11 @@ int main(int argc, char *argv[])
|
|||||||
int fd = open(filepath, O_RDONLY, 42);
|
int fd = open(filepath, O_RDONLY, 42);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
printf("%s: No manual entry for %s\n\n", argv[0], argv[1]);
|
printf("%s: No manual entry for %s\n", argv[0], argv[1]);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Prepare the buffer for reading the man file.
|
|
||||||
char buffer[BUFSIZ];
|
|
||||||
// Put on the standard output the characters.
|
|
||||||
while (read(fd, buffer, BUFSIZ) > 0)
|
|
||||||
{
|
|
||||||
puts(buffer);
|
|
||||||
}
|
|
||||||
// Close the file descriptor.
|
|
||||||
close(fd);
|
close(fd);
|
||||||
// Terminate with a pair of newlines.
|
execlp(pager, pager, filepath);
|
||||||
putchar('\n');
|
|
||||||
putchar('\n');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user