{"id":2219172,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2219172/?format=json","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.0/projects/12/?format=json","name":"Linux CIFS Client","link_name":"linux-cifs-client","list_id":"linux-cifs.vger.kernel.org","list_email":"linux-cifs@vger.kernel.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260402141839.461257-11-huiwen.he@linux.dev>","date":"2026-04-02T14:18:36","name":"[v3,10/13] smb/client: autogenerate SMB1 DOS/SRV to POSIX error mapping","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a637a7eb13e23c59fdd77b1627cf3191a897ded4","submitter":{"id":93029,"url":"http://patchwork.ozlabs.org/api/1.0/people/93029/?format=json","name":null,"email":"huiwen.he@linux.dev"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260402141839.461257-11-huiwen.he@linux.dev/mbox/","series":[{"id":498490,"url":"http://patchwork.ozlabs.org/api/1.0/series/498490/?format=json","date":"2026-04-02T14:18:28","name":"smb: improve search speed of SMB1 maperror","version":3,"mbox":"http://patchwork.ozlabs.org/series/498490/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219172/checks/","tags":{},"headers":{"Return-Path":"\n <linux-cifs+bounces-10643-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-cifs@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256\n header.s=key1 header.b=PiGBChMF;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.232.135.74; helo=sto.lore.kernel.org;\n envelope-from=linux-cifs+bounces-10643-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev\n header.b=\"PiGBChMF\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=91.218.175.178","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.dev","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=linux.dev"],"Received":["from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fmkZT37Jyz1yGJ\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 03 Apr 2026 01:22:09 +1100 (AEDT)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sto.lore.kernel.org (Postfix) with ESMTP id EEA7A307EA91\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  2 Apr 2026 14:20:16 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id DC64530C35F;\n\tThu,  2 Apr 2026 14:20:15 +0000 (UTC)","from out-178.mta0.migadu.com (out-178.mta0.migadu.com\n [91.218.175.178])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id AB7D83E9F81\n\tfor <linux-cifs@vger.kernel.org>; Thu,  2 Apr 2026 14:20:12 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775139615; cv=none;\n b=Unu6nUrl8rSdRXUdmrJp05WtFJXLAdnQeOtLP2s2Hc3wL3aXY2JqQG6K/k6Nw8mfWf/ciGc67aVsvkOCyckhjtcT5GifRoYsqVHKev57j81w2KgyxR30DEdqyXOzdTEvPS/frT7GKnL3ZNLrbaWS3SnV7YHB0BiOWUPGk0SO4Uw=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775139615; c=relaxed/simple;\n\tbh=rHruvPYPhyg30ALkqklA+DiuLv3EFXDqy7aHlZz0hkA=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=BSe8FVAweY2ETeRXIVZ36KEDc41UTBlB3WH1R4z8NfJ1DyYn2pLB4opF5hSTeisFPuzRycZuLG45bpOHcX67jqnSQV9qsumy26JO9lcOYb3mdnVFxJpTSUWCECJ03V0gUkMO4VqOhNfDNuIWihEvmr+/9HeadvVMzo9JiMxxvgY=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.dev;\n spf=pass smtp.mailfrom=linux.dev;\n dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev\n header.b=PiGBChMF; arc=none smtp.client-ip=91.218.175.178","X-Report-Abuse":"Please report any abuse attempt to abuse@migadu.com and\n include these headers.","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1;\n\tt=1775139610;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\t to:to:cc:cc:mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding:\n\t in-reply-to:in-reply-to:references:references;\n\tbh=f/EEHcw2uOTHs8rFwYOK5k29+WmC+X7l+Y2Z5RmqpWQ=;\n\tb=PiGBChMFAvbOwvcdFTqUovVwdXzpERO6O8fozjCFQxaVKr48izT6wyHqAjfgH8Q9OKG695\n\t41+AZzWvpA8Ccon+yzss3UbrvTDyI4s5N/TRpDHr0X7vpV96SWQSfEy4hJDv+AR4ZEH4xn\n\tMTiOuemh6w2G6sqWgkEQyYj0eSIFDOk=","From":"huiwen.he@linux.dev","To":"smfrench@gmail.com,\n\tlinkinjeon@kernel.org,\n\tdhowells@redhat.com,\n\tchenxiaosong@kylinos.cn,\n\tchenxiaosong@chenxiaosong.com,\n\ttangyouling@kylinos.cn","Cc":"linux-cifs@vger.kernel.org,\n\tHuiwen He <hehuiwen@kylinos.cn>","Subject":"[PATCH v3 10/13] smb/client: autogenerate SMB1 DOS/SRV to POSIX error\n mapping","Date":"Thu,  2 Apr 2026 14:18:36 +0000","Message-ID":"<20260402141839.461257-11-huiwen.he@linux.dev>","In-Reply-To":"<20260402141839.461257-1-huiwen.he@linux.dev>","References":"<20260402141839.461257-1-huiwen.he@linux.dev>","Precedence":"bulk","X-Mailing-List":"linux-cifs@vger.kernel.org","List-Id":"<linux-cifs.vger.kernel.org>","List-Subscribe":"<mailto:linux-cifs+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-cifs+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Migadu-Flow":"FLOW_OUT"},"content":"From: Huiwen He <hehuiwen@kylinos.cn>\n\nExtend the `gen_smb1_mapping` script to support generating sorted POSIX\nerror mapping tables for both ERRDOS and ERRSRV classes at compile time.\n\nThe script parses annotations from smberr.h to generate smb1_err_dos_map.c\nand smb1_err_srv_map.c, which are included as the contents of the arrays\nmapping_table_ERRDOS[] and mapping_table_ERRSRV[], respectively.\n\nThis ensures that the mapping logic remains synchronized with the source\nheaders and prepares for faster error lookups using binary search in the\nfuture.\n\nSigned-off-by: Huiwen He <hehuiwen@kylinos.cn>\nReviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>\n---\n fs/smb/client/.gitignore       |  2 +\n fs/smb/client/Makefile         |  9 +++-\n fs/smb/client/gen_smb1_mapping | 29 +++++++++++-\n fs/smb/client/smb1maperror.c   | 85 ++++------------------------------\n fs/smb/client/smberr.h         | 12 ++++-\n 5 files changed, 57 insertions(+), 80 deletions(-)","diff":"diff --git a/fs/smb/client/.gitignore b/fs/smb/client/.gitignore\nindex d5ea5ac6015d..66e6e2ade0bd 100644\n--- a/fs/smb/client/.gitignore\n+++ b/fs/smb/client/.gitignore\n@@ -1,2 +1,4 @@\n smb1_mapping_table.c\n+smb1_err_dos_map.c\n+smb1_err_srv_map.c\n smb2_mapping_table.c\ndiff --git a/fs/smb/client/Makefile b/fs/smb/client/Makefile\nindex 220a97c8a488..6e83b5204699 100644\n--- a/fs/smb/client/Makefile\n+++ b/fs/smb/client/Makefile\n@@ -46,13 +46,18 @@ cifs-$(CONFIG_CIFS_COMPRESSION) += compress.o compress/lz77.o\n \n ifneq ($(CONFIG_CIFS_ALLOW_INSECURE_LEGACY),)\n #\n-# Build the SMB1 error mapping tables from nterr.h\n+# Build the SMB1 error mapping tables from nterr.h and smberr.h\n #\n-smb1-gen-y := smb1_mapping_table.c\n+smb1-gen-y := smb1_mapping_table.c \\\n+\t      smb1_err_dos_map.c \\\n+\t      smb1_err_srv_map.c\n \n $(obj)/smb1_mapping_table.c: $(src)/nterr.h $(src)/gen_smb1_mapping FORCE\n \t$(call if_changed,gen_smb1_mapping)\n \n+$(obj)/smb1_err_%.c: $(src)/smberr.h $(src)/gen_smb1_mapping FORCE\n+\t$(call if_changed,gen_smb1_mapping)\n+\n $(obj)/smb1maperror.o: $(addprefix $(obj)/, $(smb1-gen-y))\n \n quiet_cmd_gen_smb1_mapping = GEN     $@\ndiff --git a/fs/smb/client/gen_smb1_mapping b/fs/smb/client/gen_smb1_mapping\nindex b2439fc09fe9..ef07c766e191 100644\n--- a/fs/smb/client/gen_smb1_mapping\n+++ b/fs/smb/client/gen_smb1_mapping\n@@ -22,6 +22,7 @@ my $output_name = (split m|/|, $out_file)[-1];\n my $script_name = (split m|/|, $0)[-1];\n my @list     = ();\n my %seen     = ();\n+my $current_class = \"\";\n \n # Parse annotated entries from the input file\n open(my $in, \"<\", $in_file) or die \"Cannot open $in_file: $!\";\n@@ -46,6 +47,20 @@ if ($in_file =~ /nterr\\.h$/) {\n \t\t\tpush @list, { val => $val, name => $name, class => $class, code => $code };\n \t\t}\n \t}\n+} elsif ($in_file =~ /smberr\\.h$/) {\n+\twhile (<$in>) {\n+\t\t# Detect current error class from header comments (ERRDOS or ERRSRV)\n+\t\tif (/generated with the (\\w+) error class/) {\n+\t\t\t$current_class = $1;\n+\t\t}\n+\n+\t\t# Match #define ERR... or Err... <value> // -POSIX_ERR\n+\t\tif (/^\\s*#define\\s+((?:ERR|Err)[A-Za-z0-9_]+)\\s+([0-9a-fA-FxX]+)\\s*\\/\\/\\s*(-[A-Z0-9_]+)/) {\n+\t\t\tmy ($name, $val_str, $error) = ($1, $2, $3);\n+\t\t\tmy $val = ($val_str =~ /^0x/i) ? hex($val_str) : $val_str;\n+\t\t\tpush @list, { val => $val, name => $name, error => $error, class => $current_class };\n+\t\t}\n+\t}\n }\n close($in);\n \n@@ -60,7 +75,7 @@ open(my $out, \">\", $out_file) or die \"Cannot open $out_file: $!\";\n print $out \"/* Autogenerated from $input_name by $script_name */\\n\\n\";\n \n if ($output_name eq \"smb1_mapping_table.c\") {\n-\t# Generate NT status -> DOS error mapping file smb1_mapping_table.c\n+\t# Generate NT status -> DOS error mapping file\n \n \tmy $count = scalar @list;\n \tmy $full_names = \"\";\n@@ -81,5 +96,17 @@ if ($output_name eq \"smb1_mapping_table.c\") {\n \n \t\t$full_names = \"\";\n \t}\n+} elsif ($output_name eq \"smb1_err_dos_map.c\" || $output_name eq \"smb1_err_srv_map.c\") {\n+\t# Generate SMB1 error -> POSIX error mapping file\n+\n+\t# Filtered by exact output filename\n+\tmy $filter = ($output_name eq \"smb1_err_dos_map.c\") ? \"ERRDOS\" : \"ERRSRV\";\n+\tforeach my $e (@list) {\n+\t\tif (!$filter || $e->{class} eq $filter) {\n+\t\t\tprintf $out \"\\t{%s, %s},\\n\", $e->{name}, $e->{error};\n+\t\t}\n+\t}\n+} else {\n+\tdie \"Error: Unsupported output target: $output_name\\n\";\n }\n close($out);\ndiff --git a/fs/smb/client/smb1maperror.c b/fs/smb/client/smb1maperror.c\nindex 419057f296a7..294ac9646bff 100644\n--- a/fs/smb/client/smb1maperror.c\n+++ b/fs/smb/client/smb1maperror.c\n@@ -21,85 +21,20 @@ struct smb_to_posix_error {\n };\n \n static const struct smb_to_posix_error mapping_table_ERRDOS[] = {\n-\t{ERRbadfunc, -EINVAL},\n-\t{ERRbadfile, -ENOENT},\n-\t{ERRbadpath, -ENOTDIR},\n-\t{ERRnofids, -EMFILE},\n-\t{ERRnoaccess, -EACCES},\n-\t{ERRbadfid, -EBADF},\n-\t{ERRbadmcb, -EIO},\n-\t{ERRnomem, -EREMOTEIO},\n-\t{ERRbadmem, -EFAULT},\n-\t{ERRbadenv, -EFAULT},\n-\t{ERRbadformat, -EINVAL},\n-\t{ERRbadaccess, -EACCES},\n-\t{ERRbaddata, -EIO},\n-\t{ERRbaddrive, -ENXIO},\n-\t{ERRremcd, -EACCES},\n-\t{ERRdiffdevice, -EXDEV},\n-\t{ERRnofiles, -ENOENT},\n-\t{ERRwriteprot, -EROFS},\n-\t{ERRbadshare, -EBUSY},\n-\t{ERRlock, -EACCES},\n-\t{ERRunsup, -EINVAL},\n-\t{ERRnosuchshare, -ENXIO},\n-\t{ERRfilexists, -EEXIST},\n-\t{ERRinvparm, -EINVAL},\n-\t{ERRdiskfull, -ENOSPC},\n-\t{ERRinvname, -ENOENT},\n-\t{ERRunknownlevel, -EOPNOTSUPP},\n-\t{ERRdirnotempty, -ENOTEMPTY},\n-\t{ERRnotlocked, -ENOLCK},\n-\t{ERRcancelviolation, -ENOLCK},\n-\t{ERRalreadyexists, -EEXIST},\n-\t{ERRmoredata, -EOVERFLOW},\n-\t{ERReasnotsupported, -EOPNOTSUPP},\n-\t{ErrQuota, -EDQUOT},\n-\t{ErrNotALink, -ENOLINK},\n-\t{ERRnetlogonNotStarted, -ENOPROTOOPT},\n-\t{ERRsymlink, -EOPNOTSUPP},\n-\t{ErrTooManyLinks, -EMLINK},\n+/*\n+ * Automatically generated by the `gen_smb1_mapping` script,\n+ * sorted by DOS error code (ascending).\n+ */\n+#include \"smb1_err_dos_map.c\"\n \t{0, 0}\n };\n \n static const struct smb_to_posix_error mapping_table_ERRSRV[] = {\n-\t{ERRerror, -EIO},\n-\t{ERRbadpw, -EACCES},  /* was EPERM */\n-\t{ERRbadtype, -EREMOTE},\n-\t{ERRaccess, -EACCES},\n-\t{ERRinvtid, -ENXIO},\n-\t{ERRinvnetname, -ENXIO},\n-\t{ERRinvdevice, -ENXIO},\n-\t{ERRqfull, -ENOSPC},\n-\t{ERRqtoobig, -ENOSPC},\n-\t{ERRqeof, -EIO},\n-\t{ERRinvpfid, -EBADF},\n-\t{ERRsmbcmd, -EBADRQC},\n-\t{ERRsrverror, -EIO},\n-\t{ERRbadBID, -EIO},\n-\t{ERRfilespecs, -EINVAL},\n-\t{ERRbadLink, -EIO},\n-\t{ERRbadpermits, -EINVAL},\n-\t{ERRbadPID, -ESRCH},\n-\t{ERRsetattrmode, -EINVAL},\n-\t{ERRpaused, -EHOSTDOWN},\n-\t{ERRmsgoff, -EHOSTDOWN},\n-\t{ERRnoroom, -ENOSPC},\n-\t{ERRrmuns, -EUSERS},\n-\t{ERRtimeout, -ETIME},\n-\t{ERRnoresource, -EREMOTEIO},\n-\t{ERRtoomanyuids, -EUSERS},\n-\t{ERRbaduid, -EACCES},\n-\t{ERRusempx, -EIO},\n-\t{ERRusestd, -EIO},\n-\t{ERR_NOTIFY_ENUM_DIR, -ENOBUFS},\n-\t{ERRnoSuchUser, -EACCES},\n-\t{ERRaccountexpired, -EKEYEXPIRED},\n-\t{ERRbadclient, -EACCES},\n-\t{ERRbadLogonTime, -EACCES},\n-\t{ERRpasswordExpired, -EKEYEXPIRED},\n-\n-\t{ERRnosupport, -EINVAL},\n+/*\n+ * Automatically generated by the `gen_smb1_mapping` script,\n+ * sorted by SRV error code (ascending).\n+ */\n+#include \"smb1_err_srv_map.c\"\n \t{0, 0}\n };\n \ndiff --git a/fs/smb/client/smberr.h b/fs/smb/client/smberr.h\nindex d3633623473a..4ec2c5ffae25 100644\n--- a/fs/smb/client/smberr.h\n+++ b/fs/smb/client/smberr.h\n@@ -24,7 +24,11 @@\n \n /*#define SUCCESS\t0\tThe request was successful. */\n \n-/* The following error codes may be generated with the ERRDOS error class.*/\n+/*\n+ * The following error codes may be generated with the ERRDOS error class.\n+ * The comment at the end of each definition indicates the POSIX error\n+ * code; it is used to generate the `mapping_table_ERRDOS` array.\n+ */\n \n /*\n  * Invalid function. The server did not\n@@ -162,7 +166,11 @@\n #define ERRsymlink              0xFFFD\t// -EOPNOTSUPP\n #define ErrTooManyLinks         0xFFFE\t// -EMLINK\n \n-/* Following error codes may be generated with the ERRSRV error class.*/\n+/*\n+ * The following error codes may be generated with the ERRSRV error class.\n+ * The comment at the end of each definition indicates the POSIX error\n+ * code; it is used to generate the `mapping_table_ERRSRV` array.\n+ */\n \n /*\n  * Non-specific error code. It is\n","prefixes":["v3","10/13"]}