[glib/wip/smcv/statx-no-required-mask: 1/2] glocalfile: Remove the concept of the required mask




commit 7b7956361f95e017c737d37208bff18c225e28cd
Author: Simon McVittie <smcv collabora com>
Date:   Tue Sep 15 10:35:08 2020 +0100

    glocalfile: Remove the concept of the required mask
    
    It is not actually guaranteed that *any* of the flags in the
    returned stx_mask will be set by statx(): for example, if the
    filesystem has no concept of POSIX user and group IDs (like FAT),
    the kernel could validly clear the STATX_UID and STATX_GID bits in
    the returned stx_mask. Linux 5.8 does not appear to do this in practice,
    even for FAT, but the statx(2) man page suggests that it perhaps should.
    
    However, what *is* guaranteed is that for the STATX_BASIC_STATS (those
    that correspond to what is in the traditional struct stat), even if the
    bit in stx_mask is cleared, there will be *something* in the
    corresponding struct field (in practice the same harmless value that
    traditional stat() would have placed in the struct stat). Rely on those
    compatibility values being reasonable, and don't second-guess the kernel.
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 gio/glocalfile.c     |  6 ++----
 gio/glocalfileinfo.c |  3 ---
 gio/glocalfileinfo.h | 61 +++++-----------------------------------------------
 3 files changed, 7 insertions(+), 63 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index a87de9cc4..fe1fc9ef7 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -1352,7 +1352,7 @@ g_local_file_read (GFile         *file,
       return NULL;
     }
 
-  ret = g_local_file_fstat (fd, G_LOCAL_FILE_STAT_FIELD_TYPE, G_LOCAL_FILE_STAT_FIELD_ALL, &buf);
+  ret = g_local_file_fstat (fd, G_LOCAL_FILE_STAT_FIELD_TYPE, &buf);
 
   if (ret == 0 && S_ISDIR (_g_stat_mode (&buf)))
     {
@@ -2703,9 +2703,7 @@ g_local_file_measure_size_of_file (gint           parent_fd,
 
 #if defined (AT_FDCWD)
   if (g_local_file_fstatat (parent_fd, name->data, AT_SYMLINK_NOFOLLOW,
-                            G_LOCAL_FILE_STAT_FIELD_BASIC_STATS,
-                            G_LOCAL_FILE_STAT_FIELD_ALL & (~G_LOCAL_FILE_STAT_FIELD_ATIME),
-                            &buf) != 0)
+                            G_LOCAL_FILE_STAT_FIELD_BASIC_STATS, &buf) != 0)
     {
       int errsv = errno;
       return g_local_file_measure_size_error (state->flags, errsv, name, error);
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index 90fcb3336..b9c099cac 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -1808,7 +1808,6 @@ _g_local_file_info_get (const char             *basename,
 
   res = g_local_file_lstat (path,
                             G_LOCAL_FILE_STAT_FIELD_BASIC_STATS | G_LOCAL_FILE_STAT_FIELD_BTIME,
-                            G_LOCAL_FILE_STAT_FIELD_ALL & (~G_LOCAL_FILE_STAT_FIELD_BTIME) & 
(~G_LOCAL_FILE_STAT_FIELD_ATIME),
                             &statbuf);
 
   if (res == -1)
@@ -1858,7 +1857,6 @@ _g_local_file_info_get (const char             *basename,
        {
           res = g_local_file_stat (path,
                                    G_LOCAL_FILE_STAT_FIELD_BASIC_STATS | G_LOCAL_FILE_STAT_FIELD_BTIME,
-                                   G_LOCAL_FILE_STAT_FIELD_ALL & (~G_LOCAL_FILE_STAT_FIELD_BTIME) & 
(~G_LOCAL_FILE_STAT_FIELD_ATIME),
                                    &statbuf2);
 
          /* Report broken links as symlinks */
@@ -2081,7 +2079,6 @@ _g_local_file_info_get_from_fd (int         fd,
 
   if (g_local_file_fstat (fd,
                           G_LOCAL_FILE_STAT_FIELD_BASIC_STATS | G_LOCAL_FILE_STAT_FIELD_BTIME,
-                          G_LOCAL_FILE_STAT_FIELD_ALL & (~G_LOCAL_FILE_STAT_FIELD_BTIME) & 
(~G_LOCAL_FILE_STAT_FIELD_ATIME),
                           &stat_buf) == -1)
     {
       int errsv = errno;
diff --git a/gio/glocalfileinfo.h b/gio/glocalfileinfo.h
index f2beb70cd..53ccd7a84 100644
--- a/gio/glocalfileinfo.h
+++ b/gio/glocalfileinfo.h
@@ -80,33 +80,17 @@ g_local_file_statx (int                  dirfd,
                     const char          *pathname,
                     int                  flags,
                     GLocalFileStatField  mask,
-                    GLocalFileStatField  mask_required,
                     GLocalFileStat      *stat_buf)
 {
-  int retval;
-
-  /* Allow the caller to set mask_required==G_LOCAL_FILE_STAT_FIELD_ALL as a
-   * shortcut for saying it’s equal to @mask. */
-  mask_required &= mask;
-
-  retval = statx (dirfd, pathname, flags, mask, stat_buf);
-  if (retval == 0 && (stat_buf->stx_mask & mask_required) != mask_required)
-    {
-      /* Not all required fields could be returned. */
-      errno = ERANGE;
-      return -1;
-    }
-
-  return retval;
+  return statx (dirfd, pathname, flags, mask, stat_buf);
 }
 
 static inline int
 g_local_file_fstat (int                  fd,
                     GLocalFileStatField  mask,
-                    GLocalFileStatField  mask_required,
                     GLocalFileStat      *stat_buf)
 {
-  return g_local_file_statx (fd, "", AT_EMPTY_PATH, mask, mask_required, stat_buf);
+  return g_local_file_statx (fd, "", AT_EMPTY_PATH, mask, stat_buf);
 }
 
 static inline int
@@ -114,32 +98,29 @@ g_local_file_fstatat (int                  fd,
                       const char          *path,
                       int                  flags,
                       GLocalFileStatField  mask,
-                      GLocalFileStatField  mask_required,
                       GLocalFileStat      *stat_buf)
 {
-  return g_local_file_statx (fd, path, flags, mask, mask_required, stat_buf);
+  return g_local_file_statx (fd, path, flags, mask, stat_buf);
 }
 
 static inline int
 g_local_file_lstat (const char          *path,
                     GLocalFileStatField  mask,
-                    GLocalFileStatField  mask_required,
                     GLocalFileStat      *stat_buf)
 {
   return g_local_file_statx (AT_FDCWD, path,
                              AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW | AT_STATX_SYNC_AS_STAT,
-                             mask, mask_required, stat_buf);
+                             mask, stat_buf);
 }
 
 static inline int
 g_local_file_stat (const char          *path,
                    GLocalFileStatField  mask,
-                   GLocalFileStatField  mask_required,
                    GLocalFileStat      *stat_buf)
 {
   return g_local_file_statx (AT_FDCWD, path,
                              AT_NO_AUTOMOUNT | AT_STATX_SYNC_AS_STAT,
-                             mask, mask_required, stat_buf);
+                             mask, stat_buf);
 }
 
 inline static gboolean _g_stat_has_field  (const GLocalFileStat *buf, GLocalFileStatField field) { return 
buf->stx_mask & field; }
@@ -204,16 +185,8 @@ typedef enum
 static inline int
 g_local_file_fstat (int                  fd,
                     GLocalFileStatField  mask,
-                    GLocalFileStatField  mask_required,
                     GLocalFileStat      *stat_buf)
 {
-  if ((G_LOCAL_FILE_STAT_FIELD_BASIC_STATS & (mask_required & mask)) != (mask_required & mask))
-    {
-      /* Only G_LOCAL_FILE_STAT_FIELD_BASIC_STATS are supported. */
-      errno = ERANGE;
-      return -1;
-    }
-
 #ifdef G_OS_WIN32
   return GLIB_PRIVATE_CALL (g_win32_fstat) (fd, stat_buf);
 #else
@@ -226,16 +199,8 @@ g_local_file_fstatat (int                  fd,
                       const char          *path,
                       int                  flags,
                       GLocalFileStatField  mask,
-                      GLocalFileStatField  mask_required,
                       GLocalFileStat      *stat_buf)
 {
-  if ((G_LOCAL_FILE_STAT_FIELD_BASIC_STATS & (mask_required & mask)) != (mask_required & mask))
-    {
-      /* Only G_LOCAL_FILE_STAT_FIELD_BASIC_STATS are supported. */
-      errno = ERANGE;
-      return -1;
-    }
-
 #ifdef G_OS_WIN32
   /* Currently not supported on Windows */
   errno = ENOSYS;
@@ -248,16 +213,8 @@ g_local_file_fstatat (int                  fd,
 static inline int
 g_local_file_lstat (const char          *path,
                     GLocalFileStatField  mask,
-                    GLocalFileStatField  mask_required,
                     GLocalFileStat      *stat_buf)
 {
-  if ((G_LOCAL_FILE_STAT_FIELD_BASIC_STATS & (mask_required & mask)) != (mask_required & mask))
-    {
-      /* Only G_LOCAL_FILE_STAT_FIELD_BASIC_STATS are supported. */
-      errno = ERANGE;
-      return -1;
-    }
-
 #ifdef G_OS_WIN32
   return GLIB_PRIVATE_CALL (g_win32_lstat_utf8) (path, stat_buf);
 #else
@@ -268,16 +225,8 @@ g_local_file_lstat (const char          *path,
 static inline int
 g_local_file_stat (const char          *path,
                    GLocalFileStatField  mask,
-                   GLocalFileStatField  mask_required,
                    GLocalFileStat      *stat_buf)
 {
-  if ((G_LOCAL_FILE_STAT_FIELD_BASIC_STATS & (mask_required & mask)) != (mask_required & mask))
-    {
-      /* Only G_LOCAL_FILE_STAT_FIELD_BASIC_STATS are supported. */
-      errno = ERANGE;
-      return -1;
-    }
-
 #ifdef G_OS_WIN32
   return GLIB_PRIVATE_CALL (g_win32_stat_utf8) (path, stat_buf);
 #else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]