From: "Thomas Weißschuh" <linux@weissschuh.net>
To: linux-fsdevel@vger.kernel.org
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
linux-kernel@vger.kernel.org, "Karel Zak" <kzak@redhat.com>,
"Masatake YAMATO" <yamato@redhat.com>,
linux-api@vger.kernel.org
Subject: [PATCH] proc: add byteorder file
Date: Tue, 1 Nov 2022 01:50:43 +0100 [thread overview]
Message-ID: <20221101005043.1791-1-linux@weissschuh.net> (raw)
Certain files in procfs are formatted in byteorder dependent ways. For
example the IP addresses in /proc/net/udp.
Assuming the byteorder of the userspace program is not guaranteed to be
correct in the face of emulation as for example with qemu-user.
Also this makes it easier for non-compiled applications like
shellscripts to discover the byteorder.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Development of userspace part: https://github.com/util-linux/util-linux/pull/1872
---
Documentation/ABI/testing/procfs-byteorder | 12 +++++++++
fs/proc/Makefile | 1 +
fs/proc/byteorder.c | 31 ++++++++++++++++++++++
3 files changed, 44 insertions(+)
create mode 100644 Documentation/ABI/testing/procfs-byteorder
create mode 100644 fs/proc/byteorder.c
diff --git a/Documentation/ABI/testing/procfs-byteorder b/Documentation/ABI/testing/procfs-byteorder
new file mode 100644
index 000000000000..bb80aae889be
--- /dev/null
+++ b/Documentation/ABI/testing/procfs-byteorder
@@ -0,0 +1,12 @@
+What: /proc/byteorder
+Date: February 2023
+KernelVersion: 6.2
+Contact: linux-fsdevel@vger.kernel.org
+Description:
+ The current endianness of the running kernel.
+
+ Access: Read
+
+ Valid values:
+ "little", "big"
+Users: util-linux
diff --git a/fs/proc/Makefile b/fs/proc/Makefile
index bd08616ed8ba..c790d3665358 100644
--- a/fs/proc/Makefile
+++ b/fs/proc/Makefile
@@ -12,6 +12,7 @@ proc-$(CONFIG_MMU) := task_mmu.o
proc-y += inode.o root.o base.o generic.o array.o \
fd.o
proc-$(CONFIG_TTY) += proc_tty.o
+proc-y += byteorder.o
proc-y += cmdline.o
proc-y += consoles.o
proc-y += cpuinfo.o
diff --git a/fs/proc/byteorder.c b/fs/proc/byteorder.c
new file mode 100644
index 000000000000..39644b281da9
--- /dev/null
+++ b/fs/proc/byteorder.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <asm/byteorder.h>
+#include <linux/fs.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include "internal.h"
+
+#if defined(__LITTLE_ENDIAN)
+#define BYTEORDER_STRING "little"
+#elif defined(__BIG_ENDIAN)
+#define BYTEORDER_STRING "big"
+#else
+#error Unknown byteorder
+#endif
+
+static int byteorder_seq_show(struct seq_file *seq, void *)
+{
+ seq_puts(seq, BYTEORDER_STRING "\n");
+ return 0;
+}
+
+static int __init proc_byteorder_init(void)
+{
+ struct proc_dir_entry *pde;
+
+ pde = proc_create_single("byteorder", 0444, NULL, byteorder_seq_show);
+ pde_make_permanent(pde);
+ return 0;
+}
+fs_initcall(proc_byteorder_init);
base-commit: 5aaef24b5c6d4246b2cac1be949869fa36577737
--
2.38.1
next reply other threads:[~2022-11-01 0:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-01 0:50 Thomas Weißschuh [this message]
2022-11-01 4:34 ` [PATCH] proc: add byteorder file Greg KH
2022-11-01 4:42 ` Thomas Weißschuh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221101005043.1791-1-linux@weissschuh.net \
--to=linux@weissschuh.net \
--cc=kzak@redhat.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yamato@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox