ee965fe12d
Sync up with android12-5.10 for the following commits:fb39cdb9eaANDROID: export reclaim_pages1f8f6d59a2ANDROID: vendor_hook: Add hook to not be stuck ro rmap lock in kswapd or direct_reclaim91bfc78bc0ANDROID: Update symbol list for mtk02df0b2661ANDROID: GKI: rockchip: Add symbols for cryptoefdf581d14ANDROID: GKI: rockchip: Add symbol pci_disable_link_state504ce2d3a6ANDROID: GKI: rockchip: Add symbols for sounda6b6bc98b7ANDROID: GKI: rockchip: Add symbols for videof3a311b456BACKPORT: f2fs: do not set compression bit if kernel doesn't supportb0988144b0UPSTREAM: exfat: improve performance of exfat_free_cluster when using dirsync mount00d3b8c0ccANDROID: GKI: rockchip: Add symbols for drm dp936f1e35d1UPSTREAM: arm64: perf: Support new DT compatiblesed931dc8ffUPSTREAM: arm64: perf: Simplify registration boilerplatebb6c018ab6UPSTREAM: arm64: perf: Support Denver and Carmel PMUsd306fd9d47UPSTREAM: arm64: perf: add support for Cortex-A7809f78c3f7eANDROID: GKI: rockchip: Update symbol for devfreqe7ed66854eANDROID: GKI: rockchip: Update symbols for drma3e70ff5bfANDROID: GKI: Update symbols to symbol lista09241c6ddUPSTREAM: ASoC: hdmi-codec: make hdmi_codec_controls static9eda09e511UPSTREAM: ASoC: hdmi-codec: Add a prepare hook4ad97b395fUPSTREAM: ASoC: hdmi-codec: Add iec958 controlsc0c2f6962dUPSTREAM: ASoC: hdmi-codec: Rework to support more controls4c6eb3db8aUPSTREAM: ALSA: iec958: Split status creation and fill580d2e7c78UPSTREAM: ALSA: doc: Clarify IEC958 controls iface8b4bb1bca0UPSTREAM: ASoC: hdmi-codec: remove unused spk_mask member5a2c4a5d1eUPSTREAM: ASoC: hdmi-codec: remove useless initialization49e502f0c0UPSTREAM: ASoC: codec: hdmi-codec: Support IEC958 encoded PCM format9bf69acb92UPSTREAM: ASoC: hdmi-codec: Fix return value in hdmi_codec_set_jack()056409c7dcUPSTREAM: ASoC: hdmi-codec: Add RX support5e75deab3aUPSTREAM: ASoC: hdmi-codec: Get ELD in before reporting plugged eventd6207c39cbANDROID: GKI: rockchip: Add symbols for display driver1c3ed9d481BACKPORT: KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID843d3cb41bBACKPORT: io_uring: always grab file table for deferred statx784cc16aedBACKPORT: Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put2b377175a3ANDROID: add two func in mm/memcontrol.ce56f8712cfANDROID: vendor_hooks: protect multi-mapcount pages in kernel3f775b9367ANDROID: vendor_hooks: account page-mapcount1d2287f56eFROMGIT: io_uring: Use original task for req identity in io_identity_cow()e0c9da25b2FROMLIST: binder: fix UAF of ref->proc caused by race condition12f4322442ANDROID: vendor_hooks: Guard cgroup struct with CONFIG_CGROUPS6532784c78ANDROID: vendor_hooks: add hooks for remove_vm_area.c9a70dd592ANDROID: GKI: allow mm vendor hooks header inclusion from header files039080d064ANDROID: Update symbol list of mediatek9e8dedef1eANDROID: sched: add vendor hook to PELT multiplier573c7f061dANDROID: Guard hooks with their CONFIG_ options14f646cca5ANDROID: fix kernelci issue for allnoconfig builds4442801a43ANDROID: sched: Introducing PELT multiplierb2e5773ea4FROMGIT: binder: fix redefinition of seq_file attributes9c2a5eef8fMerge tag 'android12-5.10.117_r00' into 'android12-5.10'5fa1e1affcANDROID: GKI: pcie: Fix the broken dw_pcie structure51b3e17071UPSTREAM: PCI: dwc: Support multiple ATU memory regionsa8d7f6518eANDROID: oplus: Update the ABI xml and symbol list4536de1b70ANDROID: vendor_hooks: add hooks in __alloc_pages_slowpathd63c961c9dANDROID: GKI: Update symbols to symbol list41cbbe08f9FROMGIT: arm64: fix oops in concurrently setting insn_emulation sysctlsc301d142e8FROMGIT: usb: dwc3: core: Do not perform GCTL_CORE_SOFTRESET during bootup8b19ed264bANDROID: vendor_hooks:vendor hook for mmput242b11e574ANDROID: vendor_hooks:vendor hook for pidfd_open0e1cb27700ANDROID: vendor_hook: Add hook in shmem_writepage()8ee37d0bcdBACKPORT: iommu/dma: Fix race condition during iova_domain initialization321bf845e1FROMGIT: usb: dwc3: core: Deprecate GCTL.CORESOFTRESETc5eb0edfdeFROMGIT: usb: dwc3: gadget: Prevent repeat pullup()8de633b735FROMGIT: Binder: add TF_UPDATE_TXN to replace outdated txne8fce59434BACKPORT: FROMGIT: cgroup: Use separate src/dst nodes when preloading css_sets for migrationf26c566455UPSTREAM: usb: gadget: f_uac2: allow changing interface name via configfs98fa7f7dfdUPSTREAM: usb: gadget: f_uac1: allow changing interface name via configfs29172165caUPSTREAM: usb: gadget: f_uac1: Add suspend callbackff5468c71eUPSTREAM: usb: gadget: f_uac2: Add suspend callback31e6d620c1UPSTREAM: usb: gadget: u_audio: Add suspend call17643c1fddUPSTREAM: usb: gadget: u_audio: Rate ctl notifies about current srate (0=stopped)308955e3a6UPSTREAM: usb: gadget: f_uac1: Support multiple sampling ratesae03eadb42UPSTREAM: usb: gadget: f_uac2: Support multiple sampling ratesbedc53fae4UPSTREAM: usb: gadget:audio: Replace deprecated macro S_IRUGO37e0d5eddbUPSTREAM: usb: gadget: u_audio: Add capture/playback srate getter3251bb3250UPSTREAM: usb: gadget: u_audio: Move dynamic srate from params to rtd530916be97UPSTREAM: usb: gadget: u_audio: Support multiple sampling rates7f496d5a99UPSTREAM: docs: ABI: fixed formatting in configfs-usb-gadget-uac22500cb53e6UPSTREAM: usb: gadget: u_audio: Subdevice 0 for capture ctlsc386f34bd4UPSTREAM: usb: gadget: u_audio: fix calculations for small bIntervalf74e3e2fe4UPSTREAM: docs: ABI: fixed req_number desc in UAC102949bae5cUPSTREAM: docs: ABI: added missing num_requests param to UAC2e1377ac38fUPSTREAM: usb:gadget: f_uac1: fixed sync playback4b7c8905c5UPSTREAM: usb: gadget: u_audio.c: Adding Playback Pitch ctl for sync playbacke29d2b5178UPSTREAM: ABI: configfs-usb-gadget-uac2: fix a broken tableec313ae88dUPSTREAM: ABI: configfs-usb-gadget-uac1: fix a broken tablebf46bbe087UPSTREAM: usb: gadget: f_uac1: fixing inconsistent indentingb9c4cbbf7aUPSTREAM: docs: usb: fix malformed tablea380b466e0UPSTREAM: usb: gadget: f_uac1: add volume and mute supporte2c0816af2BACKPORT: usb: gadget: f_uac2: add volume and mute support8430eb0243UPSTREAM: usb: gadget: u_audio: add bi-directional volume and mute support257d21b184UPSTREAM: usb: audio-v2: add ability to define feature unit descriptor1002747429ANDROID: mm: shmem: use reclaim_pages() to recalim pages from a list6719763187UPSTREAM: usb: gadget: f_uac1: disable IN/OUT ep if unused And add the new symbols being tracked due to abi additions from the android12-5.10 branch: Leaf changes summary: 85 artifacts changed Changed leaf types summary: 0 leaf type changed Removed/Changed/Added functions summary: 0 Removed, 0 Changed, 69 Added functions Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 16 Added variables 69 Added functions: [A] 'function void __dev_kfree_skb_irq(sk_buff*, skb_free_reason)' [A] 'function int __page_mapcount(page*)' [A] 'function int __traceiter_android_vh_add_page_to_lrulist(void*, page*, bool, lru_list)' [A] 'function int __traceiter_android_vh_alloc_pages_slowpath_begin(void*, gfp_t, unsigned int, unsigned long int*)' [A] 'function int __traceiter_android_vh_alloc_pages_slowpath_end(void*, gfp_t, unsigned int, unsigned long int)' [A] 'function int __traceiter_android_vh_del_page_from_lrulist(void*, page*, bool, lru_list)' [A] 'function int __traceiter_android_vh_do_traversal_lruvec(void*, lruvec*)' [A] 'function int __traceiter_android_vh_mark_page_accessed(void*, page*)' [A] 'function int __traceiter_android_vh_mutex_unlock_slowpath_end(void*, mutex*, task_struct*)' [A] 'function int __traceiter_android_vh_page_should_be_protected(void*, page*, bool*)' [A] 'function int __traceiter_android_vh_rwsem_mark_wake_readers(void*, rw_semaphore*, rwsem_waiter*)' [A] 'function int __traceiter_android_vh_rwsem_set_owner(void*, rw_semaphore*)' [A] 'function int __traceiter_android_vh_rwsem_set_reader_owned(void*, rw_semaphore*)' [A] 'function int __traceiter_android_vh_rwsem_up_read_end(void*, rw_semaphore*)' [A] 'function int __traceiter_android_vh_rwsem_up_write_end(void*, rw_semaphore*)' [A] 'function int __traceiter_android_vh_sched_pelt_multiplier(void*, unsigned int, unsigned int, int*)' [A] 'function int __traceiter_android_vh_show_mapcount_pages(void*, void*)' [A] 'function int __traceiter_android_vh_update_page_mapcount(void*, page*, bool, bool, bool*, bool*)' [A] 'function int __v4l2_ctrl_handler_setup(v4l2_ctrl_handler*)' [A] 'function int crypto_ahash_final(ahash_request*)' [A] 'function crypto_akcipher* crypto_alloc_akcipher(const char*, u32, u32)' [A] 'function int crypto_register_akcipher(akcipher_alg*)' [A] 'function void crypto_unregister_akcipher(akcipher_alg*)' [A] 'function int des_expand_key(des_ctx*, const u8*, unsigned int)' [A] 'function void dev_pm_opp_unregister_set_opp_helper(opp_table*)' [A] 'function net_device* devm_alloc_etherdev_mqs(device*, int, unsigned int, unsigned int)' [A] 'function mii_bus* devm_mdiobus_alloc_size(device*, int)' [A] 'function int devm_of_mdiobus_register(device*, mii_bus*, device_node*)' [A] 'function int devm_register_netdev(device*, net_device*)' [A] 'function bool disable_hardirq(unsigned int)' [A] 'function void do_traversal_all_lruvec()' [A] 'function drm_connector_status drm_bridge_detect(drm_bridge*)' [A] 'function edid* drm_bridge_get_edid(drm_bridge*, drm_connector*)' [A] 'function int drm_bridge_get_modes(drm_bridge*, drm_connector*)' [A] 'function int drm_dp_get_phy_test_pattern(drm_dp_aux*, drm_dp_phy_test_params*)' [A] 'function int drm_dp_read_desc(drm_dp_aux*, drm_dp_desc*, bool)' [A] 'function int drm_dp_read_dpcd_caps(drm_dp_aux*, u8*)' [A] 'function int drm_dp_read_sink_count(drm_dp_aux*)' [A] 'function int drm_dp_set_phy_test_pattern(drm_dp_aux*, drm_dp_phy_test_params*, u8)' [A] 'function uint64_t drm_format_info_min_pitch(const drm_format_info*, int, unsigned int)' [A] 'function int drm_mm_reserve_node(drm_mm*, drm_mm_node*)' [A] 'function bool drm_probe_ddc(i2c_adapter*)' [A] 'function void drm_self_refresh_helper_cleanup(drm_crtc*)' [A] 'function int drm_self_refresh_helper_init(drm_crtc*)' [A] 'function int get_pelt_halflife()' [A] 'function ssize_t hdmi_avi_infoframe_pack_only(const hdmi_avi_infoframe*, void*, size_t)' [A] 'function ssize_t iio_read_const_attr(device*, device_attribute*, char*)' [A] 'function bool mipi_dsi_packet_format_is_short(u8)' [A] 'function platform_device* of_device_alloc(device_node*, const char*, device*)' [A] 'function lruvec* page_to_lruvec(page*, pg_data_t*)' [A] 'function int pci_disable_link_state(pci_dev*, int)' [A] 'function int regmap_test_bits(regmap*, unsigned int, unsigned int)' [A] 'function unsigned int regulator_get_linear_step(regulator*)' [A] 'function int regulator_suspend_enable(regulator_dev*, suspend_state_t)' [A] 'function int rsa_parse_priv_key(rsa_key*, void*, unsigned int)' [A] 'function int rsa_parse_pub_key(rsa_key*, void*, unsigned int)' [A] 'function int sg_nents(scatterlist*)' [A] 'function int snd_pcm_create_iec958_consumer_default(u8*, size_t)' [A] 'function int snd_pcm_fill_iec958_consumer(snd_pcm_runtime*, u8*, size_t)' [A] 'function int snd_pcm_fill_iec958_consumer_hw_params(snd_pcm_hw_params*, u8*, size_t)' [A] 'function int snd_soc_dapm_force_bias_level(snd_soc_dapm_context*, snd_soc_bias_level)' [A] 'function int snd_soc_jack_add_zones(snd_soc_jack*, int, snd_soc_jack_zone*)' [A] 'function int snd_soc_jack_get_type(snd_soc_jack*, int)' [A] 'function void tcpm_tcpc_reset(tcpm_port*)' [A] 'function int v4l2_enum_dv_timings_cap(v4l2_enum_dv_timings*, const v4l2_dv_timings_cap*, v4l2_check_dv_timings_fnc*, void*)' [A] 'function void v4l2_print_dv_timings(const char*, const char*, const v4l2_dv_timings*, bool)' [A] 'function int v4l2_src_change_event_subdev_subscribe(v4l2_subdev*, v4l2_fh*, v4l2_event_subscription*)' [A] 'function void v4l2_subdev_notify_event(v4l2_subdev*, const v4l2_event*)' [A] 'function bool v4l2_valid_dv_timings(const v4l2_dv_timings*, const v4l2_dv_timings_cap*, v4l2_check_dv_timings_fnc*, void*)' 16 Added variables: [A] 'tracepoint __tracepoint_android_vh_add_page_to_lrulist' [A] 'tracepoint __tracepoint_android_vh_alloc_pages_slowpath_begin' [A] 'tracepoint __tracepoint_android_vh_alloc_pages_slowpath_end' [A] 'tracepoint __tracepoint_android_vh_del_page_from_lrulist' [A] 'tracepoint __tracepoint_android_vh_do_traversal_lruvec' [A] 'tracepoint __tracepoint_android_vh_mark_page_accessed' [A] 'tracepoint __tracepoint_android_vh_mutex_unlock_slowpath_end' [A] 'tracepoint __tracepoint_android_vh_page_should_be_protected' [A] 'tracepoint __tracepoint_android_vh_rwsem_mark_wake_readers' [A] 'tracepoint __tracepoint_android_vh_rwsem_set_owner' [A] 'tracepoint __tracepoint_android_vh_rwsem_set_reader_owned' [A] 'tracepoint __tracepoint_android_vh_rwsem_up_read_end' [A] 'tracepoint __tracepoint_android_vh_rwsem_up_write_end' [A] 'tracepoint __tracepoint_android_vh_sched_pelt_multiplier' [A] 'tracepoint __tracepoint_android_vh_show_mapcount_pages' [A] 'tracepoint __tracepoint_android_vh_update_page_mapcount' Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I47eefe85b949d3f358da95a9b6553660b9be0791
450 lines
9.9 KiB
C
450 lines
9.9 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
|
|
*/
|
|
|
|
#include <linux/slab.h>
|
|
#include <asm/unaligned.h>
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include "exfat_raw.h"
|
|
#include "exfat_fs.h"
|
|
|
|
static int exfat_mirror_bh(struct super_block *sb, sector_t sec,
|
|
struct buffer_head *bh)
|
|
{
|
|
struct buffer_head *c_bh;
|
|
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
sector_t sec2;
|
|
int err = 0;
|
|
|
|
if (sbi->FAT2_start_sector != sbi->FAT1_start_sector) {
|
|
sec2 = sec - sbi->FAT1_start_sector + sbi->FAT2_start_sector;
|
|
c_bh = sb_getblk(sb, sec2);
|
|
if (!c_bh)
|
|
return -ENOMEM;
|
|
memcpy(c_bh->b_data, bh->b_data, sb->s_blocksize);
|
|
set_buffer_uptodate(c_bh);
|
|
mark_buffer_dirty(c_bh);
|
|
if (sb->s_flags & SB_SYNCHRONOUS)
|
|
err = sync_dirty_buffer(c_bh);
|
|
brelse(c_bh);
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
static int __exfat_ent_get(struct super_block *sb, unsigned int loc,
|
|
unsigned int *content)
|
|
{
|
|
unsigned int off;
|
|
sector_t sec;
|
|
struct buffer_head *bh;
|
|
|
|
sec = FAT_ENT_OFFSET_SECTOR(sb, loc);
|
|
off = FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc);
|
|
|
|
bh = sb_bread(sb, sec);
|
|
if (!bh)
|
|
return -EIO;
|
|
|
|
*content = le32_to_cpu(*(__le32 *)(&bh->b_data[off]));
|
|
|
|
/* remap reserved clusters to simplify code */
|
|
if (*content > EXFAT_BAD_CLUSTER)
|
|
*content = EXFAT_EOF_CLUSTER;
|
|
|
|
brelse(bh);
|
|
return 0;
|
|
}
|
|
|
|
int exfat_ent_set(struct super_block *sb, unsigned int loc,
|
|
unsigned int content)
|
|
{
|
|
unsigned int off;
|
|
sector_t sec;
|
|
__le32 *fat_entry;
|
|
struct buffer_head *bh;
|
|
|
|
sec = FAT_ENT_OFFSET_SECTOR(sb, loc);
|
|
off = FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc);
|
|
|
|
bh = sb_bread(sb, sec);
|
|
if (!bh)
|
|
return -EIO;
|
|
|
|
fat_entry = (__le32 *)&(bh->b_data[off]);
|
|
*fat_entry = cpu_to_le32(content);
|
|
exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS);
|
|
exfat_mirror_bh(sb, sec, bh);
|
|
brelse(bh);
|
|
return 0;
|
|
}
|
|
|
|
int exfat_ent_get(struct super_block *sb, unsigned int loc,
|
|
unsigned int *content)
|
|
{
|
|
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
int err;
|
|
|
|
if (!is_valid_cluster(sbi, loc)) {
|
|
exfat_fs_error(sb, "invalid access to FAT (entry 0x%08x)",
|
|
loc);
|
|
return -EIO;
|
|
}
|
|
|
|
err = __exfat_ent_get(sb, loc, content);
|
|
if (err) {
|
|
exfat_fs_error(sb,
|
|
"failed to access to FAT (entry 0x%08x, err:%d)",
|
|
loc, err);
|
|
return err;
|
|
}
|
|
|
|
if (*content == EXFAT_FREE_CLUSTER) {
|
|
exfat_fs_error(sb,
|
|
"invalid access to FAT free cluster (entry 0x%08x)",
|
|
loc);
|
|
return -EIO;
|
|
}
|
|
|
|
if (*content == EXFAT_BAD_CLUSTER) {
|
|
exfat_fs_error(sb,
|
|
"invalid access to FAT bad cluster (entry 0x%08x)",
|
|
loc);
|
|
return -EIO;
|
|
}
|
|
|
|
if (*content != EXFAT_EOF_CLUSTER && !is_valid_cluster(sbi, *content)) {
|
|
exfat_fs_error(sb,
|
|
"invalid access to FAT (entry 0x%08x) bogus content (0x%08x)",
|
|
loc, *content);
|
|
return -EIO;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain,
|
|
unsigned int len)
|
|
{
|
|
if (!len)
|
|
return 0;
|
|
|
|
while (len > 1) {
|
|
if (exfat_ent_set(sb, chain, chain + 1))
|
|
return -EIO;
|
|
chain++;
|
|
len--;
|
|
}
|
|
|
|
if (exfat_ent_set(sb, chain, EXFAT_EOF_CLUSTER))
|
|
return -EIO;
|
|
return 0;
|
|
}
|
|
|
|
int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
|
|
{
|
|
unsigned int num_clusters = 0;
|
|
unsigned int clu;
|
|
struct super_block *sb = inode->i_sb;
|
|
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
int cur_cmap_i, next_cmap_i;
|
|
|
|
/* invalid cluster number */
|
|
if (p_chain->dir == EXFAT_FREE_CLUSTER ||
|
|
p_chain->dir == EXFAT_EOF_CLUSTER ||
|
|
p_chain->dir < EXFAT_FIRST_CLUSTER)
|
|
return 0;
|
|
|
|
/* no cluster to truncate */
|
|
if (p_chain->size == 0)
|
|
return 0;
|
|
|
|
/* check cluster validation */
|
|
if (!is_valid_cluster(sbi, p_chain->dir)) {
|
|
exfat_err(sb, "invalid start cluster (%u)", p_chain->dir);
|
|
return -EIO;
|
|
}
|
|
|
|
clu = p_chain->dir;
|
|
|
|
cur_cmap_i = next_cmap_i =
|
|
BITMAP_OFFSET_SECTOR_INDEX(sb, CLUSTER_TO_BITMAP_ENT(clu));
|
|
|
|
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
|
unsigned int last_cluster = p_chain->dir + p_chain->size - 1;
|
|
|
|
do {
|
|
bool sync = false;
|
|
|
|
if (clu < last_cluster)
|
|
next_cmap_i =
|
|
BITMAP_OFFSET_SECTOR_INDEX(sb, CLUSTER_TO_BITMAP_ENT(clu+1));
|
|
|
|
/* flush bitmap only if index would be changed or for last cluster */
|
|
if (clu == last_cluster || cur_cmap_i != next_cmap_i) {
|
|
sync = true;
|
|
cur_cmap_i = next_cmap_i;
|
|
}
|
|
|
|
exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode)));
|
|
clu++;
|
|
num_clusters++;
|
|
} while (num_clusters < p_chain->size);
|
|
} else {
|
|
do {
|
|
bool sync = false;
|
|
unsigned int n_clu = clu;
|
|
int err = exfat_get_next_cluster(sb, &n_clu);
|
|
|
|
if (err || n_clu == EXFAT_EOF_CLUSTER)
|
|
sync = true;
|
|
else
|
|
next_cmap_i =
|
|
BITMAP_OFFSET_SECTOR_INDEX(sb, CLUSTER_TO_BITMAP_ENT(n_clu));
|
|
|
|
if (cur_cmap_i != next_cmap_i) {
|
|
sync = true;
|
|
cur_cmap_i = next_cmap_i;
|
|
}
|
|
|
|
exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode)));
|
|
clu = n_clu;
|
|
|
|
num_clusters++;
|
|
|
|
if (err)
|
|
goto dec_used_clus;
|
|
} while (clu != EXFAT_EOF_CLUSTER);
|
|
}
|
|
|
|
dec_used_clus:
|
|
sbi->used_clusters -= num_clusters;
|
|
return 0;
|
|
}
|
|
|
|
int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_chain,
|
|
unsigned int *ret_clu)
|
|
{
|
|
unsigned int clu, next;
|
|
unsigned int count = 0;
|
|
|
|
next = p_chain->dir;
|
|
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
|
*ret_clu = next + p_chain->size - 1;
|
|
return 0;
|
|
}
|
|
|
|
do {
|
|
count++;
|
|
clu = next;
|
|
if (exfat_ent_get(sb, clu, &next))
|
|
return -EIO;
|
|
} while (next != EXFAT_EOF_CLUSTER);
|
|
|
|
if (p_chain->size != count) {
|
|
exfat_fs_error(sb,
|
|
"bogus directory size (clus : ondisk(%d) != counted(%d))",
|
|
p_chain->size, count);
|
|
return -EIO;
|
|
}
|
|
|
|
*ret_clu = clu;
|
|
return 0;
|
|
}
|
|
|
|
int exfat_zeroed_cluster(struct inode *dir, unsigned int clu)
|
|
{
|
|
struct super_block *sb = dir->i_sb;
|
|
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
struct buffer_head *bhs[MAX_BUF_PER_PAGE];
|
|
int nr_bhs = MAX_BUF_PER_PAGE;
|
|
sector_t blknr, last_blknr;
|
|
int err, i, n;
|
|
|
|
blknr = exfat_cluster_to_sector(sbi, clu);
|
|
last_blknr = blknr + sbi->sect_per_clus;
|
|
|
|
if (last_blknr > sbi->num_sectors && sbi->num_sectors > 0) {
|
|
exfat_fs_error_ratelimit(sb,
|
|
"%s: out of range(sect:%llu len:%u)",
|
|
__func__, (unsigned long long)blknr,
|
|
sbi->sect_per_clus);
|
|
return -EIO;
|
|
}
|
|
|
|
/* Zeroing the unused blocks on this cluster */
|
|
while (blknr < last_blknr) {
|
|
for (n = 0; n < nr_bhs && blknr < last_blknr; n++, blknr++) {
|
|
bhs[n] = sb_getblk(sb, blknr);
|
|
if (!bhs[n]) {
|
|
err = -ENOMEM;
|
|
goto release_bhs;
|
|
}
|
|
memset(bhs[n]->b_data, 0, sb->s_blocksize);
|
|
}
|
|
|
|
err = exfat_update_bhs(bhs, n, IS_DIRSYNC(dir));
|
|
if (err)
|
|
goto release_bhs;
|
|
|
|
for (i = 0; i < n; i++)
|
|
brelse(bhs[i]);
|
|
}
|
|
return 0;
|
|
|
|
release_bhs:
|
|
exfat_err(sb, "failed zeroed sect %llu\n", (unsigned long long)blknr);
|
|
for (i = 0; i < n; i++)
|
|
bforget(bhs[i]);
|
|
return err;
|
|
}
|
|
|
|
int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
|
struct exfat_chain *p_chain, bool sync_bmap)
|
|
{
|
|
int ret = -ENOSPC;
|
|
unsigned int num_clusters = 0, total_cnt;
|
|
unsigned int hint_clu, new_clu, last_clu = EXFAT_EOF_CLUSTER;
|
|
struct super_block *sb = inode->i_sb;
|
|
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
|
|
total_cnt = EXFAT_DATA_CLUSTER_COUNT(sbi);
|
|
|
|
if (unlikely(total_cnt < sbi->used_clusters)) {
|
|
exfat_fs_error_ratelimit(sb,
|
|
"%s: invalid used clusters(t:%u,u:%u)\n",
|
|
__func__, total_cnt, sbi->used_clusters);
|
|
return -EIO;
|
|
}
|
|
|
|
if (num_alloc > total_cnt - sbi->used_clusters)
|
|
return -ENOSPC;
|
|
|
|
hint_clu = p_chain->dir;
|
|
/* find new cluster */
|
|
if (hint_clu == EXFAT_EOF_CLUSTER) {
|
|
if (sbi->clu_srch_ptr < EXFAT_FIRST_CLUSTER) {
|
|
exfat_err(sb, "sbi->clu_srch_ptr is invalid (%u)\n",
|
|
sbi->clu_srch_ptr);
|
|
sbi->clu_srch_ptr = EXFAT_FIRST_CLUSTER;
|
|
}
|
|
|
|
hint_clu = exfat_find_free_bitmap(sb, sbi->clu_srch_ptr);
|
|
if (hint_clu == EXFAT_EOF_CLUSTER)
|
|
return -ENOSPC;
|
|
}
|
|
|
|
/* check cluster validation */
|
|
if (!is_valid_cluster(sbi, hint_clu)) {
|
|
exfat_err(sb, "hint_cluster is invalid (%u)",
|
|
hint_clu);
|
|
hint_clu = EXFAT_FIRST_CLUSTER;
|
|
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
|
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
|
num_clusters))
|
|
return -EIO;
|
|
p_chain->flags = ALLOC_FAT_CHAIN;
|
|
}
|
|
}
|
|
|
|
p_chain->dir = EXFAT_EOF_CLUSTER;
|
|
|
|
while ((new_clu = exfat_find_free_bitmap(sb, hint_clu)) !=
|
|
EXFAT_EOF_CLUSTER) {
|
|
if (new_clu != hint_clu &&
|
|
p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
|
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
|
num_clusters)) {
|
|
ret = -EIO;
|
|
goto free_cluster;
|
|
}
|
|
p_chain->flags = ALLOC_FAT_CHAIN;
|
|
}
|
|
|
|
/* update allocation bitmap */
|
|
if (exfat_set_bitmap(inode, new_clu, sync_bmap)) {
|
|
ret = -EIO;
|
|
goto free_cluster;
|
|
}
|
|
|
|
num_clusters++;
|
|
|
|
/* update FAT table */
|
|
if (p_chain->flags == ALLOC_FAT_CHAIN) {
|
|
if (exfat_ent_set(sb, new_clu, EXFAT_EOF_CLUSTER)) {
|
|
ret = -EIO;
|
|
goto free_cluster;
|
|
}
|
|
}
|
|
|
|
if (p_chain->dir == EXFAT_EOF_CLUSTER) {
|
|
p_chain->dir = new_clu;
|
|
} else if (p_chain->flags == ALLOC_FAT_CHAIN) {
|
|
if (exfat_ent_set(sb, last_clu, new_clu)) {
|
|
ret = -EIO;
|
|
goto free_cluster;
|
|
}
|
|
}
|
|
last_clu = new_clu;
|
|
|
|
if (--num_alloc == 0) {
|
|
sbi->clu_srch_ptr = hint_clu;
|
|
sbi->used_clusters += num_clusters;
|
|
|
|
p_chain->size += num_clusters;
|
|
return 0;
|
|
}
|
|
|
|
hint_clu = new_clu + 1;
|
|
if (hint_clu >= sbi->num_clusters) {
|
|
hint_clu = EXFAT_FIRST_CLUSTER;
|
|
|
|
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
|
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
|
num_clusters)) {
|
|
ret = -EIO;
|
|
goto free_cluster;
|
|
}
|
|
p_chain->flags = ALLOC_FAT_CHAIN;
|
|
}
|
|
}
|
|
}
|
|
free_cluster:
|
|
if (num_clusters)
|
|
exfat_free_cluster(inode, p_chain);
|
|
return ret;
|
|
}
|
|
|
|
int exfat_count_num_clusters(struct super_block *sb,
|
|
struct exfat_chain *p_chain, unsigned int *ret_count)
|
|
{
|
|
unsigned int i, count;
|
|
unsigned int clu;
|
|
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
|
|
if (!p_chain->dir || p_chain->dir == EXFAT_EOF_CLUSTER) {
|
|
*ret_count = 0;
|
|
return 0;
|
|
}
|
|
|
|
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
|
*ret_count = p_chain->size;
|
|
return 0;
|
|
}
|
|
|
|
clu = p_chain->dir;
|
|
count = 0;
|
|
for (i = EXFAT_FIRST_CLUSTER; i < sbi->num_clusters; i++) {
|
|
count++;
|
|
if (exfat_ent_get(sb, clu, &clu))
|
|
return -EIO;
|
|
if (clu == EXFAT_EOF_CLUSTER)
|
|
break;
|
|
}
|
|
|
|
*ret_count = count;
|
|
return 0;
|
|
}
|