From 5b7c4cabbb65f5c469464da6c5f614cbd7f730f2 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 21 Feb 2023 18:24:12 -0800 Subject: Merge tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next Pull networking updates from Jakub Kicinski: "Core: - Add dedicated kmem_cache for typical/small skb->head, avoid having to access struct page at kfree time, and improve memory use. - Introduce sysctl to set default RPS configuration for new netdevs. - Define Netlink protocol specification format which can be used to describe messages used by each family and auto-generate parsers. Add tools for generating kernel data structures and uAPI headers. - Expose all net/core sysctls inside netns. - Remove 4s sleep in netpoll if carrier is instantly detected on boot. - Add configurable limit of MDB entries per port, and port-vlan. - Continue populating drop reasons throughout the stack. - Retire a handful of legacy Qdiscs and classifiers. Protocols: - Support IPv4 big TCP (TSO frames larger than 64kB). - Add IP_LOCAL_PORT_RANGE socket option, to control local port range on socket by socket basis. - Track and report in procfs number of MPTCP sockets used. - Support mixing IPv4 and IPv6 flows in the in-kernel MPTCP path manager. - IPv6: don't check net.ipv6.route.max_size and rely on garbage collection to free memory (similarly to IPv4). - Support Penultimate Segment Pop (PSP) flavor in SRv6 (RFC8986). - ICMP: add per-rate limit counters. - Add support for user scanning requests in ieee802154. - Remove static WEP support. - Support minimal Wi-Fi 7 Extremely High Throughput (EHT) rate reporting. - WiFi 7 EHT channel puncturing support (client & AP). BPF: - Add a rbtree data structure following the "next-gen data structure" precedent set by recently added linked list, that is, by using kfunc + kptr instead of adding a new BPF map type. - Expose XDP hints via kfuncs with initial support for RX hash and timestamp metadata. - Add BPF_F_NO_TUNNEL_KEY extension to bpf_skb_set_tunnel_key to better support decap on GRE tunnel devices not operating in collect metadata. - Improve x86 JIT's codegen for PROBE_MEM runtime error checks. - Remove the need for trace_printk_lock for bpf_trace_printk and bpf_trace_vprintk helpers. - Extend libbpf's bpf_tracing.h support for tracing arguments of kprobes/uprobes and syscall as a special case. - Significantly reduce the search time for module symbols by livepatch and BPF. - Enable cpumasks to be used as kptrs, which is useful for tracing programs tracking which tasks end up running on which CPUs in different time intervals. - Add support for BPF trampoline on s390x and riscv64. - Add capability to export the XDP features supported by the NIC. - Add __bpf_kfunc tag for marking kernel functions as kfuncs. - Add cgroup.memory=nobpf kernel parameter option to disable BPF memory accounting for container environments. Netfilter: - Remove the CLUSTERIP target. It has been marked as obsolete for years, and we still have WARN splats wrt races of the out-of-band /proc interface installed by this target. - Add 'destroy' commands to nf_tables. They are identical to the existing 'delete' commands, but do not return an error if the referenced object (set, chain, rule...) did not exist. Driver API: - Improve cpumask_local_spread() locality to help NICs set the right IRQ affinity on AMD platforms. - Separate C22 and C45 MDIO bus transactions more clearly. - Introduce new DCB table to control DSCP rewrite on egress. - Support configuration of Physical Layer Collision Avoidance (PLCA) Reconciliation Sublayer (RS) (802.3cg-2019). Modern version of shared medium Ethernet. - Support for MAC Merge layer (IEEE 802.3-2018 clause 99). Allowing preemption of low priority frames by high priority frames. - Add support for controlling MACSec offload using netlink SET. - Rework devlink instance refcounts to allow registration and de-registration under the instance lock. Split the code into multiple files, drop some of the unnecessarily granular locks and factor out common parts of netlink operation handling. - Add TX frame aggregation parameters (for USB drivers). - Add a new attr TCA_EXT_WARN_MSG to report TC (offload) warning messages with notifications for debug. - Allow offloading of UDP NEW connections via act_ct. - Add support for per action HW stats in TC. - Support hardware miss to TC action (continue processing in SW from a specific point in the action chain). - Warn if old Wireless Extension user space interface is used with modern cfg80211/mac80211 drivers. Do not support Wireless Extensions for Wi-Fi 7 devices at all. Everyone should switch to using nl80211 interface instead. - Improve the CAN bit timing configuration. Use extack to return error messages directly to user space, update the SJW handling, including the definition of a new default value that will benefit CAN-FD controllers, by increasing their oscillator tolerance. New hardware / drivers: - Ethernet: - nVidia BlueField-3 support (control traffic driver) - Ethernet support for imx93 SoCs - Motorcomm yt8531 gigabit Ethernet PHY - onsemi NCN26000 10BASE-T1S PHY (with support for PLCA) - Microchip LAN8841 PHY (incl. cable diagnostics and PTP) - Amlogic gxl MDIO mux - WiFi: - RealTek RTL8188EU (rtl8xxxu) - Qualcomm Wi-Fi 7 devices (ath12k) - CAN: - Renesas R-Car V4H Drivers: - Bluetooth: - Set Per Platform Antenna Gain (PPAG) for Intel controllers. - Ethernet NICs: - Intel (1G, igc): - support TSN / Qbv / packet scheduling features of i226 model - Intel (100G, ice): - use GNSS subsystem instead of TTY - multi-buffer XDP support - extend support for GPIO pins to E823 devices - nVidia/Mellanox: - update the shared buffer configuration on PFC commands - implement PTP adjphase function for HW offset control - TC support for Geneve and GRE with VF tunnel offload - more efficient crypto key management method - multi-port eswitch support - Netronome/Corigine: - add DCB IEEE support - support IPsec offloading for NFP3800 - Freescale/NXP (enetc): - support XDP_REDIRECT for XDP non-linear buffers - improve reconfig, avoid link flap and waiting for idle - support MAC Merge layer - Other NICs: - sfc/ef100: add basic devlink support for ef100 - ionic: rx_push mode operation (writing descriptors via MMIO) - bnxt: use the auxiliary bus abstraction for RDMA - r8169: disable ASPM and reset bus in case of tx timeout - cpsw: support QSGMII mode for J721e CPSW9G - cpts: support pulse-per-second output - ngbe: add an mdio bus driver - usbnet: optimize usbnet_bh() by avoiding unnecessary queuing - r8152: handle devices with FW with NCM support - amd-xgbe: support 10Mbps, 2.5GbE speeds and rx-adaptation - virtio-net: support multi buffer XDP - virtio/vsock: replace virtio_vsock_pkt with sk_buff - tsnep: XDP support - Ethernet high-speed switches: - nVidia/Mellanox (mlxsw): - add support for latency TLV (in FW control messages) - Microchip (sparx5): - separate explicit and implicit traffic forwarding rules, make the implicit rules always active - add support for egress DSCP rewrite - IS0 VCAP support (Ingress Classification) - IS2 VCAP filters (protos, L3 addrs, L4 ports, flags, ToS etc.) - ES2 VCAP support (Egress Access Control) - support for Per-Stream Filtering and Policing (802.1Q, 8.6.5.1) - Ethernet embedded switches: - Marvell (mv88e6xxx): - add MAB (port auth) offload support - enable PTP receive for mv88e6390 - NXP (ocelot): - support MAC Merge layer - support for the the vsc7512 internal copper phys - Microchip: - lan9303: convert to PHYLINK - lan966x: support TC flower filter statistics - lan937x: PTP support for KSZ9563/KSZ8563 and LAN937x - lan937x: support Credit Based Shaper configuration - ksz9477: support Energy Efficient Ethernet - other: - qca8k: convert to regmap read/write API, use bulk operations - rswitch: Improve TX timestamp accuracy - Intel WiFi (iwlwifi): - EHT (Wi-Fi 7) rate reporting - STEP equalizer support: transfer some STEP (connection to radio on platforms with integrated wifi) related parameters from the BIOS to the firmware. - Qualcomm 802.11ax WiFi (ath11k): - IPQ5018 support - Fine Timing Measurement (FTM) responder role support - channel 177 support - MediaTek WiFi (mt76): - per-PHY LED support - mt7996: EHT (Wi-Fi 7) support - Wireless Ethernet Dispatch (WED) reset support - switch to using page pool allocator - RealTek WiFi (rtw89): - support new version of Bluetooth co-existance - Mobile: - rmnet: support TX aggregation" * tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next: (1872 commits) page_pool: add a comment explaining the fragment counter usage net: ethtool: fix __ethtool_dev_mm_supported() implementation ethtool: pse-pd: Fix double word in comments xsk: add linux/vmalloc.h to xsk.c sefltests: netdevsim: wait for devlink instance after netns removal selftest: fib_tests: Always cleanup before exit net/mlx5e: Align IPsec ASO result memory to be as required by hardware net/mlx5e: TC, Set CT miss to the specific ct action instance net/mlx5e: Rename CHAIN_TO_REG to MAPPED_OBJ_TO_REG net/mlx5: Refactor tc miss handling to a single function net/mlx5: Kconfig: Make tc offload depend on tc skb extension net/sched: flower: Support hardware miss to tc action net/sched: flower: Move filter handle initialization earlier net/sched: cls_api: Support hardware miss to tc action net/sched: Rename user cookie and act cookie sfc: fix builds without CONFIG_RTC_LIB sfc: clean up some inconsistent indentings net/mlx4_en: Introduce flexible array to silence overflow warning net: lan966x: Fix possible deadlock inside PTP net/ulp: Remove redundant ->clone() test in inet_clone_ulp(). ... --- fs/sysv/super.c | 594 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 594 insertions(+) create mode 100644 fs/sysv/super.c (limited to 'fs/sysv/super.c') diff --git a/fs/sysv/super.c b/fs/sysv/super.c new file mode 100644 index 000000000..3365a30dc --- /dev/null +++ b/fs/sysv/super.c @@ -0,0 +1,594 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * linux/fs/sysv/inode.c + * + * minix/inode.c + * Copyright (C) 1991, 1992 Linus Torvalds + * + * xenix/inode.c + * Copyright (C) 1992 Doug Evans + * + * coh/inode.c + * Copyright (C) 1993 Pascal Haible, Bruno Haible + * + * sysv/inode.c + * Copyright (C) 1993 Paul B. Monday + * + * sysv/inode.c + * Copyright (C) 1993 Bruno Haible + * Copyright (C) 1997, 1998 Krzysztof G. Baranowski + * + * This file contains code for read/parsing the superblock. + */ + +#include +#include +#include +#include +#include "sysv.h" + +/* + * The following functions try to recognize specific filesystems. + * + * We recognize: + * - Xenix FS by its magic number. + * - SystemV FS by its magic number. + * - Coherent FS by its funny fname/fpack field. + * - SCO AFS by s_nfree == 0xffff + * - V7 FS has no distinguishing features. + * + * We discriminate among SystemV4 and SystemV2 FS by the assumption that + * the time stamp is not < 01-01-1980. + */ + +enum { + JAN_1_1980 = (10*365 + 2) * 24 * 60 * 60 +}; + +static void detected_xenix(struct sysv_sb_info *sbi, unsigned *max_links) +{ + struct buffer_head *bh1 = sbi->s_bh1; + struct buffer_head *bh2 = sbi->s_bh2; + struct xenix_super_block * sbd1; + struct xenix_super_block * sbd2; + + if (bh1 != bh2) + sbd1 = sbd2 = (struct xenix_super_block *) bh1->b_data; + else { + /* block size = 512, so bh1 != bh2 */ + sbd1 = (struct xenix_super_block *) bh1->b_data; + sbd2 = (struct xenix_super_block *) (bh2->b_data - 512); + } + + *max_links = XENIX_LINK_MAX; + sbi->s_fic_size = XENIX_NICINOD; + sbi->s_flc_size = XENIX_NICFREE; + sbi->s_sbd1 = (char *)sbd1; + sbi->s_sbd2 = (char *)sbd2; + sbi->s_sb_fic_count = &sbd1->s_ninode; + sbi->s_sb_fic_inodes = &sbd1->s_inode[0]; + sbi->s_sb_total_free_inodes = &sbd2->s_tinode; + sbi->s_bcache_count = &sbd1->s_nfree; + sbi->s_bcache = &sbd1->s_free[0]; + sbi->s_free_blocks = &sbd2->s_tfree; + sbi->s_sb_time = &sbd2->s_time; + sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd1->s_isize); + sbi->s_nzones = fs32_to_cpu(sbi, sbd1->s_fsize); +} + +static void detected_sysv4(struct sysv_sb_info *sbi, unsigned *max_links) +{ + struct sysv4_super_block * sbd; + struct buffer_head *bh1 = sbi->s_bh1; + struct buffer_head *bh2 = sbi->s_bh2; + + if (bh1 == bh2) + sbd = (struct sysv4_super_block *) (bh1->b_data + BLOCK_SIZE/2); + else + sbd = (struct sysv4_super_block *) bh2->b_data; + + *max_links = SYSV_LINK_MAX; + sbi->s_fic_size = SYSV_NICINOD; + sbi->s_flc_size = SYSV_NICFREE; + sbi->s_sbd1 = (char *)sbd; + sbi->s_sbd2 = (char *)sbd; + sbi->s_sb_fic_count = &sbd->s_ninode; + sbi->s_sb_fic_inodes = &sbd->s_inode[0]; + sbi->s_sb_total_free_inodes = &sbd->s_tinode; + sbi->s_bcache_count = &sbd->s_nfree; + sbi->s_bcache = &sbd->s_free[0]; + sbi->s_free_blocks = &sbd->s_tfree; + sbi->s_sb_time = &sbd->s_time; + sbi->s_sb_state = &sbd->s_state; + sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize); + sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize); +} + +static void detected_sysv2(struct sysv_sb_info *sbi, unsigned *max_links) +{ + struct sysv2_super_block *sbd; + struct buffer_head *bh1 = sbi->s_bh1; + struct buffer_head *bh2 = sbi->s_bh2; + + if (bh1 == bh2) + sbd = (struct sysv2_super_block *) (bh1->b_data + BLOCK_SIZE/2); + else + sbd = (struct sysv2_super_block *) bh2->b_data; + + *max_links = SYSV_LINK_MAX; + sbi->s_fic_size = SYSV_NICINOD; + sbi->s_flc_size = SYSV_NICFREE; + sbi->s_sbd1 = (char *)sbd; + sbi->s_sbd2 = (char *)sbd; + sbi->s_sb_fic_count = &sbd->s_ninode; + sbi->s_sb_fic_inodes = &sbd->s_inode[0]; + sbi->s_sb_total_free_inodes = &sbd->s_tinode; + sbi->s_bcache_count = &sbd->s_nfree; + sbi->s_bcache = &sbd->s_free[0]; + sbi->s_free_blocks = &sbd->s_tfree; + sbi->s_sb_time = &sbd->s_time; + sbi->s_sb_state = &sbd->s_state; + sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize); + sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize); +} + +static void detected_coherent(struct sysv_sb_info *sbi, unsigned *max_links) +{ + struct coh_super_block * sbd; + struct buffer_head *bh1 = sbi->s_bh1; + + sbd = (struct coh_super_block *) bh1->b_data; + + *max_links = COH_LINK_MAX; + sbi->s_fic_size = COH_NICINOD; + sbi->s_flc_size = COH_NICFREE; + sbi->s_sbd1 = (char *)sbd; + sbi->s_sbd2 = (char *)sbd; + sbi->s_sb_fic_count = &sbd->s_ninode; + sbi->s_sb_fic_inodes = &sbd->s_inode[0]; + sbi->s_sb_total_free_inodes = &sbd->s_tinode; + sbi->s_bcache_count = &sbd->s_nfree; + sbi->s_bcache = &sbd->s_free[0]; + sbi->s_free_blocks = &sbd->s_tfree; + sbi->s_sb_time = &sbd->s_time; + sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize); + sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize); +} + +static void detected_v7(struct sysv_sb_info *sbi, unsigned *max_links) +{ + struct buffer_head *bh2 = sbi->s_bh2; + struct v7_super_block *sbd = (struct v7_super_block *)bh2->b_data; + + *max_links = V7_LINK_MAX; + sbi->s_fic_size = V7_NICINOD; + sbi->s_flc_size = V7_NICFREE; + sbi->s_sbd1 = (char *)sbd; + sbi->s_sbd2 = (char *)sbd; + sbi->s_sb_fic_count = &sbd->s_ninode; + sbi->s_sb_fic_inodes = &sbd->s_inode[0]; + sbi->s_sb_total_free_inodes = &sbd->s_tinode; + sbi->s_bcache_count = &sbd->s_nfree; + sbi->s_bcache = &sbd->s_free[0]; + sbi->s_free_blocks = &sbd->s_tfree; + sbi->s_sb_time = &sbd->s_time; + sbi->s_firstdatazone = fs16_to_cpu(sbi, sbd->s_isize); + sbi->s_nzones = fs32_to_cpu(sbi, sbd->s_fsize); +} + +static int detect_xenix(struct sysv_sb_info *sbi, struct buffer_head *bh) +{ + struct xenix_super_block *sbd = (struct xenix_super_block *)bh->b_data; + if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0x2b5544)) + sbi->s_bytesex = BYTESEX_LE; + else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0x2b5544)) + sbi->s_bytesex = BYTESEX_BE; + else + return 0; + switch (fs32_to_cpu(sbi, sbd->s_type)) { + case 1: + sbi->s_type = FSTYPE_XENIX; + return 1; + case 2: + sbi->s_type = FSTYPE_XENIX; + return 2; + default: + return 0; + } +} + +static int detect_sysv(struct sysv_sb_info *sbi, struct buffer_head *bh) +{ + struct super_block *sb = sbi->s_sb; + /* All relevant fields are at the same offsets in R2 and R4 */ + struct sysv4_super_block * sbd; + u32 type; + + sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2); + if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0xfd187e20)) + sbi->s_bytesex = BYTESEX_LE; + else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0xfd187e20)) + sbi->s_bytesex = BYTESEX_BE; + else + return 0; + + type = fs32_to_cpu(sbi, sbd->s_type); + + if (fs16_to_cpu(sbi, sbd->s_nfree) == 0xffff) { + sbi->s_type = FSTYPE_AFS; + sbi->s_forced_ro = 1; + if (!sb_rdonly(sb)) { + printk("SysV FS: SCO EAFS on %s detected, " + "forcing read-only mode.\n", + sb->s_id); + } + return type; + } + + if (fs32_to_cpu(sbi, sbd->s_time) < JAN_1_1980) { + /* this is likely to happen on SystemV2 FS */ + if (type > 3 || type < 1) + return 0; + sbi->s_type = FSTYPE_SYSV2; + return type; + } + if ((type > 3 || type < 1) && (type > 0x30 || type < 0x10)) + return 0; + + /* On Interactive Unix (ISC) Version 4.0/3.x s_type field = 0x10, + 0x20 or 0x30 indicates that symbolic links and the 14-character + filename limit is gone. Due to lack of information about this + feature read-only mode seems to be a reasonable approach... -KGB */ + + if (type >= 0x10) { + printk("SysV FS: can't handle long file names on %s, " + "forcing read-only mode.\n", sb->s_id); + sbi->s_forced_ro = 1; + } + + sbi->s_type = FSTYPE_SYSV4; + return type >= 0x10 ? type >> 4 : type; +} + +static int detect_coherent(struct sysv_sb_info *sbi, struct buffer_head *bh) +{ + struct coh_super_block * sbd; + + sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2); + if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6)) + || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6))) + return 0; + sbi->s_bytesex = BYTESEX_PDP; + sbi->s_type = FSTYPE_COH; + return 1; +} + +static int detect_sysv_odd(struct sysv_sb_info *sbi, struct buffer_head *bh) +{ + int size = detect_sysv(sbi, bh); + + return size>2 ? 0 : size; +} + +static struct { + int block; + int (*test)(struct sysv_sb_info *, struct buffer_head *); +} flavours[] = { + {1, detect_xenix}, + {0, detect_sysv}, + {0, detect_coherent}, + {9, detect_sysv_odd}, + {15,detect_sysv_odd}, + {18,detect_sysv}, +}; + +static char *flavour_names[] = { + [FSTYPE_XENIX] = "Xenix", + [FSTYPE_SYSV4] = "SystemV", + [FSTYPE_SYSV2] = "SystemV Release 2", + [FSTYPE_COH] = "Coherent", + [FSTYPE_V7] = "V7", + [FSTYPE_AFS] = "AFS", +}; + +static void (*flavour_setup[])(struct sysv_sb_info *, unsigned *) = { + [FSTYPE_XENIX] = detected_xenix, + [FSTYPE_SYSV4] = detected_sysv4, + [FSTYPE_SYSV2] = detected_sysv2, + [FSTYPE_COH] = detected_coherent, + [FSTYPE_V7] = detected_v7, + [FSTYPE_AFS] = detected_sysv4, +}; + +static int complete_read_super(struct super_block *sb, int silent, int size) +{ + struct sysv_sb_info *sbi = SYSV_SB(sb); + struct inode *root_inode; + char *found = flavour_names[sbi->s_type]; + u_char n_bits = size+8; + int bsize = 1 << n_bits; + int bsize_4 = bsize >> 2; + + sbi->s_firstinodezone = 2; + + flavour_setup[sbi->s_type](sbi, &sb->s_max_links); + if (sbi->s_firstdatazone < sbi->s_firstinodezone) + return 0; + + sbi->s_ndatazones = sbi->s_nzones - sbi->s_firstdatazone; + sbi->s_inodes_per_block = bsize >> 6; + sbi->s_inodes_per_block_1 = (bsize >> 6)-1; + sbi->s_inodes_per_block_bits = n_bits-6; + sbi->s_ind_per_block = bsize_4; + sbi->s_ind_per_block_2 = bsize_4*bsize_4; + sbi->s_toobig_block = 10 + bsize_4 * (1 + bsize_4 * (1 + bsize_4)); + sbi->s_ind_per_block_bits = n_bits-2; + + sbi->s_ninodes = (sbi->s_firstdatazone - sbi->s_firstinodezone) + << sbi->s_inodes_per_block_bits; + + if (!silent) + printk("VFS: Found a %s FS (block size = %ld) on device %s\n", + found, sb->s_blocksize, sb->s_id); + + sb->s_magic = SYSV_MAGIC_BASE + sbi->s_type; + /* set up enough so that it can read an inode */ + sb->s_op = &sysv_sops; + if (sbi->s_forced_ro) + sb->s_flags |= SB_RDONLY; + root_inode = sysv_iget(sb, SYSV_ROOT_INO); + if (IS_ERR(root_inode)) { + printk("SysV FS: get root inode failed\n"); + return 0; + } + sb->s_root = d_make_root(root_inode); + if (!sb->s_root) { + printk("SysV FS: get root dentry failed\n"); + return 0; + } + return 1; +} + +static int sysv_fill_super(struct super_block *sb, void *data, int silent) +{ + struct buffer_head *bh1, *bh = NULL; + struct sysv_sb_info *sbi; + unsigned long blocknr; + int size = 0, i; + + BUILD_BUG_ON(1024 != sizeof (struct xenix_super_block)); + BUILD_BUG_ON(512 != sizeof (struct sysv4_super_block)); + BUILD_BUG_ON(512 != sizeof (struct sysv2_super_block)); + BUILD_BUG_ON(500 != sizeof (struct coh_super_block)); + BUILD_BUG_ON(64 != sizeof (struct sysv_inode)); + + sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL); + if (!sbi) + return -ENOMEM; + + sbi->s_sb = sb; + sbi->s_block_base = 0; + mutex_init(&sbi->s_lock); + sb->s_fs_info = sbi; + sb->s_time_min = 0; + sb->s_time_max = U32_MAX; + sb_set_blocksize(sb, BLOCK_SIZE); + + for (i = 0; i < ARRAY_SIZE(flavours) && !size; i++) { + brelse(bh); + bh = sb_bread(sb, flavours[i].block); + if (!bh) + continue; + size = flavours[i].test(SYSV_SB(sb), bh); + } + + if (!size) + goto Eunknown; + + switch (size) { + case 1: + blocknr = bh->b_blocknr << 1; + brelse(bh); + sb_set_blocksize(sb, 512); + bh1 = sb_bread(sb, blocknr); + bh = sb_bread(sb, blocknr + 1); + break; + case 2: + bh1 = bh; + break; + case 3: + blocknr = bh->b_blocknr >> 1; + brelse(bh); + sb_set_blocksize(sb, 2048); + bh1 = bh = sb_bread(sb, blocknr); + break; + default: + goto Ebadsize; + } + + if (bh && bh1) { + sbi->s_bh1 = bh1; + sbi->s_bh2 = bh; + if (complete_read_super(sb, silent, size)) + return 0; + } + + brelse(bh1); + brelse(bh); + sb_set_blocksize(sb, BLOCK_SIZE); + printk("oldfs: cannot read superblock\n"); +failed: + kfree(sbi); + return -EINVAL; + +Eunknown: + brelse(bh); + if (!silent) + printk("VFS: unable to find oldfs superblock on device %s\n", + sb->s_id); + goto failed; +Ebadsize: + brelse(bh); + if (!silent) + printk("VFS: oldfs: unsupported block size (%dKb)\n", + 1<<(size-2)); + goto failed; +} + +static int v7_sanity_check(struct super_block *sb, struct buffer_head *bh) +{ + struct v7_super_block *v7sb; + struct sysv_inode *v7i; + struct buffer_head *bh2; + struct sysv_sb_info *sbi; + + sbi = sb->s_fs_info; + + /* plausibility check on superblock */ + v7sb = (struct v7_super_block *) bh->b_data; + if (fs16_to_cpu(sbi, v7sb->s_nfree) > V7_NICFREE || + fs16_to_cpu(sbi, v7sb->s_ninode) > V7_NICINOD || + fs32_to_cpu(sbi, v7sb->s_fsize) > V7_MAXSIZE) + return 0; + + /* plausibility check on root inode: it is a directory, + with a nonzero size that is a multiple of 16 */ + bh2 = sb_bread(sb, 2); + if (bh2 == NULL) + return 0; + + v7i = (struct sysv_inode *)(bh2->b_data + 64); + if ((fs16_to_cpu(sbi, v7i->i_mode) & ~0777) != S_IFDIR || + (fs32_to_cpu(sbi, v7i->i_size) == 0) || + (fs32_to_cpu(sbi, v7i->i_size) & 017) || + (fs32_to_cpu(sbi, v7i->i_size) > V7_NFILES * + sizeof(struct sysv_dir_entry))) { + brelse(bh2); + return 0; + } + + brelse(bh2); + return 1; +} + +static int v7_fill_super(struct super_block *sb, void *data, int silent) +{ + struct sysv_sb_info *sbi; + struct buffer_head *bh; + + BUILD_BUG_ON(sizeof(struct v7_super_block) != 440); + BUILD_BUG_ON(sizeof(struct sysv_inode) != 64); + + sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL); + if (!sbi) + return -ENOMEM; + + sbi->s_sb = sb; + sbi->s_block_base = 0; + sbi->s_type = FSTYPE_V7; + mutex_init(&sbi->s_lock); + sb->s_fs_info = sbi; + sb->s_time_min = 0; + sb->s_time_max = U32_MAX; + + sb_set_blocksize(sb, 512); + + if ((bh = sb_bread(sb, 1)) == NULL) { + if (!silent) + printk("VFS: unable to read V7 FS superblock on " + "device %s.\n", sb->s_id); + goto failed; + } + + /* Try PDP-11 UNIX */ + sbi->s_bytesex = BYTESEX_PDP; + if (v7_sanity_check(sb, bh)) + goto detected; + + /* Try PC/IX, v7/x86 */ + sbi->s_bytesex = BYTESEX_LE; + if (v7_sanity_check(sb, bh)) + goto detected; + + goto failed; + +detected: + sbi->s_bh1 = bh; + sbi->s_bh2 = bh; + if (complete_read_super(sb, silent, 1)) + return 0; + +failed: + printk(KERN_ERR "VFS: could not find a valid V7 on %s.\n", + sb->s_id); + brelse(bh); + kfree(sbi); + return -EINVAL; +} + +/* Every kernel module contains stuff like this. */ + +static struct dentry *sysv_mount(struct file_system_type *fs_type, + int flags, const char *dev_name, void *data) +{ + return mount_bdev(fs_type, flags, dev_name, data, sysv_fill_super); +} + +static struct dentry *v7_mount(struct file_system_type *fs_type, + int flags, const char *dev_name, void *data) +{ + return mount_bdev(fs_type, flags, dev_name, data, v7_fill_super); +} + +static struct file_system_type sysv_fs_type = { + .owner = THIS_MODULE, + .name = "sysv", + .mount = sysv_mount, + .kill_sb = kill_block_super, + .fs_flags = FS_REQUIRES_DEV, +}; +MODULE_ALIAS_FS("sysv"); + +static struct file_system_type v7_fs_type = { + .owner = THIS_MODULE, + .name = "v7", + .mount = v7_mount, + .kill_sb = kill_block_super, + .fs_flags = FS_REQUIRES_DEV, +}; +MODULE_ALIAS_FS("v7"); +MODULE_ALIAS("v7"); + +static int __init init_sysv_fs(void) +{ + int error; + + error = sysv_init_icache(); + if (error) + goto out; + error = register_filesystem(&sysv_fs_type); + if (error) + goto destroy_icache; + error = register_filesystem(&v7_fs_type); + if (error) + goto unregister; + return 0; + +unregister: + unregister_filesystem(&sysv_fs_type); +destroy_icache: + sysv_destroy_icache(); +out: + return error; +} + +static void __exit exit_sysv_fs(void) +{ + unregister_filesystem(&sysv_fs_type); + unregister_filesystem(&v7_fs_type); + sysv_destroy_icache(); +} + +module_init(init_sysv_fs) +module_exit(exit_sysv_fs) +MODULE_LICENSE("GPL"); -- cgit v1.2.3