285 Commits

Author SHA1 Message Date
Florian Fischer 44b1acf33c ext2: update the vfs_file_t length after writing
The vfs_file_t->length field is initialized but never used afterwards.
It seams correct to updated it after the inode size possibly changed.
2024-02-13 21:59:57 +01:00
Florian Fischer 4d4504486d ext2: write the inode back if its size is updated
If there is enough space in an inode but the file grows the
inode is never written back to the device and thus the new size is
not persisted.

	int fd = creat("foo", 660);
	write(fd, "foo", 3); // New blocks are allocated and inode written back
	write(fd, "\n", 1); // size is adapted but not written back
	close(fd);
	// Reading the file afterwards will only return "foo".

The code snippet reproduces the bug.

This is fixed by always writing the inode back to the device if
the size is updated.
2024-02-13 21:59:57 +01:00
Florian Fischer f7e53f9b00 ext2: do not update inode size when allocating new blocks
New blocks for an inode are allocated when data blocks
should be written and not enough blocks are allocated yet
or during allocating new direntries in ext2_allocate_direntry.

When writing the first time to a newly created file (inode.size==0),
new blocks must be allocated and the inode size is erroneously set to
(blocks_count / fs->blocks_per_block_count) * fs->block_size
regardless of the actually written data.

	int fd = creat("foo", 0660);
	write(fd, "foo", 3);

This code snippet will create a new inode with size 4096 instead
of the correct size 3.

ext2_write_inode_data will correctly set the size to 3.
However, ext2_allocate_block called by ext2_write_inode_block will
set the inode size to 4096.

This is fixed by removing the size update during ext2_allocate_block.
2024-02-13 21:51:04 +01:00
Enrico Fraccaroli 1832c77fdb Merge pull request #21 from fischerling/fix-creat-fd-flags
creat: set flags in opened file descriptor
2024-01-29 05:24:58 +01:00
Florian Fischer 89e6d75627 creat: set flags in opened file descriptor
creat.2 is supposed to be equivalent to open.2 with the
flags O_WRONLY|O_CREAT|O_TRUNC.

However, in MentOS the fd returned by creat.2 has no flags whatsoever
and is thus not writable.

Set the flags of the file descriptor before returning it.
2024-01-28 21:50:30 +01:00
Florian Fischer 4c6cbc3360 vfs: fix permission check when creating files
When creating new files in a directory the creating process
must be allowed to write the directory not to read it.
2024-01-28 21:47:50 +01:00
Enrico Fraccaroli (Galfurian) 30e01ba560 Update version 2024-01-17 13:49:48 +01:00
Enrico Fraccaroli (Galfurian) eca55dfed8 Clean up cmake files (Part 2)
I've kept just one cmake project, in the root directory. The
subdirectories just set up the targets.

The asm compiler is serached just one time, from the root
directory cmake file.

Global compilation flags are set in the root cmake file, and
each subdirectory cmake file sets specific flags if necessary
(e.g., programs need the -u_start specified)
2024-01-17 13:34:32 +01:00
Enrico Fraccaroli (Galfurian) 0b75cd9c2a Clean up cmake files (Part 1)
I've been cleaning up the way compilation flags are passed to the targets
and there are still some changes that must be made, in the next commit.

I've also done some renaming, all_programs into programs and the same for
tests.

The gdb initialization file now is just one, populated using the find command
and using realpath to get the absolute path to the files. I've tested if the
generated gdb.run file works and it does.
2024-01-17 13:16:50 +01:00
Enrico Fraccaroli 34eeedcbcf Improve the generation of programs and tests. 2024-01-15 11:26:20 +01:00
Enrico Fraccaroli 5ce583fdd8 Rollback patch for archive creation that broke clang compilation 2024-01-15 11:14:34 +01:00
Florian Fischer ef92ba670b exit: properly set the process' exit code when calling exit()
In order to detect the exit status using
WSTATUSCODE ((status & 0xff00) >> 8) the exit code must
be shifted by 8 to the left.

