@@ -1396,12 +1396,45 @@ impl Cage {
13961396 }
13971397
13981398 //------------------------------------STATFS SYSCALL------------------------------------
1399+ /// ### Description
1400+ ///
1401+ /// `statfs_syscall` retrieves file system status information for the file
1402+ /// system containing the file specified by `path` and populates the
1403+ /// provided `databuf` with this information.
1404+ ///
1405+ /// ### Arguments
1406+ ///
1407+ /// It accepts two parameters:
1408+ /// * `path` - A string slice that specifies the file path for which file
1409+ /// system status information is to be retrieved.
1410+ /// * `databuf` - A mutable reference to a `FSData` struct where the file
1411+ /// system status will be stored.
1412+ ///
1413+ /// ### Returns
1414+ ///
1415+ /// For a successful call, the return value will be 0. On error, a negative
1416+ /// errno is returned to indicate the error.
1417+ ///
1418+ /// ### Errors
1419+ ///
1420+ /// * `ENOENT` - The file specified by `path` does not exist or the path is
1421+ /// invalid.
1422+ ///
1423+ /// ### Panics
1424+ ///
1425+ /// * There are no panics that can happen in this function.
1426+ ///
1427+ /// For more detailed description of all the commands and return values,
1428+ /// refer to the statfs man page [here](https://man7.org/linux/man-pages/man2/statfs.2.html).
13991429
14001430 pub fn statfs_syscall ( & self , path : & str , databuf : & mut FSData ) -> i32 {
1431+ //convert the path to an absolute path of type `PathBuf`
14011432 let truepath = normpath ( convpath ( path) , self ) ;
14021433
14031434 //Walk the file tree to get inode from path
14041435 if let Some ( inodenum) = metawalk ( truepath. as_path ( ) ) {
1436+ // won't panic since check for inode number in table is already happening in
1437+ // above 'metawalk' function
14051438 let _inodeobj = FS_METADATA . inodetable . get ( & inodenum) . unwrap ( ) ;
14061439
14071440 //populate the dev id field -- can be done outside of the helper
@@ -1415,35 +1448,80 @@ impl Cage {
14151448 }
14161449
14171450 //------------------------------------FSTATFS SYSCALL------------------------------------
1451+ /// ### Description
1452+ ///
1453+ /// `fstatfs_syscall` retrieves file system status information for the file
1454+ /// system containing the file specified by the file descriptor `fd` and
1455+ /// populates the provided `databuf` with this information.
1456+ ///
1457+ /// ### Arguments
1458+ ///
1459+ /// It accepts two parameters:
1460+ /// * `fd` - The file descriptor that refers to the open file.
1461+ /// * `databuf` - A mutable reference to a `FSData` struct where the file
1462+ /// system status will be stored.
1463+ ///
1464+ /// ### Returns
1465+ ///
1466+ /// For a successful call, the return value will be 0. On error, a negative
1467+ /// errno is returned to indicate the error.
1468+ ///
1469+ /// ### Errors
1470+ ///
1471+ /// * `EBADF` - The file descriptor `fd` is either invalid or it refers to a
1472+ /// socket, stream, pipe, or epoll file descriptor, which are not
1473+ /// supported by this function.
1474+ ///
1475+ /// ### Panics
1476+ ///
1477+ /// * If the file descriptor provided isn't in the appropriate range, this
1478+ /// function can panic.
1479+ ///
1480+ /// For more detailed description of all the commands and return values,
1481+ /// refer to the statfs man page [here](https://man7.org/linux/man-pages/man2/statfs.2.html).
14181482
14191483 pub fn fstatfs_syscall ( & self , fd : i32 , databuf : & mut FSData ) -> i32 {
1484+ // BUG: If the provided file descriptor is out of bounds, get_filedescriptor
1485+ // returns Err(), unwrapping on which produces a 'panic!'
1486+ // otherwise, file descriptor table entry is stored in 'checkedfd'
14201487 let checkedfd = self . get_filedescriptor ( fd) . unwrap ( ) ;
14211488 let unlocked_fd = checkedfd. read ( ) ;
1489+
14221490 if let Some ( filedesc_enum) = & * unlocked_fd {
14231491 //populate the dev id field -- can be done outside of the helper
14241492 databuf. f_fsid = FS_METADATA . dev_id ;
14251493
14261494 match filedesc_enum {
1495+ // if the fd points to a normal file descriptor
14271496 File ( normalfile_filedesc_obj) => {
1497+ // won't panic since we have already checked that the entries exist
1498+ // in the FS_METADATA inode table
14281499 let _inodeobj = FS_METADATA
14291500 . inodetable
14301501 . get ( & normalfile_filedesc_obj. inode )
14311502 . unwrap ( ) ;
14321503
1504+ // populate the databuf using a helper function
14331505 return Self :: _istatfs_helper ( self , databuf) ;
14341506 }
1507+
1508+ // if the fd points to a socket, pipe, stream, or epoll file descriptor
14351509 Socket ( _) | Pipe ( _) | Stream ( _) | Epoll ( _) => {
14361510 return syscall_error (
14371511 Errno :: EBADF ,
14381512 "fstatfs" ,
1439- "can't fstatfs on socket, stream, pipe , or epollfd " ,
1513+ "can't fstatfs on sockets, streams, pipes , or epoll fds " ,
14401514 ) ;
14411515 }
14421516 }
1517+ } else {
1518+ return syscall_error ( Errno :: EBADF , "statfs" , "invalid file descriptor" ) ;
14431519 }
1444- return syscall_error ( Errno :: EBADF , "statfs" , "invalid file descriptor" ) ;
14451520 }
14461521
1522+ // These values have (probably) been picked up from the previously used
1523+ // environment, and have been working fine till now for our purposes
1524+ // TODO: Figure out how to populate the databuf values properly
14471525 pub fn _istatfs_helper ( & self , databuf : & mut FSData ) -> i32 {
14481526 databuf. f_type = 0xBEEFC0DE ; //unassigned
14491527 databuf. f_bsize = 4096 ;
@@ -5306,16 +5384,19 @@ impl Cage {
53065384
53075385 /// ### Description
53085386 ///
5309- /// `shmget_syscall` returns the shared memory segment identifier associated with a particular `key`
5310- /// If a key doesn't exist, shmget creates a new memory segment and attaches it to the key.
5311- /// Traditionally if the value of the key equals `IPC_PRIVATE`, we also create a new memory segment which
5312- /// is not associated with a key during this syscall,
5313- /// but for our implementaion, we return an error and only create a new memory
5314- /// segment when the IPC_CREAT flag is specified in the`shmflag` argument.
5387+ /// `shmget_syscall` returns the shared memory segment identifier associated
5388+ /// with a particular `key` If a key doesn't exist, shmget creates a new
5389+ /// memory segment and attaches it to the key. Traditionally if the
5390+ /// value of the key equals `IPC_PRIVATE`, we also create a new memory
5391+ /// segment which is not associated with a key during this syscall,
5392+ /// but for our implementaion, we return an error and only create a new
5393+ /// memory segment when the IPC_CREAT flag is specified in the`shmflag`
5394+ /// argument.
53155395 ///
53165396 /// ### Returns
53175397 ///
5318- /// An 32 bit integer which represens the identifier of the memory segment associated with the key
5398+ /// An 32 bit integer which represens the identifier of the memory segment
5399+ /// associated with the key
53195400 ///
53205401 /// ### Arguments
53215402 ///
@@ -5324,20 +5405,22 @@ impl Cage {
53245405 /// `shmflag` : mode flags which indicate whether to create a new key or not
53255406 /// The `shmflag` is composed of the following
53265407 /// * IPC_CREAT - specify that the system call creates a new segment
5327- /// * IPC_EXCL - this flag is used with IPC_CREAT to cause this function to fail when IPC_CREAT is also used
5328- /// and the key passed has a memory segment associated with it.
5408+ /// * IPC_EXCL - this flag is used with IPC_CREAT to cause this function to
5409+ /// fail when IPC_CREAT is also used and the key passed has a memory
5410+ /// segment associated with it.
53295411 ///
53305412 /// ### Errors
53315413 ///
53325414 /// * ENOENT : the key equals the `IPC_PRIVATE` constant
5333- /// * EEXIST : key exists and yet either `IPC_CREAT` or `IPC_EXCL` are passed as flags
5415+ /// * EEXIST : key exists and yet either `IPC_CREAT` or `IPC_EXCL` are
5416+ /// passed as flags
53345417 /// * ENOENT : key did not exist and the `IPC_CREAT` flag was not passed
5335- /// * EINVAL : the size passed was less than the minimum size of segment or greater than the maximum possible size
5418+ /// * EINVAL : the size passed was less than the minimum size of segment or
5419+ /// greater than the maximum possible size
53365420 ///
53375421 /// ### Panics
53385422 ///
53395423 /// There are no cases where the function directly panics
5340- ///
53415424 pub fn shmget_syscall ( & self , key : i32 , size : usize , shmflg : i32 ) -> i32 {
53425425 //Check if the key passed equals the IPC_PRIVATE flag
53435426 if key == IPC_PRIVATE {
@@ -5349,7 +5432,8 @@ impl Cage {
53495432 // data of the shm table
53505433 let metadata = & SHM_METADATA ;
53515434
5352- // Check if there exists a memory segment associated with the key passed as argument
5435+ // Check if there exists a memory segment associated with the key passed as
5436+ // argument
53535437 match metadata. shmkeyidtable . entry ( key) {
53545438 // If there exists a memory segment at that key
53555439 interface:: RustHashEntry :: Occupied ( occupied) => {
@@ -5375,8 +5459,8 @@ impl Cage {
53755459 ) ;
53765460 }
53775461
5378- // If memory segment doesn't exist and IPC_CREAT was specified - we create a new memory segment
5379- // Check if the size passed is a valid value
5462+ // If memory segment doesn't exist and IPC_CREAT was specified - we create a new
5463+ // memory segment Check if the size passed is a valid value
53805464 if ( size as u32 ) < SHMMIN || ( size as u32 ) > SHMMAX {
53815465 return syscall_error (
53825466 Errno :: EINVAL ,
0 commit comments