@@ -170,7 +170,28 @@ os_fstat(os_file_handle handle, struct __wasi_filestat_t *buf)
170170 return __WASI_ESUCCESS ;
171171 }
172172
173- return os_fstatat (handle , ptr -> path , buf , 0 );
173+ // Get file information using Zephyr's fs_stat function
174+ struct fs_dirent entry ;
175+ rc = fs_stat (ptr -> path , & entry );
176+ if (rc < 0 ) {
177+ return convert_errno (- rc );
178+ }
179+
180+ // Fill in the __wasi_filestat_t structure
181+ buf -> st_dev = 0 ; // Zephyr's fs_stat doesn't provide a device ID
182+ buf -> st_ino = 0 ; // Zephyr's fs_stat doesn't provide an inode number
183+ buf -> st_filetype = entry .type == FS_DIR_ENTRY_DIR
184+ ? __WASI_FILETYPE_DIRECTORY
185+ : __WASI_FILETYPE_REGULAR_FILE ;
186+ buf -> st_nlink = 1 ; // Zephyr's fs_stat doesn't provide a link count
187+ buf -> st_size = entry .size ;
188+ buf -> st_atim = 0 ; // Zephyr's fs_stat doesn't provide timestamps
189+ buf -> st_mtim = 0 ;
190+ buf -> st_ctim = 0 ;
191+
192+ return __WASI_ESUCCESS ;
193+
194+ // return os_fstatat(handle, ptr->path, buf, 0);
174195 }
175196 else {
176197 // socklen_t socktypelen = sizeof(socktype);
@@ -214,8 +235,18 @@ os_fstatat(os_file_handle handle, const char *path,
214235 return __WASI_EBADF ;
215236 }
216237
238+ char abs_path [MAX_FILE_NAME + 1 ];
239+
240+ if (handle == NULL ) {
241+ return __WASI_EINVAL ; // Or another appropriate error code
242+ }
243+
244+ if (!build_absolute_path (abs_path , sizeof (abs_path ), path )) {
245+ return __WASI_ENOMEM ;
246+ }
247+
217248 // Get file information using Zephyr's fs_stat function
218- rc = fs_stat (path , & entry );
249+ rc = fs_stat (abs_path , & entry );
219250 if (rc < 0 ) {
220251 return convert_errno (- rc );
221252 }
@@ -798,11 +829,7 @@ os_unlinkat(os_file_handle handle, const char *path, bool is_dir)
798829 return __WASI_ENOMEM ;
799830 }
800831
801- if (is_dir ) {
802- return __WASI_ENOTDIR ;
803- }
804-
805- int rc = fs_unlink (path );
832+ int rc = fs_unlink (abs_path );
806833 if (rc < 0 ) {
807834 return convert_errno (- rc );
808835 }
0 commit comments