Skip to content

Commit ba30c7b

Browse files
Maksymilian Goryszewskicfriedt
authored andcommitted
lib: posix: fs: Basic fstat() using seek and tell
Implement limited posix fstat() Signed-off-by: Maksymilian Goryszewski <[email protected]>
1 parent eb7e086 commit ba30c7b

File tree

1 file changed

+29
-0
lines changed
  • lib/posix/options

1 file changed

+29
-0
lines changed

lib/posix/options/fs.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,35 @@ static int fs_ioctl_vmeth(void *obj, unsigned int request, va_list args)
154154
struct posix_fs_desc *ptr = obj;
155155

156156
switch (request) {
157+
case ZFD_IOCTL_STAT: {
158+
struct stat *buf = va_arg(args, struct stat *);
159+
long offset = fs_tell(&ptr->file);
160+
long current;
161+
162+
if (offset < 0) {
163+
return offset;
164+
}
165+
166+
memset(buf, 0, sizeof(struct stat));
167+
168+
rc = fs_seek(&ptr->file, 0, FS_SEEK_END);
169+
if (rc < 0) {
170+
return rc;
171+
}
172+
173+
current = fs_tell(&ptr->file);
174+
if (current >= 0) {
175+
buf->st_size = current;
176+
buf->st_mode = ptr->is_dir ? S_IFDIR : S_IFREG;
177+
}
178+
179+
rc = fs_seek(&ptr->file, offset, FS_SEEK_SET);
180+
181+
if (current < 0) {
182+
rc = current;
183+
}
184+
break;
185+
}
157186
case ZFD_IOCTL_FSYNC: {
158187
rc = fs_sync(&ptr->file);
159188
break;

0 commit comments

Comments
 (0)