@@ -104,6 +104,7 @@ use crate::safeposix::shm::*;
104104impl Cage {
105105 /// ## ------------------OPEN SYSCALL------------------
106106 /// ### Description
107+ ///
107108 /// The `open_syscall()` creates an open file description that refers to a
108109 /// file and a file descriptor that refers to that open file description.
109110 /// The file descriptor is used by other I/O functions to refer to that
@@ -114,6 +115,7 @@ impl Cage {
114115 /// are checked and based on them, file is updated accordingly.
115116
116117 /// ### Function Arguments
118+ ///
117119 /// The `open_syscall()` receives three arguments:
118120 /// * `path` - This argument points to a pathname naming the file. For
119121 /// example: "/parentdir/file1" represents a file which will be either
@@ -129,11 +131,13 @@ impl Cage {
129131 /// search permissions on the new file.
130132
131133 /// ### Returns
134+ ///
132135 /// Upon successful completion of this call, a file descriptor is returned
133136 /// which points the file which is opened. Otherwise, errors or panics
134137 /// are returned for different scenarios.
135138 ///
136- /// ### Errors and Panics
139+ /// ### Errors
140+ ///
137141 /// * ENFILE - no available file descriptor number could be found
138142 /// * ENOENT - tried to open a file that did not exist
139143 /// * EINVAL - the input flags contain S_IFCHR flag representing a special
@@ -145,9 +149,15 @@ impl Cage {
145149 /// passed
146150 /// * ENXIO - the file is of type UNIX domain socket
147151 ///
148- /// A panic occurs when there is some issue fetching the file descriptor.
152+ /// ### Panics
149153 ///
150- /// for more detailed description of all the commands and return values, see
154+ /// * If truepath.file_name() returns None or if to_str() fails, causing
155+ /// unwrap() to panic.
156+ /// * If the parent inode does not exist in the inode table, causing
157+ /// unwrap() to panic.
158+ /// * When there is some other issue fetching the file descriptor.
159+ ///
160+ /// For more detailed description of all the commands and return values, see
151161 /// [open(2)](https://man7.org/linux/man-pages/man2/open.2.html)
152162
153163 // This function is used to create a new File Descriptor Object and return it.
@@ -915,9 +925,61 @@ impl Cage {
915925 }
916926 }
917927
918- //------------------------------------CREAT SYSCALL------------------------------------
919-
928+ /// ## ------------------CREAT SYSCALL------------------
929+ /// ### Description
930+ ///
931+ /// The `creat_syscall()` is similar to `open_syscall()` with the "flags"
932+ /// parameter for open_syscall set to representing create, truncate or write
933+ /// only for the file. It simplifies the process of creating a new file or
934+ /// truncating an existing one by combining the O_CREAT, O_TRUNC, and
935+ /// O_WRONLY flags.
936+ /// There are generally two cases which occur when this syscall happens:
937+ /// Case 1: If the file to be opened doesn't exist, then due to O_CREAT flag,
938+ /// a new file is created at the given location and a new file descriptor is
939+ /// created and returned.
940+ /// Case 2: If the file already exists, then due to O_TRUNC flag, the file
941+ /// size gets reduced to 0, and the existing file descriptor is returned.
942+ ///
943+ /// ### Function Arguments
944+ ///
945+ /// The `creat_syscall()` receives two arguments:
946+ /// * `path` - This argument points to a pathname naming the file. For
947+ /// example: "/parentdir/file1" represents a file which will be either
948+ /// opened if exists or will be created at the given path.
949+ /// * `mode` - This represents the permission of the newly created file. The
950+ /// general mode used is "S_IRWXA": which represents the read, write, and
951+ /// search permissions on the new file.
952+ ///
953+ /// ### Returns
954+ ///
955+ /// Upon successful completion of this call, a file descriptor is returned
956+ /// which points the file which is opened. Otherwise, errors or panics
957+ /// are returned for different scenarios.
958+ ///
959+ /// ### Errors
960+ ///
961+ /// * ENFILE - no available file descriptor number could be found
962+ /// * ENOENT - tried to open a file that did not exist
963+ /// * EPERM - the mode bits for a file are not sane
964+ /// * ENOTDIR - tried to create a file as a child of something that isn't a
965+ /// directory
966+ /// * EEXIST - the given file already exists
967+ /// * ENXIO - the file is of type UNIX domain socket
968+ ///
969+ /// ### Panics
970+ ///
971+ /// * If truepath.file_name() returns None or if to_str() fails, causing
972+ /// unwrap() to panic.
973+ /// * If the parent inode does not exist in the inode table, causing
974+ /// unwrap() to panic.
975+ /// * When there is some other issue fetching the file descriptor.
976+ ///
977+ /// For more detailed description of all the commands and return values, see
978+ /// [creat(3p)](https://man7.org/linux/man-pages/man3/creat.3p.html)
920979 pub fn creat_syscall ( & self , path : & str , mode : u32 ) -> i32 {
980+ // These flags represent that the given file is either newly created
981+ // (if it doesn't exist) or truncated to zero length (if it does exist),
982+ // and it is opened for write-only access.
921983 self . open_syscall ( path, O_CREAT | O_TRUNC | O_WRONLY , mode)
922984 }
923985
@@ -4488,8 +4550,8 @@ impl Cage {
44884550 drop ( sementry) ;
44894551 // Acquire the semaphore. This operation will block the calling process until
44904552 // the
4491- /// semaphore becomes available. The`lock` method internally
4492- /// decrements the semaphore value.
4553+ // semaphore becomes available. The`lock` method internally
4554+ // decrements the semaphore value.
44934555 // The lock fun is located in misc.rs
44944556 semaphore. lock ( ) ;
44954557 } else {
0 commit comments