mirror of
https://github.com/torvalds/linux.git
synced 2026-07-29 10:41:49 +02:00
Linux kernel source tree
Label the SMB2 status entries with error codes as a prelude to
autogenerating the mapping table. This was done with the following script:
#!/usr/bin/perl -w
use strict;
my @error_mapping_table = ();
my %statuses = ();
#
# Read the status list
#
my $f = "fs/smb/common/smb2status.h";
open FILE, "<$f" || die $f;
my @contents = <FILE>;
close FILE || die;
my $l = 0;
foreach (@contents) {
$l++;
if (m!^#define\s*([A-Za-z0-9_]+)\s+cpu_to_le32[(]([0-9a-fA-Fx]+)[)]!) {
my $status = $1;
my $code = $2;
my $s;
next if ($status =~ /^STATUS_SEVERITY/);
if (exists($statuses{$status})) {
print("$f:$l: Duplicate declaration of ", $s->{status}, "\n");
} else {
my %_s = (
status => $status,
code => hex($code)
);
$statuses{$status} = \%_s;
}
}
}
#
# Read the SMB2 status => error mapping table
#
$f = "fs/smb/client/smb2maperror.c";
open(MFILE, "<$f") || die $f;
my @maperror = <MFILE>;
close MFILE || die;
my $parse = 0;
my $acc = "";
$l = 0;
foreach my $line (@maperror) {
chomp $line;
$l++;
if ($parse == 0 &&
$line =~ /^static const struct status_to_posix_error smb2_error_map_table/) {
$parse = 1;
next;
}
last if ($parse >= 1 && $line =~ /^[}];/);
if ($parse == 1) {
if ($line =~ /[\t][{].*[}],/) {
$acc = $line;
$parse = 3;
} elsif ($line =~ /[\t][{].*/) {
$acc = $line;
$parse = 2;
next;
} elsif ($line =~ m!^\s*/[*].*[*]/!) {
next;
} else {
die "smb2maperror.c:$l: unparseable mapping element\n";
}
}
if ($parse == 2) {
if ($line =~ /.*[}],/) {
$acc .= $line;
$parse = 3;
} else {
$acc .= $line;
}
}
if ($parse == 3) {
$acc =~ s/\s+//g;
if ($acc =~ m/[{](.*)[}]/) {
$acc = $1;
} else {
die "'$acc'";
}
my ($status, $error, $string) = split(/,/, $acc);
if (exists($statuses{$status})) {
my $s = $statuses{$status};
if (exists($s->{error})) {
print("$f:$l: Dup mapping entry $status\n");
}
$s->{error} = $error;
#print $s->{code}, " => ", $error, "\n";
} else {
print STDERR "$f:$l: Unknown status $status\n";
}
$acc = "";
$parse = 1;
}
}
#
# Sort the error table by STATUS_* value
#
my @order = ();
foreach my $status (keys(%statuses)) {
my $s = $statuses{$status};
push @order, $s;
unless (exists($s->{code})) {
print("Unknown code for ", $s->{status}, "\n")
} else {
#print("Code for ", $s->{status}, " is ", $s->{code}, "\n");
}
}
@order = sort( { $a->{code} <=> $b->{code} } @order);
foreach my $s (@order) {
my $status = $s->{status};
my $error = $s->{error};
my $code = $s->{code};
my $pad = " ";
if (length($status) < 32) {
my $n = 32 - length($status);
$pad = "\t" x ((($n-1) / 8) + 1);
}
#printf("#define %s%scpu_to_le32(0x%08x) // -%s\n", $status, $pad, $code, $error);
#printf("\t%s%s= 0x%08x, // -%s\n", $status, $pad, $code, $error);
}
#
# Decorate the definitions
#
my @output = ();
for (my $i = 0; $i <= $#contents; $i++) {
my $line = $contents[$i];
if ($line =~ m!^#define\s*([A-Za-z0-9_]+)\s+cpu_to_le32[(]([0-9a-fA-Fx]+)[)]!) {
my $status = $1;
my $code = $2;
if ($status =~ /^STATUS_SEVERITY/) {
push @output, $line;
next;
}
my $pad = " ";
if (length($status) < 40) {
my $n = 40 - length($status);
$pad = "\t" x ((($n-1) / 8) + 1);
}
my $s = $statuses{$1};
my $error = "EIO";
if (exists($s->{error})) {
$error = $s->{error};
} else {
if (!$s->{code}) {
print "ZERO ", $status, "\n";
$error = "0";
} else {
$error = "-EIO";
}
}
#my $rev = "#define " . $status . $pad . "_S(" . $2 . ", " . $error . ")\n";
my $rev = "#define " . $status . $pad . "cpu_to_le32(" . $2 . ") // " . $error . "\n";
push @output, $rev;
} else {
push @output, $line;
}
}
open FILE, ">fs/smb/common/smb2status.h" || die;
print FILE @output;
close FILE || die;
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Steve French <stfrench@microsoft.com>
cc: ChenXiaoSong <chenxiaosong@kylinos.cn>
cc: linux-cifs@vger.kernel.org
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Reviewed-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/linux-cifs/20260106071507.1420900-2-chenxiaosong.chenxiaosong@linux.dev/
Signed-off-by: Steve French <stfrench@microsoft.com>
|
||
|---|---|---|
| arch | ||
| block | ||
| certs | ||
| crypto | ||
| Documentation | ||
| drivers | ||
| fs | ||
| include | ||
| init | ||
| io_uring | ||
| ipc | ||
| kernel | ||
| lib | ||
| LICENSES | ||
| mm | ||
| net | ||
| rust | ||
| samples | ||
| scripts | ||
| security | ||
| sound | ||
| tools | ||
| usr | ||
| virt | ||
| .clang-format | ||
| .clippy.toml | ||
| .cocciconfig | ||
| .editorconfig | ||
| .get_maintainer.ignore | ||
| .gitattributes | ||
| .gitignore | ||
| .mailmap | ||
| .pylintrc | ||
| .rustfmt.toml | ||
| COPYING | ||
| CREDITS | ||
| Kbuild | ||
| Kconfig | ||
| MAINTAINERS | ||
| Makefile | ||
| README | ||
Linux kernel ============ The Linux kernel is the core of any Linux operating system. It manages hardware, system resources, and provides the fundamental services for all other software. Quick Start ----------- * Report a bug: See Documentation/admin-guide/reporting-issues.rst * Get the latest kernel: https://kernel.org * Build the kernel: See Documentation/admin-guide/quickly-build-trimmed-linux.rst * Join the community: https://lore.kernel.org/ Essential Documentation ----------------------- All users should be familiar with: * Building requirements: Documentation/process/changes.rst * Code of Conduct: Documentation/process/code-of-conduct.rst * License: See COPYING Documentation can be built with make htmldocs or viewed online at: https://www.kernel.org/doc/html/latest/ Who Are You? ============ Find your role below: * New Kernel Developer - Getting started with kernel development * Academic Researcher - Studying kernel internals and architecture * Security Expert - Hardening and vulnerability analysis * Backport/Maintenance Engineer - Maintaining stable kernels * System Administrator - Configuring and troubleshooting * Maintainer - Leading subsystems and reviewing patches * Hardware Vendor - Writing drivers for new hardware * Distribution Maintainer - Packaging kernels for distros For Specific Users ================== New Kernel Developer -------------------- Welcome! Start your kernel development journey here: * Getting Started: Documentation/process/development-process.rst * Your First Patch: Documentation/process/submitting-patches.rst * Coding Style: Documentation/process/coding-style.rst * Build System: Documentation/kbuild/index.rst * Development Tools: Documentation/dev-tools/index.rst * Kernel Hacking Guide: Documentation/kernel-hacking/hacking.rst * Core APIs: Documentation/core-api/index.rst Academic Researcher ------------------- Explore the kernel's architecture and internals: * Researcher Guidelines: Documentation/process/researcher-guidelines.rst * Memory Management: Documentation/mm/index.rst * Scheduler: Documentation/scheduler/index.rst * Networking Stack: Documentation/networking/index.rst * Filesystems: Documentation/filesystems/index.rst * RCU (Read-Copy Update): Documentation/RCU/index.rst * Locking Primitives: Documentation/locking/index.rst * Power Management: Documentation/power/index.rst Security Expert --------------- Security documentation and hardening guides: * Security Documentation: Documentation/security/index.rst * LSM Development: Documentation/security/lsm-development.rst * Self Protection: Documentation/security/self-protection.rst * Reporting Vulnerabilities: Documentation/process/security-bugs.rst * CVE Procedures: Documentation/process/cve.rst * Embargoed Hardware Issues: Documentation/process/embargoed-hardware-issues.rst * Security Features: Documentation/userspace-api/seccomp_filter.rst Backport/Maintenance Engineer ----------------------------- Maintain and stabilize kernel versions: * Stable Kernel Rules: Documentation/process/stable-kernel-rules.rst * Backporting Guide: Documentation/process/backporting.rst * Applying Patches: Documentation/process/applying-patches.rst * Subsystem Profile: Documentation/maintainer/maintainer-entry-profile.rst * Git for Maintainers: Documentation/maintainer/configure-git.rst System Administrator -------------------- Configure, tune, and troubleshoot Linux systems: * Admin Guide: Documentation/admin-guide/index.rst * Kernel Parameters: Documentation/admin-guide/kernel-parameters.rst * Sysctl Tuning: Documentation/admin-guide/sysctl/index.rst * Tracing/Debugging: Documentation/trace/index.rst * Performance Security: Documentation/admin-guide/perf-security.rst * Hardware Monitoring: Documentation/hwmon/index.rst Maintainer ---------- Lead kernel subsystems and manage contributions: * Maintainer Handbook: Documentation/maintainer/index.rst * Pull Requests: Documentation/maintainer/pull-requests.rst * Managing Patches: Documentation/maintainer/modifying-patches.rst * Rebasing and Merging: Documentation/maintainer/rebasing-and-merging.rst * Development Process: Documentation/process/maintainer-handbooks.rst * Maintainer Entry Profile: Documentation/maintainer/maintainer-entry-profile.rst * Git Configuration: Documentation/maintainer/configure-git.rst Hardware Vendor --------------- Write drivers and support new hardware: * Driver API Guide: Documentation/driver-api/index.rst * Driver Model: Documentation/driver-api/driver-model/driver.rst * Device Drivers: Documentation/driver-api/infrastructure.rst * Bus Types: Documentation/driver-api/driver-model/bus.rst * Device Tree Bindings: Documentation/devicetree/bindings/ * Power Management: Documentation/driver-api/pm/index.rst * DMA API: Documentation/core-api/dma-api.rst Distribution Maintainer ----------------------- Package and distribute the kernel: * Stable Kernel Rules: Documentation/process/stable-kernel-rules.rst * ABI Documentation: Documentation/ABI/README * Kernel Configuration: Documentation/kbuild/kconfig.rst * Module Signing: Documentation/admin-guide/module-signing.rst * Kernel Parameters: Documentation/admin-guide/kernel-parameters.rst * Tainted Kernels: Documentation/admin-guide/tainted-kernels.rst Communication and Support ========================= * Mailing Lists: https://lore.kernel.org/ * IRC: #kernelnewbies on irc.oftc.net * Bugzilla: https://bugzilla.kernel.org/ * MAINTAINERS file: Lists subsystem maintainers and mailing lists * Email Clients: Documentation/process/email-clients.rst