-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmZuzl4ACgkQONu9yGCS aT7+ohAAyRkTis6xeME1FWIJthCJl8FzUq9nfN+OccK3TwCbXyZKXlZK8lVz0T5U DvG1Tg+rR76+hIJghMIy2FEPRBA19WMq9a+Ms2ZyyggPrlgksFivO8N8YgnIxabb EJPN7pAzO+GA+vd8YeGeK1ldq8QUISlN35s+hkur1jeBctWRcpHeOTjIej/Qytmj ny1o7hCp179+SPygSEYEYtguACaQflhfBjOgAQ9DwWjP6vO2W9Vb16X4tiT0udHm ExPjOwxbEMN/7m9gKrnl6WcIROSOy55FnfcYZP+NRY4jBlANUgXF1ca9hAhcIKSv oOyeRN5S3FZAdxIHG9SFU9b6MPwJSeO5ETQyfiRGNFRkXOa2tKknNSsuACu8kSwx SKJIpcuW1DkortwsYFbilXdl6TrK6oCcEczV5qtludcRoDznfUGejb5e81v3yYkO no6ORvBJSBnEObY+gpexvxQp2Ae1+YkSLJaDzYWMC+JHBIgWTz2F2qJJkP6bRAUV QduFTdTenDnL7zW3DseZGJKotU95cUoKNAwa7wfboZeygHc2+KaUOchKcqI0P9dZ pS27RzcAJJ2uufujofyxOOhzFKw98WFurfNsMZTDBwHuqReoiRAS7pi0PeTMuqUv GC8V1eIKgeWdI+pdTZLXylziiM41IylLjU/hxCrsykb+EwFa5NY= =B1lK -----END PGP SIGNATURE----- Merge 5.10.219 into android12-5.10-lts Changes in 5.10.219 x86/tsc: Trust initial offset in architectural TSC-adjust MSRs tty: n_gsm: fix possible out-of-bounds in gsm0_receive() speakup: Fix sizeof() vs ARRAY_SIZE() bug ring-buffer: Fix a race between readers and resize checks net: smc91x: Fix m68k kernel compilation for ColdFire CPU nilfs2: fix unexpected freezing of nilfs_segctor_sync() nilfs2: fix potential hang in nilfs_detach_log_writer() ALSA: core: Fix NULL module pointer assignment at card init wifi: cfg80211: fix the order of arguments for trace events of the tx_rx_evt class net: usb: qmi_wwan: add Telit FN920C04 compositions drm/amd/display: Set color_mgmt_changed to true on unsuspend ASoC: rt5645: Fix the electric noise due to the CBJ contacts floating ASoC: dt-bindings: rt5645: add cbj sleeve gpio property regulator: vqmmc-ipq4019: fix module autoloading ASoC: rt715: add vendor clear control register ASoC: da7219-aad: fix usage of device_get_named_child_node() drm/amdkfd: Flush the process wq before creating a kfd_process nvme: find numa distance only if controller has valid numa id openpromfs: finish conversion to the new mount API crypto: bcm - Fix pointer arithmetic firmware: raspberrypi: Use correct device for DMA mappings ecryptfs: Fix buffer size for tag 66 packet nilfs2: fix out-of-range warning parisc: add missing export of __cmpxchg_u8() crypto: ccp - drop platform ifdef checks crypto: x86/nh-avx2 - add missing vzeroupper crypto: x86/sha256-avx2 - add missing vzeroupper s390/cio: fix tracepoint subchannel type field jffs2: prevent xattr node from overflowing the eraseblock soc: mediatek: cmdq: Fix typo of CMDQ_JUMP_RELATIVE null_blk: Fix missing mutex_destroy() at module removal md: fix resync softlockup when bitmap size is less than array size wifi: ath10k: poll service ready message before failing x86/boot: Ignore relocations in .notes sections in walk_relocs() too qed: avoid truncating work queue length scsi: ufs: qcom: Perform read back after writing reset bit scsi: ufs-qcom: Fix ufs RST_n spec violation scsi: ufs: qcom: Perform read back after writing REG_UFS_SYS1CLK_1US scsi: ufs: ufs-qcom: Fix the Qcom register name for offset 0xD0 scsi: ufs: ufs-qcom: Clear qunipro_g4_sel for HW version major 5 scsi: ufs: qcom: Perform read back after writing unipro mode scsi: ufs: qcom: Perform read back after writing CGC enable scsi: ufs: cdns-pltfrm: Perform read back after writing HCLKDIV scsi: ufs: core: Perform read back after disabling interrupts scsi: ufs: core: Perform read back after disabling UIC_COMMAND_COMPL irqchip/alpine-msi: Fix off-by-one in allocation error path irqchip/loongson-pch-msi: Fix off-by-one on allocation error path ACPI: disable -Wstringop-truncation gfs2: Fix "ignore unlock failures after withdraw" selftests/bpf: Fix umount cgroup2 error in test_sockmap cpufreq: Reorganize checks in cpufreq_offline() cpufreq: Split cpufreq_offline() cpufreq: Rearrange locking in cpufreq_remove_dev() cpufreq: exit() callback is optional net: export inet_lookup_reuseport and inet6_lookup_reuseport net: remove duplicate reuseport_lookup functions udp: Avoid call to compute_score on multiple sites scsi: libsas: Fix the failure of adding phy with zero-address to port scsi: hpsa: Fix allocation size for Scsi_Host private data x86/purgatory: Switch to the position-independent small code model wifi: ath10k: Fix an error code problem in ath10k_dbg_sta_write_peer_debug_trigger() wifi: ath10k: populate board data for WCN3990 tcp: avoid premature drops in tcp_add_backlog() net: give more chances to rcu in netdev_wait_allrefs_any() macintosh/via-macii: Fix "BUG: sleeping function called from invalid context" wifi: carl9170: add a proper sanity check for endpoints wifi: ar5523: enable proper endpoint verification sh: kprobes: Merge arch_copy_kprobe() into arch_prepare_kprobe() Revert "sh: Handle calling csum_partial with misaligned data" selftests/binderfs: use the Makefile's rules, not Make's implicit rules HID: intel-ish-hid: ipc: Add check for pci_alloc_irq_vectors scsi: bfa: Ensure the copied buf is NUL terminated scsi: qedf: Ensure the copied buf is NUL terminated wifi: mwl8k: initialize cmd->addr[] properly usb: aqc111: stop lying about skb->truesize net: usb: sr9700: stop lying about skb->truesize m68k: Fix spinlock race in kernel thread creation m68k: mac: Fix reboot hang on Mac IIci net: ipv6: fix wrong start position when receive hop-by-hop fragment eth: sungem: remove .ndo_poll_controller to avoid deadlocks net: ethernet: cortina: Locking fixes af_unix: Fix data races in unix_release_sock/unix_stream_sendmsg net: usb: smsc95xx: stop lying about skb->truesize net: openvswitch: fix overwriting ct original tuple for ICMPv6 ipv6: sr: add missing seg6_local_exit ipv6: sr: fix incorrect unregister order ipv6: sr: fix invalid unregister error path net/mlx5: Discard command completions in internal error drm/amd/display: Fix potential index out of bounds in color transformation function ASoC: soc-acpi: add helper to identify parent driver. ASoC: Intel: Disable route checks for Skylake boards mtd: rawnand: hynix: fixed typo fbdev: shmobile: fix snprintf truncation drm/meson: vclk: fix calculation of 59.94 fractional rates drm/mediatek: Add 0 size check to mtk_drm_gem_obj powerpc/fsl-soc: hide unused const variable fbdev: sisfb: hide unused variables media: ngene: Add dvb_ca_en50221_init return value check media: radio-shark2: Avoid led_names truncations drm: bridge: cdns-mhdp8546: Fix possible null pointer dereference fbdev: sh7760fb: allow modular build media: atomisp: ssh_css: Fix a null-pointer dereference in load_video_binaries drm/arm/malidp: fix a possible null pointer dereference drm: vc4: Fix possible null pointer dereference ASoC: tracing: Export SND_SOC_DAPM_DIR_OUT to its value drm/bridge: lt9611: Don't log an error when DSI host can't be found drm/bridge: tc358775: Don't log an error when DSI host can't be found drm/panel: simple: Add missing Innolux G121X1-L03 format, flags, connector drm/mipi-dsi: use correct return type for the DSC functions RDMA/hns: Refactor the hns_roce_buf allocation flow RDMA/hns: Create QP with selected QPN for bank load balance RDMA/hns: Fix incorrect symbol types RDMA/hns: Fix return value in hns_roce_map_mr_sg RDMA/hns: Use complete parentheses in macros RDMA/hns: Modify the print level of CQE error clk: qcom: mmcc-msm8998: fix venus clock issue x86/insn: Fix PUSH instruction in x86 instruction decoder opcode map ext4: avoid excessive credit estimate in ext4_tmpfile() sunrpc: removed redundant procp check ext4: simplify calculation of blkoff in ext4_mb_new_blocks_simple ext4: fix unit mismatch in ext4_mb_new_blocks_simple ext4: try all groups in ext4_mb_new_blocks_simple ext4: remove unused parameter from ext4_mb_new_blocks_simple() ext4: fix potential unnitialized variable SUNRPC: Fix gss_free_in_token_pages() selftests/kcmp: Make the test output consistent and clear selftests/kcmp: remove unused open mode RDMA/IPoIB: Fix format truncation compilation errors net: qrtr: fix null-ptr-deref in qrtr_ns_remove net: qrtr: ns: Fix module refcnt netrom: fix possible dead-lock in nr_rt_ioctl() af_packet: do not call packet_read_pending() from tpacket_destruct_skb() sched/fair: Allow disabling sched_balance_newidle with sched_relax_domain_level greybus: lights: check return of get_channel_from_mode f2fs: fix to wait on page writeback in __clone_blkaddrs() soundwire: cadence: fix invalid PDI offset dmaengine: idma64: Add check for dma_set_max_seg_size firmware: dmi-id: add a release callback function serial: max3100: Lock port->lock when calling uart_handle_cts_change() serial: max3100: Update uart_driver_registered on driver removal serial: max3100: Fix bitwise types greybus: arche-ctrl: move device table to its right location serial: sc16is7xx: add proper sched.h include for sched_set_fifo() f2fs: compress: support chksum f2fs: add compress_mode mount option f2fs: compress: clean up parameter of __f2fs_cluster_blocks() f2fs: compress: remove unneeded preallocation f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit f2fs: compress: fix to relocate check condition in f2fs_{release,reserve}_compress_blocks() f2fs: add cp_error check in f2fs_write_compressed_pages f2fs: fix to force keeping write barrier for strict fsync mode f2fs: do not allow partial truncation on pinned file f2fs: fix typos in comments f2fs: fix to relocate check condition in f2fs_fallocate() f2fs: fix to check pinfile flag in f2fs_move_file_range() iio: pressure: dps310: support negative temperature values fpga: region: change FPGA indirect article to an fpga: region: Rename dev to parent for parent device docs: driver-api: fpga: avoid using UTF-8 chars fpga: region: Use standard dev_release for class driver fpga: region: add owner module and take its refcount microblaze: Remove gcc flag for non existing early_printk.c file microblaze: Remove early printk call from cpuinfo-static.c usb: gadget: u_audio: Clear uac pointer when freed. stm class: Fix a double free in stm_register_device() ppdev: Remove usage of the deprecated ida_simple_xx() API ppdev: Add an error check in register_device extcon: max8997: select IRQ_DOMAIN instead of depending on it PCI/EDR: Align EDR_PORT_DPC_ENABLE_DSM with PCI Firmware r3.3 PCI/EDR: Align EDR_PORT_LOCATE_DSM with PCI Firmware r3.3 f2fs: compress: fix to cover {reserve,release}_compress_blocks() w/ cp_rwsem lock f2fs: fix to release node block count in error path of f2fs_new_node_page() f2fs: compress: don't allow unaligned truncation on released compress inode serial: sh-sci: protect invalidating RXDMA on shutdown libsubcmd: Fix parse-options memory leak s390/ipl: Fix incorrect initialization of len fields in nvme reipl block s390/ipl: Fix incorrect initialization of nvme dump block Input: ims-pcu - fix printf string overflow Input: ioc3kbd - convert to platform remove callback returning void Input: ioc3kbd - add device table mmc: sdhci_am654: Add tuning algorithm for delay chain mmc: sdhci_am654: Write ITAPDLY for DDR52 timing mmc: sdhci_am654: Drop lookup for deprecated ti,otap-del-sel mmc: sdhci_am654: Add OTAP/ITAP delay enable mmc: sdhci_am654: Add ITAPDLYSEL in sdhci_j721e_4bit_set_clock mmc: sdhci_am654: Fix ITAPDLY for HS400 timing Input: pm8xxx-vibrator - correct VIB_MAX_LEVELS calculation drm/msm/dpu: Always flush the slave INTF on the CTL um: Fix return value in ubd_init() um: Add winch to winch_handlers before registering winch IRQ um: vector: fix bpfflash parameter evaluation drm/bridge: tc358775: fix support for jeida-18 and jeida-24 media: stk1160: fix bounds checking in stk1160_copy_video() scsi: qla2xxx: Replace all non-returning strlcpy() with strscpy() media: flexcop-usb: clean up endpoint sanity checks media: flexcop-usb: fix sanity check of bNumEndpoints powerpc/pseries: Add failure related checks for h_get_mpp and h_get_ppp um: Fix the -Wmissing-prototypes warning for __switch_mm media: cec: cec-adap: always cancel work in cec_transmit_msg_fh media: cec: cec-api: add locking in cec_release() media: core headers: fix kernel-doc warnings media: cec: fix a deadlock situation media: cec: call enable_adap on s_log_addrs media: cec: abort if the current transmit was canceled media: cec: correctly pass on reply results media: cec: use call_op and check for !unregistered media: cec-adap.c: drop activate_cnt, use state info instead media: cec: core: avoid recursive cec_claim_log_addrs media: cec: core: avoid confusing "transmit timed out" message null_blk: Fix the WARNING: modpost: missing MODULE_DESCRIPTION() regulator: bd71828: Don't overwrite runtime voltages x86/kconfig: Select ARCH_WANT_FRAME_POINTERS again when UNWINDER_FRAME_POINTER=y nfc: nci: Fix uninit-value in nci_rx_work ASoC: tas2552: Add TX path for capturing AUDIO-OUT data sunrpc: fix NFSACL RPC retry on soft mount rpcrdma: fix handling for RDMA_CM_EVENT_DEVICE_REMOVAL ipv6: sr: fix memleak in seg6_hmac_init_algo params: lift param_set_uint_minmax to common code tcp: Fix shift-out-of-bounds in dctcp_update_alpha(). openvswitch: Set the skbuff pkt_type for proper pmtud support. arm64: asm-bug: Add .align 2 to the end of __BUG_ENTRY virtio: delete vq in vp_find_vqs_msix() when request_irq() fails net: fec: avoid lock evasion when reading pps_enable tls: fix missing memory barrier in tls_init nfc: nci: Fix kcov check in nci_rx_work() nfc: nci: Fix handling of zero-length payload packets in nci_rx_work() netfilter: nfnetlink_queue: acquire rcu_read_lock() in instance_destroy_rcu() netfilter: nft_payload: restore vlan q-in-q match support spi: Don't mark message DMA mapped when no transfer in it is nvmet: fix ns enable/disable possible hang net/mlx5e: Use rx_missed_errors instead of rx_dropped for reporting buffer exhaustion dma-buf/sw-sync: don't enable IRQ from sync_print_obj() bpf: Fix potential integer overflow in resolve_btfids enic: Validate length of nl attributes in enic_set_vf_port net: usb: smsc95xx: fix changing LED_SEL bit value updated from EEPROM bpf: Allow delete from sockmap/sockhash only if update is allowed net:fec: Add fec_enet_deinit() netfilter: tproxy: bail out if IP has been disabled on the device kconfig: fix comparison to constant symbols, 'm', 'n' spi: stm32: Don't warn about spurious interrupts ipvlan: Dont Use skb->sk in ipvlan_process_v{4,6}_outbound hwmon: (shtc1) Fix property misspelling ALSA: timer: Set lower bound of start tick time genirq/cpuhotplug, x86/vector: Prevent vector leak during CPU offline media: cec: core: add adap_nb_transmit_canceled() callback SUNRPC: Fix loop termination condition in gss_free_in_token_pages() binder: fix max_thread type inconsistency mmc: core: Do not force a retune before RPMB switch io_uring: fail NOP if non-zero op flags is passed in afs: Don't cross .backup mountpoint from backup volume nilfs2: fix use-after-free of timer for log writer thread vxlan: Fix regression when dropping packets due to invalid src addresses x86/mm: Remove broken vsyscall emulation code from the page fault code netfilter: nf_tables: restrict tunnel object to NFPROTO_NETDEV netfilter: nf_tables: Fix potential data-race in __nft_obj_type_get() f2fs: fix to do sanity check on i_xattr_nid in sanity_check_inode() media: lgdt3306a: Add a check against null-pointer-def drm/amdgpu: add error handle to avoid out-of-bounds ata: pata_legacy: make legacy_exit() work again ACPI: resource: Do IRQ override on TongFang GXxHRXx and GMxHGxx arm64: tegra: Correct Tegra132 I2C alias arm64: dts: qcom: qcs404: fix bluetooth device address md/raid5: fix deadlock that raid5d() wait for itself to clear MD_SB_CHANGE_PENDING wifi: rtl8xxxu: Fix the TX power of RTL8192CU, RTL8723AU wifi: rtlwifi: rtl8192de: Fix low speed with WPA3-SAE wifi: rtlwifi: rtl8192de: Fix endianness issue in RX path arm64: dts: hi3798cv200: fix the size of GICR media: mc: mark the media devnode as registered from the, start media: mxl5xx: Move xpt structures off stack media: v4l2-core: hold videodev_lock until dev reg, finishes mmc: core: Add mmc_gpiod_set_cd_config() function mmc: sdhci-acpi: Sort DMI quirks alphabetically mmc: sdhci-acpi: Fix Lenovo Yoga Tablet 2 Pro 1380 sdcard slot not working mmc: sdhci-acpi: Disable write protect detection on Toshiba WT10-A fbdev: savage: Handle err return when savagefb_check_var failed KVM: arm64: Allow AArch32 PSTATE.M to be restored as System mode crypto: ecrdsa - Fix module auto-load on add_key crypto: qat - Fix ADF_DEV_RESET_SYNC memory leak net/ipv6: Fix route deleting failure when metric equals 0 net/9p: fix uninit-value in p9_client_rpc() intel_th: pci: Add Meteor Lake-S CPU support sparc64: Fix number of online CPUs watchdog: rti_wdt: Set min_hw_heartbeat_ms to accommodate a safety margin kdb: Fix buffer overflow during tab-complete kdb: Use format-strings rather than '\0' injection in kdb_read() kdb: Fix console handling when editing and tab-completing commands kdb: Merge identical case statements in kdb_read() kdb: Use format-specifiers rather than memset() for padding in kdb_read() net: fix __dst_negative_advice() race sparc: move struct termio to asm/termios.h ext4: fix mb_cache_entry's e_refcnt leak in ext4_xattr_block_cache_find() s390/ap: Fix crash in AP internal function modify_bitmap() nfs: fix undefined behavior in nfs_block_bits() NFS: Fix READ_PLUS when server doesn't support OP_READ_PLUS scsi: ufs: ufs-qcom: Clear qunipro_g4_sel for HW major version > 5 f2fs: compress: fix compression chksum RDMA/hns: Use mutex instead of spinlock for ida allocation RDMA/hns: Fix CQ and QP cache affinity Linux 5.10.219 Change-Id: I0e21ff44d28df2a2802a9fb35f0959bb5ab528fc Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1368 lines
32 KiB
C
1368 lines
32 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* fs/f2fs/namei.c
|
|
*
|
|
* Copyright (c) 2012 Samsung Electronics Co., Ltd.
|
|
* http://www.samsung.com/
|
|
*/
|
|
#include <linux/fs.h>
|
|
#include <linux/f2fs_fs.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/random.h>
|
|
#include <linux/dcache.h>
|
|
#include <linux/namei.h>
|
|
#include <linux/quotaops.h>
|
|
|
|
#include "f2fs.h"
|
|
#include "node.h"
|
|
#include "segment.h"
|
|
#include "xattr.h"
|
|
#include "acl.h"
|
|
#include <trace/events/f2fs.h>
|
|
|
|
static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
nid_t ino;
|
|
struct inode *inode;
|
|
bool nid_free = false;
|
|
bool encrypt = false;
|
|
int xattr_size = 0;
|
|
int err;
|
|
|
|
inode = new_inode(dir->i_sb);
|
|
if (!inode)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
f2fs_lock_op(sbi);
|
|
if (!f2fs_alloc_nid(sbi, &ino)) {
|
|
f2fs_unlock_op(sbi);
|
|
err = -ENOSPC;
|
|
goto fail;
|
|
}
|
|
f2fs_unlock_op(sbi);
|
|
|
|
nid_free = true;
|
|
|
|
inode_init_owner(inode, dir, mode);
|
|
|
|
inode->i_ino = ino;
|
|
inode->i_blocks = 0;
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
|
F2FS_I(inode)->i_crtime = inode->i_mtime;
|
|
inode->i_generation = prandom_u32();
|
|
|
|
if (S_ISDIR(inode->i_mode))
|
|
F2FS_I(inode)->i_current_depth = 1;
|
|
|
|
err = insert_inode_locked(inode);
|
|
if (err) {
|
|
err = -EINVAL;
|
|
goto fail;
|
|
}
|
|
|
|
if (f2fs_sb_has_project_quota(sbi) &&
|
|
(F2FS_I(dir)->i_flags & F2FS_PROJINHERIT_FL))
|
|
F2FS_I(inode)->i_projid = F2FS_I(dir)->i_projid;
|
|
else
|
|
F2FS_I(inode)->i_projid = make_kprojid(&init_user_ns,
|
|
F2FS_DEF_PROJID);
|
|
|
|
err = fscrypt_prepare_new_inode(dir, inode, &encrypt);
|
|
if (err)
|
|
goto fail_drop;
|
|
|
|
err = dquot_initialize(inode);
|
|
if (err)
|
|
goto fail_drop;
|
|
|
|
set_inode_flag(inode, FI_NEW_INODE);
|
|
|
|
if (encrypt)
|
|
f2fs_set_encrypted_inode(inode);
|
|
|
|
if (f2fs_sb_has_extra_attr(sbi)) {
|
|
set_inode_flag(inode, FI_EXTRA_ATTR);
|
|
F2FS_I(inode)->i_extra_isize = F2FS_TOTAL_EXTRA_ATTR_SIZE;
|
|
}
|
|
|
|
if (test_opt(sbi, INLINE_XATTR))
|
|
set_inode_flag(inode, FI_INLINE_XATTR);
|
|
|
|
if (f2fs_may_inline_dentry(inode))
|
|
set_inode_flag(inode, FI_INLINE_DENTRY);
|
|
|
|
if (f2fs_sb_has_flexible_inline_xattr(sbi)) {
|
|
f2fs_bug_on(sbi, !f2fs_has_extra_attr(inode));
|
|
if (f2fs_has_inline_xattr(inode))
|
|
xattr_size = F2FS_OPTION(sbi).inline_xattr_size;
|
|
/* Otherwise, will be 0 */
|
|
} else if (f2fs_has_inline_xattr(inode) ||
|
|
f2fs_has_inline_dentry(inode)) {
|
|
xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
|
|
}
|
|
F2FS_I(inode)->i_inline_xattr_size = xattr_size;
|
|
|
|
F2FS_I(inode)->i_flags =
|
|
f2fs_mask_flags(mode, F2FS_I(dir)->i_flags & F2FS_FL_INHERITED);
|
|
|
|
if (S_ISDIR(inode->i_mode))
|
|
F2FS_I(inode)->i_flags |= F2FS_INDEX_FL;
|
|
|
|
if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL)
|
|
set_inode_flag(inode, FI_PROJ_INHERIT);
|
|
|
|
if (f2fs_sb_has_compression(sbi)) {
|
|
/* Inherit the compression flag in directory */
|
|
if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) &&
|
|
f2fs_may_compress(inode))
|
|
set_compress_context(inode);
|
|
}
|
|
|
|
/* Should enable inline_data after compression set */
|
|
if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode))
|
|
set_inode_flag(inode, FI_INLINE_DATA);
|
|
|
|
stat_inc_inline_xattr(inode);
|
|
stat_inc_inline_inode(inode);
|
|
stat_inc_inline_dir(inode);
|
|
|
|
f2fs_set_inode_flags(inode);
|
|
|
|
f2fs_init_extent_tree(inode);
|
|
|
|
trace_f2fs_new_inode(inode, 0);
|
|
return inode;
|
|
|
|
fail:
|
|
trace_f2fs_new_inode(inode, err);
|
|
make_bad_inode(inode);
|
|
if (nid_free)
|
|
set_inode_flag(inode, FI_FREE_NID);
|
|
iput(inode);
|
|
return ERR_PTR(err);
|
|
fail_drop:
|
|
trace_f2fs_new_inode(inode, err);
|
|
dquot_drop(inode);
|
|
inode->i_flags |= S_NOQUOTA;
|
|
if (nid_free)
|
|
set_inode_flag(inode, FI_FREE_NID);
|
|
clear_nlink(inode);
|
|
unlock_new_inode(inode);
|
|
iput(inode);
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
static inline int is_extension_exist(const unsigned char *s, const char *sub,
|
|
bool tmp_ext)
|
|
{
|
|
size_t slen = strlen(s);
|
|
size_t sublen = strlen(sub);
|
|
int i;
|
|
|
|
if (sublen == 1 && *sub == '*')
|
|
return 1;
|
|
|
|
/*
|
|
* filename format of multimedia file should be defined as:
|
|
* "filename + '.' + extension + (optional: '.' + temp extension)".
|
|
*/
|
|
if (slen < sublen + 2)
|
|
return 0;
|
|
|
|
if (!tmp_ext) {
|
|
/* file has no temp extension */
|
|
if (s[slen - sublen - 1] != '.')
|
|
return 0;
|
|
return !strncasecmp(s + slen - sublen, sub, sublen);
|
|
}
|
|
|
|
for (i = 1; i < slen - sublen; i++) {
|
|
if (s[i] != '.')
|
|
continue;
|
|
if (!strncasecmp(s + i + 1, sub, sublen))
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Set file's temperature for hot/cold data separation
|
|
*/
|
|
static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
|
|
const unsigned char *name)
|
|
{
|
|
__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
|
|
int i, cold_count, hot_count;
|
|
|
|
f2fs_down_read(&sbi->sb_lock);
|
|
|
|
cold_count = le32_to_cpu(sbi->raw_super->extension_count);
|
|
hot_count = sbi->raw_super->hot_ext_count;
|
|
|
|
for (i = 0; i < cold_count + hot_count; i++) {
|
|
if (is_extension_exist(name, extlist[i], true))
|
|
break;
|
|
}
|
|
|
|
f2fs_up_read(&sbi->sb_lock);
|
|
|
|
if (i == cold_count + hot_count)
|
|
return;
|
|
|
|
if (i < cold_count)
|
|
file_set_cold(inode);
|
|
else
|
|
file_set_hot(inode);
|
|
}
|
|
|
|
int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
|
|
bool hot, bool set)
|
|
{
|
|
__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
|
|
int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
|
|
int hot_count = sbi->raw_super->hot_ext_count;
|
|
int total_count = cold_count + hot_count;
|
|
int start, count;
|
|
int i;
|
|
|
|
if (set) {
|
|
if (total_count == F2FS_MAX_EXTENSION)
|
|
return -EINVAL;
|
|
} else {
|
|
if (!hot && !cold_count)
|
|
return -EINVAL;
|
|
if (hot && !hot_count)
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (hot) {
|
|
start = cold_count;
|
|
count = total_count;
|
|
} else {
|
|
start = 0;
|
|
count = cold_count;
|
|
}
|
|
|
|
for (i = start; i < count; i++) {
|
|
if (strcmp(name, extlist[i]))
|
|
continue;
|
|
|
|
if (set)
|
|
return -EINVAL;
|
|
|
|
memcpy(extlist[i], extlist[i + 1],
|
|
F2FS_EXTENSION_LEN * (total_count - i - 1));
|
|
memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN);
|
|
if (hot)
|
|
sbi->raw_super->hot_ext_count = hot_count - 1;
|
|
else
|
|
sbi->raw_super->extension_count =
|
|
cpu_to_le32(cold_count - 1);
|
|
return 0;
|
|
}
|
|
|
|
if (!set)
|
|
return -EINVAL;
|
|
|
|
if (hot) {
|
|
memcpy(extlist[count], name, strlen(name));
|
|
sbi->raw_super->hot_ext_count = hot_count + 1;
|
|
} else {
|
|
char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];
|
|
|
|
memcpy(buf, &extlist[cold_count],
|
|
F2FS_EXTENSION_LEN * hot_count);
|
|
memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN);
|
|
memcpy(extlist[cold_count], name, strlen(name));
|
|
memcpy(&extlist[cold_count + 1], buf,
|
|
F2FS_EXTENSION_LEN * hot_count);
|
|
sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
|
|
const unsigned char *name)
|
|
{
|
|
__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
|
|
unsigned char (*ext)[F2FS_EXTENSION_LEN];
|
|
unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
|
|
int i, cold_count, hot_count;
|
|
|
|
if (!f2fs_sb_has_compression(sbi) ||
|
|
is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
|
|
F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
|
|
!f2fs_may_compress(inode))
|
|
return;
|
|
|
|
f2fs_down_read(&sbi->sb_lock);
|
|
|
|
cold_count = le32_to_cpu(sbi->raw_super->extension_count);
|
|
hot_count = sbi->raw_super->hot_ext_count;
|
|
|
|
for (i = cold_count; i < cold_count + hot_count; i++) {
|
|
if (is_extension_exist(name, extlist[i], false)) {
|
|
f2fs_up_read(&sbi->sb_lock);
|
|
return;
|
|
}
|
|
}
|
|
|
|
f2fs_up_read(&sbi->sb_lock);
|
|
|
|
ext = F2FS_OPTION(sbi).extensions;
|
|
|
|
for (i = 0; i < ext_cnt; i++) {
|
|
if (!is_extension_exist(name, ext[i], false))
|
|
continue;
|
|
|
|
/* Do not use inline_data with compression */
|
|
stat_dec_inline_inode(inode);
|
|
clear_inode_flag(inode, FI_INLINE_DATA);
|
|
set_compress_context(inode);
|
|
return;
|
|
}
|
|
}
|
|
|
|
static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
|
bool excl)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
struct inode *inode;
|
|
nid_t ino = 0;
|
|
int err;
|
|
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
return -EIO;
|
|
if (!f2fs_is_checkpoint_ready(sbi))
|
|
return -ENOSPC;
|
|
|
|
err = dquot_initialize(dir);
|
|
if (err)
|
|
return err;
|
|
|
|
inode = f2fs_new_inode(dir, mode);
|
|
if (IS_ERR(inode))
|
|
return PTR_ERR(inode);
|
|
|
|
if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
|
|
set_file_temperature(sbi, inode, dentry->d_name.name);
|
|
|
|
set_compress_inode(sbi, inode, dentry->d_name.name);
|
|
|
|
inode->i_op = &f2fs_file_inode_operations;
|
|
inode->i_fop = &f2fs_file_operations;
|
|
inode->i_mapping->a_ops = &f2fs_dblock_aops;
|
|
ino = inode->i_ino;
|
|
|
|
f2fs_lock_op(sbi);
|
|
err = f2fs_add_link(dentry, inode);
|
|
if (err)
|
|
goto out;
|
|
f2fs_unlock_op(sbi);
|
|
|
|
f2fs_alloc_nid_done(sbi, ino);
|
|
|
|
d_instantiate_new(dentry, inode);
|
|
|
|
if (IS_DIRSYNC(dir))
|
|
f2fs_sync_fs(sbi->sb, 1);
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
return 0;
|
|
out:
|
|
f2fs_handle_failed_inode(inode);
|
|
return err;
|
|
}
|
|
|
|
static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
|
|
struct dentry *dentry)
|
|
{
|
|
struct inode *inode = d_inode(old_dentry);
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
int err;
|
|
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
return -EIO;
|
|
if (!f2fs_is_checkpoint_ready(sbi))
|
|
return -ENOSPC;
|
|
|
|
err = fscrypt_prepare_link(old_dentry, dir, dentry);
|
|
if (err)
|
|
return err;
|
|
|
|
if (is_inode_flag_set(dir, FI_PROJ_INHERIT) &&
|
|
(!projid_eq(F2FS_I(dir)->i_projid,
|
|
F2FS_I(old_dentry->d_inode)->i_projid)))
|
|
return -EXDEV;
|
|
|
|
err = dquot_initialize(dir);
|
|
if (err)
|
|
return err;
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
|
|
inode->i_ctime = current_time(inode);
|
|
ihold(inode);
|
|
|
|
set_inode_flag(inode, FI_INC_LINK);
|
|
f2fs_lock_op(sbi);
|
|
err = f2fs_add_link(dentry, inode);
|
|
if (err)
|
|
goto out;
|
|
f2fs_unlock_op(sbi);
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
if (IS_DIRSYNC(dir))
|
|
f2fs_sync_fs(sbi->sb, 1);
|
|
return 0;
|
|
out:
|
|
clear_inode_flag(inode, FI_INC_LINK);
|
|
iput(inode);
|
|
f2fs_unlock_op(sbi);
|
|
return err;
|
|
}
|
|
|
|
struct dentry *f2fs_get_parent(struct dentry *child)
|
|
{
|
|
struct qstr dotdot = QSTR_INIT("..", 2);
|
|
struct page *page;
|
|
unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot, &page);
|
|
|
|
if (!ino) {
|
|
if (IS_ERR(page))
|
|
return ERR_CAST(page);
|
|
return ERR_PTR(-ENOENT);
|
|
}
|
|
return d_obtain_alias(f2fs_iget(child->d_sb, ino));
|
|
}
|
|
|
|
static int __recover_dot_dentries(struct inode *dir, nid_t pino)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
struct qstr dot = QSTR_INIT(".", 1);
|
|
struct qstr dotdot = QSTR_INIT("..", 2);
|
|
struct f2fs_dir_entry *de;
|
|
struct page *page;
|
|
int err = 0;
|
|
|
|
if (f2fs_readonly(sbi->sb)) {
|
|
f2fs_info(sbi, "skip recovering inline_dots inode (ino:%lu, pino:%u) in readonly mountpoint",
|
|
dir->i_ino, pino);
|
|
return 0;
|
|
}
|
|
|
|
err = dquot_initialize(dir);
|
|
if (err)
|
|
return err;
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
|
|
f2fs_lock_op(sbi);
|
|
|
|
de = f2fs_find_entry(dir, &dot, &page);
|
|
if (de) {
|
|
f2fs_put_page(page, 0);
|
|
} else if (IS_ERR(page)) {
|
|
err = PTR_ERR(page);
|
|
goto out;
|
|
} else {
|
|
err = f2fs_do_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR);
|
|
if (err)
|
|
goto out;
|
|
}
|
|
|
|
de = f2fs_find_entry(dir, &dotdot, &page);
|
|
if (de)
|
|
f2fs_put_page(page, 0);
|
|
else if (IS_ERR(page))
|
|
err = PTR_ERR(page);
|
|
else
|
|
err = f2fs_do_add_link(dir, &dotdot, NULL, pino, S_IFDIR);
|
|
out:
|
|
if (!err)
|
|
clear_inode_flag(dir, FI_INLINE_DOTS);
|
|
|
|
f2fs_unlock_op(sbi);
|
|
return err;
|
|
}
|
|
|
|
static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
|
|
unsigned int flags)
|
|
{
|
|
struct inode *inode = NULL;
|
|
struct f2fs_dir_entry *de;
|
|
struct page *page;
|
|
struct dentry *new;
|
|
nid_t ino = -1;
|
|
int err = 0;
|
|
unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
|
|
struct f2fs_filename fname;
|
|
|
|
trace_f2fs_lookup_start(dir, dentry, flags);
|
|
|
|
if (dentry->d_name.len > F2FS_NAME_LEN) {
|
|
err = -ENAMETOOLONG;
|
|
goto out;
|
|
}
|
|
|
|
err = f2fs_prepare_lookup(dir, dentry, &fname);
|
|
generic_set_encrypted_ci_d_ops(dentry);
|
|
if (err == -ENOENT)
|
|
goto out_splice;
|
|
if (err)
|
|
goto out;
|
|
de = __f2fs_find_entry(dir, &fname, &page);
|
|
f2fs_free_filename(&fname);
|
|
|
|
if (!de) {
|
|
if (IS_ERR(page)) {
|
|
err = PTR_ERR(page);
|
|
goto out;
|
|
}
|
|
err = -ENOENT;
|
|
goto out_splice;
|
|
}
|
|
|
|
ino = le32_to_cpu(de->ino);
|
|
f2fs_put_page(page, 0);
|
|
|
|
inode = f2fs_iget(dir->i_sb, ino);
|
|
if (IS_ERR(inode)) {
|
|
err = PTR_ERR(inode);
|
|
goto out;
|
|
}
|
|
|
|
if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) {
|
|
err = __recover_dot_dentries(dir, root_ino);
|
|
if (err)
|
|
goto out_iput;
|
|
}
|
|
|
|
if (f2fs_has_inline_dots(inode)) {
|
|
err = __recover_dot_dentries(inode, dir->i_ino);
|
|
if (err)
|
|
goto out_iput;
|
|
}
|
|
if (IS_ENCRYPTED(dir) &&
|
|
(S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
|
|
!fscrypt_has_permitted_context(dir, inode)) {
|
|
f2fs_warn(F2FS_I_SB(inode), "Inconsistent encryption contexts: %lu/%lu",
|
|
dir->i_ino, inode->i_ino);
|
|
err = -EPERM;
|
|
goto out_iput;
|
|
}
|
|
out_splice:
|
|
#ifdef CONFIG_UNICODE
|
|
if (!inode && IS_CASEFOLDED(dir)) {
|
|
/* Eventually we want to call d_add_ci(dentry, NULL)
|
|
* for negative dentries in the encoding case as
|
|
* well. For now, prevent the negative dentry
|
|
* from being cached.
|
|
*/
|
|
trace_f2fs_lookup_end(dir, dentry, ino, err);
|
|
return NULL;
|
|
}
|
|
#endif
|
|
new = d_splice_alias(inode, dentry);
|
|
err = PTR_ERR_OR_ZERO(new);
|
|
trace_f2fs_lookup_end(dir, dentry, ino, !new ? -ENOENT : err);
|
|
return new;
|
|
out_iput:
|
|
iput(inode);
|
|
out:
|
|
trace_f2fs_lookup_end(dir, dentry, ino, err);
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
struct inode *inode = d_inode(dentry);
|
|
struct f2fs_dir_entry *de;
|
|
struct page *page;
|
|
int err;
|
|
|
|
trace_f2fs_unlink_enter(dir, dentry);
|
|
|
|
if (unlikely(f2fs_cp_error(sbi))) {
|
|
err = -EIO;
|
|
goto fail;
|
|
}
|
|
|
|
err = dquot_initialize(dir);
|
|
if (err)
|
|
goto fail;
|
|
err = dquot_initialize(inode);
|
|
if (err)
|
|
goto fail;
|
|
|
|
de = f2fs_find_entry(dir, &dentry->d_name, &page);
|
|
if (!de) {
|
|
if (IS_ERR(page))
|
|
err = PTR_ERR(page);
|
|
goto fail;
|
|
}
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
|
|
f2fs_lock_op(sbi);
|
|
err = f2fs_acquire_orphan_inode(sbi);
|
|
if (err) {
|
|
f2fs_unlock_op(sbi);
|
|
f2fs_put_page(page, 0);
|
|
goto fail;
|
|
}
|
|
f2fs_delete_entry(de, page, dir, inode);
|
|
f2fs_unlock_op(sbi);
|
|
|
|
#ifdef CONFIG_UNICODE
|
|
/* VFS negative dentries are incompatible with Encoding and
|
|
* Case-insensitiveness. Eventually we'll want avoid
|
|
* invalidating the dentries here, alongside with returning the
|
|
* negative dentries at f2fs_lookup(), when it is better
|
|
* supported by the VFS for the CI case.
|
|
*/
|
|
if (IS_CASEFOLDED(dir))
|
|
d_invalidate(dentry);
|
|
#endif
|
|
if (IS_DIRSYNC(dir))
|
|
f2fs_sync_fs(sbi->sb, 1);
|
|
fail:
|
|
trace_f2fs_unlink_exit(inode, err);
|
|
return err;
|
|
}
|
|
|
|
static const char *f2fs_get_link(struct dentry *dentry,
|
|
struct inode *inode,
|
|
struct delayed_call *done)
|
|
{
|
|
const char *link = page_get_link(dentry, inode, done);
|
|
|
|
if (!IS_ERR(link) && !*link) {
|
|
/* this is broken symlink case */
|
|
do_delayed_call(done);
|
|
clear_delayed_call(done);
|
|
link = ERR_PTR(-ENOENT);
|
|
}
|
|
return link;
|
|
}
|
|
|
|
static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
|
|
const char *symname)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
struct inode *inode;
|
|
size_t len = strlen(symname);
|
|
struct fscrypt_str disk_link;
|
|
int err;
|
|
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
return -EIO;
|
|
if (!f2fs_is_checkpoint_ready(sbi))
|
|
return -ENOSPC;
|
|
|
|
err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize,
|
|
&disk_link);
|
|
if (err)
|
|
return err;
|
|
|
|
err = dquot_initialize(dir);
|
|
if (err)
|
|
return err;
|
|
|
|
inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
|
|
if (IS_ERR(inode))
|
|
return PTR_ERR(inode);
|
|
|
|
if (IS_ENCRYPTED(inode))
|
|
inode->i_op = &f2fs_encrypted_symlink_inode_operations;
|
|
else
|
|
inode->i_op = &f2fs_symlink_inode_operations;
|
|
inode_nohighmem(inode);
|
|
inode->i_mapping->a_ops = &f2fs_dblock_aops;
|
|
|
|
f2fs_lock_op(sbi);
|
|
err = f2fs_add_link(dentry, inode);
|
|
if (err)
|
|
goto out_f2fs_handle_failed_inode;
|
|
f2fs_unlock_op(sbi);
|
|
f2fs_alloc_nid_done(sbi, inode->i_ino);
|
|
|
|
err = fscrypt_encrypt_symlink(inode, symname, len, &disk_link);
|
|
if (err)
|
|
goto err_out;
|
|
|
|
err = page_symlink(inode, disk_link.name, disk_link.len);
|
|
|
|
err_out:
|
|
d_instantiate_new(dentry, inode);
|
|
|
|
/*
|
|
* Let's flush symlink data in order to avoid broken symlink as much as
|
|
* possible. Nevertheless, fsyncing is the best way, but there is no
|
|
* way to get a file descriptor in order to flush that.
|
|
*
|
|
* Note that, it needs to do dir->fsync to make this recoverable.
|
|
* If the symlink path is stored into inline_data, there is no
|
|
* performance regression.
|
|
*/
|
|
if (!err) {
|
|
filemap_write_and_wait_range(inode->i_mapping, 0,
|
|
disk_link.len - 1);
|
|
|
|
if (IS_DIRSYNC(dir))
|
|
f2fs_sync_fs(sbi->sb, 1);
|
|
} else {
|
|
f2fs_unlink(dir, dentry);
|
|
}
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
goto out_free_encrypted_link;
|
|
|
|
out_f2fs_handle_failed_inode:
|
|
f2fs_handle_failed_inode(inode);
|
|
out_free_encrypted_link:
|
|
if (disk_link.name != (unsigned char *)symname)
|
|
kfree(disk_link.name);
|
|
return err;
|
|
}
|
|
|
|
static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
struct inode *inode;
|
|
int err;
|
|
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
return -EIO;
|
|
|
|
err = dquot_initialize(dir);
|
|
if (err)
|
|
return err;
|
|
|
|
inode = f2fs_new_inode(dir, S_IFDIR | mode);
|
|
if (IS_ERR(inode))
|
|
return PTR_ERR(inode);
|
|
|
|
inode->i_op = &f2fs_dir_inode_operations;
|
|
inode->i_fop = &f2fs_dir_operations;
|
|
inode->i_mapping->a_ops = &f2fs_dblock_aops;
|
|
mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
|
|
|
|
set_inode_flag(inode, FI_INC_LINK);
|
|
f2fs_lock_op(sbi);
|
|
err = f2fs_add_link(dentry, inode);
|
|
if (err)
|
|
goto out_fail;
|
|
f2fs_unlock_op(sbi);
|
|
|
|
f2fs_alloc_nid_done(sbi, inode->i_ino);
|
|
|
|
d_instantiate_new(dentry, inode);
|
|
|
|
if (IS_DIRSYNC(dir))
|
|
f2fs_sync_fs(sbi->sb, 1);
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
return 0;
|
|
|
|
out_fail:
|
|
clear_inode_flag(inode, FI_INC_LINK);
|
|
f2fs_handle_failed_inode(inode);
|
|
return err;
|
|
}
|
|
|
|
static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
|
|
{
|
|
struct inode *inode = d_inode(dentry);
|
|
|
|
if (f2fs_empty_dir(inode))
|
|
return f2fs_unlink(dir, dentry);
|
|
return -ENOTEMPTY;
|
|
}
|
|
|
|
static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
|
|
umode_t mode, dev_t rdev)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
struct inode *inode;
|
|
int err = 0;
|
|
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
return -EIO;
|
|
if (!f2fs_is_checkpoint_ready(sbi))
|
|
return -ENOSPC;
|
|
|
|
err = dquot_initialize(dir);
|
|
if (err)
|
|
return err;
|
|
|
|
inode = f2fs_new_inode(dir, mode);
|
|
if (IS_ERR(inode))
|
|
return PTR_ERR(inode);
|
|
|
|
init_special_inode(inode, inode->i_mode, rdev);
|
|
inode->i_op = &f2fs_special_inode_operations;
|
|
|
|
f2fs_lock_op(sbi);
|
|
err = f2fs_add_link(dentry, inode);
|
|
if (err)
|
|
goto out;
|
|
f2fs_unlock_op(sbi);
|
|
|
|
f2fs_alloc_nid_done(sbi, inode->i_ino);
|
|
|
|
d_instantiate_new(dentry, inode);
|
|
|
|
if (IS_DIRSYNC(dir))
|
|
f2fs_sync_fs(sbi->sb, 1);
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
return 0;
|
|
out:
|
|
f2fs_handle_failed_inode(inode);
|
|
return err;
|
|
}
|
|
|
|
static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
|
|
umode_t mode, struct inode **whiteout)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
struct inode *inode;
|
|
int err;
|
|
|
|
err = dquot_initialize(dir);
|
|
if (err)
|
|
return err;
|
|
|
|
inode = f2fs_new_inode(dir, mode);
|
|
if (IS_ERR(inode))
|
|
return PTR_ERR(inode);
|
|
|
|
if (whiteout) {
|
|
init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
|
|
inode->i_op = &f2fs_special_inode_operations;
|
|
} else {
|
|
inode->i_op = &f2fs_file_inode_operations;
|
|
inode->i_fop = &f2fs_file_operations;
|
|
inode->i_mapping->a_ops = &f2fs_dblock_aops;
|
|
}
|
|
|
|
f2fs_lock_op(sbi);
|
|
err = f2fs_acquire_orphan_inode(sbi);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = f2fs_do_tmpfile(inode, dir);
|
|
if (err)
|
|
goto release_out;
|
|
|
|
/*
|
|
* add this non-linked tmpfile to orphan list, in this way we could
|
|
* remove all unused data of tmpfile after abnormal power-off.
|
|
*/
|
|
f2fs_add_orphan_inode(inode);
|
|
f2fs_alloc_nid_done(sbi, inode->i_ino);
|
|
|
|
if (whiteout) {
|
|
f2fs_i_links_write(inode, false);
|
|
|
|
spin_lock(&inode->i_lock);
|
|
inode->i_state |= I_LINKABLE;
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
*whiteout = inode;
|
|
} else {
|
|
d_tmpfile(dentry, inode);
|
|
}
|
|
/* link_count was changed by d_tmpfile as well. */
|
|
f2fs_unlock_op(sbi);
|
|
unlock_new_inode(inode);
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
return 0;
|
|
|
|
release_out:
|
|
f2fs_release_orphan_inode(sbi);
|
|
out:
|
|
f2fs_handle_failed_inode(inode);
|
|
return err;
|
|
}
|
|
|
|
static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
|
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
return -EIO;
|
|
if (!f2fs_is_checkpoint_ready(sbi))
|
|
return -ENOSPC;
|
|
|
|
return __f2fs_tmpfile(dir, dentry, mode, NULL);
|
|
}
|
|
|
|
static int f2fs_create_whiteout(struct inode *dir, struct inode **whiteout)
|
|
{
|
|
if (unlikely(f2fs_cp_error(F2FS_I_SB(dir))))
|
|
return -EIO;
|
|
|
|
return __f2fs_tmpfile(dir, NULL, S_IFCHR | WHITEOUT_MODE, whiteout);
|
|
}
|
|
|
|
static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|
struct inode *new_dir, struct dentry *new_dentry,
|
|
unsigned int flags)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
|
|
struct inode *old_inode = d_inode(old_dentry);
|
|
struct inode *new_inode = d_inode(new_dentry);
|
|
struct inode *whiteout = NULL;
|
|
struct page *old_dir_page = NULL;
|
|
struct page *old_page, *new_page = NULL;
|
|
struct f2fs_dir_entry *old_dir_entry = NULL;
|
|
struct f2fs_dir_entry *old_entry;
|
|
struct f2fs_dir_entry *new_entry;
|
|
int err;
|
|
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
return -EIO;
|
|
if (!f2fs_is_checkpoint_ready(sbi))
|
|
return -ENOSPC;
|
|
|
|
if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
|
|
(!projid_eq(F2FS_I(new_dir)->i_projid,
|
|
F2FS_I(old_dentry->d_inode)->i_projid)))
|
|
return -EXDEV;
|
|
|
|
/*
|
|
* If new_inode is null, the below renaming flow will
|
|
* add a link in old_dir which can convert inline_dir.
|
|
* After then, if we failed to get the entry due to other
|
|
* reasons like ENOMEM, we had to remove the new entry.
|
|
* Instead of adding such the error handling routine, let's
|
|
* simply convert first here.
|
|
*/
|
|
if (old_dir == new_dir && !new_inode) {
|
|
err = f2fs_try_convert_inline_dir(old_dir, new_dentry);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
if (flags & RENAME_WHITEOUT) {
|
|
err = f2fs_create_whiteout(old_dir, &whiteout);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
err = dquot_initialize(old_dir);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = dquot_initialize(new_dir);
|
|
if (err)
|
|
goto out;
|
|
|
|
if (new_inode) {
|
|
err = dquot_initialize(new_inode);
|
|
if (err)
|
|
goto out;
|
|
}
|
|
|
|
err = -ENOENT;
|
|
old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
|
|
if (!old_entry) {
|
|
if (IS_ERR(old_page))
|
|
err = PTR_ERR(old_page);
|
|
goto out;
|
|
}
|
|
|
|
if (S_ISDIR(old_inode->i_mode)) {
|
|
old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
|
|
if (!old_dir_entry) {
|
|
if (IS_ERR(old_dir_page))
|
|
err = PTR_ERR(old_dir_page);
|
|
goto out_old;
|
|
}
|
|
}
|
|
|
|
if (new_inode) {
|
|
|
|
err = -ENOTEMPTY;
|
|
if (old_dir_entry && !f2fs_empty_dir(new_inode))
|
|
goto out_dir;
|
|
|
|
err = -ENOENT;
|
|
new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
|
|
&new_page);
|
|
if (!new_entry) {
|
|
if (IS_ERR(new_page))
|
|
err = PTR_ERR(new_page);
|
|
goto out_dir;
|
|
}
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
|
|
f2fs_lock_op(sbi);
|
|
|
|
err = f2fs_acquire_orphan_inode(sbi);
|
|
if (err)
|
|
goto put_out_dir;
|
|
|
|
f2fs_set_link(new_dir, new_entry, new_page, old_inode);
|
|
new_page = NULL;
|
|
|
|
new_inode->i_ctime = current_time(new_inode);
|
|
f2fs_down_write(&F2FS_I(new_inode)->i_sem);
|
|
if (old_dir_entry)
|
|
f2fs_i_links_write(new_inode, false);
|
|
f2fs_i_links_write(new_inode, false);
|
|
f2fs_up_write(&F2FS_I(new_inode)->i_sem);
|
|
|
|
if (!new_inode->i_nlink)
|
|
f2fs_add_orphan_inode(new_inode);
|
|
else
|
|
f2fs_release_orphan_inode(sbi);
|
|
} else {
|
|
f2fs_balance_fs(sbi, true);
|
|
|
|
f2fs_lock_op(sbi);
|
|
|
|
err = f2fs_add_link(new_dentry, old_inode);
|
|
if (err) {
|
|
f2fs_unlock_op(sbi);
|
|
goto out_dir;
|
|
}
|
|
|
|
if (old_dir_entry)
|
|
f2fs_i_links_write(new_dir, true);
|
|
}
|
|
|
|
f2fs_down_write(&F2FS_I(old_inode)->i_sem);
|
|
if (!old_dir_entry || whiteout)
|
|
file_lost_pino(old_inode);
|
|
else
|
|
/* adjust dir's i_pino to pass fsck check */
|
|
f2fs_i_pino_write(old_inode, new_dir->i_ino);
|
|
f2fs_up_write(&F2FS_I(old_inode)->i_sem);
|
|
|
|
old_inode->i_ctime = current_time(old_inode);
|
|
f2fs_mark_inode_dirty_sync(old_inode, false);
|
|
|
|
f2fs_delete_entry(old_entry, old_page, old_dir, NULL);
|
|
old_page = NULL;
|
|
|
|
if (whiteout) {
|
|
set_inode_flag(whiteout, FI_INC_LINK);
|
|
err = f2fs_add_link(old_dentry, whiteout);
|
|
if (err)
|
|
goto put_out_dir;
|
|
|
|
spin_lock(&whiteout->i_lock);
|
|
whiteout->i_state &= ~I_LINKABLE;
|
|
spin_unlock(&whiteout->i_lock);
|
|
|
|
iput(whiteout);
|
|
}
|
|
|
|
if (old_dir_entry) {
|
|
if (old_dir != new_dir)
|
|
f2fs_set_link(old_inode, old_dir_entry,
|
|
old_dir_page, new_dir);
|
|
else
|
|
f2fs_put_page(old_dir_page, 0);
|
|
f2fs_i_links_write(old_dir, false);
|
|
}
|
|
if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) {
|
|
f2fs_add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
|
|
if (S_ISDIR(old_inode->i_mode))
|
|
f2fs_add_ino_entry(sbi, old_inode->i_ino,
|
|
TRANS_DIR_INO);
|
|
}
|
|
|
|
f2fs_unlock_op(sbi);
|
|
|
|
if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
|
|
f2fs_sync_fs(sbi->sb, 1);
|
|
|
|
f2fs_update_time(sbi, REQ_TIME);
|
|
return 0;
|
|
|
|
put_out_dir:
|
|
f2fs_unlock_op(sbi);
|
|
f2fs_put_page(new_page, 0);
|
|
out_dir:
|
|
if (old_dir_entry)
|
|
f2fs_put_page(old_dir_page, 0);
|
|
out_old:
|
|
f2fs_put_page(old_page, 0);
|
|
out:
|
|
if (whiteout)
|
|
iput(whiteout);
|
|
return err;
|
|
}
|
|
|
|
static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
|
{
|
|
struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
|
|
struct inode *old_inode = d_inode(old_dentry);
|
|
struct inode *new_inode = d_inode(new_dentry);
|
|
struct page *old_dir_page, *new_dir_page;
|
|
struct page *old_page, *new_page;
|
|
struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
|
|
struct f2fs_dir_entry *old_entry, *new_entry;
|
|
int old_nlink = 0, new_nlink = 0;
|
|
int err;
|
|
|
|
if (unlikely(f2fs_cp_error(sbi)))
|
|
return -EIO;
|
|
if (!f2fs_is_checkpoint_ready(sbi))
|
|
return -ENOSPC;
|
|
|
|
if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
|
|
!projid_eq(F2FS_I(new_dir)->i_projid,
|
|
F2FS_I(old_dentry->d_inode)->i_projid)) ||
|
|
(is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
|
|
!projid_eq(F2FS_I(old_dir)->i_projid,
|
|
F2FS_I(new_dentry->d_inode)->i_projid)))
|
|
return -EXDEV;
|
|
|
|
err = dquot_initialize(old_dir);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = dquot_initialize(new_dir);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = -ENOENT;
|
|
old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
|
|
if (!old_entry) {
|
|
if (IS_ERR(old_page))
|
|
err = PTR_ERR(old_page);
|
|
goto out;
|
|
}
|
|
|
|
new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page);
|
|
if (!new_entry) {
|
|
if (IS_ERR(new_page))
|
|
err = PTR_ERR(new_page);
|
|
goto out_old;
|
|
}
|
|
|
|
/* prepare for updating ".." directory entry info later */
|
|
if (old_dir != new_dir) {
|
|
if (S_ISDIR(old_inode->i_mode)) {
|
|
old_dir_entry = f2fs_parent_dir(old_inode,
|
|
&old_dir_page);
|
|
if (!old_dir_entry) {
|
|
if (IS_ERR(old_dir_page))
|
|
err = PTR_ERR(old_dir_page);
|
|
goto out_new;
|
|
}
|
|
}
|
|
|
|
if (S_ISDIR(new_inode->i_mode)) {
|
|
new_dir_entry = f2fs_parent_dir(new_inode,
|
|
&new_dir_page);
|
|
if (!new_dir_entry) {
|
|
if (IS_ERR(new_dir_page))
|
|
err = PTR_ERR(new_dir_page);
|
|
goto out_old_dir;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* If cross rename between file and directory those are not
|
|
* in the same directory, we will inc nlink of file's parent
|
|
* later, so we should check upper boundary of its nlink.
|
|
*/
|
|
if ((!old_dir_entry || !new_dir_entry) &&
|
|
old_dir_entry != new_dir_entry) {
|
|
old_nlink = old_dir_entry ? -1 : 1;
|
|
new_nlink = -old_nlink;
|
|
err = -EMLINK;
|
|
if ((old_nlink > 0 && old_dir->i_nlink >= F2FS_LINK_MAX) ||
|
|
(new_nlink > 0 && new_dir->i_nlink >= F2FS_LINK_MAX))
|
|
goto out_new_dir;
|
|
}
|
|
|
|
f2fs_balance_fs(sbi, true);
|
|
|
|
f2fs_lock_op(sbi);
|
|
|
|
/* update ".." directory entry info of old dentry */
|
|
if (old_dir_entry)
|
|
f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir);
|
|
|
|
/* update ".." directory entry info of new dentry */
|
|
if (new_dir_entry)
|
|
f2fs_set_link(new_inode, new_dir_entry, new_dir_page, old_dir);
|
|
|
|
/* update directory entry info of old dir inode */
|
|
f2fs_set_link(old_dir, old_entry, old_page, new_inode);
|
|
|
|
f2fs_down_write(&F2FS_I(old_inode)->i_sem);
|
|
if (!old_dir_entry)
|
|
file_lost_pino(old_inode);
|
|
else
|
|
/* adjust dir's i_pino to pass fsck check */
|
|
f2fs_i_pino_write(old_inode, new_dir->i_ino);
|
|
f2fs_up_write(&F2FS_I(old_inode)->i_sem);
|
|
|
|
old_dir->i_ctime = current_time(old_dir);
|
|
if (old_nlink) {
|
|
f2fs_down_write(&F2FS_I(old_dir)->i_sem);
|
|
f2fs_i_links_write(old_dir, old_nlink > 0);
|
|
f2fs_up_write(&F2FS_I(old_dir)->i_sem);
|
|
}
|
|
f2fs_mark_inode_dirty_sync(old_dir, false);
|
|
|
|
/* update directory entry info of new dir inode */
|
|
f2fs_set_link(new_dir, new_entry, new_page, old_inode);
|
|
|
|
f2fs_down_write(&F2FS_I(new_inode)->i_sem);
|
|
if (!new_dir_entry)
|
|
file_lost_pino(new_inode);
|
|
else
|
|
/* adjust dir's i_pino to pass fsck check */
|
|
f2fs_i_pino_write(new_inode, old_dir->i_ino);
|
|
f2fs_up_write(&F2FS_I(new_inode)->i_sem);
|
|
|
|
new_dir->i_ctime = current_time(new_dir);
|
|
if (new_nlink) {
|
|
f2fs_down_write(&F2FS_I(new_dir)->i_sem);
|
|
f2fs_i_links_write(new_dir, new_nlink > 0);
|
|
f2fs_up_write(&F2FS_I(new_dir)->i_sem);
|
|
}
|
|
f2fs_mark_inode_dirty_sync(new_dir, false);
|
|
|
|
if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) {
|
|
f2fs_add_ino_entry(sbi, old_dir->i_ino, TRANS_DIR_INO);
|
|
f2fs_add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
|
|
}
|
|
|
|
f2fs_unlock_op(sbi);
|
|
|
|
if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
|
|
f2fs_sync_fs(sbi->sb, 1);
|
|
|
|
f2fs_update_time(sbi, REQ_TIME);
|
|
return 0;
|
|
out_new_dir:
|
|
if (new_dir_entry) {
|
|
f2fs_put_page(new_dir_page, 0);
|
|
}
|
|
out_old_dir:
|
|
if (old_dir_entry) {
|
|
f2fs_put_page(old_dir_page, 0);
|
|
}
|
|
out_new:
|
|
f2fs_put_page(new_page, 0);
|
|
out_old:
|
|
f2fs_put_page(old_page, 0);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
|
|
struct inode *new_dir, struct dentry *new_dentry,
|
|
unsigned int flags)
|
|
{
|
|
int err;
|
|
|
|
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
|
|
return -EINVAL;
|
|
|
|
err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry,
|
|
flags);
|
|
if (err)
|
|
return err;
|
|
|
|
if (flags & RENAME_EXCHANGE) {
|
|
return f2fs_cross_rename(old_dir, old_dentry,
|
|
new_dir, new_dentry);
|
|
}
|
|
/*
|
|
* VFS has already handled the new dentry existence case,
|
|
* here, we just deal with "RENAME_NOREPLACE" as regular rename.
|
|
*/
|
|
return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
|
|
}
|
|
|
|
static const char *f2fs_encrypted_get_link(struct dentry *dentry,
|
|
struct inode *inode,
|
|
struct delayed_call *done)
|
|
{
|
|
struct page *page;
|
|
const char *target;
|
|
|
|
if (!dentry)
|
|
return ERR_PTR(-ECHILD);
|
|
|
|
page = read_mapping_page(inode->i_mapping, 0, NULL);
|
|
if (IS_ERR(page))
|
|
return ERR_CAST(page);
|
|
|
|
target = fscrypt_get_symlink(inode, page_address(page),
|
|
inode->i_sb->s_blocksize, done);
|
|
put_page(page);
|
|
return target;
|
|
}
|
|
|
|
static int f2fs_encrypted_symlink_getattr(const struct path *path,
|
|
struct kstat *stat, u32 request_mask,
|
|
unsigned int query_flags)
|
|
{
|
|
f2fs_getattr(path, stat, request_mask, query_flags);
|
|
|
|
return fscrypt_symlink_getattr(path, stat);
|
|
}
|
|
|
|
const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
|
|
.get_link = f2fs_encrypted_get_link,
|
|
.getattr = f2fs_encrypted_symlink_getattr,
|
|
.setattr = f2fs_setattr,
|
|
.listxattr = f2fs_listxattr,
|
|
};
|
|
|
|
const struct inode_operations f2fs_dir_inode_operations = {
|
|
.create = f2fs_create,
|
|
.lookup = f2fs_lookup,
|
|
.link = f2fs_link,
|
|
.unlink = f2fs_unlink,
|
|
.symlink = f2fs_symlink,
|
|
.mkdir = f2fs_mkdir,
|
|
.rmdir = f2fs_rmdir,
|
|
.mknod = f2fs_mknod,
|
|
.rename = f2fs_rename2,
|
|
.tmpfile = f2fs_tmpfile,
|
|
.getattr = f2fs_getattr,
|
|
.setattr = f2fs_setattr,
|
|
.get_acl = f2fs_get_acl,
|
|
.set_acl = f2fs_set_acl,
|
|
.listxattr = f2fs_listxattr,
|
|
.fiemap = f2fs_fiemap,
|
|
};
|
|
|
|
const struct inode_operations f2fs_symlink_inode_operations = {
|
|
.get_link = f2fs_get_link,
|
|
.getattr = f2fs_getattr,
|
|
.setattr = f2fs_setattr,
|
|
.listxattr = f2fs_listxattr,
|
|
};
|
|
|
|
const struct inode_operations f2fs_special_inode_operations = {
|
|
.getattr = f2fs_getattr,
|
|
.setattr = f2fs_setattr,
|
|
.get_acl = f2fs_get_acl,
|
|
.set_acl = f2fs_set_acl,
|
|
.listxattr = f2fs_listxattr,
|
|
};
|