Changes in 4.9.311 USB: serial: pl2303: add IBM device IDs USB: serial: simple: add Nokia phone driver netdevice: add the case if dev is NULL virtio_console: break out of buf poll on remove ethernet: sun: Free the coherent when failing in probing af_key: add __GFP_ZERO flag for compose_sadb_supported in function pfkey_register block: Add a helper to validate the block size virtio-blk: Use blk_validate_block_size() to validate block size USB: usb-storage: Fix use of bitfields for hardware data in ene_ub6250.c coresight: Fix TRCCONFIGR.QE sysfs interface iio: inkern: apply consumer scale on IIO_VAL_INT cases iio: inkern: make a best effort on offset calculation clk: uniphier: Fix fixed-rate initialization ptrace: Check PTRACE_O_SUSPEND_SECCOMP permission on PTRACE_SEIZE SUNRPC: avoid race between mod_timer() and del_timer_sync() NFSD: prevent underflow in nfssvc_decode_writeargs() can: ems_usb: ems_usb_start_xmit(): fix double dev_kfree_skb() in error path jffs2: fix use-after-free in jffs2_clear_xattr_subsystem jffs2: fix memory leak in jffs2_do_mount_fs jffs2: fix memory leak in jffs2_scan_medium mm/pages_alloc.c: don't create ZONE_MOVABLE beyond the end of a node mempolicy: mbind_range() set_policy() after vma_merge() scsi: libsas: Fix sas_ata_qc_issue() handling of NCQ NON DATA commands Revert "Input: clear BTN_RIGHT/MIDDLE on buttonpads" ALSA: cs4236: fix an incorrect NULL check on list iterator drivers: hamradio: 6pack: fix UAF bug caused by mod_timer() video: fbdev: sm712fb: Fix crash in smtcfb_read() video: fbdev: atari: Atari 2 bpp (STe) palette bugfix ARM: dts: exynos: fix UART3 pins configuration in Exynos5250 ARM: dts: exynos: add missing HDMI supplies on SMDK5250 ARM: dts: exynos: add missing HDMI supplies on SMDK5420 carl9170: fix missing bit-wise or operator for tx_params thermal: int340x: Increase bitmap size lib/raid6/test: fix multiple definition linking error DEC: Limit PMAX memory probing to R3k systems media: davinci: vpif: fix unbalanced runtime PM get brcmfmac: firmware: Allocate space for default boardrev in nvram brcmfmac: pcie: Replace brcmf_pcie_copy_mem_todev with memcpy_toio PCI: pciehp: Clear cmd_busy bit in polling mode crypto: authenc - Fix sleep in atomic context in decrypt_tail crypto: mxs-dcp - Fix scatterlist processing spi: tegra114: Add missing IRQ check in tegra_spi_probe selftests/x86: Add validity check and allow field splitting hwmon: (pmbus) Add mutex to regulator ops hwmon: (sch56xx-common) Replace WDOG_ACTIVE with WDOG_HW_RUNNING PM: hibernate: fix __setup handler error handling PM: suspend: fix return value of __setup handler crypto: vmx - add missing dependencies crypto: ccp - ccp_dmaengine_unregister release dma channels hwmon: (pmbus) Add Vin unit off handling clocksource: acpi_pm: fix return value of __setup handler sched/debug: Remove mpol_get/put and task_lock/unlock from sched_show_numa perf/core: Fix address filter parser for multiple filters perf/x86/intel/pt: Fix address filter config for 32-bit kernel video: fbdev: smscufx: Fix null-ptr-deref in ufx_usb_probe() video: fbdev: fbcvt.c: fix printing in fb_cvt_print_name() ARM: dts: qcom: ipq4019: fix sleep clock soc: ti: wkup_m3_ipc: Fix IRQ check in wkup_m3_ipc_probe media: usb: go7007: s2250-board: fix leak in probe() ASoC: ti: davinci-i2s: Add check for clk_enable() ALSA: spi: Add check for clk_enable() arm64: dts: ns2: Fix spi-cpol and spi-cpha property arm64: dts: broadcom: Fix sata nodename printk: fix return value of printk.devkmsg __setup handler ASoC: mxs-saif: Handle errors for clk_enable ASoC: atmel_ssc_dai: Handle errors for clk_enable memory: emif: Add check for setup_interrupts memory: emif: check the pointer temp in get_device_details() ALSA: firewire-lib: fix uninitialized flag for AV/C deferred transaction ASoC: atmel: Add missing of_node_put() in at91sam9g20ek_audio_probe ASoC: wm8350: Handle error for wm8350_register_irq ASoC: fsi: Add check for clk_enable video: fbdev: omapfb: Add missing of_node_put() in dvic_probe_of ASoC: dmaengine: do not use a NULL prepare_slave_config() callback ASoC: mxs: Fix error handling in mxs_sgtl5000_probe ASoC: imx-es8328: Fix error return code in imx_es8328_probe() mtd: onenand: Check for error irq drm/edid: Don't clear formats if using deep color ath9k_htc: fix uninit value bugs ray_cs: Check ioremap return value power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init HID: i2c-hid: fix GET/SET_REPORT for unnumbered reports iwlwifi: Fix -EIO error code that is never returned scsi: pm8001: Fix command initialization in pm80XX_send_read_log() scsi: pm8001: Fix command initialization in pm8001_chip_ssp_tm_req() scsi: pm8001: Fix payload initialization in pm80xx_set_thermal_config() scsi: pm8001: Fix abort all task initialization TOMOYO: fix __setup handlers return values ext2: correct max file size computing drm/tegra: Fix reference leak in tegra_dsi_ganged_probe KVM: x86: Fix emulation in writing cr8 KVM: x86/emulator: Defer not-present segment check in __load_segment_descriptor() i2c: xiic: Make bus names unique power: supply: wm8350-power: Handle error for wm8350_register_irq power: supply: wm8350-power: Add missing free in free_charger_irq powerpc/sysdev: fix incorrect use to determine if list is empty mfd: mc13xxx: Add check for mc13xxx_irq_request MIPS: RB532: fix return value of __setup handler USB: storage: ums-realtek: fix error code in rts51x_read_mem() af_netlink: Fix shift out of bounds in group mask calculation i2c: mux: demux-pinctrl: do not deactivate a master that is not active mfd: asic3: Add missing iounmap() on error asic3_mfd_probe mxser: fix xmit_buf leak in activate when LSR == 0xff pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() iio: adc: Add check for devm_request_threaded_irq clk: qcom: clk-rcg2: Update the frac table for pixel clock remoteproc: qcom_wcnss: Add missing of_node_put() in wcnss_alloc_memory_region clk: loongson1: Terminate clk_div_table with sentinel element clk: clps711x: Terminate clk_div_table with sentinel element clk: tegra: tegra124-emc: Fix missing put_device() call in emc_ensure_emc_driver NFS: remove unneeded check in decode_devicenotify_args() pinctrl: mediatek: Fix missing of_node_put() in mtk_pctrl_init pinctrl: nomadik: Add missing of_node_put() in nmk_pinctrl_probe pinctrl/rockchip: Add missing of_node_put() in rockchip_pinctrl_probe tty: hvc: fix return value of __setup handler kgdboc: fix return value of __setup handler kgdbts: fix return value of __setup handler jfs: fix divide error in dbNextAG netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options net: phy: broadcom: Fix brcm_fet_config_init() qlcnic: dcb: default to returning -EOPNOTSUPP net/x25: Fix null-ptr-deref caused by x25_disconnect selinux: use correct type for context length loop: use sysfs_emit() in the sysfs xxx show() Fix incorrect type in assignment of ipv6 port for audit irqchip/nvic: Release nvic_base upon failure ACPICA: Avoid walking the ACPI Namespace if it is not there ACPI/APEI: Limit printable size of BERT table data PM: core: keep irq flags in device_pm_check_callbacks() spi: tegra20: Use of_device_get_match_data() ext4: don't BUG if someone dirty pages without asking ext4 first ntfs: add sanity check on allocation size video: fbdev: nvidiafb: Use strscpy() to prevent buffer overflow video: fbdev: w100fb: Reset global state video: fbdev: cirrusfb: check pixclock to avoid divide by zero video: fbdev: omapfb: acx565akm: replace snprintf with sysfs_emit ARM: dts: qcom: fix gic_irq_domain_translate warnings for msm8960 ARM: dts: bcm2837: Add the missing L1/L2 cache information video: fbdev: omapfb: panel-dsi-cm: Use sysfs_emit() instead of snprintf() video: fbdev: omapfb: panel-tpo-td043mtea1: Use sysfs_emit() instead of snprintf() ASoC: soc-core: skip zero num_dai component in searching dai name media: cx88-mpeg: clear interrupt status register before streaming video ARM: tegra: tamonten: Fix I2C3 pad setting ARM: mmp: Fix failure to remove sram device video: fbdev: sm712fb: Fix crash in smtcfb_write() media: hdpvr: initialize dev->worker at hdpvr_register_videodev mmc: host: Return an error when ->enable_sdio_irq() ops is missing scsi: qla2xxx: Fix incorrect reporting of task management failure KVM: Prevent module exit until all VMs are freed ubifs: Add missing iput if do_tmpfile() failed in rename whiteout ubifs: setflags: Make dirtied_ino_d 8 bytes aligned gfs2: Make sure FITRIM minlen is rounded up to fs block size pinctrl: pinconf-generic: Print arguments for bias-pull-* ACPI: CPPC: Avoid out of bounds access when parsing _CPC data mm/mmap: return 1 from stack_guard_gap __setup() handler mm/memcontrol: return 1 from cgroup.memory __setup() handler ubi: fastmap: Return error code if memory allocation fails in add_aeb() ASoC: topology: Allow TLV control to be either read or write ARM: dts: spear1340: Update serial node properties ARM: dts: spear13xx: Update SPI dma properties openvswitch: Fixed nd target mask field in the flow dump. KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated rtc: wm8350: Handle error for wm8350_register_irq ARM: 9187/1: JIVE: fix return value of __setup handler KVM: x86/svm: Clear reserved bits written to PerfEvtSeln MSRs ath5k: fix OOB in ath5k_eeprom_read_pcal_info_5111 ptp: replace snprintf with sysfs_emit powerpc: dts: t104xrdb: fix phy type for FMAN 4/5 scsi: mvsas: Replace snprintf() with sysfs_emit() scsi: bfa: Replace snprintf() with sysfs_emit() iommu/arm-smmu-v3: fix event handling soft lockup dm ioctl: prevent potential spectre v1 gadget scsi: pm8001: Fix pm8001_mpi_task_abort_resp() scsi: aha152x: Fix aha152x_setup() __setup handler return value bnxt_en: Eliminate unintended link toggle during FW reset MIPS: fix fortify panic when copying asm exception handlers scsi: libfc: Fix use after free in fc_exch_abts_resp() usb: dwc3: omap: fix "unbalanced disables for smps10_out1" on omap5evm xtensa: fix DTC warning unit_address_format Bluetooth: Fix use after free in hci_send_acl init/main.c: return 1 from handled __setup() functions w1: w1_therm: fixes w1_seq for ds28ea00 sensors SUNRPC/call_alloc: async tasks mustn't block waiting for memory 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 mm: fix race between MADV_FREE reclaim and blkdev direct IO read scsi: zorro7xx: Fix a resource leak in zorro7xx_remove_one() net: stmmac: Fix unset max_speed difference between DT and non-DT platforms drm/imx: Fix memory leak in imx_pd_connector_get_modes drbd: Fix five use after free bugs in get_initial_state mmmremap.c: avoid pointless invalidate_range_start/end on mremap(old_size=0) mm/mempolicy: fix mpol_new leak in shared_policy_replace x86/pm: Save the MSR validity status at context setup x86/speculation: Restore speculation related MSRs during S3 resume arm64: patch_text: Fixup last cpu should be master tools build: Use $(shell ) instead of `` to get embedded libperl's ccopts dmaengine: Revert "dmaengine: shdma: Fix runtime PM imbalance on error" mm: don't skip swap entry even if zap_details specified arm64: module: remove (NOLOAD) from linker script xfrm: policy: match with both mark and mask on user interfaces veth: Ensure eth header is in skb's linear part net: ethernet: stmmac: fix altr_tse_pcs function when using a fixed-link nfc: nci: add flush_workqueue to prevent uaf cifs: potential buffer overflow in handling symlinks drm/amdkfd: Check for potential null return of kmalloc_array() scsi: ibmvscsis: Increase INITIAL_SRP_LIMIT to 1024 net: micrel: fix KS8851_MLL Kconfig gpu: ipu-v3: Fix dev_dbg frequency output scsi: mvsas: Add PCI ID of RocketRaid 2640 drivers: net: slip: fix NPD bug in sl_tx_timeout() mm, page_alloc: fix build_zonerefs_node() mm: kmemleak: take a full lowmem check in kmemleak_*_phys() ALSA: pcm: Test for "silence" field in struct "pcm_format_data" ARM: davinci: da850-evm: Avoid NULL pointer dereference smp: Fix offline cpu check in flush_smp_call_function_queue() i2c: pasemi: Wait for write xfers to finish gcc-plugins: latent_entropy: use /dev/urandom Linux 4.9.311 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ia8f55c5ae2f0eb71b0893d8271a10dfd3c78b3b8
432 lines
13 KiB
C
432 lines
13 KiB
C
/*
|
|
* JFFS2 -- Journalling Flash File System, Version 2.
|
|
*
|
|
* Copyright © 2001-2007 Red Hat, Inc.
|
|
* Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
|
|
*
|
|
* Created by David Woodhouse <dwmw2@infradead.org>
|
|
*
|
|
* For licensing information, see the file 'LICENCE' in this directory.
|
|
*
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/mtd/mtd.h>
|
|
#include <linux/mm.h> /* kvfree() */
|
|
#include "nodelist.h"
|
|
|
|
static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *,
|
|
struct jffs2_inode_cache *, struct jffs2_full_dirent **);
|
|
|
|
static inline struct jffs2_inode_cache *
|
|
first_inode_chain(int *i, struct jffs2_sb_info *c)
|
|
{
|
|
for (; *i < c->inocache_hashsize; (*i)++) {
|
|
if (c->inocache_list[*i])
|
|
return c->inocache_list[*i];
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static inline struct jffs2_inode_cache *
|
|
next_inode(int *i, struct jffs2_inode_cache *ic, struct jffs2_sb_info *c)
|
|
{
|
|
/* More in this chain? */
|
|
if (ic->next)
|
|
return ic->next;
|
|
(*i)++;
|
|
return first_inode_chain(i, c);
|
|
}
|
|
|
|
#define for_each_inode(i, c, ic) \
|
|
for (i = 0, ic = first_inode_chain(&i, (c)); \
|
|
ic; \
|
|
ic = next_inode(&i, ic, (c)))
|
|
|
|
|
|
static void jffs2_build_inode_pass1(struct jffs2_sb_info *c,
|
|
struct jffs2_inode_cache *ic,
|
|
int *dir_hardlinks)
|
|
{
|
|
struct jffs2_full_dirent *fd;
|
|
|
|
dbg_fsbuild("building directory inode #%u\n", ic->ino);
|
|
|
|
/* For each child, increase nlink */
|
|
for(fd = ic->scan_dents; fd; fd = fd->next) {
|
|
struct jffs2_inode_cache *child_ic;
|
|
if (!fd->ino)
|
|
continue;
|
|
|
|
/* we can get high latency here with huge directories */
|
|
|
|
child_ic = jffs2_get_ino_cache(c, fd->ino);
|
|
if (!child_ic) {
|
|
dbg_fsbuild("child \"%s\" (ino #%u) of dir ino #%u doesn't exist!\n",
|
|
fd->name, fd->ino, ic->ino);
|
|
jffs2_mark_node_obsolete(c, fd->raw);
|
|
/* Clear the ic/raw union so it doesn't cause problems later. */
|
|
fd->ic = NULL;
|
|
continue;
|
|
}
|
|
|
|
/* From this point, fd->raw is no longer used so we can set fd->ic */
|
|
fd->ic = child_ic;
|
|
child_ic->pino_nlink++;
|
|
/* If we appear (at this stage) to have hard-linked directories,
|
|
* set a flag to trigger a scan later */
|
|
if (fd->type == DT_DIR) {
|
|
child_ic->flags |= INO_FLAGS_IS_DIR;
|
|
if (child_ic->pino_nlink > 1)
|
|
*dir_hardlinks = 1;
|
|
}
|
|
|
|
dbg_fsbuild("increased nlink for child \"%s\" (ino #%u)\n", fd->name, fd->ino);
|
|
/* Can't free scan_dents so far. We might need them in pass 2 */
|
|
}
|
|
}
|
|
|
|
/* Scan plan:
|
|
- Scan physical nodes. Build map of inodes/dirents. Allocate inocaches as we go
|
|
- Scan directory tree from top down, setting nlink in inocaches
|
|
- Scan inocaches for inodes with nlink==0
|
|
*/
|
|
static int jffs2_build_filesystem(struct jffs2_sb_info *c)
|
|
{
|
|
int ret, i, dir_hardlinks = 0;
|
|
struct jffs2_inode_cache *ic;
|
|
struct jffs2_full_dirent *fd;
|
|
struct jffs2_full_dirent *dead_fds = NULL;
|
|
|
|
dbg_fsbuild("build FS data structures\n");
|
|
|
|
/* First, scan the medium and build all the inode caches with
|
|
lists of physical nodes */
|
|
|
|
c->flags |= JFFS2_SB_FLAG_SCANNING;
|
|
ret = jffs2_scan_medium(c);
|
|
c->flags &= ~JFFS2_SB_FLAG_SCANNING;
|
|
if (ret)
|
|
goto exit;
|
|
|
|
dbg_fsbuild("scanned flash completely\n");
|
|
jffs2_dbg_dump_block_lists_nolock(c);
|
|
|
|
dbg_fsbuild("pass 1 starting\n");
|
|
c->flags |= JFFS2_SB_FLAG_BUILDING;
|
|
/* Now scan the directory tree, increasing nlink according to every dirent found. */
|
|
for_each_inode(i, c, ic) {
|
|
if (ic->scan_dents) {
|
|
jffs2_build_inode_pass1(c, ic, &dir_hardlinks);
|
|
cond_resched();
|
|
}
|
|
}
|
|
|
|
dbg_fsbuild("pass 1 complete\n");
|
|
|
|
/* Next, scan for inodes with nlink == 0 and remove them. If
|
|
they were directories, then decrement the nlink of their
|
|
children too, and repeat the scan. As that's going to be
|
|
a fairly uncommon occurrence, it's not so evil to do it this
|
|
way. Recursion bad. */
|
|
dbg_fsbuild("pass 2 starting\n");
|
|
|
|
for_each_inode(i, c, ic) {
|
|
if (ic->pino_nlink)
|
|
continue;
|
|
|
|
jffs2_build_remove_unlinked_inode(c, ic, &dead_fds);
|
|
cond_resched();
|
|
}
|
|
|
|
dbg_fsbuild("pass 2a starting\n");
|
|
|
|
while (dead_fds) {
|
|
fd = dead_fds;
|
|
dead_fds = fd->next;
|
|
|
|
ic = jffs2_get_ino_cache(c, fd->ino);
|
|
|
|
if (ic)
|
|
jffs2_build_remove_unlinked_inode(c, ic, &dead_fds);
|
|
jffs2_free_full_dirent(fd);
|
|
}
|
|
|
|
dbg_fsbuild("pass 2a complete\n");
|
|
|
|
if (dir_hardlinks) {
|
|
/* If we detected directory hardlinks earlier, *hopefully*
|
|
* they are gone now because some of the links were from
|
|
* dead directories which still had some old dirents lying
|
|
* around and not yet garbage-collected, but which have
|
|
* been discarded above. So clear the pino_nlink field
|
|
* in each directory, so that the final scan below can
|
|
* print appropriate warnings. */
|
|
for_each_inode(i, c, ic) {
|
|
if (ic->flags & INO_FLAGS_IS_DIR)
|
|
ic->pino_nlink = 0;
|
|
}
|
|
}
|
|
dbg_fsbuild("freeing temporary data structures\n");
|
|
|
|
/* Finally, we can scan again and free the dirent structs */
|
|
for_each_inode(i, c, ic) {
|
|
while(ic->scan_dents) {
|
|
fd = ic->scan_dents;
|
|
ic->scan_dents = fd->next;
|
|
/* We do use the pino_nlink field to count nlink of
|
|
* directories during fs build, so set it to the
|
|
* parent ino# now. Now that there's hopefully only
|
|
* one. */
|
|
if (fd->type == DT_DIR) {
|
|
if (!fd->ic) {
|
|
/* We'll have complained about it and marked the coresponding
|
|
raw node obsolete already. Just skip it. */
|
|
continue;
|
|
}
|
|
|
|
/* We *have* to have set this in jffs2_build_inode_pass1() */
|
|
BUG_ON(!(fd->ic->flags & INO_FLAGS_IS_DIR));
|
|
|
|
/* We clear ic->pino_nlink ∀ directories' ic *only* if dir_hardlinks
|
|
* is set. Otherwise, we know this should never trigger anyway, so
|
|
* we don't do the check. And ic->pino_nlink still contains the nlink
|
|
* value (which is 1). */
|
|
if (dir_hardlinks && fd->ic->pino_nlink) {
|
|
JFFS2_ERROR("child dir \"%s\" (ino #%u) of dir ino #%u is also hard linked from dir ino #%u\n",
|
|
fd->name, fd->ino, ic->ino, fd->ic->pino_nlink);
|
|
/* Should we unlink it from its previous parent? */
|
|
}
|
|
|
|
/* For directories, ic->pino_nlink holds that parent inode # */
|
|
fd->ic->pino_nlink = ic->ino;
|
|
}
|
|
jffs2_free_full_dirent(fd);
|
|
}
|
|
ic->scan_dents = NULL;
|
|
cond_resched();
|
|
}
|
|
jffs2_build_xattr_subsystem(c);
|
|
c->flags &= ~JFFS2_SB_FLAG_BUILDING;
|
|
|
|
dbg_fsbuild("FS build complete\n");
|
|
|
|
/* Rotate the lists by some number to ensure wear levelling */
|
|
jffs2_rotate_lists(c);
|
|
|
|
ret = 0;
|
|
|
|
exit:
|
|
if (ret) {
|
|
for_each_inode(i, c, ic) {
|
|
while(ic->scan_dents) {
|
|
fd = ic->scan_dents;
|
|
ic->scan_dents = fd->next;
|
|
jffs2_free_full_dirent(fd);
|
|
}
|
|
}
|
|
jffs2_clear_xattr_subsystem(c);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *c,
|
|
struct jffs2_inode_cache *ic,
|
|
struct jffs2_full_dirent **dead_fds)
|
|
{
|
|
struct jffs2_raw_node_ref *raw;
|
|
struct jffs2_full_dirent *fd;
|
|
|
|
dbg_fsbuild("removing ino #%u with nlink == zero.\n", ic->ino);
|
|
|
|
raw = ic->nodes;
|
|
while (raw != (void *)ic) {
|
|
struct jffs2_raw_node_ref *next = raw->next_in_ino;
|
|
dbg_fsbuild("obsoleting node at 0x%08x\n", ref_offset(raw));
|
|
jffs2_mark_node_obsolete(c, raw);
|
|
raw = next;
|
|
}
|
|
|
|
if (ic->scan_dents) {
|
|
int whinged = 0;
|
|
dbg_fsbuild("inode #%u was a directory which may have children...\n", ic->ino);
|
|
|
|
while(ic->scan_dents) {
|
|
struct jffs2_inode_cache *child_ic;
|
|
|
|
fd = ic->scan_dents;
|
|
ic->scan_dents = fd->next;
|
|
|
|
if (!fd->ino) {
|
|
/* It's a deletion dirent. Ignore it */
|
|
dbg_fsbuild("child \"%s\" is a deletion dirent, skipping...\n", fd->name);
|
|
jffs2_free_full_dirent(fd);
|
|
continue;
|
|
}
|
|
if (!whinged)
|
|
whinged = 1;
|
|
|
|
dbg_fsbuild("removing child \"%s\", ino #%u\n", fd->name, fd->ino);
|
|
|
|
child_ic = jffs2_get_ino_cache(c, fd->ino);
|
|
if (!child_ic) {
|
|
dbg_fsbuild("cannot remove child \"%s\", ino #%u, because it doesn't exist\n",
|
|
fd->name, fd->ino);
|
|
jffs2_free_full_dirent(fd);
|
|
continue;
|
|
}
|
|
|
|
/* Reduce nlink of the child. If it's now zero, stick it on the
|
|
dead_fds list to be cleaned up later. Else just free the fd */
|
|
child_ic->pino_nlink--;
|
|
|
|
if (!child_ic->pino_nlink) {
|
|
dbg_fsbuild("inode #%u (\"%s\") now has no links; adding to dead_fds list.\n",
|
|
fd->ino, fd->name);
|
|
fd->next = *dead_fds;
|
|
*dead_fds = fd;
|
|
} else {
|
|
dbg_fsbuild("inode #%u (\"%s\") has now got nlink %d. Ignoring.\n",
|
|
fd->ino, fd->name, child_ic->pino_nlink);
|
|
jffs2_free_full_dirent(fd);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
We don't delete the inocache from the hash list and free it yet.
|
|
The erase code will do that, when all the nodes are completely gone.
|
|
*/
|
|
}
|
|
|
|
static void jffs2_calc_trigger_levels(struct jffs2_sb_info *c)
|
|
{
|
|
uint32_t size;
|
|
|
|
/* Deletion should almost _always_ be allowed. We're fairly
|
|
buggered once we stop allowing people to delete stuff
|
|
because there's not enough free space... */
|
|
c->resv_blocks_deletion = 2;
|
|
|
|
/* Be conservative about how much space we need before we allow writes.
|
|
On top of that which is required for deletia, require an extra 2%
|
|
of the medium to be available, for overhead caused by nodes being
|
|
split across blocks, etc. */
|
|
|
|
size = c->flash_size / 50; /* 2% of flash size */
|
|
size += c->nr_blocks * 100; /* And 100 bytes per eraseblock */
|
|
size += c->sector_size - 1; /* ... and round up */
|
|
|
|
c->resv_blocks_write = c->resv_blocks_deletion + (size / c->sector_size);
|
|
|
|
/* When do we let the GC thread run in the background */
|
|
|
|
c->resv_blocks_gctrigger = c->resv_blocks_write + 1;
|
|
|
|
/* When do we allow garbage collection to merge nodes to make
|
|
long-term progress at the expense of short-term space exhaustion? */
|
|
c->resv_blocks_gcmerge = c->resv_blocks_deletion + 1;
|
|
|
|
/* When do we allow garbage collection to eat from bad blocks rather
|
|
than actually making progress? */
|
|
c->resv_blocks_gcbad = 0;//c->resv_blocks_deletion + 2;
|
|
|
|
/* What number of 'very dirty' eraseblocks do we allow before we
|
|
trigger the GC thread even if we don't _need_ the space. When we
|
|
can't mark nodes obsolete on the medium, the old dirty nodes cause
|
|
performance problems because we have to inspect and discard them. */
|
|
c->vdirty_blocks_gctrigger = c->resv_blocks_gctrigger;
|
|
if (jffs2_can_mark_obsolete(c))
|
|
c->vdirty_blocks_gctrigger *= 10;
|
|
|
|
/* If there's less than this amount of dirty space, don't bother
|
|
trying to GC to make more space. It'll be a fruitless task */
|
|
c->nospc_dirty_size = c->sector_size + (c->flash_size / 100);
|
|
|
|
dbg_fsbuild("trigger levels (size %d KiB, block size %d KiB, %d blocks)\n",
|
|
c->flash_size / 1024, c->sector_size / 1024, c->nr_blocks);
|
|
dbg_fsbuild("Blocks required to allow deletion: %d (%d KiB)\n",
|
|
c->resv_blocks_deletion, c->resv_blocks_deletion*c->sector_size/1024);
|
|
dbg_fsbuild("Blocks required to allow writes: %d (%d KiB)\n",
|
|
c->resv_blocks_write, c->resv_blocks_write*c->sector_size/1024);
|
|
dbg_fsbuild("Blocks required to quiesce GC thread: %d (%d KiB)\n",
|
|
c->resv_blocks_gctrigger, c->resv_blocks_gctrigger*c->sector_size/1024);
|
|
dbg_fsbuild("Blocks required to allow GC merges: %d (%d KiB)\n",
|
|
c->resv_blocks_gcmerge, c->resv_blocks_gcmerge*c->sector_size/1024);
|
|
dbg_fsbuild("Blocks required to GC bad blocks: %d (%d KiB)\n",
|
|
c->resv_blocks_gcbad, c->resv_blocks_gcbad*c->sector_size/1024);
|
|
dbg_fsbuild("Amount of dirty space required to GC: %d bytes\n",
|
|
c->nospc_dirty_size);
|
|
dbg_fsbuild("Very dirty blocks before GC triggered: %d\n",
|
|
c->vdirty_blocks_gctrigger);
|
|
}
|
|
|
|
int jffs2_do_mount_fs(struct jffs2_sb_info *c)
|
|
{
|
|
int ret;
|
|
int i;
|
|
int size;
|
|
|
|
c->free_size = c->flash_size;
|
|
c->nr_blocks = c->flash_size / c->sector_size;
|
|
size = sizeof(struct jffs2_eraseblock) * c->nr_blocks;
|
|
#ifndef __ECOS
|
|
if (jffs2_blocks_use_vmalloc(c))
|
|
c->blocks = vzalloc(size);
|
|
else
|
|
#endif
|
|
c->blocks = kzalloc(size, GFP_KERNEL);
|
|
if (!c->blocks)
|
|
return -ENOMEM;
|
|
|
|
for (i=0; i<c->nr_blocks; i++) {
|
|
INIT_LIST_HEAD(&c->blocks[i].list);
|
|
c->blocks[i].offset = i * c->sector_size;
|
|
c->blocks[i].free_size = c->sector_size;
|
|
}
|
|
|
|
INIT_LIST_HEAD(&c->clean_list);
|
|
INIT_LIST_HEAD(&c->very_dirty_list);
|
|
INIT_LIST_HEAD(&c->dirty_list);
|
|
INIT_LIST_HEAD(&c->erasable_list);
|
|
INIT_LIST_HEAD(&c->erasing_list);
|
|
INIT_LIST_HEAD(&c->erase_checking_list);
|
|
INIT_LIST_HEAD(&c->erase_pending_list);
|
|
INIT_LIST_HEAD(&c->erasable_pending_wbuf_list);
|
|
INIT_LIST_HEAD(&c->erase_complete_list);
|
|
INIT_LIST_HEAD(&c->free_list);
|
|
INIT_LIST_HEAD(&c->bad_list);
|
|
INIT_LIST_HEAD(&c->bad_used_list);
|
|
c->highest_ino = 1;
|
|
c->summary = NULL;
|
|
|
|
ret = jffs2_sum_init(c);
|
|
if (ret)
|
|
goto out_free;
|
|
|
|
if (jffs2_build_filesystem(c)) {
|
|
dbg_fsbuild("build_fs failed\n");
|
|
jffs2_free_ino_caches(c);
|
|
jffs2_free_raw_node_refs(c);
|
|
ret = -EIO;
|
|
goto out_sum_exit;
|
|
}
|
|
|
|
jffs2_calc_trigger_levels(c);
|
|
|
|
return 0;
|
|
|
|
out_sum_exit:
|
|
jffs2_sum_exit(c);
|
|
out_free:
|
|
kvfree(c->blocks);
|
|
|
|
return ret;
|
|
}
|