@@ -308,62 +308,34 @@ int zvfs_alloc_fd(void *obj, const struct fd_op_vtable *vtable)
308308 return fd ;
309309}
310310
311- static bool supports_pread_pwrite ( uint32_t mode )
311+ static ssize_t zvfs_rw ( int fd , void * buf , size_t sz , bool is_write )
312312{
313- switch (mode & ZVFS_MODE_IFMT ) {
314- case ZVFS_MODE_IFSHM :
315- return true;
316- default :
317- return false;
318- }
319- }
320-
321- static ssize_t zvfs_rw (int fd , void * buf , size_t sz , bool is_write , const size_t * from_offset )
322- {
323- bool prw ;
324313 ssize_t res ;
325- const size_t * off ;
326314
327315 if (_check_fd (fd ) < 0 ) {
328316 return -1 ;
329317 }
330318
331319 (void )k_mutex_lock (& fdtable [fd ].lock , K_FOREVER );
332320
333- prw = supports_pread_pwrite (fdtable [fd ].mode );
334- if (from_offset != NULL && !prw ) {
335- /*
336- * Seekable file types should support pread() / pwrite() and per-fd offset passing.
337- * Otherwise, it's a bug.
338- */
339- errno = ENOTSUP ;
340- res = -1 ;
341- goto unlock ;
342- }
343-
344- /* If there is no specified from_offset, then use the current offset of the fd */
345- off = (from_offset == NULL ) ? & fdtable [fd ].offset : from_offset ;
346-
347321 if (is_write ) {
348- if (fdtable [fd ].vtable -> write_offs == NULL ) {
322+ if (fdtable [fd ].vtable -> write_offset == NULL ) {
349323 res = -1 ;
350324 errno = EIO ;
351325 } else {
352- res = fdtable [fd ].vtable -> write_offs (fdtable [fd ].obj , buf , sz , * off );
326+ res = fdtable [fd ].vtable -> write_offset (fdtable [fd ].obj , buf , sz ,
327+ fdtable [fd ].offset );
353328 }
354329 } else {
355- if (fdtable [fd ].vtable -> read_offs == NULL ) {
330+ if (fdtable [fd ].vtable -> read == NULL ) {
356331 res = -1 ;
357332 errno = EIO ;
358333 } else {
359- res = fdtable [fd ].vtable -> read_offs (fdtable [fd ].obj , buf , sz , * off );
334+ res = fdtable [fd ].vtable -> read_offset (fdtable [fd ].obj , buf , sz ,
335+ fdtable [fd ].offset );
360336 }
361337 }
362- if (res > 0 && prw && from_offset == NULL ) {
363- /*
364- * only update the fd offset when from_offset is not specified
365- * See pread() / pwrite()
366- */
338+ if (res > 0 ) {
367339 fdtable [fd ].offset += res ;
368340 }
369341
@@ -373,14 +345,14 @@ static ssize_t zvfs_rw(int fd, void *buf, size_t sz, bool is_write, const size_t
373345 return res ;
374346}
375347
376- ssize_t zvfs_read (int fd , void * buf , size_t sz , const size_t * from_offset )
348+ ssize_t zvfs_read (int fd , void * buf , size_t sz )
377349{
378- return zvfs_rw (fd , buf , sz , false, from_offset );
350+ return zvfs_rw (fd , buf , sz , false);
379351}
380352
381- ssize_t zvfs_write (int fd , const void * buf , size_t sz , const size_t * from_offset )
353+ ssize_t zvfs_write (int fd , const void * buf , size_t sz )
382354{
383- return zvfs_rw (fd , (void * )buf , sz , true, from_offset );
355+ return zvfs_rw (fd , (void * )buf , sz , true);
384356}
385357
386358int zvfs_close (int fd )
@@ -522,7 +494,7 @@ static ssize_t stdinout_read_vmeth(void *obj, void *buffer, size_t count)
522494static ssize_t stdinout_write_vmeth (void * obj , const void * buffer , size_t count )
523495{
524496#if defined(CONFIG_BOARD_NATIVE_POSIX )
525- return zvfs_write (1 , buffer , count , NULL );
497+ return zvfs_write (1 , buffer , count );
526498#elif defined(CONFIG_NEWLIB_LIBC ) || defined(CONFIG_ARCMWDT_LIBC )
527499 return z_impl_zephyr_write_stdout (buffer , count );
528500#else
0 commit comments