mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] [f]statvfs: allocate spare for f_type
@ 2023-06-23 20:36 наб
  2023-06-24  4:39 ` Szabolcs Nagy
  0 siblings, 1 reply; 4+ messages in thread
From: наб @ 2023-06-23 20:36 UTC (permalink / raw)
  Cc: musl

[-- Attachment #1: Type: text/plain, Size: 1713 bytes --]

This is the only missing part in struct statvfs.
The LSB calls [f]statfs() deprecated, and its weird types are definitely
off-putting. However, its use is required to get f_type.

Instead, allocate one of the six spares to f_type,
copied directly from struct statfs.
This then becomes a small extension to the standard interface on Linux,
instead of two different interfaces, one of which is quite odd due to
being an ABI type, and there no longer is any reason to use statfs().

The underlying kernel type is a mess, but all architectures agree on u32
(or more) for the ABI, and all filesystem magicks are 32-bit integers.

Link: https://lore.kernel.org/linux-man/f54kudgblgk643u32tb6at4cd3kkzha6hslahv24szs4raroaz@ogivjbfdaqtb/t/#u
---
 include/sys/statvfs.h | 3 ++-
 src/stat/statvfs.c    | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/sys/statvfs.h b/include/sys/statvfs.h
index 57a6b806..71d9d1f9 100644
--- a/include/sys/statvfs.h
+++ b/include/sys/statvfs.h
@@ -23,7 +23,8 @@ struct statvfs {
 	unsigned long f_fsid;
 #endif
 	unsigned long f_flag, f_namemax;
-	int __reserved[6];
+	unsigned int f_type;
+	int __reserved[5];
 };
 
 int statvfs (const char *__restrict, struct statvfs *__restrict);
diff --git a/src/stat/statvfs.c b/src/stat/statvfs.c
index bfbb5fee..bc12da8b 100644
--- a/src/stat/statvfs.c
+++ b/src/stat/statvfs.c
@@ -39,6 +39,7 @@ static void fixup(struct statvfs *out, const struct statfs *in)
 	out->f_fsid = in->f_fsid.__val[0];
 	out->f_flag = in->f_flags;
 	out->f_namemax = in->f_namelen;
+	out->f_type = in->f_type;
 }
 
 int statvfs(const char *restrict path, struct statvfs *restrict buf)
-- 
2.39.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [musl] [PATCH] [f]statvfs: allocate spare for f_type
  2023-06-23 20:36 [musl] [PATCH] [f]statvfs: allocate spare for f_type наб
@ 2023-06-24  4:39 ` Szabolcs Nagy
  2023-08-17 20:05   ` [musl] [PATCH v2] " наб
  0 siblings, 1 reply; 4+ messages in thread
From: Szabolcs Nagy @ 2023-06-24  4:39 UTC (permalink / raw)
  To: наб; +Cc: musl

* наб <nabijaczleweli@nabijaczleweli.xyz> [2023-06-23 22:36:11 +0200]:
> This is the only missing part in struct statvfs.
> The LSB calls [f]statfs() deprecated, and its weird types are definitely
> off-putting. However, its use is required to get f_type.
> 
> Instead, allocate one of the six spares to f_type,
> copied directly from struct statfs.
> This then becomes a small extension to the standard interface on Linux,
> instead of two different interfaces, one of which is quite odd due to
> being an ABI type, and there no longer is any reason to use statfs().
> 
> The underlying kernel type is a mess, but all architectures agree on u32
> (or more) for the ABI, and all filesystem magicks are 32-bit integers.
> 
> Link: https://lore.kernel.org/linux-man/f54kudgblgk643u32tb6at4cd3kkzha6hslahv24szs4raroaz@ogivjbfdaqtb/t/#u

fwiw this looks good to me assuming the glibc patch gets accepted:

https://patchwork.sourceware.org/project/glibc/patch/169a6ec2a9957495275964afd0697fa3aea1c6b6.1687552604.git.nabijaczleweli@nabijaczleweli.xyz/


> ---
>  include/sys/statvfs.h | 3 ++-
>  src/stat/statvfs.c    | 1 +
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/include/sys/statvfs.h b/include/sys/statvfs.h
> index 57a6b806..71d9d1f9 100644
> --- a/include/sys/statvfs.h
> +++ b/include/sys/statvfs.h
> @@ -23,7 +23,8 @@ struct statvfs {
>  	unsigned long f_fsid;
>  #endif
>  	unsigned long f_flag, f_namemax;
> -	int __reserved[6];
> +	unsigned int f_type;
> +	int __reserved[5];
>  };
>  
>  int statvfs (const char *__restrict, struct statvfs *__restrict);
> diff --git a/src/stat/statvfs.c b/src/stat/statvfs.c
> index bfbb5fee..bc12da8b 100644
> --- a/src/stat/statvfs.c
> +++ b/src/stat/statvfs.c
> @@ -39,6 +39,7 @@ static void fixup(struct statvfs *out, const struct statfs *in)
>  	out->f_fsid = in->f_fsid.__val[0];
>  	out->f_flag = in->f_flags;
>  	out->f_namemax = in->f_namelen;
> +	out->f_type = in->f_type;
>  }
>  
>  int statvfs(const char *restrict path, struct statvfs *restrict buf)
> -- 
> 2.39.2



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [musl] [PATCH v2] [f]statvfs: allocate spare for f_type
  2023-06-24  4:39 ` Szabolcs Nagy
