summaryrefslogtreecommitdiffstats
path: root/fs
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'for-next/misc'Sascha Hauer2024-03-151-0/+2
|\
| * of: partition: Also add partitions created by addpart to the boot dtbUwe Kleine-König2024-03-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A partition added interactively using addpart was added in of_partition_fixup() before commit aec676b568 ("cdev: record whether partition is parsed from OF"). Restore that behaviour. To do that a new flag DEVFS_PARTITION_FOR_FIXUP is created that behaves very similar what DEVFS_PARTITION_FROM_OF did before. The only difference is that addpart makes use of it (and that stat uses a different string to describe it). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.barebox.org/20240312100918.604105-1-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: efi: move definitions into headerAhmad Fatoum2024-03-051-59/+0
| | | | | | | | | | | | | | | | | | EFI loader support will require access to these same definitions, so move them into a header. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-78-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi: payload: suppress EFI payload initcalls when not EFI-loadedAhmad Fatoum2024-03-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | For development, it has proven very useful to be able to load the same barebox binary both as EFI loader and EFI payload and debug the interaction. For this to work, we need to mark all current EFI payload initcalls as such to avoid running them when barebox is not running as EFI payload. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-63-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi: don't hide structs, enums or unions behind _tAhmad Fatoum2024-03-051-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Kernel coding style is to usually not hide the fact that a type is a struct or enum behind a typedef. Follow that in the EFI code. Besides being more descriptive, this also allows forward declarations, so <efi.h> doesn't have to be included everywhere. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-53-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | filetype: have cdev_detect_type take a cdevAhmad Fatoum2024-03-051-3/+11
| | | | | | | | | | | | | | | | | | | | | | cdev_detect_type reads as if it would take a cdev argument, but instead it takes the adev's path. Fix it, so it takes a cdev and change the only user. A new user will be added later that will pass in an already open cdev. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-51-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: stat: add option for statatAhmad Fatoum2024-03-051-3/+2
| | | | | | | | | | | | | | | | | | The stat command is a debugging aid for developing the VFS, so it makes sense to add support for dirfd, so they can be tested interactively. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-44-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: support opening /Ahmad Fatoum2024-03-051-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | With open() on / no longer accessing uninitialized memory, it now always fails with errno == ENOENT. This is because d_lookup only compares children of /, but never / itself. Fix this by comparing the parent and while at it, rework the existing code to be more concise. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-42-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: initialize struct nameidata::lastAhmad Fatoum2024-03-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | The last member is normally written by link_path_walk(), before being read by __lookup_hash, among others. In the special case of calling open() on "/", link_path_walk() will terminate early without setting the last member, leading __d_alloc called by __lookup_hash to read uninitialized memory. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-41-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: introduce new findmnt commandAhmad Fatoum2024-03-051-3/+1
| | | | | | | | | | | | | | | | | | | | EFI loader support will need to map barebox VFS paths to fs_device and back. Make development easier by providing a findmnt command to test the mapping. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-40-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement O_CHROOTAhmad Fatoum2024-03-051-2/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For use by EFI file system path resolution, implement an O_CHROOT flag that will map / to the root of the file system the dirfd points to instead of the VFS root. If the dirfd points to a mountpoint, it will be followed to the file system inside. This is similar to Linux openat2 with RESOLVE_IN_ROOT. Without this, the EFI protocol would have to do path sanitization itself before passing paths to the barebox VFS implementation. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-39-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: support different root directoriesAhmad Fatoum2024-03-051-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | A root directory is a directory that has itself as the parent. There is only one such directory, but for chroot support we will want to stop path resolution at a non-root directory as well. We do this by giving struct nameidata a d_root field, which serves as a root directory for the lookup. As we initialize it to the global root directory, this introduces no functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-38-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement O_PATHAhmad Fatoum2024-03-051-24/+34
| | | | | | | | | | | | | | | | | | | | For use with the newly added openat and friends API, add O_PATH file descriptors that are not usable for doing actual I/O, but only for use as dirfd. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-37-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement openat and friendsAhmad Fatoum2024-03-051-60/+80
| | | | | | | | | | | | | | | | | | | | | | | | The EFI file system API takes as handle an arbitrary file within the volume. Directory iteration should happen relative to that file, which lends itself well to mapping this to openat and friends. Add support for these to barebox in preparation. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-36-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: set current working dir directly when mounting rootAhmad Fatoum2024-03-051-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The default current working directory is the root directory, but this can't be initialized statically, because the root directory is only mounted at runtime. Therefore, the get_pwd accessor initializes the current working directory on first access. Instead we could just initialize them when we mount the root directory and simplify the code a tiny bit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-35-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: always check path_init for errorsAhmad Fatoum2024-03-051-0/+4
| | | | | | | | | | | | | | | | | | | | | | We have three calls to path_init, but Only one of them checks the returned pointer value for errors. This didn't hurt so far, because the function always succeeded, but a follow-up commit will cause it to fail in some circumstances, so prepare for that by duly checking the return value. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-34-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: remove unused member from struct nameidataAhmad Fatoum2024-03-051-9/+0
| | | | | | | | | | | | | | | | | | A number of members in the struct are either unused or only ever written and never read. Drop them to tidy up the code. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-33-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement fdopendir and rewinddirAhmad Fatoum2024-03-051-2/+53
| | | | | | | | | | | | | | | | | | | | | | | | We will be using the incoming O_PATH support to implement the EFI file system protocol for when barebox acts as EFI loader. The protocol also requires being able to rewind iteration, so add support for that too. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-32-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: factor out opendir iterationAhmad Fatoum2024-03-051-20/+32
| | | | | | | | | | | | | | | | | | In preparation for supporting fdopendir and rewinddir, add an __opendir helper that is reused in a follow-up commit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-31-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: opendir: reference mount point until closedir is calledAhmad Fatoum2024-03-051-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | We currently don't keep the path used for opendir alive beyond the function, because all files are read and added into a linked list at once. If an unmount happens before closedir though, the file names will become invalidated, which shouldn't happen. Keep the path alive for longer to block unmount until directory iteration is over. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-30-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: drop unused LOOKUP_ flagsAhmad Fatoum2024-03-051-10/+1
| | | | | | | | | | | | | | | | | | Most flags used during VFS lookup are apparently unused, so let's delete them to make the code easier to reason about. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-29-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: turn creat into static inline helperAhmad Fatoum2024-03-051-6/+0
| | | | | | | | | | | | | | | | | | creat is a oneliner that can be inlined at no extra cost, so move it into a header. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-28-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: fix unreaddir, so readdir returns unread dirent firstAhmad Fatoum2024-03-051-1/+1
| | | | | | | | | | | | | | | | | | | | unreaddir should return a directory entry at the top of the list, so readdir consumes it again, not at the end. Fixes: 7876018f7333 ("fs: implement unreaddir") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-27-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: stat: display bootable partition table bit infoAhmad Fatoum2024-03-051-0/+4
| | | | | | | | | | | | | | | | | | | | There's no common code yet, but board code may iterate over cdevs to handle the boot partition specially. Make writing such code easier by adding the new flags to the stat command's output. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-23-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: stat: print DT node for cdevs if availableAhmad Fatoum2024-03-051-0/+5
| | | | | | | | | | | | | | | | | | It may not be directly apparent, what device a cdev spawned from. Have stat report this information for debugging purposes. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-21-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | cdev: implement setter/getter for cdev device nodeAhmad Fatoum2024-03-052-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | A cdev has two device tree node pointers, one directly at struct cdev.device_node and another indirectly via cdev.dev->device_node. We may want to remove cdev::device_node in future, but till then to avoid users having to guess, which device_node is the correct one, add a helper to set and get the device tree node. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-19-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOADAhmad Fatoum2024-03-051-2/+2
| | | | | | | | | | | | | | | | | | | | The symbol is internal, so we don't break anything by renaming it. CONFIG_EFI_PAYLOAD is clearer in intent, as BOOTUP doesn't clearly indificate whether barebox would act as EFI payload or as EFI loader. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-9-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | treewide: add errno_set helper for returning positive error code in errnoAhmad Fatoum2024-03-051-84/+28
|/ | | | | | | | | | | We have this sequence at multiple places: Check a return value for being below zero and if so, turn it positive and store into errno. Instead of opencoding it everywhere, add a helper to encapsulate this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: move cdev open count to cdev_open()/cdev_close()Sascha Hauer2024-02-162-6/+11
| | | | | | | | | | All code opening a cdev goes through cdev_open(), so open counting must be done there and not in devfs_open() which itself only calls cdev_open(). Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20240215074757.960200-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2024-01-232-22/+28
|\
| * uImage: use IS_ENABLED(CONFIG_TIMESTAMP)Antony Pavlov2024-01-111-14/+10
| | | | | | | | | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Link: https://lore.barebox.org/20240103170725.846378-2-antonynpavlov@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * cdev: add cdev_alloc helper for creating cdevsAhmad Fatoum2024-01-111-6/+15
| | | | | | | | | | | | | | | | | | | | | | | | We have different helpers for creating cdevs, depending on whether they are loop devices, partitions or links. Create a common cdev_alloc function, so it's easier to instrument cdev creation during debugging. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103102035.2630735-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * cdev: simplify loop in cdev_by_device_nodeAhmad Fatoum2024-01-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We don't need to compare the cdev's device node pointer both against NULL and against the searched for device node on each iteration. Instead, it's sufficient to just compare the device nodes directly. To maintain previous behavior, when searching for a NULL device node, we shouldn't return the first cdev, but return NULL. Do that via an early exit instead of doing it after iterating over all cdevs. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103102035.2630735-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | cdev: delete partitions when deleting master cdevAhmad Fatoum2024-01-081-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | blockdevice_unregister only calls devfs_remove on the root cdev and leaves the partition cdevs dangling. This doesn't break until the block device parent struct device is freed at which time, it will iterate over its cdevs to free them. If there's partitions there, list_del on the partitions triggers a use after free. Fix this by removing partitions whenever the master cdev is deleted. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103101629.2629497-7-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | cdev: export and use cdevfs_del_partitionAhmad Fatoum2024-01-081-8/+15
| | | | | | | | | | | | | | | | | | | | | | Like what's the case with cdevfs_add_partition, a couple of users already have a cdev, so it's wasteful to get its name and do a lookup only to arrive at the same cdev. Export a cdevfs_del_partition that directly works on the cdev and start using it instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103101629.2629497-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | cdev: export cdevfs_add_partition for general useAhmad Fatoum2024-01-081-1/+7
| | | | | | | | | | | | | | | | | | | | | | __devfs_add_partition was added, so it can internally be used by functions that already have a cdev and don't require looking it up first by file path. This is useful elsewhere as well, so create an exported wrapper around it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103101629.2629497-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | cdev: make __devfs_add_partition's last argument optionalAhmad Fatoum2024-01-081-6/+8
|/ | | | | | | | | | Follow-up commit will expose __devfs_add_partition after rename to more users. Most of these don't care about the last parameter, so accept NULL to indicate that it won't be read back. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103101629.2629497-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: add open O_TMPFILE supportAhmad Fatoum2023-12-131-0/+29
| | | | | | | | | | | | | | | | | | | | | | barebox dentry cache is never cleared with the assumption that there should be enough RAM anyway to cache all lookups until boot. When fuzzing barebox however, there is no limit to how many dentries are added to the cache. This is e.g. problematic when fuzzing the FIT parser: FIT images can have compressed payloads. Compressed payloads are passed to uncompress_buf_to_buf, which uses a new random file in ramfs as destination. A fuzzer would thus create a dentry for every iteration, rapidly depleting memory. A general solution for that would be dropping the dentry cache on memory pressure. In the special case of uncompress_buf_to_buf, it would already be enough though to sidestep the dentry cache and create an anonymous file. Linux provides this with the O_TMPFILE option, so let's add the equivalent to barebox. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122170323.15175-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: check for valid flags before removing a partitionSascha Hauer2023-10-121-5/+5
| | | | | | | | When a partition is a mtd device then it is removed before checking if the cdev actually a partition. move the call to mtd_del_partition() further down to a point where we know the operation is valid. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2023-09-251-1/+1
|\
| * fs: fat: enable VFAT long file names by defaultAhmad Fatoum2023-09-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Apparently, this option defaulted to 'n' since the very beginning, so users newly enabling FAT may unwittingly run into a cryptic: barebox@board:/ cp something /mnt/mmc0.0/freertos-main.elf could not open /mnt/mmc0.0/freertos-main.elf: Invalid argument As FAT file systems nowadays are VFAT by default and allow up to 255 characters in file names, there's no reason to restrict barebox to classic 8.3 file names by default. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230913103552.1644839-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: ext4: initialize variable to silence GCC false-positiveAhmad Fatoum2023-09-121-1/+1
|/ | | | | | | | | | GCC complains about ino not being defined in some cases, which appears to be a false positive. Nevertheless, initialize it to the same fallback value used in ext4fs_get_ino, which is called below. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230911122504.2720431-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* filetype: return error and pass filetype as pointer argumentSascha Hauer2023-08-181-3/+4
| | | | | | | | | | | | | | | | | file_name_detect_type(), file_name_detect_type_offset() and cdev_detect_type() return the filetype. With this all errors from these functions remain undetected and are just returned as filetype_unknown. Explicitly return an error code and pass the filetype as pointer argument so that callers can detect and handle errors. This fixes a bug in the bootm code where the returned filetype was erroneously tested for being smaller than 0. This was never true and so the corresponding error message was never printed. Now with this patch a non existing initrd or device tree file is responded with a meaningful error message. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/state'Sascha Hauer2023-06-222-26/+74
|\
| * common: partitions: efi: record type UUID in cdevAhmad Fatoum2023-06-121-0/+2
| | | | | | | | | | | | | | | | | | | | We already record DOS partition type in cdev, so let's do the same for GPT Type UUID. This will be used in a later commit to identify barebox-state partitions. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-19-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * cdev: use cdev::dos_partition_type only if cdev_is_mbr_partitionedAhmad Fatoum2023-06-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | dos_partition_type == 0 can mean that either a partition is not a MBR partition or that it indeed has a partition type of 0x00. In preparation for using that field in a union, explicitly check if we have a MBR partition. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-18-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * common: partitions: record whether disk is GPT or MBR partitionedAhmad Fatoum2023-06-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the only way to differentiate between a GPT disk and a MBR one is to check whether the cdev's device has a guid (=> GPT) or a nt_signature (=> MBR) device parameter. We already have a flag parameter though, so let's record this info there for easy retrieval. We intentionally don't use the struct cdev::filetype member, because we don't want to change behavior of file_detect_type(). Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-14-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * cdev: have devfs_add_partition return existing identical partition, not NULLAhmad Fatoum2023-06-081-11/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Starting with commit 7f9f45b9bfef ("devfs: Do not create overlapping partitions"), any overlapping is disallowed. Overlapping can be useful though to bridge the gap between partition described in DT and via on-disk partition tables. Let's handle the case of identical partitions specially and have it neither be an error or a duplicate partition, but instead just return the existing partition and create a cdev link to it if the name differs. This existing partition will be given a device tree node and thus enabling schemes like: &{/state} { backend = <&state_part>; }; &mmc1 { partitions { compatible = "fixed-partitions"; #address-cells = <2>; #size-cells = <2>; state_part: partition@5300000 { label = "barebox-state"; /* will be folded with overlapping GPT partition if found */ reg = <0x0 0x5300000 0x0 0x100000>; }; }; }; Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-12-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * cdev: record whether partition is parsed from OFAhmad Fatoum2023-06-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Later code will make it possible to define an on-disk-described partition in the DT as well. For this reason, we can't assume DEVFS_PARTITION_FROM_TABLE to mean !DT, so let's add a dedicated flag for that. Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-11-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * cdev: use more descriptive struct cdev::diskuuid/partuuidAhmad Fatoum2023-06-082-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The UUID field has different meanings: For a master cdev: - GPT Header DiskGUID if GPT-formatted - MBR Header NT Disk Signature if MBR-formatted For a partition cdev: - GPT UniquePartitionGUID - MBR Header NT Disk Signature followed by "-${partititon_number}" Later code will add yet another UUID (Partition Type GUID), so let's make existing code more readable by using either diskuuid or partuuid as appropriate. No functional change. Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-10-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>