Skip to content

Commit 7983214

Browse files
ext2: link
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 728a819 commit 7983214

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

src/aero_kernel/src/fs/ext2/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl INode {
271271

272272
entry.entry_size = block_size as _;
273273
entry.inode = ext2_inode.id as _;
274-
entry.file_type = 2;
274+
entry.file_type = 2; // FIXME: This is fucked.
275275
entry.set_name(name);
276276

277277
fs.block.write(block * block_size, entry.as_bytes());
@@ -374,13 +374,28 @@ impl INodeInterface for INode {
374374
}
375375

376376
fn write_at(&self, offset: usize, usr_buffer: &[u8]) -> super::Result<usize> {
377-
if !self.metadata()?.is_file() {
377+
if !self.metadata()?.is_file() && !self.metadata()?.is_symlink() {
378378
return Err(FileSystemError::NotSupported);
379379
}
380380

381381
self.write(offset, usr_buffer)
382382
}
383383

384+
fn link(&self, name: &str, src: DirCacheItem) -> super::Result<()> {
385+
if !self.metadata()?.is_directory() {
386+
return Err(FileSystemError::NotSupported);
387+
}
388+
389+
if src.inode().metadata()?.is_directory() {
390+
return Err(FileSystemError::NotSupported);
391+
}
392+
393+
let inode = self.make_inode(name, FileType::Symlink)?;
394+
inode.write_at(0, src.name().as_bytes())?;
395+
396+
Ok(())
397+
}
398+
384399
fn truncate(&self, _size: usize) -> super::Result<()> {
385400
Ok(())
386401
}

src/aero_kernel/src/fs/inode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub trait INodeInterface: Send + Sync {
256256
Err(FileSystemError::NotSupported)
257257
}
258258

259-
fn link(&self, _name: &str, _src: INodeCacheItem) -> Result<()> {
259+
fn link(&self, _name: &str, _src: DirCacheItem) -> Result<()> {
260260
Err(FileSystemError::NotSupported)
261261
}
262262
}

src/aero_kernel/src/fs/ramfs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,9 @@ impl INodeInterface for LockedRamINode {
412412
Some(self.0.read().filesystem.clone())
413413
}
414414

415-
fn link(&self, name: &str, src: INodeCacheItem) -> Result<()> {
415+
fn link(&self, name: &str, src: DirCacheItem) -> Result<()> {
416+
let src = src.inode();
417+
416418
// ensure: The dest inode (self) is a directory.
417419
if self.metadata()?.file_type() != FileType::Directory {
418420
return Err(FileSystemError::NotDirectory);

src/aero_kernel/src/syscall/fs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ pub fn event_fd(_initval: usize, flags: usize) -> Result<usize, SyscallError> {
520520
/// file.
521521
#[syscall]
522522
pub fn link(src_path: &Path, dest_path: &Path) -> Result<usize, SyscallError> {
523-
let src = fs::lookup_path(src_path)?.inode();
523+
let src = fs::lookup_path(src_path)?;
524524
let (dest_dir, dest_name) = dest_path.parent_and_basename();
525525

526526
let dest_dir = fs::lookup_path(dest_dir)?.inode();
@@ -531,7 +531,9 @@ pub fn link(src_path: &Path, dest_path: &Path) -> Result<usize, SyscallError> {
531531
// strong references to it.
532532
//
533533
// TODO: Should this be moved to the inode impl?
534-
if dest_dir.weak_filesystem().unwrap().as_ptr() != src.weak_filesystem().unwrap().as_ptr() {
534+
if dest_dir.weak_filesystem().unwrap().as_ptr()
535+
!= src.inode().weak_filesystem().unwrap().as_ptr()
536+
{
535537
return Err(SyscallError::EINVAL);
536538
}
537539

src/aero_kernel/src/syscall/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl SysLog {
198198
pub fn flush(self) {
199199
let mut result = String::new();
200200

201-
if self.result.map(|e| e.is_ok()).unwrap_or_default() {
201+
if self.result.unwrap().is_ok() {
202202
result.push_str("\x1b[1;32m");
203203
} else {
204204
result.push_str("\x1b[1;31m");

0 commit comments

Comments
 (0)