]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[linux] Use fstat() rather than statx()
authorMichael Brown <mcb30@ipxe.org>
Wed, 3 Mar 2021 00:34:02 +0000 (00:34 +0000)
committerMichael Brown <mcb30@ipxe.org>
Wed, 3 Mar 2021 01:01:58 +0000 (01:01 +0000)
The statx() system call has a clean header file and a consistent
layout, but was unfortunately added only in kernel 4.11.

Using stat() or fstat() directly is extremely messy since glibc does
not necessarily use the kernel native data structures.  However, as
the only current use case is to obtain the length of an open file, we
can merely provide a wrapper that does precisely this.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/linux_api.h
src/interface/linux/linux_api.c
src/interface/linux/linux_sysfs.c

index ab2e8014de6d872c47a9c8c27a9eccf074f809de..5b0b242d188b9e235ace101975072528d6132402 100644 (file)
@@ -46,7 +46,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <linux/ioctl.h>
 #include <linux/poll.h>
 #include <linux/fs.h>
-#include <linux/stat.h>
 #define MAP_FAILED ( ( void * ) -1 )
 #endif
 
@@ -66,8 +65,7 @@ extern ssize_t __asmcall linux_read ( int fd, void *buf, size_t count );
 extern ssize_t __asmcall linux_write ( int fd, const void *buf, size_t count );
 extern int __asmcall linux_fcntl ( int fd, int cmd, ... );
 extern int __asmcall linux_ioctl ( int fd, unsigned long request, ... );
-extern int __asmcall linux_statx ( int dirfd, const char *pathname, int flags,
-                                  unsigned int mask, struct statx *statxbuf );
+extern int __asmcall linux_fstat_size ( int fd, size_t *size );
 extern int __asmcall linux_poll ( struct pollfd *fds, unsigned int nfds,
                                  int timeout );
 extern int __asmcall linux_nanosleep ( const struct timespec *req,
index 6fa2b0e76b557b11e0755117dd019746e64fd73c..d1f969aa7195f3d65fb0cc305cb4a112826af2af 100644 (file)
@@ -200,14 +200,15 @@ int __asmcall linux_ioctl ( int fd, unsigned long request, ... ) {
 }
 
 /**
- * Wrap statx()
+ * Wrap part of fstat()
  *
  */
-int __asmcall linux_statx ( int dirfd, const char *pathname, int flags,
-                           unsigned int mask, struct statx *statxbuf ) {
+int __asmcall linux_fstat_size ( int fd, size_t *size ) {
+       struct stat stat;
        int ret;
 
-       ret = statx ( dirfd, pathname, flags, mask, statxbuf );
+       ret = fstat ( fd, &stat );
+       *size = stat.st_size;
        if ( ret == -1 )
                linux_errno = errno;
        return ret;
@@ -531,7 +532,7 @@ PROVIDE_IPXE_SYM ( linux_read );
 PROVIDE_IPXE_SYM ( linux_write );
 PROVIDE_IPXE_SYM ( linux_fcntl );
 PROVIDE_IPXE_SYM ( linux_ioctl );
-PROVIDE_IPXE_SYM ( linux_statx );
+PROVIDE_IPXE_SYM ( linux_fstat_size );
 PROVIDE_IPXE_SYM ( linux_poll );
 PROVIDE_IPXE_SYM ( linux_nanosleep );
 PROVIDE_IPXE_SYM ( linux_usleep );
index 0b9f1f5d958c59deeb23ba70f48849e78333cfc6..463bc2ab92a37bc1b025387917dcad95158dc53a 100644 (file)
@@ -40,7 +40,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
  * @ret len            Length read, or negative error
  */
 int linux_sysfs_read ( const char *filename, userptr_t *data ) {
-       struct statx statx;
        size_t offset;
        size_t len;
        ssize_t read;
@@ -57,13 +56,12 @@ int linux_sysfs_read ( const char *filename, userptr_t *data ) {
        }
 
        /* Get file length */
-       if ( linux_statx ( fd, "", AT_EMPTY_PATH, STATX_SIZE, &statx ) == -1 ) {
+       if ( linux_fstat_size ( fd, &len ) == -1 ) {
                rc = -ELINUX ( linux_errno );
                DBGC ( filename, "LINUX could not stat %s: %s\n",
                       filename, linux_strerror ( linux_errno ) );
                goto err_stat;
        }
-       len = statx.stx_size;
 
        /* Allocate buffer */
        *data = umalloc ( len );