From patchwork Tue Nov 1 00:50:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2643399wru; Mon, 31 Oct 2022 17:54:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ku6aaXzjj9vKCUCufV/UXx7i31lMDTzRW76x2mKxV+TZgFq0gUam3XkpxbAYD+bqwqPDf X-Received: by 2002:a05:6402:847:b0:453:943b:bf4 with SMTP id b7-20020a056402084700b00453943b0bf4mr16504008edz.301.1667264077718; Mon, 31 Oct 2022 17:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667264077; cv=none; d=google.com; s=arc-20160816; b=yqx0qiZhqH9wf+cQdF3uZ7ScOcnhqlsR5SwbzmcjoP3iNY71s2XaASAhxmAX9nx7Mh ZiSC8ADc+esN6ufPTRnqTM7naWXbpTd28J1IpK/pXt+qyj3As4Y/GJdGENX831ixbPRe XgGmHLqCzElciVTWSABasoAcAidcM4d4LEcKOebRaWfrFbIt226AznDGqFLIF8FFlAJK nHa8cQfoN72Kx+TOAgjyiRw+SDiGNGzyp/2Id77dGFbIsx8zYee2lxMrekyJrZmSCNos 5OupyDOmdQnzSMy08I6KjIE+0cRMP6yRk/5343J8w90UML0tkG6vKlbud3EmHBbkBfsO 3QVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:dkim-signature:from; bh=b5Vf6fEX9VDotTcFpCHW5HkRjOMXn0tsP5pF0Kxokko=; b=x4+lNZBrCDhob55mmfl3ZYu7UySazQ+o4tQwyzCzZCrYID4GrFk5Etc4MqEZDGzGOl Nbcsl6sHiaqYCNDS2tuKSyKApdvuGqnlOqN4UgrjLfrOR4cUcJ2bakMIDRjssi/8d3GO YLk0O6GgyziBJMbLseGQNCFb4hr/x95HPyrb/oc4snrUleRt4POyeJb1A1BLn4SlbzkX Q1O724VhMmXq5ffVx/HwY9aALELYKJS4GeDhFBWGABrCG26/oUSzOfd53zzdXi0yhghu iEMs3Rf2YogqvmDtfV5HjXB0QLqfjQ8D3/LBCvz4cdpLLrH80ETp0Xppmy1nlnk+nWWH QSbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b="O/4Tj3Ph"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x12-20020a05640226cc00b00461f44d7bfcsi11136014edd.573.2022.10.31.17.54.09; Mon, 31 Oct 2022 17:54:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b="O/4Tj3Ph"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbiKAAuy (ORCPT + 99 others); Mon, 31 Oct 2022 20:50:54 -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_Wei=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_Wei=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 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= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748253097413110196?= X-GMAIL-MSGID: =?utf-8?q?1748253097413110196?= 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 --- 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 base-commit: 5aaef24b5c6d4246b2cac1be949869fa36577737 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 +#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 = proc_create_single("byteorder", 0444, NULL, byteorder_seq_show); + pde_make_permanent(pde); + return 0; +} +fs_initcall(proc_byteorder_init);