From nobody Sun Feb 8 09:32:49 2026 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F425156F20 for ; Sun, 25 Jan 2026 14:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769350549; cv=none; b=A8MwE//NlHu2ia+KuO5y7B+lWNQi7elGdMnmamNiB8GmKarwHKJBivLlRpzXR+kfIvhWFh0Tp+XZdPX/x9C8uOJMsTI1PEAA99YpynKFSmb8V/AB68mWoS8S117Gg281kt9A5Ks9FZM7p/UKShfgKBhHFBqSIuCY4MoeY0quoSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769350549; c=relaxed/simple; bh=QGqt3Aux3twCcABLjHQ/Ga7oCvF1NTPOcQsWQVGV3Xw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jVdPu40133qB7RQ6LeprtyMXZ6tS0qQCVlu64gKEBqyZFO2+wKl3HZIYL0Jo5oDusaAEydwxXmYaHUZ5T4EYTve1Dm+MHFxDe5zASpP1P7gh6Kl0vq/U0AEVYijPNNMbZH82jmsjZO8nWpeCfdFekNjHtZm1OhDWAcW5XXyR7uI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kfItEUh0; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kfItEUh0" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-81ecbdfdcebso1864778b3a.1 for ; Sun, 25 Jan 2026 06:15:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769350548; x=1769955348; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sJiKhU14Mhs8ijvHzdc1uU3OQsSQcJ/y7OjoVneEUNo=; b=kfItEUh0pd4Vcbt45g8xwIwtRpGO/iNvkCMz+yeR3zmujqIYROZ2xsoo/tscfMIbdZ p2+AQhvDVphFowFaeEDmcts9kD+kbSpl2RKgvhHcUtrtMkykgryU42jGkoQa1ijFnp2m d5vt+gAvjMcJ/m99MEkKLPXBAiseWjvOE3JeaSBJhC7bmmB/kdWJrleHoGk/5MXrOZIQ vHT2C7ubG4uDhEUcaumbRaY86GRbtVzCP+7UkI6gj3yI/g/+xpQsIXWONsTxoprUpmTj QmWeGzuwB77SvIgtyDgJVkmBoqaT1gFTTZv4rOTbYv3IKP5DKCptkoyotuV2Nu+1EFQt C39Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769350548; x=1769955348; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=sJiKhU14Mhs8ijvHzdc1uU3OQsSQcJ/y7OjoVneEUNo=; b=VeM2Rbw4eM9q19EW8DCbHDrIew0tzjyiu7ij3/tOj9TQ/Y6lp6C5P7kFPz+yP3TGwG OwqqYCh8En67aaUk1042sFiStb2E5mJXo/b4NFS5lxKoiZCZ2sc0Geb/0eL0cPuJdQOX ysFWWHImOZKQJL9gHAU8jIhbn2g/gxirmFYBJuuw6fPCtqIKlMrJqFtPOcQb/8NcuuWd wwO0Hq4zB3lPfIEL3dElUyp6du0lzMLUI93kcbdlhWJAyVCaYVcKqbRMB0kj1W3a4vLZ UVs2LDWbgsxcp6QQYB5j+JwQtqM0nxf/ej1cfG6zOxswZI+dqld9nwjd9UiX0ud307+m TK0A== X-Gm-Message-State: AOJu0YwsXP6l45gsMV1oOKZcbT5lAOoZZTP1kAIN39/JuPcnr1ZhTCRa lyF8M1Kcwn6jXRwRdwTPgTgf8IXH1g2Lv0oihT3iMikWYyZzLIrn+zff X-Gm-Gg: AZuq6aKNGt5XUOy5qCKz/MXfz1JFLeId6CBsrMxq66HynTX/IIT7Cdsw5KVDLLNxrWG +611wzJlIckgFQY9o8GppkxA366hJKhWmXFLCVfWTMy4rZfIwQ3lX5x36RZn9Mn6Ws2BiAAFQWb szhv2RfFJKJqqFC5Rx9IqwoKwIfCn7qcYAICOTj9Sh2JJxpcmSgsJJFfn4io9Fi+EGVR3FsqPa4 5uKrGF/iAZCWLRHhTxuId3mPNWOEXLBSr50r81zNfDqzicQsDFIUuqXUGo+ZvTdZQhirAgVznv/ wBVKgxANeIY1t3egC+xat/utqf2NtIDIBWUJ7mv8ExEiqIYKI9pmfBiVz7xUEttwFSQ8X/ufJJV ggDFd6wBBvq2WBfFVDezOmH+WiiLe0YNpp6nWrgpXuanLQynXXyWnc9/l4RdHann7bzinDOrMTx /C4XLPG3O7Af+V83lZeix84bE2bp/VZNSkHvVXC/d1zR1EwhkdUZZtFQ== X-Received: by 2002:a05:6a21:2e18:b0:340:cc06:94f5 with SMTP id adf61e73a8af0-38e9f1cc3dfmr1469019637.44.1769350547814; Sun, 25 Jan 2026 06:15:47 -0800 (PST) Received: from toolbx ([103.230.182.3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c635a4135e6sm6334225a12.25.2026.01.25.06.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 06:15:47 -0800 (PST) From: Dorjoy Chowdhury To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, jlayton@kernel.org, chuck.lever@oracle.com, alex.aring@gmail.com, arnd@arndb.de Subject: [PATCH 1/2] open: new O_REGULAR flag support Date: Sun, 25 Jan 2026 20:14:05 +0600 Message-ID: <20260125141518.59493-2-dorjoychy111@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260125141518.59493-1-dorjoychy111@gmail.com> References: <20260125141518.59493-1-dorjoychy111@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This flag indicates the path should be opened if it's a regular file. A relevant error code ENOTREGULAR(35) has been introduced. For example, if open is called on path /dev/null with O_REGULAR in the flag param, it will return -ENOTREGULAR. When used in combination with O_CREAT, either the regular file is created, or if the path already exists, it is opened if it's a regular file. Otherwise, -ENOTREGULAR is returned. -EINVAL is returned when O_REGULAR is combined with O_DIRECTORY (not part of O_TMPFILE) because it doesn't make sense to open a path that is both a directory and a regular file. Signed-off-by: Dorjoy Chowdhury --- fs/fcntl.c | 2 +- fs/namei.c | 6 ++++++ fs/open.c | 4 +++- include/linux/fcntl.h | 2 +- include/uapi/asm-generic/errno-base.h | 1 + include/uapi/asm-generic/fcntl.h | 4 ++++ 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index f93dbca08435..62ab4ad2b6f5 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -1169,7 +1169,7 @@ static int __init fcntl_init(void) * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY * is defined as O_NONBLOCK on some platforms and not on others. */ - BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ !=3D + BUILD_BUG_ON(21 - 1 /* for O_RDONLY being 0 */ !=3D HWEIGHT32( (VALID_OPEN_FLAGS & ~(O_NONBLOCK | O_NDELAY)) | __FMODE_EXEC)); diff --git a/fs/namei.c b/fs/namei.c index cf16b6822dd3..365f3cc77e1c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4617,6 +4617,10 @@ static int do_open(struct nameidata *nd, if (unlikely(error)) return error; } + + if ((open_flag & O_REGULAR) && !d_is_reg(nd->path.dentry)) + return -ENOTREGULAR; + if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry)) return -ENOTDIR; =20 @@ -4766,6 +4770,8 @@ static int do_o_path(struct nameidata *nd, unsigned f= lags, struct file *file) struct path path; int error =3D path_lookupat(nd, flags, &path); if (!error) { + if ((file->f_flags & O_REGULAR) && !d_is_reg(path.dentry)) + return -ENOTREGULAR; audit_inode(nd->name, path.dentry, 0); error =3D vfs_open(&path, file); path_put(&path); diff --git a/fs/open.c b/fs/open.c index f328622061c5..670cd6b4967a 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1212,7 +1212,7 @@ struct file *kernel_file_open(const struct path *path= , int flags, EXPORT_SYMBOL_GPL(kernel_file_open); =20 #define WILL_CREATE(flags) (flags & (O_CREAT | __O_TMPFILE)) -#define O_PATH_FLAGS (O_DIRECTORY | O_NOFOLLOW | O_PATH | O_CLOEXEC) +#define O_PATH_FLAGS (O_DIRECTORY | O_NOFOLLOW | O_PATH | O_CLOEXEC | O_R= EGULAR) =20 inline struct open_how build_open_how(int flags, umode_t mode) { @@ -1289,6 +1289,8 @@ inline int build_open_flags(const struct open_how *ho= w, struct open_flags *op) return -EINVAL; if (!(acc_mode & MAY_WRITE)) return -EINVAL; + } else if ((flags & O_DIRECTORY) && (flags & O_REGULAR)) { + return -EINVAL; } if (flags & O_PATH) { /* O_PATH only permits certain other flags to be set. */ diff --git a/include/linux/fcntl.h b/include/linux/fcntl.h index a332e79b3207..4fd07b0e0a17 100644 --- a/include/linux/fcntl.h +++ b/include/linux/fcntl.h @@ -10,7 +10,7 @@ (O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC | \ O_APPEND | O_NDELAY | O_NONBLOCK | __O_SYNC | O_DSYNC | \ FASYNC | O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | \ - O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE) + O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE | O_REGULAR) =20 /* List of all valid flags for the how->resolve argument: */ #define VALID_RESOLVE_FLAGS \ diff --git a/include/uapi/asm-generic/errno-base.h b/include/uapi/asm-gener= ic/errno-base.h index 9653140bff92..ea9a96d30737 100644 --- a/include/uapi/asm-generic/errno-base.h +++ b/include/uapi/asm-generic/errno-base.h @@ -36,5 +36,6 @@ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ +#define ENOTREGULAR 35 /* Not a regular file */ =20 #endif diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fc= ntl.h index 613475285643..11e5eadab868 100644 --- a/include/uapi/asm-generic/fcntl.h +++ b/include/uapi/asm-generic/fcntl.h @@ -88,6 +88,10 @@ #define __O_TMPFILE 020000000 #endif =20 +#ifndef O_REGULAR +#define O_REGULAR 040000000 +#endif + /* a horrid kludge trying to make sure that this will fail on old kernels = */ #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) =20 --=20 2.52.0 From nobody Sun Feb 8 09:32:49 2026 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7A2C318EDA for ; Sun, 25 Jan 2026 14:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769350554; cv=none; b=o0ppgZg4SFt3yHrHksi4C1oaUvDxylyyfkLHa+ugei4AnF9Ogx37UMiAeG8VvvzIgsqXVhfekvTrk7YSd4NjGnAJAfArOE380QE82PBKlUfnwxyogkGco9+E8fsqnl4qILiqltAmijFdvb+yCbBJ1G/zBTIKCXQGfmFlQGACxfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769350554; c=relaxed/simple; bh=zbm88tZ5EKGHb6dIIBgtcubs1/j7WvW74bC5PmEIF3Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VkSzatNXFfp5xd+j6S/hiyPlK9Gnkx5ZS+3lkb9OpE6KsvliGeDuVBRHA8dYWbYeTFpS/Btse0jRLkViPOlTMM5v8vJwx0WY8RZnFTPVDWAJmy5P8r6mQofCdKXFA0xzpHZYIJAE+VnoAHl7dzVMrqQpxsSYG4v4Y1cwqTe/f2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eAJEVnZM; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eAJEVnZM" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-c626bd75628so1269368a12.3 for ; Sun, 25 Jan 2026 06:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769350552; x=1769955352; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0HDHyt8o7AOVvqViroBB2au4kbVsQeTCVMosjUYhWB4=; b=eAJEVnZM/1j38E7TMKeCr5cZAGaSeREO/bJH5uXtrRwVir/1kdH16yvWY79MWFLQEf ZuqbLIOdmTGB7MHHDOoLqZUq5q/yRdmtAFV2xJ54JvWljw6RFvzC0w0mwS2GdcBqDUAf xurDjc4Bl6jTPYip4Re93qUAUVDgTlVOtSjYEptLJm1TtjiIpn9R3Ajb+4mKj+5coPH7 Y0hTss7A4XOqMAE11IyJSKpnvzsYPmMxiIjJsFsEEtc4gXoqK47Cp30nKgmQUP/MSTfw leMJNDpJoEQHOzpijFotJCHEJ8ScyoMQVaoWfpE62HA483MtrVqk7pCOCxmDe/bE5xn8 Ko+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769350552; x=1769955352; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0HDHyt8o7AOVvqViroBB2au4kbVsQeTCVMosjUYhWB4=; b=X5rR2Si2IAO/UnAc8gTu8GoQ3pBNsBoGYCWERpCc4o7WQ8FeExtuXHykccjBw/symW u7JykUBLhfgPW09xRnravQwvfKRh10ufuvcr0DTHjFFRATZELjXExYsAK3xM3P7ZSe+B 1DvgYRy2QVObNYAYIDuk+nHI4G3x3gor8AAIXU1eZQgX20JzjOWTZ8RST87H+XN5rdHY VXZdbGpRt/bpD3QrpBEyotMgs8/MmJmXO+g2etrZHxoGc6gYkANbHsDDTJZbCfFHp43t ac/g3UyrAFU5A3BG7nBgLgCZB5zXwgCiGGmBd8XJ2P39lOn9E/1Hn4CiOsep+P9JxD0l 4Z0A== X-Gm-Message-State: AOJu0Yw7fSU8ogBct33pmtC5GefMENde/UqjvhEiYBktYEUn2z+S8rQG 5VCaqMjMca86OdrhuA3XNXihNXoDR3oMT3QdFxnrF8o+1hs0yxwJEt7j X-Gm-Gg: AZuq6aI4kaMWz58pKYrvBlJBa0863gCGnVe0IX9XngG0uEXiCrQTkGOtazUSamWpHlY 8L7tCteqf9rhCD0xaV72NdJ8Y78TlLwIUIGYDfnfEn+qEkCL6TGvLqZ3bFLVIDlXmO1YtU1x/gS cYeIiUwxEIhDL++Hu8I+IsA5ij/7hUa0jxOyjGAAe7PY1IW5zqlYLg6EXSSWYEFymaXvj1iO+Rd T3doUfbo8wFh5JWtIQE59JXZ+FdwKwLYkqM2ACUbc6MpO3IzuzsDJpdWSuq5FOLLH2Hxwhwu0L0 EnzFxOfGjpqvxX/CRjnlMscWF6hjn0k4a1Hyh73CEGZWOZ/olXATYAx8Rxz5seuSdzvekumvZFn wn7ds42Q2M66DrxnrrD4ZgkdrbcBsEvs+n0/nG6Et70zsbL1K7xjOytLpAfUuXI8KBN0541TyRP DrLP7/WSE1JfZJwGMGpvDZiXQyILr2HcwnvKQdUGsqYmg= X-Received: by 2002:a17:90b:388e:b0:340:bb64:c5e with SMTP id 98e67ed59e1d1-353c40e25a1mr1406748a91.14.1769350552220; Sun, 25 Jan 2026 06:15:52 -0800 (PST) Received: from toolbx ([103.230.182.3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c635a4135e6sm6334225a12.25.2026.01.25.06.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 06:15:51 -0800 (PST) From: Dorjoy Chowdhury To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, jlayton@kernel.org, chuck.lever@oracle.com, alex.aring@gmail.com, arnd@arndb.de Subject: [PATCH 2/2] kselftest/openat2: test for O_REGULAR flag Date: Sun, 25 Jan 2026 20:14:06 +0600 Message-ID: <20260125141518.59493-3-dorjoychy111@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260125141518.59493-1-dorjoychy111@gmail.com> References: <20260125141518.59493-1-dorjoychy111@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Just a happy path test. Signed-off-by: Dorjoy Chowdhury --- .../testing/selftests/openat2/openat2_test.c | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/openat2/openat2_test.c b/tools/testing= /selftests/openat2/openat2_test.c index 0e161ef9e9e4..c2f8771e2dae 100644 --- a/tools/testing/selftests/openat2/openat2_test.c +++ b/tools/testing/selftests/openat2/openat2_test.c @@ -320,8 +320,42 @@ void test_openat2_flags(void) } } =20 +#ifndef O_REGULAR +#define O_REGULAR 040000000 +#endif + +#ifndef ENOTREGULAR +#define ENOTREGULAR 35 +#endif + +void test_openat2_o_regular_flag(void) +{ + if (!openat2_supported) { + ksft_test_result_skip("Skipping %s as openat2 is not supported\n", __fun= c__); + return; + } + + struct open_how how =3D { + .flags =3D O_REGULAR | O_RDONLY + }; + + int fd =3D sys_openat2(AT_FDCWD, "/dev/null", &how); + + if (fd =3D=3D ENOENT) { + ksft_test_result_skip("Skipping %s as there is no /dev/null\n", __func__= ); + return; + } + + if (fd !=3D -ENOTREGULAR) { + ksft_test_result_fail("openat2 should return ENOTREGULAR\n"); + return; + } + + ksft_test_result_pass("%s succeeded\n", __func__); +} + #define NUM_TESTS (NUM_OPENAT2_STRUCT_VARIATIONS * NUM_OPENAT2_STRUCT_TEST= S + \ - NUM_OPENAT2_FLAG_TESTS) + NUM_OPENAT2_FLAG_TESTS + 1) =20 int main(int argc, char **argv) { @@ -330,6 +364,7 @@ int main(int argc, char **argv) =20 test_openat2_struct(); test_openat2_flags(); + test_openat2_o_regular_flag(); =20 if (ksft_get_fail_cnt() + ksft_get_error_cnt() > 0) ksft_exit_fail(); --=20 2.52.0