@ 2023-08-17 20:05   ` наб
  2024-08-24 15:00     ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: наб @ 2023-08-17 20:05 UTC (permalink / raw)
  To: Szabolcs Nagy; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 1864 bytes --]

This is the only missing part in struct statvfs.
The LSB calls [f]statfs() deprecated, and its weird types are definitely
off-putting. However, its use is required to get f_type.

Instead, allocate one of the six spares to f_type,
copied directly from struct statfs.
This then becomes a small extension to the standard interface on Linux,
instead of two different interfaces, one of which is quite odd due to
being an ABI type, and there no longer is any reason to use statfs().

The underlying kernel type is a mess, but all architectures agree on u32
(or more) for the ABI, and all filesystem magicks are 32-bit integers.

Link: https://lore.kernel.org/linux-man/f54kudgblgk643u32tb6at4cd3kkzha6hslahv24szs4raroaz@ogivjbfdaqtb/t/#u
Link: https://sourceware.org/git/?p=glibc.git;a=commit;h=92861d93cdad13834f4d8f39504b550a80ad8200
---
Applied in glibc for 2.39, so resending rebased.

 include/sys/statvfs.h | 3 ++-
 src/stat/statvfs.c    | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/sys/statvfs.h b/include/sys/statvfs.h
index 57a6b806..71d9d1f9 100644
--- a/include/sys/statvfs.h
+++ b/include/sys/statvfs.h
@@ -23,7 +23,8 @@ struct statvfs {
 	unsigned long f_fsid;
 #endif
 	unsigned long f_flag, f_namemax;
-	int __reserved[6];
+	unsigned int f_type;
+	int __reserved[5];
 };
 
 int statvfs (const char *__restrict, struct statvfs *__restrict);
diff --git a/src/stat/statvfs.c b/src/stat/statvfs.c
index bfbb5fee..bc12da8b 100644
--- a/src/stat/statvfs.c
+++ b/src/stat/statvfs.c
@@ -39,6 +39,7 @@ static void fixup(struct statvfs *out, const struct statfs *in)
 	out->f_fsid = in->f_fsid.__val[0];
 	out->f_flag = in->f_flags;
 	out->f_namemax = in->f_namelen;
+	out->f_type = in->f_type;
 }
 
 int statvfs(const char *restrict path, struct statvfs *restrict buf)
-- 
2.39.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [musl] [PATCH v2] [f]statvfs: allocate spare for f_type
  2023-08-17 20:05   ` [musl] [PATCH v2] " наб
@ 2024-08-24 15:00     ` Rich Felker
  0 siblings, 0 replies; 4+ messages in thread
From: Rich Felker @ 2024-08-24 15:00 UTC (permalink / raw)
  To: наб; +Cc: Szabolcs Nagy, musl

On Thu, Aug 17, 2023 at 10:05:14PM +0200, наб wrote:
> This is the only missing part in struct statvfs.
> The LSB calls [f]statfs() deprecated, and its weird types are definitely
> off-putting. However, its use is required to get f_type.
> 
> Instead, allocate one of the six spares to f_type,
> copied directly from struct statfs.
> This then becomes a small extension to the standard interface on Linux,
> instead of two different interfaces, one of which is quite odd due to
> being an ABI type, and there no longer is any reason to use statfs().
> 
> The underlying kernel type is a mess, but all architectures agree on u32
> (or more) for the ABI, and all filesystem magicks are 32-bit integers.

Revisiting this, the commit message was incorrect, particularly the
wording:

    "This is the only missing part in struct statvfs."

struct statvfs has unsigned long f_fsid, which is only a 32-bit field
and does not represent the full (total 64-bit) pair fsid_t from struct
statfs that Linux provides.

I did some digging into what this actually is, and on filesystems that
have a uuid in the superblock, it's a very basic hash (xor of upper
and lower half) of the uuid into a 64-bit value.

glibc combines the upper and lower half to a single 64-bit unsigned
long on 64-bit archs, but uses only the first 32-bit part on 32-bit
archs. On musl, I intentionally only used the first part to avoid a
functionality discrepancy between 32- and 64-bit archs.

Since then, gnu coreutils has switched from using statfs to statvfs,
producing a "regression" on musl and 32-bit glibc archs. Arguably this
"regression" does not matter, since the value itself is not meaningful
and there's really nothing useful you can do with it, but it's
probably worth noting.

Rich

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-24 15:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23 20:36 [musl] [PATCH] [f]statvfs: allocate spare for f_type наб
2023-06-24  4:39 ` Szabolcs Nagy
2023-08-17 20:05   ` [musl] [PATCH v2] " наб
2024-08-24 15:00     ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).