From nobody Thu Apr 9 00:16:25 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB3AAFA3740 for ; Tue, 1 Nov 2022 00:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbiKAAuz (ORCPT ); Mon, 31 Oct 2022 20:50:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiKAAux (ORCPT ); Mon, 31 Oct 2022 20:50:53 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 807CD14D3E for ; Mon, 31 Oct 2022 17:50:50 -0700 (PDT) From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1667263848; bh=Ih90hSMCFhO4YPLOJxjstP2DevM5oYaVVK0RDWXWhYg=; h=From:To:Cc:Subject:Date:From; b=O/4Tj3Ph8aPMokTeCF6TyJh/9doYb5U8tHjzpNMIHVlpYQExOYj+O/4hF24zl4Xwi j+FLb5XWcQzj3Tot8qjkhc8xXFMzEoSkKoEsuIQWUm+Lf5J50GP9ml7N+QSf5GgQdg VLIFxOVDWEU4AE19Y5zvszGqq9TGgZca5S/vp6FA= To: linux-fsdevel@vger.kernel.org Cc: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, Karel Zak , Masatake YAMATO , linux-api@vger.kernel.org Subject: [PATCH] proc: add byteorder file Date: Tue, 1 Nov 2022 01:50:43 +0100 Message-Id: <20221101005043.1791-1-linux@weissschuh.net> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=ed25519-sha256; t=1667263841; l=2700; s=20211113; h=from:subject; bh=Ih90hSMCFhO4YPLOJxjstP2DevM5oYaVVK0RDWXWhYg=; b=Ta7OQLIgmKOBb7EZY2QPbltIZD7sna9NOI3okgEls+PXyJZ0SW4d/Fqo9VrpHPnvcVZo01r0UfIT C3PCBmz9BZbSEDfzLd6HWYdcD+gaAijlsR47TNuB2GCTo27UDfTb X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=9LP6KM4vD/8CwHW7nouRBhWLyQLcK1MkP6aTZbzUlj4= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=C3=9Fschuh --- Development of userspace part: https://github.com/util-linux/util-linux/pul= l/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) :=3D task_mmu.o proc-y +=3D inode.o root.o base.o generic.o array.o \ fd.o proc-$(CONFIG_TTY) +=3D proc_tty.o +proc-y +=3D byteorder.o proc-y +=3D cmdline.o proc-y +=3D consoles.o proc-y +=3D 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 +#include +#include +#include +#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 =3D proc_create_single("byteorder", 0444, NULL, byteorder_seq_show); + pde_make_permanent(pde); + return 0; +} +fs_initcall(proc_byteorder_init); base-commit: 5aaef24b5c6d4246b2cac1be949869fa36577737 --=20 2.38.1