MCPcopy Create free account
hub / github.com/coreutils/coreutils / print_statfs

Function print_statfs

src/stat.c:859–944  ·  view source on GitHub ↗

Print statfs info. Return zero upon success, nonzero upon failure. */

Source from the content-addressed store, hash-verified

857
858/* Print statfs info. Return zero upon success, nonzero upon failure. */
859NODISCARD
860static bool
861print_statfs (char *pformat, size_t prefix_len, MAYBE_UNUSED char mod, char m,
862 MAYBE_UNUSED int fd, char const *filename,
863 void const *data)
864{
865 STRUCT_STATVFS const *statfsbuf = data;
866 bool fail = false;
867
868 switch (m)
869 {
870 case 'n':
871 out_string (pformat, prefix_len, filename);
872 break;
873
874 case 'i':
875 {
876#if STRUCT_STATXFS_F_FSID_IS_INTEGER
877 uintmax_t fsid = statfsbuf->f_fsid;
878#else
879 typedef unsigned int fsid_word;
880 static_assert (alignof (STRUCT_STATVFS) % alignof (fsid_word) == 0);
881 static_assert (offsetof (STRUCT_STATVFS, f_fsid) % alignof (fsid_word)
882 == 0);
883 static_assert (sizeof statfsbuf->f_fsid % alignof (fsid_word) == 0);
884 fsid_word const *p = (fsid_word *) &statfsbuf->f_fsid;
885
886 /* Assume a little-endian word order, as that is compatible
887 with glibc's statvfs implementation. */
888 uintmax_t fsid = 0;
889 int words = sizeof statfsbuf->f_fsid / sizeof *p;
890 for (int i = 0; i < words && i * sizeof *p < sizeof fsid; i++)
891 {
892 uintmax_t u = p[words - 1 - i];
893 fsid |= u << (i * CHAR_BIT * sizeof *p);
894 }
895#endif
896 out_uint_x (pformat, prefix_len, fsid);
897 }
898 break;
899
900 case 'l':
901 OUT_NAMEMAX (pformat, prefix_len, SB_F_NAMEMAX (statfsbuf));
902 break;
903 case 't':
904#if HAVE_STRUCT_STATXFS_F_TYPE
905 out_uint_x (pformat, prefix_len, statfsbuf->f_type);
906#else
907 fputc ('?', stdout);
908#endif
909 break;
910 case 'T':
911 out_string (pformat, prefix_len, human_fstype (statfsbuf));
912 break;
913 case 'b':
914 out_int (pformat, prefix_len, statfsbuf->f_blocks);
915 break;
916 case 'f':

Callers

nothing calls this directly

Calls 5

out_stringFunction · 0.85
out_uint_xFunction · 0.85
human_fstypeFunction · 0.85
out_intFunction · 0.85
out_uintFunction · 0.85

Tested by

no test coverage detected