Skip to content

Commit 125adf5

Browse files
committed
Addressed review comments
1 parent a0cd57c commit 125adf5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/safeposix/syscalls/fs_calls.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,9 +2465,9 @@ impl Cage {
24652465
/// particular reference point.
24662466
/// * `whence` - It determines how the seek operation is performed. There
24672467
/// are three possible values for whence: `SEEK_SET`: The file offset is
2468-
/// set to offset bytes. `SEEK_CUR`: The file offset is set to its current
2469-
/// location plus offset bytes. `SEEK_END`: The file offset is set to the
2470-
/// size of the file plus offset bytes.
2468+
/// set to 0 + offset bytes. `SEEK_CUR`: The file offset is set to its
2469+
/// current location plus offset bytes. `SEEK_END`: The file offset is set
2470+
/// to the size of the file plus offset bytes.
24712471
///
24722472
/// ### Returns
24732473
///
@@ -3170,7 +3170,7 @@ impl Cage {
31703170
///
31713171
/// ### Panics
31723172
///
3173-
/// * There are no such panics which happen inside the function.
3173+
/// * This syscall indirectly panics when the helper function panics.
31743174
///
31753175
/// For more detailed description of all the commands and return values, see
31763176
/// [close(2)](https://man7.org/linux/man-pages/man2/close.2.html)
@@ -3267,11 +3267,15 @@ impl Cage {
32673267
// Remove the socket from the inode table and the domain
32683268
// socket paths if it is no longer needed.
32693269
drop(inodeobj);
3270+
// Get the entire path of the socket which is used for removing
3271+
// it from the metadata file.
32703272
let path = normpath(
32713273
convpath(sockhandle.localaddr.unwrap().path()),
32723274
self,
32733275
);
3276+
// Remove the reference of the inode from the inodetable
32743277
FS_METADATA.inodetable.remove(&inodenum);
3278+
// Remove any domain socket paths associated with the socket
32753279
NET_METADATA.domsock_paths.remove(&path);
32763280
}
32773281
}

src/tests/fs_tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,11 +4168,21 @@ pub mod fs_tests {
41684168
assert!(fd >= 0);
41694169

41704170
// Attempt to seek to a negative offset and check if it returns an error
4171+
// using "SEEK_SET" whence, where we are explicitly setting the file
4172+
// offset to -10 value.
41714173
assert_eq!(
41724174
cage.lseek_syscall(fd, -10, SEEK_SET),
41734175
-(Errno::EINVAL as i32)
41744176
);
41754177

4178+
// Attempt to seek to a negative offset and check if it returns an error
4179+
// using "SEEK_CUR" whence, where current position of the file is 0,
4180+
// as it's empty initially, and we are adding -10 to the offset.
4181+
assert_eq!(
4182+
cage.lseek_syscall(fd, -10, SEEK_CUR),
4183+
-(Errno::EINVAL as i32)
4184+
);
4185+
41764186
assert_eq!(cage.exit_syscall(EXIT_SUCCESS), EXIT_SUCCESS);
41774187
lindrustfinalize();
41784188
}

0 commit comments

Comments
 (0)