summaryrefslogtreecommitdiffstats
path: root/fs
Commit message (Collapse)AuthorAgeFilesLines
* include: add dedicated header for printf/printkAhmad Fatoum2021-11-013-3/+3
| | | | | | | | | | | | Including <stdio.h> for printf is a bit problematic, because it pulls in other headers for <console.h>, which includes quite a few more headers as well. To make it easier to share code between barebox and host tools make <printk.h> the new minimal header for printf and move the extra logging stuff into <linux/printk.h>. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211030141739.2207431-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: ramfs: drop free of unused dev->privAhmad Fatoum2021-11-011-1/+0
| | | | | | | | | This probably was a benign free(NULL) so far, but it serves no point, so drop it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211030141707.2207152-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: Do not create overlapping partitionsSascha Hauer2021-10-121-0/+34
| | | | | | | | | | | | | | | Until now it has been possible to create overlapping partitions. Go away from that and allow to create partitions only in unallocated areas of a device. This lowers the risk of having inconsistent partitioning and increases the chance that inconsistent partitioning is recognized by the user. We had explicit overlap checking for the environment partition which becomes unnecessary with this change and is removed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20211011073025.4187545-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: remove unused struct fs_device_d::parent_deviceAhmad Fatoum2021-10-051-1/+0
| | | | | | | | The parent_device member is unused anywhere, so drop it. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.barebox.org/20210913083019.364599-1-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/nvmem'Sascha Hauer2021-07-181-1/+1
|\
| * nvmem: add support for new read-only memory (rmem) bindingAhmad Fatoum2021-06-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Only upstream user of this binding is the raspberry pi 4 DT, where it's used to pass along bootloader-provided info to Linux. We have instances in barebox, where a previous stage bootloader passes along a memory region with info for barebox to interpret. This could in future be modelled as nvmem-rmem nodes. The binding is also quite handy for debugging. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210619034516.6737-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: fix NULL pointer dereference of fsdrv->truncate for read-only FSAhmad Fatoum2021-07-091-6/+10
|/ | | | | | | | | | | | | | fsdrv->truncate is dereferenced at times without checking for NULL before, leading to crashes, e.g. doing: edit -o /mnt/myext4/FILE some text on ext4 crashes. Fix this by returning -EROFS when truncate is unimplemented. Reported-by: Xogium <contact@xogium.me> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.barebox.org/20210707065251.760827-1-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: nfs: Start earlier to resend requestsUwe Kleine-König2021-06-111-2/+2
| | | | | | | | | | | | | | | | | | | | On a customer site we're experience a bit over 1% UDP packet loss. When wiresharking an NFS transfer of a kernel image (with the goal to boot via NFS) I saw 64 of 2555 RPC calls staying unanswered. With the current timeout setting each of them introduces a delay of 2 seconds and the whole transfer takes 137s. With the timeout reduced to 0.1s the transfer time is not optimal (going down to approx 15 seconds) but at least it becomes bearable. To still cope with a slow network (in contrast to an unreliable as pictured above) increase NFS_MAX_RESEND to keep NFS_TIMEOUT * NFS_MAX_RESEND (which defines the overall timeout before aborting the transfer) constant. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Acked-by: Gavin Schenk <g.schenk@eckelmann.de> Link: https://lore.barebox.org/20210611071351.1445370-1-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/usb-gadget'Sascha Hauer2021-05-171-3/+3
|\
| * fs: error out when writing on read-only file systemAhmad Fatoum2021-05-121-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On an ext4 partition, Running echo -a /mnt/disk0.0/file test will crash barebox because fsdrv->truncate in __write is NULL. Don't let it come to this and verify earlier that the FS implements ->write. While at it, explicitly compare with O_RDONLY (== 0) for clarity. Fixes: b3fbfad7aeaf ("fs: dentry cache implementation") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-17-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2021-05-171-1/+1
|\ \
| * | fs: nfs: Fix readlink max size checkSascha Hauer2021-05-121-1/+1
| |/ | | | | | | | | | | | | | | | | | | We must at maximum use all remaining bytes from the packet. This means we have to set length to the *minimum* of the desired length and the remaining bytes, not the *maximum*. /me goes hiding somewhere... Fixes: 574ce99401 ("fs: nfs: Fix possible buffer overflow") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/mci'Sascha Hauer2021-05-171-4/+39
|\ \
| * | fs: add linux_rootarg 'root=mmcblkXpN' supportMarco Felsch2021-05-121-4/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit fa2d0aa96941 ("mmc: core: Allow setting slot index via device tree alias") the linux kernel supports stable mmc device names. Barebox has stable names since years so now we can connect both which allows us to pass 'root=mmcblkXpN' as argument for the cmdline. Note: it is crucial that the kernel device tree and the barebox device tree uses the same mmc aliases. This patch adds the support to store the above cmdline as linux_rootarg if enabled. The partuuid is now used as fallback since it is not as unique as the mmcblkXpN scheme. It is added as build option since the system integrator needs to check if the used kernel contains the above commit. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20210510102523.7147-3-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | fs: check getname() return value in open()Sascha Hauer2021-05-071-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | getname() can return an error when for example the input path is an empty string. Check the getname() return value in open() before further using it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | fs: check for valid name in filename_lookup()Sascha Hauer2021-05-071-0/+3
| | | | | | | | | | | | | | | | | | | | | The getname() return value is passed to filename_lookup() without checking the return value, so this must be done in filename_lookup(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | fs: check for empty name in getname()Sascha Hauer2021-05-071-2/+5
|/ / | | | | | | | | | | | | getname() should return an error for an empty path. While at it, change getname() to return an error pointer. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / fs: Fix link_path_walk to return -ENOENT on empty pathJules Maselbas2021-05-031-0/+2
|/ | | | | | | | | | | | | | | link_path_walk was returning 0 when passed with an empty path, this lead calling code to assume that the struct nameidata nd is valid and thus has a `last` field populated, which is not. In the end causing a runtime crash. This issue can easily be reproduced by running the command: cat "" Reported-by: Neeraj Pal <neerajpal09@gmail.com> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Link: https://lore.barebox.org/20210417233409.637-1-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: ext4: fix bogus behavior on failure to read ext4 blockAhmad Fatoum2021-03-291-4/+4
| | | | | | | | | | | | | | The conversion of blknr from a signed 32-bit to an unsigned 64-type resulted in the check for error to never return true. Fix this. Affected configuration would behave incorrectly when served with invalid blocks. Instead of aborting and having the filesystem bubble up an error code, it would return invalid data. As there is no ext4 write support, this wouldn't lead to ext4 data corruption however. Reported-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2021-03-231-10/+19
|\
| * fs: Fix default mount when device already mountedStefan Riedmueller2021-03-171-9/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Let cdev_mount_default return an error in case the device is already mounted to a different location than the default mount point. Otherwise the automount routine can get stuck in an infinite loop spamming: mounted /dev/mmc0.0 on /mnt/mmc mounted /dev/mmc0.0 on /mnt/mmc mounted /dev/mmc0.0 on /mnt/mmc Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * fs: delete unused members in <linux/stat.h>Ahmad Fatoum2021-03-161-1/+0
| | | | | | | | | | | | | | | | Most of the struct is stuff we don't use and likely won't any time soon. Drop them. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: ubifs: remove unused variableSascha Hauer2021-03-121-2/+0
|/ | | | | | 'current' is unused. Remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2021-02-221-6/+36
|\
| * fs: increase reference count for backing store when loop mountingAhmad Fatoum2021-02-161-6/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The VFS layer already increase the mount reference count for the mount point. This means e.g. following sequence is well-behaving: mkdir -p /mnt/disk0.0/media mount -o loop backing.squashfs /mnt/disk0.0/media umount /mnt/disk0.0 barebox will do the right thing and report umount: Device or resource busy However the reference count of the file where backing.squashfs comes from is not incremented on mount with the effect that following sequence crashes: mkdir -p /media mount -o loop /mnt/disk0.0/backing.squashfs /media umount /mnt/disk0.0 # should've returned EBUSY umount /media Fix this by touching the backing store's mount reference count when loop mounting and unmounting. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/ext4'Sascha Hauer2021-02-226-63/+49
|\ \
| * | fs: ext4: support files exceeding 4GAhmad Fatoum2021-02-183-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ext4 redefines directory ACL to hold the most-significant 32-bit of the inode size for regular files. For directories, it can either be ACL or, when using largedir, the most-significant 32-bit of the directory size. Adapt the code take these upper 32-bit into consideration for determining regular file size. For directories, behavior remains unchanged as we neither support ACLs nor >= 4G directories Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | fs: ext4: use sector_t and loff_t where appropriateAhmad Fatoum2021-02-185-31/+38
| | | | | | | | | | | | | | | | | | | | | | | | While the block API now supports 64-bit LBAs, file systems like ext4 still use 31- and 32-bit integers at a couple of places. Fix them up. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | fs: ext4: ext4fs.h: remove unused struct members of ext_filesystemAhmad Fatoum2021-02-181-29/+0
| | | | | | | | | | | | | | | | | | | | | | | | struct ext_filesystem is for in-memory bookkeeping but most of it is unused by barebox and just takes up space. Drop the unused members. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | ext4: ext_common.h: drop declaration of never-defined part_offsetAhmad Fatoum2021-02-181-1/+0
| |/ | | | | | | | | | | | | | | part_offset is a left-over from the U-Boot port and unused anywhere. Drop it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / printk: port over Linux print_hex_dump_bytes/print_hex_dump_debugAhmad Fatoum2021-02-041-1/+1
|/ | | | | | | | | print_hex_dump in barebox always prints a hex dump. Most users use it for debugging though, so import Linux helpers to do so to cut down on the #ifdef DEBUG. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2020-12-111-1/+1
|\
| * fs: introduce unsetenv() to prepare for changing setenv(var, "") behaviorAhmad Fatoum2020-11-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, we treat setenv(var, "") and setenv(var, NULL) the same and delete var, which is surprising and leads to subtle quirks: - setenv(var, "") is specified by POSIX to set var to an empty string, but barebox uses it to delete variables - nv.user= calls nv_set with NULL parameter, but nv user="" doesn't Make the API more POSIX-like by providing unsetenv with the expected semantics. Most user code can then use unsetenv without worrying about whether "" or NULL is the magic deletion value. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | ubifs: remove wrong assertionSascha Hauer2020-12-101-1/+6
|/ | | | | | | | | | | In barebox copy_znode() doesn't make a copy of the znode, We are limited to readonly support, so copy_znode() returns the original node. tnc_delete() expects a znode to be dirty and has an assertion for this. In a normal r/w implementation this is correct, but not in barebox, so drop the assertion. Instead of removing it just comment it out to make sure it won't be added again with the next ubifs kernel synchronisation. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nfs: check return value of various rpc callsUwe Kleine-König2020-11-091-11/+113
| | | | | | | | | | | | | | | Check more carefully for failing requests. This improves the error message when trying to mount a non-exported nfs directory from: nfs_mount_req: file handle too big: 44831 to ERROR: NFS: Mounting failed: Permission denied . This also fixes an out-of-bounds access as the filehandle size (44831 above) is read from just after the network packet in the error case. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/percent_pe' into masterSascha Hauer2020-10-141-2/+1
|\
| * vsprintf: retire strerrorp in favor of %peAhmad Fatoum2020-09-291-2/+1
| | | | | | | | | | | | | | | | | | strerrorp() is only used along with printf. We now have a format specifier for printing error pointers directly, so use that and remove strerrorp. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/magicvar-unique-id' into masterSascha Hauer2020-10-141-5/+4
|\ \
| * | magicvar: Replace BAREBOX_MAGICVAR_NAMED with BAREBOX_MAGICVARSascha Hauer2020-10-021-5/+4
| |/ | | | | | | | | | | | | | | BAREBOX_MAGICVAR now generates a unique identifier automatically, so we can convert users of BAREBOX_MAGICVAR_NAMED to the simpler BAREBOX_MAGICVAR macro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / fs: squashfs: remove dead stores for xattr_idAhmad Fatoum2020-10-021-6/+0
|/ | | | | | | | | barebox doesn't do extended attributes in SquashFS. Remove the left-over xattr_id that's never read. Reported-by: clang-analyzer-10 Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/net' into masterSascha Hauer2020-09-251-0/+34
|\
| * fs: Warn when filesystem operations are called from a pollerSascha Hauer2020-08-191-0/+34
| | | | | | | | | | | | | | | | | | Filesystem operations possibly call into arbitrary devices, so shouldn't be used from a poller. This patch sprinkles some WARN_ONCE() when this happens. One exception is when the file which is accessed is on ramfs which doesn't have any dependencies to devices. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: Fix use after freeSascha Hauer2020-09-141-3/+3
| | | | | | | | | | | | | | | | | | | | In case of the fs mounted to '/' the root dentry of the mounted filesystem is the place where it's mounted itself, so sb->s_root is the same as fsdev->vfsmount.mountpoint. In that case make sure we only access it before it has been killed in dentry_delete_subtree(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: Drop unnecessary dput()Sascha Hauer2020-09-141-1/+0
| | | | | | | | | | | | | | Calling dput() on the root dentry during unmount time is unnecessary, the dentry will be removed later in dentry_delete_subtree() anyway. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: don't free device in remove callbackAhmad Fatoum2020-09-141-2/+9
| | | | | | | | | | | | | | | | | | | | | | The probe doesn't allocate the device, so remove shouldn't free it either. This fixes a use-after-free on barebox shutdown: Iterating over the list of devices requires that remove callbacks don't remove the devices. This happened to work so far, because apparently not much new allocations are going on during barebox shutdown, but let's do it right. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
* | fs: Use iget_locked() rather than squashfs specific functionSascha Hauer2020-08-202-18/+1
| | | | | | | | | | | | | | | | | | | | | | | | Use iget_locked() to let the core allocate the inode. This properly initializes all fields in the new inode, especially it adds the new inode to the list of all inodes for the filesystem. This prevents a NULL pointer derefence when iput() removes the inode from that list. This fixes squashfs support which is broken since 43902e5763 ("fs: free inodes we no longer need") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: squashfs: Do not free root inodeSascha Hauer2020-08-201-1/+0
| | | | | | | | | | | | | | With inode reference counting in place the core will free the root inode, so do not free it in the squashfs code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: squashfs: set s_op in timeSascha Hauer2020-08-201-2/+1
|/ | | | | | | When calling squashfs_mount() s_op needs to be set already, otherwise calling alloc_inode() yields in a NULL pointer derefence. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/ramfs'Sascha Hauer2020-07-276-164/+228
|\
| * fs: ramfs: Implement memmapSascha Hauer2020-07-051-0/+20
| | | | | | | | | | | | | | When an inode only has a single chunk then we can support memmap for it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>