Changes in 5.15.34
lib/logic_iomem: correct fallback config references
um: fix and optimize xor select template for CONFIG64 and timetravel mode
rtc: wm8350: Handle error for wm8350_register_irq
nbd: add error handling support for add_disk()
nbd: Fix incorrect error handle when first_minor is illegal in nbd_dev_add
nbd: Fix hungtask when nbd_config_put
nbd: fix possible overflow on 'first_minor' in nbd_dev_add()
kfence: count unexpectedly skipped allocations
kfence: move saving stack trace of allocations into __kfence_alloc()
kfence: limit currently covered allocations when pool nearly full
KVM: x86/pmu: Use different raw event masks for AMD and Intel
KVM: SVM: Fix kvm_cache_regs.h inclusions for is_guest_mode()
KVM: x86/svm: Clear reserved bits written to PerfEvtSeln MSRs
KVM: x86/pmu: Fix and isolate TSX-specific performance event logic
KVM: x86/emulator: Emulate RDPID only if it is enabled in guest
drm: Add orientation quirk for GPD Win Max
ath5k: fix OOB in ath5k_eeprom_read_pcal_info_5111
drm/amd/display: Add signal type check when verify stream backends same
drm/amd/amdgpu/amdgpu_cs: fix refcount leak of a dma_fence obj
drm/amd/display: Fix memory leak
drm/amd/display: Use PSR version selected during set_psr_caps
usb: gadget: tegra-xudc: Do not program SPARAM
usb: gadget: tegra-xudc: Fix control endpoint's definitions
usb: cdnsp: fix cdnsp_decode_trb function to properly handle ret value
ptp: replace snprintf with sysfs_emit
drm/amdkfd: Don't take process mutex for svm ioctls
powerpc: dts: t104xrdb: fix phy type for FMAN 4/5
ath11k: fix kernel panic during unload/load ath11k modules
ath11k: pci: fix crash on suspend if board file is not found
ath11k: mhi: use mhi_sync_power_up()
net/smc: Send directly when TCP_CORK is cleared
drm/bridge: Add missing pm_runtime_put_sync
bpf: Make dst_port field in struct bpf_sock 16-bit wide
scsi: mvsas: Replace snprintf() with sysfs_emit()
scsi: bfa: Replace snprintf() with sysfs_emit()
drm/v3d: fix missing unlock
power: supply: axp20x_battery: properly report current when discharging
mt76: mt7921: fix crash when startup fails.
mt76: dma: initialize skip_unmap in mt76_dma_rx_fill
cfg80211: don't add non transmitted BSS to 6GHz scanned channels
libbpf: Fix build issue with llvm-readelf
ipv6: make mc_forwarding atomic
net: initialize init_net earlier
powerpc: Set crashkernel offset to mid of RMA region
drm/amdgpu: Fix recursive locking warning
scsi: smartpqi: Fix kdump issue when controller is locked up
PCI: aardvark: Fix support for MSI interrupts
iommu/arm-smmu-v3: fix event handling soft lockup
usb: ehci: add pci device support for Aspeed platforms
PCI: endpoint: Fix alignment fault error in copy tests
tcp: Don't acquire inet_listen_hashbucket::lock with disabled BH.
PCI: pciehp: Add Qualcomm quirk for Command Completed erratum
scsi: mpi3mr: Fix reporting of actual data transfer size
scsi: mpi3mr: Fix memory leaks
powerpc/set_memory: Avoid spinlock recursion in change_page_attr()
power: supply: axp288-charger: Set Vhold to 4.4V
net/mlx5e: Disable TX queues before registering the netdev
usb: dwc3: pci: Set the swnode from inside dwc3_pci_quirks()
iwlwifi: mvm: Correctly set fragmented EBS
iwlwifi: mvm: move only to an enabled channel
drm/msm/dsi: Remove spurious IRQF_ONESHOT flag
ipv4: Invalidate neighbour for broadcast address upon address addition
dm ioctl: prevent potential spectre v1 gadget
dm: requeue IO if mapping table not yet available
drm/amdkfd: make CRAT table missing message informational only
vfio/pci: Stub vfio_pci_vga_rw when !CONFIG_VFIO_PCI_VGA
scsi: pm8001: Fix pm80xx_pci_mem_copy() interface
scsi: pm8001: Fix pm8001_mpi_task_abort_resp()
scsi: pm8001: Fix task leak in pm8001_send_abort_all()
scsi: pm8001: Fix tag leaks on error
scsi: pm8001: Fix memory leak in pm8001_chip_fw_flash_update_req()
mt76: mt7915: fix injected MPDU transmission to not use HW A-MSDU
powerpc/64s/hash: Make hash faults work in NMI context
mt76: mt7615: Fix assigning negative values to unsigned variable
scsi: aha152x: Fix aha152x_setup() __setup handler return value
scsi: hisi_sas: Free irq vectors in order for v3 HW
scsi: hisi_sas: Limit users changing debugfs BIST count value
net/smc: correct settings of RMB window update limit
mips: ralink: fix a refcount leak in ill_acc_of_setup()
macvtap: advertise link netns via netlink
tuntap: add sanity checks about msg_controllen in sendmsg
Bluetooth: Fix not checking for valid hdev on bt_dev_{info,warn,err,dbg}
Bluetooth: use memset avoid memory leaks
bnxt_en: Eliminate unintended link toggle during FW reset
PCI: endpoint: Fix misused goto label
MIPS: fix fortify panic when copying asm exception handlers
powerpc/64e: Tie PPC_BOOK3E_64 to PPC_FSL_BOOK3E
powerpc/secvar: fix refcount leak in format_show()
scsi: libfc: Fix use after free in fc_exch_abts_resp()
can: isotp: set default value for N_As to 50 micro seconds
can: etas_es58x: es58x_fd_rx_event_msg(): initialize rx_event_msg before calling es58x_check_msg_len()
riscv: Fixed misaligned memory access. Fixed pointer comparison.
net: account alternate interface name memory
net: limit altnames to 64k total
net/mlx5e: Remove overzealous validations in netlink EEPROM query
net: sfp: add 2500base-X quirk for Lantech SFP module
usb: dwc3: omap: fix "unbalanced disables for smps10_out1" on omap5evm
mt76: fix monitor mode crash with sdio driver
xtensa: fix DTC warning unit_address_format
MIPS: ingenic: correct unit node address
Bluetooth: Fix use after free in hci_send_acl
netfilter: conntrack: revisit gc autotuning
netlabel: fix out-of-bounds memory accesses
ceph: fix inode reference leakage in ceph_get_snapdir()
ceph: fix memory leak in ceph_readdir when note_last_dentry returns error
lib/Kconfig.debug: add ARCH dependency for FUNCTION_ALIGN option
init/main.c: return 1 from handled __setup() functions
minix: fix bug when opening a file with O_DIRECT
clk: si5341: fix reported clk_rate when output divider is 2
staging: vchiq_arm: Avoid NULL ptr deref in vchiq_dump_platform_instances
staging: vchiq_core: handle NULL result of find_service_by_handle
phy: amlogic: phy-meson-gxl-usb2: fix shared reset controller use
phy: amlogic: meson8b-usb2: Use dev_err_probe()
phy: amlogic: meson8b-usb2: fix shared reset control use
clk: rockchip: drop CLK_SET_RATE_PARENT from dclk_vop* on rk3568
cpufreq: CPPC: Fix performance/frequency conversion
opp: Expose of-node's name in debugfs
staging: wfx: fix an error handling in wfx_init_common()
w1: w1_therm: fixes w1_seq for ds28ea00 sensors
NFSv4.2: fix reference count leaks in _nfs42_proc_copy_notify()
NFSv4: Protect the state recovery thread against direct reclaim
habanalabs: fix possible memory leak in MMU DR fini
xen: delay xen_hvm_init_time_ops() if kdump is boot on vcpu>=32
clk: ti: Preserve node in ti_dt_clocks_register()
clk: Enforce that disjoints limits are invalid
SUNRPC/call_alloc: async tasks mustn't block waiting for memory
SUNRPC/xprt: async tasks mustn't block waiting for memory
SUNRPC: remove scheduling boost for "SWAPPER" tasks.
NFS: swap IO handling is slightly different for O_DIRECT IO
NFS: swap-out must always use STABLE writes.
x86: Annotate call_on_stack()
x86/Kconfig: Do not allow CONFIG_X86_X32_ABI=y with llvm-objcopy
serial: samsung_tty: do not unlock port->lock for uart_write_wakeup()
virtio_console: eliminate anonymous module_init & module_exit
jfs: prevent NULL deref in diFree
SUNRPC: Fix socket waits for write buffer space
NFS: nfsiod should not block forever in mempool_alloc()
NFS: Avoid writeback threads getting stuck in mempool_alloc()
selftests: net: Add tls config dependency for tls selftests
parisc: Fix CPU affinity for Lasi, WAX and Dino chips
parisc: Fix patch code locking and flushing
mm: fix race between MADV_FREE reclaim and blkdev direct IO read
rtc: mc146818-lib: change return values of mc146818_get_time()
rtc: Check return value from mc146818_get_time()
rtc: mc146818-lib: fix RTC presence check
drm/amdgpu: fix off by one in amdgpu_gfx_kiq_acquire()
Drivers: hv: vmbus: Fix potential crash on module unload
Revert "NFSv4: Handle the special Linux file open access mode"
NFSv4: fix open failure with O_ACCMODE flag
scsi: sr: Fix typo in CDROM(CLOSETRAY|EJECT) handling
scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map()
scsi: zorro7xx: Fix a resource leak in zorro7xx_remove_one()
vdpa/mlx5: Rename control VQ workqueue to vdpa wq
vdpa/mlx5: Propagate link status from device to vdpa driver
vdpa: mlx5: prevent cvq work from hogging CPU
net: sfc: add missing xdp queue reinitialization
net/tls: fix slab-out-of-bounds bug in decrypt_internal
vrf: fix packet sniffing for traffic originating from ip tunnels
skbuff: fix coalescing for page_pool fragment recycling
ice: Clear default forwarding VSI during VSI release
mctp: Fix check for dev_hard_header() result
net: ipv4: fix route with nexthop object delete warning
net: stmmac: Fix unset max_speed difference between DT and non-DT platforms
drm/imx: imx-ldb: Check for null pointer after calling kmemdup
drm/imx: Fix memory leak in imx_pd_connector_get_modes
drm/imx: dw_hdmi-imx: Fix bailout in error cases of probe
regulator: rtq2134: Fix missing active_discharge_on setting
regulator: atc260x: Fix missing active_discharge_on setting
arch/arm64: Fix topology initialization for core scheduling
bnxt_en: Synchronize tx when xdp redirects happen on same ring
bnxt_en: reserve space inside receive page for skb_shared_info
bnxt_en: Prevent XDP redirect from running when stopping TX queue
sfc: Do not free an empty page_ring
RDMA/mlx5: Don't remove cache MRs when a delay is needed
RDMA/mlx5: Add a missing update of cache->last_add
IB/cm: Cancel mad on the DREQ event when the state is MRA_REP_RCVD
IB/rdmavt: add lock to call to rvt_error_qp to prevent a race condition
sctp: count singleton chunks in assoc user stats
dpaa2-ptp: Fix refcount leak in dpaa2_ptp_probe
ice: Set txq_teid to ICE_INVAL_TEID on ring creation
ice: Do not skip not enabled queues in ice_vc_dis_qs_msg
ipv6: Fix stats accounting in ip6_pkt_drop
ice: synchronize_rcu() when terminating rings
ice: xsk: fix VSI state check in ice_xsk_wakeup()
net: openvswitch: don't send internal clone attribute to the userspace.
net: ethernet: mv643xx: Fix over zealous checking of_get_mac_address()
net: openvswitch: fix leak of nested actions
rxrpc: fix a race in rxrpc_exit_net()
net: sfc: fix using uninitialized xdp tx_queue
net: phy: mscc-miim: reject clause 45 register accesses
qede: confirm skb is allocated before using
spi: bcm-qspi: fix MSPI only access with bcm_qspi_exec_mem_op()
bpf: Support dual-stack sockets in bpf_tcp_check_syncookie
drbd: Fix five use after free bugs in get_initial_state
scsi: ufs: ufshpb: Fix a NULL check on list iterator
io_uring: nospec index for tags on files update
io_uring: don't touch scm_fp_list after queueing skb
SUNRPC: Handle ENOMEM in call_transmit_status()
SUNRPC: Handle low memory situations in call_status()
SUNRPC: svc_tcp_sendmsg() should handle errors from xdr_alloc_bvec()
iommu/omap: Fix regression in probe for NULL pointer dereference
perf: arm-spe: Fix perf report --mem-mode
perf tools: Fix perf's libperf_print callback
perf session: Remap buf if there is no space for event
arm64: Add part number for Arm Cortex-A78AE
scsi: mpt3sas: Fix use after free in _scsih_expander_node_remove()
scsi: ufs: ufs-pci: Add support for Intel MTL
Revert "mmc: sdhci-xenon: fix annoying 1.8V regulator warning"
mmc: block: Check for errors after write on SPI
mmc: mmci: stm32: correctly check all elements of sg list
mmc: renesas_sdhi: don't overwrite TAP settings when HS400 tuning is complete
mmc: core: Fixup support for writeback-cache for eMMC and SD
lz4: fix LZ4_decompress_safe_partial read out of bound
highmem: fix checks in __kmap_local_sched_{in,out}
mmmremap.c: avoid pointless invalidate_range_start/end on mremap(old_size=0)
mm/mempolicy: fix mpol_new leak in shared_policy_replace
io_uring: don't check req->file in io_fsync_prep()
io_uring: defer splice/tee file validity check until command issue
io_uring: implement compat handling for IORING_REGISTER_IOWQ_AFF
io_uring: fix race between timeout flush and removal
x86/pm: Save the MSR validity status at context setup
x86/speculation: Restore speculation related MSRs during S3 resume
perf/x86/intel: Update the FRONTEND MSR mask on Sapphire Rapids
btrfs: fix qgroup reserve overflow the qgroup limit
btrfs: prevent subvol with swapfile from being deleted
spi: core: add dma_map_dev for __spi_unmap_msg()
arm64: patch_text: Fixup last cpu should be master
RDMA/hfi1: Fix use-after-free bug for mm struct
gpio: Restrict usage of GPIO chip irq members before initialization
x86/msi: Fix msi message data shadow struct
x86/mm/tlb: Revert retpoline avoidance approach
perf/x86/intel: Don't extend the pseudo-encoding to GP counters
ata: sata_dwc_460ex: Fix crash due to OOB write
perf: qcom_l2_pmu: fix an incorrect NULL check on list iterator
perf/core: Inherit event_caps
irqchip/gic-v3: Fix GICR_CTLR.RWP polling
fbdev: Fix unregistering of framebuffers without device
amd/display: set backlight only if required
SUNRPC: Prevent immediate close+reconnect
drm/panel: ili9341: fix optional regulator handling
drm/amdgpu/display: change pipe policy for DCN 2.1
drm/amdgpu/smu10: fix SoC/fclk units in auto mode
drm/amdgpu/vcn: Fix the register setting for vcn1
drm/nouveau/pmu: Add missing callbacks for Tegra devices
drm/amdkfd: Create file descriptor after client is added to smi_clients list
drm/amdgpu: don't use BACO for reset in S3
KVM: SVM: Allow AVIC support on system w/ physical APIC ID > 255
net/smc: send directly on setting TCP_NODELAY
Revert "selftests: net: Add tls config dependency for tls selftests"
bpf: Make remote_port field in struct bpf_sk_lookup 16-bit wide
selftests/bpf: Fix u8 narrow load checks for bpf_sk_lookup remote_port
rtc: mc146818-lib: fix signedness bug in mc146818_get_time()
SUNRPC: Don't call connect() more than once on a TCP socket
Revert "nbd: fix possible overflow on 'first_minor' in nbd_dev_add()"
perf build: Don't use -ffat-lto-objects in the python feature test when building with clang-13
perf python: Fix probing for some clang command line options
tools build: Filter out options and warnings not supported by clang
tools build: Use $(shell ) instead of `` to get embedded libperl's ccopts
dmaengine: Revert "dmaengine: shdma: Fix runtime PM imbalance on error"
KVM: avoid NULL pointer dereference in kvm_dirty_ring_push
Revert "net/mlx5: Accept devlink user input after driver initialization complete"
ubsan: remove CONFIG_UBSAN_OBJECT_SIZE
selftests: cgroup: Make cg_create() use 0755 for permission instead of 0644
selftests: cgroup: Test open-time credential usage for migration checks
selftests: cgroup: Test open-time cgroup namespace usage for migration checks
mm: don't skip swap entry even if zap_details specified
Drivers: hv: vmbus: Replace smp_store_mb() with virt_store_mb()
x86/bug: Prevent shadowing in __WARN_FLAGS
sched: Teach the forced-newidle balancer about CPU affinity limitation.
x86,static_call: Fix __static_call_return0 for i386
irqchip/gic-v4: Wait for GICR_VPENDBASER.Dirty to clear before descheduling
powerpc/64: Fix build failure with allyesconfig in book3s_64_entry.S
irqchip/gic, gic-v3: Prevent GSI to SGI translations
mm/sparsemem: fix 'mem_section' will never be NULL gcc 12 warning
static_call: Don't make __static_call_return0 static
powerpc: Fix virt_addr_valid() for 64-bit Book3E & 32-bit
stacktrace: move filter_irq_stacks() to kernel/stacktrace.c
Linux 5.15.34
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I98049d0d8ebd427296418d31085bfde482ad30e7
726 lines
19 KiB
C
726 lines
19 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* linux/fs/minix/inode.c
|
|
*
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
*
|
|
* Copyright (C) 1996 Gertjan van Wingerde
|
|
* Minix V2 fs support.
|
|
*
|
|
* Modified for 680x0 by Andreas Schwab
|
|
* Updated to filesystem version 3 by Daniel Aragones
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include "minix.h"
|
|
#include <linux/buffer_head.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/init.h>
|
|
#include <linux/highuid.h>
|
|
#include <linux/vfs.h>
|
|
#include <linux/writeback.h>
|
|
|
|
static int minix_write_inode(struct inode *inode,
|
|
struct writeback_control *wbc);
|
|
static int minix_statfs(struct dentry *dentry, struct kstatfs *buf);
|
|
static int minix_remount (struct super_block * sb, int * flags, char * data);
|
|
|
|
static void minix_evict_inode(struct inode *inode)
|
|
{
|
|
truncate_inode_pages_final(&inode->i_data);
|
|
if (!inode->i_nlink) {
|
|
inode->i_size = 0;
|
|
minix_truncate(inode);
|
|
}
|
|
invalidate_inode_buffers(inode);
|
|
clear_inode(inode);
|
|
if (!inode->i_nlink)
|
|
minix_free_inode(inode);
|
|
}
|
|
|
|
static void minix_put_super(struct super_block *sb)
|
|
{
|
|
int i;
|
|
struct minix_sb_info *sbi = minix_sb(sb);
|
|
|
|
if (!sb_rdonly(sb)) {
|
|
if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */
|
|
sbi->s_ms->s_state = sbi->s_mount_state;
|
|
mark_buffer_dirty(sbi->s_sbh);
|
|
}
|
|
for (i = 0; i < sbi->s_imap_blocks; i++)
|
|
brelse(sbi->s_imap[i]);
|
|
for (i = 0; i < sbi->s_zmap_blocks; i++)
|
|
brelse(sbi->s_zmap[i]);
|
|
brelse (sbi->s_sbh);
|
|
kfree(sbi->s_imap);
|
|
sb->s_fs_info = NULL;
|
|
kfree(sbi);
|
|
}
|
|
|
|
static struct kmem_cache * minix_inode_cachep;
|
|
|
|
static struct inode *minix_alloc_inode(struct super_block *sb)
|
|
{
|
|
struct minix_inode_info *ei;
|
|
ei = kmem_cache_alloc(minix_inode_cachep, GFP_KERNEL);
|
|
if (!ei)
|
|
return NULL;
|
|
return &ei->vfs_inode;
|
|
}
|
|
|
|
static void minix_free_in_core_inode(struct inode *inode)
|
|
{
|
|
kmem_cache_free(minix_inode_cachep, minix_i(inode));
|
|
}
|
|
|
|
static void init_once(void *foo)
|
|
{
|
|
struct minix_inode_info *ei = (struct minix_inode_info *) foo;
|
|
|
|
inode_init_once(&ei->vfs_inode);
|
|
}
|
|
|
|
static int __init init_inodecache(void)
|
|
{
|
|
minix_inode_cachep = kmem_cache_create("minix_inode_cache",
|
|
sizeof(struct minix_inode_info),
|
|
0, (SLAB_RECLAIM_ACCOUNT|
|
|
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
|
init_once);
|
|
if (minix_inode_cachep == NULL)
|
|
return -ENOMEM;
|
|
return 0;
|
|
}
|
|
|
|
static void destroy_inodecache(void)
|
|
{
|
|
/*
|
|
* Make sure all delayed rcu free inodes are flushed before we
|
|
* destroy cache.
|
|
*/
|
|
rcu_barrier();
|
|
kmem_cache_destroy(minix_inode_cachep);
|
|
}
|
|
|
|
static const struct super_operations minix_sops = {
|
|
.alloc_inode = minix_alloc_inode,
|
|
.free_inode = minix_free_in_core_inode,
|
|
.write_inode = minix_write_inode,
|
|
.evict_inode = minix_evict_inode,
|
|
.put_super = minix_put_super,
|
|
.statfs = minix_statfs,
|
|
.remount_fs = minix_remount,
|
|
};
|
|
|
|
static int minix_remount (struct super_block * sb, int * flags, char * data)
|
|
{
|
|
struct minix_sb_info * sbi = minix_sb(sb);
|
|
struct minix_super_block * ms;
|
|
|
|
sync_filesystem(sb);
|
|
ms = sbi->s_ms;
|
|
if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
|
|
return 0;
|
|
if (*flags & SB_RDONLY) {
|
|
if (ms->s_state & MINIX_VALID_FS ||
|
|
!(sbi->s_mount_state & MINIX_VALID_FS))
|
|
return 0;
|
|
/* Mounting a rw partition read-only. */
|
|
if (sbi->s_version != MINIX_V3)
|
|
ms->s_state = sbi->s_mount_state;
|
|
mark_buffer_dirty(sbi->s_sbh);
|
|
} else {
|
|
/* Mount a partition which is read-only, read-write. */
|
|
if (sbi->s_version != MINIX_V3) {
|
|
sbi->s_mount_state = ms->s_state;
|
|
ms->s_state &= ~MINIX_VALID_FS;
|
|
} else {
|
|
sbi->s_mount_state = MINIX_VALID_FS;
|
|
}
|
|
mark_buffer_dirty(sbi->s_sbh);
|
|
|
|
if (!(sbi->s_mount_state & MINIX_VALID_FS))
|
|
printk("MINIX-fs warning: remounting unchecked fs, "
|
|
"running fsck is recommended\n");
|
|
else if ((sbi->s_mount_state & MINIX_ERROR_FS))
|
|
printk("MINIX-fs warning: remounting fs with errors, "
|
|
"running fsck is recommended\n");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static bool minix_check_superblock(struct super_block *sb)
|
|
{
|
|
struct minix_sb_info *sbi = minix_sb(sb);
|
|
|
|
if (sbi->s_imap_blocks == 0 || sbi->s_zmap_blocks == 0)
|
|
return false;
|
|
|
|
/*
|
|
* s_max_size must not exceed the block mapping limitation. This check
|
|
* is only needed for V1 filesystems, since V2/V3 support an extra level
|
|
* of indirect blocks which places the limit well above U32_MAX.
|
|
*/
|
|
if (sbi->s_version == MINIX_V1 &&
|
|
sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
static int minix_fill_super(struct super_block *s, void *data, int silent)
|
|
{
|
|
struct buffer_head *bh;
|
|
struct buffer_head **map;
|
|
struct minix_super_block *ms;
|
|
struct minix3_super_block *m3s = NULL;
|
|
unsigned long i, block;
|
|
struct inode *root_inode;
|
|
struct minix_sb_info *sbi;
|
|
int ret = -EINVAL;
|
|
|
|
sbi = kzalloc(sizeof(struct minix_sb_info), GFP_KERNEL);
|
|
if (!sbi)
|
|
return -ENOMEM;
|
|
s->s_fs_info = sbi;
|
|
|
|
BUILD_BUG_ON(32 != sizeof (struct minix_inode));
|
|
BUILD_BUG_ON(64 != sizeof(struct minix2_inode));
|
|
|
|
if (!sb_set_blocksize(s, BLOCK_SIZE))
|
|
goto out_bad_hblock;
|
|
|
|
if (!(bh = sb_bread(s, 1)))
|
|
goto out_bad_sb;
|
|
|
|
ms = (struct minix_super_block *) bh->b_data;
|
|
sbi->s_ms = ms;
|
|
sbi->s_sbh = bh;
|
|
sbi->s_mount_state = ms->s_state;
|
|
sbi->s_ninodes = ms->s_ninodes;
|
|
sbi->s_nzones = ms->s_nzones;
|
|
sbi->s_imap_blocks = ms->s_imap_blocks;
|
|
sbi->s_zmap_blocks = ms->s_zmap_blocks;
|
|
sbi->s_firstdatazone = ms->s_firstdatazone;
|
|
sbi->s_log_zone_size = ms->s_log_zone_size;
|
|
s->s_maxbytes = ms->s_max_size;
|
|
s->s_magic = ms->s_magic;
|
|
if (s->s_magic == MINIX_SUPER_MAGIC) {
|
|
sbi->s_version = MINIX_V1;
|
|
sbi->s_dirsize = 16;
|
|
sbi->s_namelen = 14;
|
|
s->s_max_links = MINIX_LINK_MAX;
|
|
} else if (s->s_magic == MINIX_SUPER_MAGIC2) {
|
|
sbi->s_version = MINIX_V1;
|
|
sbi->s_dirsize = 32;
|
|
sbi->s_namelen = 30;
|
|
s->s_max_links = MINIX_LINK_MAX;
|
|
} else if (s->s_magic == MINIX2_SUPER_MAGIC) {
|
|
sbi->s_version = MINIX_V2;
|
|
sbi->s_nzones = ms->s_zones;
|
|
sbi->s_dirsize = 16;
|
|
sbi->s_namelen = 14;
|
|
s->s_max_links = MINIX2_LINK_MAX;
|
|
} else if (s->s_magic == MINIX2_SUPER_MAGIC2) {
|
|
sbi->s_version = MINIX_V2;
|
|
sbi->s_nzones = ms->s_zones;
|
|
sbi->s_dirsize = 32;
|
|
sbi->s_namelen = 30;
|
|
s->s_max_links = MINIX2_LINK_MAX;
|
|
} else if ( *(__u16 *)(bh->b_data + 24) == MINIX3_SUPER_MAGIC) {
|
|
m3s = (struct minix3_super_block *) bh->b_data;
|
|
s->s_magic = m3s->s_magic;
|
|
sbi->s_imap_blocks = m3s->s_imap_blocks;
|
|
sbi->s_zmap_blocks = m3s->s_zmap_blocks;
|
|
sbi->s_firstdatazone = m3s->s_firstdatazone;
|
|
sbi->s_log_zone_size = m3s->s_log_zone_size;
|
|
s->s_maxbytes = m3s->s_max_size;
|
|
sbi->s_ninodes = m3s->s_ninodes;
|
|
sbi->s_nzones = m3s->s_zones;
|
|
sbi->s_dirsize = 64;
|
|
sbi->s_namelen = 60;
|
|
sbi->s_version = MINIX_V3;
|
|
sbi->s_mount_state = MINIX_VALID_FS;
|
|
sb_set_blocksize(s, m3s->s_blocksize);
|
|
s->s_max_links = MINIX2_LINK_MAX;
|
|
} else
|
|
goto out_no_fs;
|
|
|
|
if (!minix_check_superblock(s))
|
|
goto out_illegal_sb;
|
|
|
|
/*
|
|
* Allocate the buffer map to keep the superblock small.
|
|
*/
|
|
i = (sbi->s_imap_blocks + sbi->s_zmap_blocks) * sizeof(bh);
|
|
map = kzalloc(i, GFP_KERNEL);
|
|
if (!map)
|
|
goto out_no_map;
|
|
sbi->s_imap = &map[0];
|
|
sbi->s_zmap = &map[sbi->s_imap_blocks];
|
|
|
|
block=2;
|
|
for (i=0 ; i < sbi->s_imap_blocks ; i++) {
|
|
if (!(sbi->s_imap[i]=sb_bread(s, block)))
|
|
goto out_no_bitmap;
|
|
block++;
|
|
}
|
|
for (i=0 ; i < sbi->s_zmap_blocks ; i++) {
|
|
if (!(sbi->s_zmap[i]=sb_bread(s, block)))
|
|
goto out_no_bitmap;
|
|
block++;
|
|
}
|
|
|
|
minix_set_bit(0,sbi->s_imap[0]->b_data);
|
|
minix_set_bit(0,sbi->s_zmap[0]->b_data);
|
|
|
|
/* Apparently minix can create filesystems that allocate more blocks for
|
|
* the bitmaps than needed. We simply ignore that, but verify it didn't
|
|
* create one with not enough blocks and bail out if so.
|
|
*/
|
|
block = minix_blocks_needed(sbi->s_ninodes, s->s_blocksize);
|
|
if (sbi->s_imap_blocks < block) {
|
|
printk("MINIX-fs: file system does not have enough "
|
|
"imap blocks allocated. Refusing to mount.\n");
|
|
goto out_no_bitmap;
|
|
}
|
|
|
|
block = minix_blocks_needed(
|
|
(sbi->s_nzones - sbi->s_firstdatazone + 1),
|
|
s->s_blocksize);
|
|
if (sbi->s_zmap_blocks < block) {
|
|
printk("MINIX-fs: file system does not have enough "
|
|
"zmap blocks allocated. Refusing to mount.\n");
|
|
goto out_no_bitmap;
|
|
}
|
|
|
|
/* set up enough so that it can read an inode */
|
|
s->s_op = &minix_sops;
|
|
s->s_time_min = 0;
|
|
s->s_time_max = U32_MAX;
|
|
root_inode = minix_iget(s, MINIX_ROOT_INO);
|
|
if (IS_ERR(root_inode)) {
|
|
ret = PTR_ERR(root_inode);
|
|
goto out_no_root;
|
|
}
|
|
|
|
ret = -ENOMEM;
|
|
s->s_root = d_make_root(root_inode);
|
|
if (!s->s_root)
|
|
goto out_no_root;
|
|
|
|
if (!sb_rdonly(s)) {
|
|
if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */
|
|
ms->s_state &= ~MINIX_VALID_FS;
|
|
mark_buffer_dirty(bh);
|
|
}
|
|
if (!(sbi->s_mount_state & MINIX_VALID_FS))
|
|
printk("MINIX-fs: mounting unchecked file system, "
|
|
"running fsck is recommended\n");
|
|
else if (sbi->s_mount_state & MINIX_ERROR_FS)
|
|
printk("MINIX-fs: mounting file system with errors, "
|
|
"running fsck is recommended\n");
|
|
|
|
return 0;
|
|
|
|
out_no_root:
|
|
if (!silent)
|
|
printk("MINIX-fs: get root inode failed\n");
|
|
goto out_freemap;
|
|
|
|
out_no_bitmap:
|
|
printk("MINIX-fs: bad superblock or unable to read bitmaps\n");
|
|
out_freemap:
|
|
for (i = 0; i < sbi->s_imap_blocks; i++)
|
|
brelse(sbi->s_imap[i]);
|
|
for (i = 0; i < sbi->s_zmap_blocks; i++)
|
|
brelse(sbi->s_zmap[i]);
|
|
kfree(sbi->s_imap);
|
|
goto out_release;
|
|
|
|
out_no_map:
|
|
ret = -ENOMEM;
|
|
if (!silent)
|
|
printk("MINIX-fs: can't allocate map\n");
|
|
goto out_release;
|
|
|
|
out_illegal_sb:
|
|
if (!silent)
|
|
printk("MINIX-fs: bad superblock\n");
|
|
goto out_release;
|
|
|
|
out_no_fs:
|
|
if (!silent)
|
|
printk("VFS: Can't find a Minix filesystem V1 | V2 | V3 "
|
|
"on device %s.\n", s->s_id);
|
|
out_release:
|
|
brelse(bh);
|
|
goto out;
|
|
|
|
out_bad_hblock:
|
|
printk("MINIX-fs: blocksize too small for device\n");
|
|
goto out;
|
|
|
|
out_bad_sb:
|
|
printk("MINIX-fs: unable to read superblock\n");
|
|
out:
|
|
s->s_fs_info = NULL;
|
|
kfree(sbi);
|
|
return ret;
|
|
}
|
|
|
|
static int minix_statfs(struct dentry *dentry, struct kstatfs *buf)
|
|
{
|
|
struct super_block *sb = dentry->d_sb;
|
|
struct minix_sb_info *sbi = minix_sb(sb);
|
|
u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
|
|
buf->f_type = sb->s_magic;
|
|
buf->f_bsize = sb->s_blocksize;
|
|
buf->f_blocks = (sbi->s_nzones - sbi->s_firstdatazone) << sbi->s_log_zone_size;
|
|
buf->f_bfree = minix_count_free_blocks(sb);
|
|
buf->f_bavail = buf->f_bfree;
|
|
buf->f_files = sbi->s_ninodes;
|
|
buf->f_ffree = minix_count_free_inodes(sb);
|
|
buf->f_namelen = sbi->s_namelen;
|
|
buf->f_fsid = u64_to_fsid(id);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int minix_get_block(struct inode *inode, sector_t block,
|
|
struct buffer_head *bh_result, int create)
|
|
{
|
|
if (INODE_VERSION(inode) == MINIX_V1)
|
|
return V1_minix_get_block(inode, block, bh_result, create);
|
|
else
|
|
return V2_minix_get_block(inode, block, bh_result, create);
|
|
}
|
|
|
|
static int minix_writepage(struct page *page, struct writeback_control *wbc)
|
|
{
|
|
return block_write_full_page(page, minix_get_block, wbc);
|
|
}
|
|
|
|
static int minix_readpage(struct file *file, struct page *page)
|
|
{
|
|
return block_read_full_page(page,minix_get_block);
|
|
}
|
|
|
|
int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len)
|
|
{
|
|
return __block_write_begin(page, pos, len, minix_get_block);
|
|
}
|
|
|
|
static void minix_write_failed(struct address_space *mapping, loff_t to)
|
|
{
|
|
struct inode *inode = mapping->host;
|
|
|
|
if (to > inode->i_size) {
|
|
truncate_pagecache(inode, inode->i_size);
|
|
minix_truncate(inode);
|
|
}
|
|
}
|
|
|
|
static int minix_write_begin(struct file *file, struct address_space *mapping,
|
|
loff_t pos, unsigned len, unsigned flags,
|
|
struct page **pagep, void **fsdata)
|
|
{
|
|
int ret;
|
|
|
|
ret = block_write_begin(mapping, pos, len, flags, pagep,
|
|
minix_get_block);
|
|
if (unlikely(ret))
|
|
minix_write_failed(mapping, pos + len);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static sector_t minix_bmap(struct address_space *mapping, sector_t block)
|
|
{
|
|
return generic_block_bmap(mapping,block,minix_get_block);
|
|
}
|
|
|
|
static const struct address_space_operations minix_aops = {
|
|
.set_page_dirty = __set_page_dirty_buffers,
|
|
.readpage = minix_readpage,
|
|
.writepage = minix_writepage,
|
|
.write_begin = minix_write_begin,
|
|
.write_end = generic_write_end,
|
|
.bmap = minix_bmap,
|
|
.direct_IO = noop_direct_IO
|
|
};
|
|
|
|
static const struct inode_operations minix_symlink_inode_operations = {
|
|
.get_link = page_get_link,
|
|
.getattr = minix_getattr,
|
|
};
|
|
|
|
void minix_set_inode(struct inode *inode, dev_t rdev)
|
|
{
|
|
if (S_ISREG(inode->i_mode)) {
|
|
inode->i_op = &minix_file_inode_operations;
|
|
inode->i_fop = &minix_file_operations;
|
|
inode->i_mapping->a_ops = &minix_aops;
|
|
} else if (S_ISDIR(inode->i_mode)) {
|
|
inode->i_op = &minix_dir_inode_operations;
|
|
inode->i_fop = &minix_dir_operations;
|
|
inode->i_mapping->a_ops = &minix_aops;
|
|
} else if (S_ISLNK(inode->i_mode)) {
|
|
inode->i_op = &minix_symlink_inode_operations;
|
|
inode_nohighmem(inode);
|
|
inode->i_mapping->a_ops = &minix_aops;
|
|
} else
|
|
init_special_inode(inode, inode->i_mode, rdev);
|
|
}
|
|
|
|
/*
|
|
* The minix V1 function to read an inode.
|
|
*/
|
|
static struct inode *V1_minix_iget(struct inode *inode)
|
|
{
|
|
struct buffer_head * bh;
|
|
struct minix_inode * raw_inode;
|
|
struct minix_inode_info *minix_inode = minix_i(inode);
|
|
int i;
|
|
|
|
raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
|
|
if (!raw_inode) {
|
|
iget_failed(inode);
|
|
return ERR_PTR(-EIO);
|
|
}
|
|
if (raw_inode->i_nlinks == 0) {
|
|
printk("MINIX-fs: deleted inode referenced: %lu\n",
|
|
inode->i_ino);
|
|
brelse(bh);
|
|
iget_failed(inode);
|
|
return ERR_PTR(-ESTALE);
|
|
}
|
|
inode->i_mode = raw_inode->i_mode;
|
|
i_uid_write(inode, raw_inode->i_uid);
|
|
i_gid_write(inode, raw_inode->i_gid);
|
|
set_nlink(inode, raw_inode->i_nlinks);
|
|
inode->i_size = raw_inode->i_size;
|
|
inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec = raw_inode->i_time;
|
|
inode->i_mtime.tv_nsec = 0;
|
|
inode->i_atime.tv_nsec = 0;
|
|
inode->i_ctime.tv_nsec = 0;
|
|
inode->i_blocks = 0;
|
|
for (i = 0; i < 9; i++)
|
|
minix_inode->u.i1_data[i] = raw_inode->i_zone[i];
|
|
minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
|
|
brelse(bh);
|
|
unlock_new_inode(inode);
|
|
return inode;
|
|
}
|
|
|
|
/*
|
|
* The minix V2 function to read an inode.
|
|
*/
|
|
static struct inode *V2_minix_iget(struct inode *inode)
|
|
{
|
|
struct buffer_head * bh;
|
|
struct minix2_inode * raw_inode;
|
|
struct minix_inode_info *minix_inode = minix_i(inode);
|
|
int i;
|
|
|
|
raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
|
|
if (!raw_inode) {
|
|
iget_failed(inode);
|
|
return ERR_PTR(-EIO);
|
|
}
|
|
if (raw_inode->i_nlinks == 0) {
|
|
printk("MINIX-fs: deleted inode referenced: %lu\n",
|
|
inode->i_ino);
|
|
brelse(bh);
|
|
iget_failed(inode);
|
|
return ERR_PTR(-ESTALE);
|
|
}
|
|
inode->i_mode = raw_inode->i_mode;
|
|
i_uid_write(inode, raw_inode->i_uid);
|
|
i_gid_write(inode, raw_inode->i_gid);
|
|
set_nlink(inode, raw_inode->i_nlinks);
|
|
inode->i_size = raw_inode->i_size;
|
|
inode->i_mtime.tv_sec = raw_inode->i_mtime;
|
|
inode->i_atime.tv_sec = raw_inode->i_atime;
|
|
inode->i_ctime.tv_sec = raw_inode->i_ctime;
|
|
inode->i_mtime.tv_nsec = 0;
|
|
inode->i_atime.tv_nsec = 0;
|
|
inode->i_ctime.tv_nsec = 0;
|
|
inode->i_blocks = 0;
|
|
for (i = 0; i < 10; i++)
|
|
minix_inode->u.i2_data[i] = raw_inode->i_zone[i];
|
|
minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
|
|
brelse(bh);
|
|
unlock_new_inode(inode);
|
|
return inode;
|
|
}
|
|
|
|
/*
|
|
* The global function to read an inode.
|
|
*/
|
|
struct inode *minix_iget(struct super_block *sb, unsigned long ino)
|
|
{
|
|
struct inode *inode;
|
|
|
|
inode = iget_locked(sb, ino);
|
|
if (!inode)
|
|
return ERR_PTR(-ENOMEM);
|
|
if (!(inode->i_state & I_NEW))
|
|
return inode;
|
|
|
|
if (INODE_VERSION(inode) == MINIX_V1)
|
|
return V1_minix_iget(inode);
|
|
else
|
|
return V2_minix_iget(inode);
|
|
}
|
|
|
|
/*
|
|
* The minix V1 function to synchronize an inode.
|
|
*/
|
|
static struct buffer_head * V1_minix_update_inode(struct inode * inode)
|
|
{
|
|
struct buffer_head * bh;
|
|
struct minix_inode * raw_inode;
|
|
struct minix_inode_info *minix_inode = minix_i(inode);
|
|
int i;
|
|
|
|
raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
|
|
if (!raw_inode)
|
|
return NULL;
|
|
raw_inode->i_mode = inode->i_mode;
|
|
raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode));
|
|
raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode));
|
|
raw_inode->i_nlinks = inode->i_nlink;
|
|
raw_inode->i_size = inode->i_size;
|
|
raw_inode->i_time = inode->i_mtime.tv_sec;
|
|
if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
|
|
raw_inode->i_zone[0] = old_encode_dev(inode->i_rdev);
|
|
else for (i = 0; i < 9; i++)
|
|
raw_inode->i_zone[i] = minix_inode->u.i1_data[i];
|
|
mark_buffer_dirty(bh);
|
|
return bh;
|
|
}
|
|
|
|
/*
|
|
* The minix V2 function to synchronize an inode.
|
|
*/
|
|
static struct buffer_head * V2_minix_update_inode(struct inode * inode)
|
|
{
|
|
struct buffer_head * bh;
|
|
struct minix2_inode * raw_inode;
|
|
struct minix_inode_info *minix_inode = minix_i(inode);
|
|
int i;
|
|
|
|
raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
|
|
if (!raw_inode)
|
|
return NULL;
|
|
raw_inode->i_mode = inode->i_mode;
|
|
raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode));
|
|
raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode));
|
|
raw_inode->i_nlinks = inode->i_nlink;
|
|
raw_inode->i_size = inode->i_size;
|
|
raw_inode->i_mtime = inode->i_mtime.tv_sec;
|
|
raw_inode->i_atime = inode->i_atime.tv_sec;
|
|
raw_inode->i_ctime = inode->i_ctime.tv_sec;
|
|
if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
|
|
raw_inode->i_zone[0] = old_encode_dev(inode->i_rdev);
|
|
else for (i = 0; i < 10; i++)
|
|
raw_inode->i_zone[i] = minix_inode->u.i2_data[i];
|
|
mark_buffer_dirty(bh);
|
|
return bh;
|
|
}
|
|
|
|
static int minix_write_inode(struct inode *inode, struct writeback_control *wbc)
|
|
{
|
|
int err = 0;
|
|
struct buffer_head *bh;
|
|
|
|
if (INODE_VERSION(inode) == MINIX_V1)
|
|
bh = V1_minix_update_inode(inode);
|
|
else
|
|
bh = V2_minix_update_inode(inode);
|
|
if (!bh)
|
|
return -EIO;
|
|
if (wbc->sync_mode == WB_SYNC_ALL && buffer_dirty(bh)) {
|
|
sync_dirty_buffer(bh);
|
|
if (buffer_req(bh) && !buffer_uptodate(bh)) {
|
|
printk("IO error syncing minix inode [%s:%08lx]\n",
|
|
inode->i_sb->s_id, inode->i_ino);
|
|
err = -EIO;
|
|
}
|
|
}
|
|
brelse (bh);
|
|
return err;
|
|
}
|
|
|
|
int minix_getattr(struct user_namespace *mnt_userns, const struct path *path,
|
|
struct kstat *stat, u32 request_mask, unsigned int flags)
|
|
{
|
|
struct super_block *sb = path->dentry->d_sb;
|
|
struct inode *inode = d_inode(path->dentry);
|
|
|
|
generic_fillattr(&init_user_ns, inode, stat);
|
|
if (INODE_VERSION(inode) == MINIX_V1)
|
|
stat->blocks = (BLOCK_SIZE / 512) * V1_minix_blocks(stat->size, sb);
|
|
else
|
|
stat->blocks = (sb->s_blocksize / 512) * V2_minix_blocks(stat->size, sb);
|
|
stat->blksize = sb->s_blocksize;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* The function that is called for file truncation.
|
|
*/
|
|
void minix_truncate(struct inode * inode)
|
|
{
|
|
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)))
|
|
return;
|
|
if (INODE_VERSION(inode) == MINIX_V1)
|
|
V1_minix_truncate(inode);
|
|
else
|
|
V2_minix_truncate(inode);
|
|
}
|
|
|
|
static struct dentry *minix_mount(struct file_system_type *fs_type,
|
|
int flags, const char *dev_name, void *data)
|
|
{
|
|
return mount_bdev(fs_type, flags, dev_name, data, minix_fill_super);
|
|
}
|
|
|
|
static struct file_system_type minix_fs_type = {
|
|
.owner = THIS_MODULE,
|
|
.name = "minix",
|
|
.mount = minix_mount,
|
|
.kill_sb = kill_block_super,
|
|
.fs_flags = FS_REQUIRES_DEV,
|
|
};
|
|
MODULE_ALIAS_FS("minix");
|
|
|
|
static int __init init_minix_fs(void)
|
|
{
|
|
int err = init_inodecache();
|
|
if (err)
|
|
goto out1;
|
|
err = register_filesystem(&minix_fs_type);
|
|
if (err)
|
|
goto out;
|
|
return 0;
|
|
out:
|
|
destroy_inodecache();
|
|
out1:
|
|
return err;
|
|
}
|
|
|
|
static void __exit exit_minix_fs(void)
|
|
{
|
|
unregister_filesystem(&minix_fs_type);
|
|
destroy_inodecache();
|
|
}
|
|
|
|
module_init(init_minix_fs)
|
|
module_exit(exit_minix_fs)
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
|
|
|