From nobody Mon Feb 9 06:24:56 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