Separate the kernel process exit logic from the actual system call.
2024-01-13 14:31:00 +01:00
Enrico Fraccaroli (Galfurian) 290ed59d0b Try to fix compilation under MacOS 2023-11-30 13:28:09 -05:00
Enrico Fraccaroli (Galfurian) 3e51197ae4 Try to fix compilation under MacOS 2023-11-30 13:16:09 -05:00
Enrico Fraccaroli (Galfurian) 327e29791e Use gcc@11 under MacOS 2023-11-30 11:47:15 -05:00
Enrico Fraccaroli (Galfurian) 4292149567 Use x86_64-elf-gcc under MacOS 2023-11-29 10:45:27 -05:00
Enrico Fraccaroli (Galfurian) 030c16d29e Use x86_64-elf-gcc under MacOS 2023-11-29 10:40:27 -05:00
Enrico Fraccaroli (Galfurian) 29e9d2ff11 Use x86_64-elf-gcc under MacOS 2023-11-29 10:38:44 -05:00
Enrico Fraccaroli (Galfurian) 24b2182bec Use x86_64-elf-gcc under MacOS 2023-11-29 10:37:47 -05:00
Enrico Fraccaroli (Galfurian) 654a3165c0 Use x86_64-elf-gcc under MacOS 2023-11-29 10:34:42 -05:00
Enrico Fraccaroli (Galfurian) 7ce609fddc Fix compilation with clang 15.0.7 2023-11-28 10:10:28 -05:00
Enrico Fraccaroli (Galfurian) 75abb84f25 Fix procfs inability to set st_mode properly 2023-11-24 15:50:20 -05:00
Enrico Fraccaroli (Galfurian) f066dd2ad9 Add support for reading symlinks 2023-11-21 14:20:41 -05:00
Enrico Fraccaroli (Galfurian) 1197797ee1 Add symlink function (not yet implemented in ext2) 2023-09-01 11:17:40 -04:00
Enrico Fraccaroli (Galfurian) 163e83009d Make tokenize work with a const char pointer. 2023-08-30 15:38:52 -04:00
Enrico Fraccaroli (Galfurian) 78c1ff4bd4 Minor improvements to the string-related functions. 2023-08-30 11:51:25 -04:00
Enrico Fraccaroli (Galfurian) d50d997d6e Wrap single line statements inside braces. 2023-08-24 12:17:16 -04:00
Enrico Fraccaroli (Galfurian) 6b077ccfac Improve comments and code formatting. 2023-08-23 09:55:05 -04:00
Enrico Fraccaroli (Galfurian) 452aa40770 Properly set exit code for killed processed. 2023-08-22 16:32:43 -04:00
Enrico Fraccaroli (Galfurian) c82779f1af After queuing a SEGV for the process that caused a page fault, we call the scheduler to properly handle it. 2023-08-22 15:40:05 -04:00
Enrico Fraccaroli (Galfurian) aafa26ea38 Send a SIGSEGV whenever a page is not copy-on-write, and the user is trying to write on a readonly address. 2023-08-22 09:26:39 -04:00
Enrico Fraccaroli (Galfurian) 3fc0ba78ca Send a SIGSEGV whenever a page is not present and the user is involved. 2023-08-22 09:25:34 -04:00
Enrico Fraccaroli (Galfurian) a50c1a892f Return an integer from __page_handle_cow, allowing the caller to react to an error. 2023-08-22 09:24:55 -04:00
Enrico Fraccaroli (Galfurian) 08d87ea439 Add code that allows to create READONLY shared memory. 2023-08-22 09:24:01 -04:00
Enrico Fraccaroli (Galfurian) 34319442aa Implement shmat and shmdt 2023-08-16 14:45:04 -04:00
Enrico Fraccaroli (Galfurian) dde6e6bc9e First rough implementation of shared memory. 2023-08-16 11:49:52 -04:00
Enrico Fraccaroli (Galfurian) 07d603f47a Fix wrong error check 2023-08-11 13:40:46 -04:00
Enrico Fraccaroli (Galfurian) df0a3701aa Improve format 2023-08-11 13:40:22 -04:00
Enrico Fraccaroli (Galfurian) 8578f078c6 Improve formatting and enable FLOATING_POINT_ERR 2023-08-11 13:39:45 -04:00
Enrico Fraccaroli (Galfurian) 20091b196f Start working on shared memory 2023-08-11 13:39:18 -04:00
Enrico Fraccaroli (Galfurian) b7f85b9500 Improve format 2023-08-11 13:38:57 -04:00
Enrico Fraccaroli (Galfurian) 83d4beb33d Clean up boot sequence code. 2023-08-11 13:31:32 -04:00
Enrico Fraccaroli (Galfurian) 954f6342ec Increase wait time. 2023-08-11 13:12:08 -04:00
Enrico Fraccaroli (Galfurian) ee2c0ebd88 Fix how ATA driver determines the type of a device. 2023-07-12 14:28:36 -04:00
Enrico Fraccaroli (Galfurian) 1cbc7519c9 Add missing pragma once 2023-07-12 14:27:21 -04:00
Enrico Fraccaroli (Galfurian) 16b905625d Turn port-io into header-only. 2023-07-12 14:26:52 -04:00
Enrico Fraccaroli (Galfurian) 707c0e408b Improve dec_to_binary function 2023-07-12 14:26:14 -04:00
Enrico Fraccaroli (Galfurian) dc5a30573c Reorganize PCI functionalities, and ATA drivers. 2023-07-01 16:07:00 -04:00
Enrico Fraccaroli (Galfurian) 3ed59b6f55 Add function to count element in arrays. 2023-06-29 15:48:56 -04:00
Enrico Fraccaroli (Galfurian) 86e046d080 Minor naming changes inside port_io 2023-06-29 13:00:15 -04:00