summaryrefslogtreecommitdiffstats
path: root/fs/fs.c
Commit message (Collapse)AuthorAgeFilesLines
* fs: Don't bother filesystems without link support with additional stat() callsSascha Hauer2017-09-061-0/+10
| | | | | | | | | | | | | In __canonicalize_path() we only call stat() to know if the path is a link or not. When the filesystem doesn't support links we already know that it's not a link, so we do not need to call stat(). This helps the tftp filesystem since the parent directories of a file to be opened won't be stat()ed anymore, something tftp does not support. Fixes: a602bebc fs: Implement links to directories Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: avoid pathes with '//' in __canonicalize_path()Sascha Hauer2017-09-061-2/+7
| | | | | | | | | In __canonicalize_path pathes beginning with '//' can occur. This is normally not a problem since normalize_path() will clean this up, but it means we cannot call get_fsdevice_by_path() on these pathes in this function, as needed in the next patch. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Make locally used function canonicalize_dir() staticSascha Hauer2017-06-271-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2017-06-141-4/+32
|\
| * fs: add cdev_create_loop and cdev_remove_loop for loop mount optionPhilipp Zabel2017-06-061-4/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow to create a loopback cdev from a file. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Fixed up with: fs: Makefile: Add parseopt to all builds parseopt.h was included to fs.c with commit 9248b, but parseopt.o has a dependency to CONFIG_FS_NFS. Moved parseopt.o to the default build to eliminate build failures. Signed-off-by: Daniel Schultz <d.schultz@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * fs: Create automount entries for the default mount pathesSascha Hauer2017-05-101-0/+14
| | | | | | | | | | | | | | | | | | | | In barebox the default mount path for a cdev is /mnt/<cdevname> which can be mounted with "mount <cdevname>" without specifying a target path explicitly. Simplify this further by creating automount entries for the default mount pathes which makes a manual mount completely unnecessary. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fixup! fs: Implement links to directoriesSascha Hauer2017-05-111-2/+2
| |
* | fs: Implement links to directoriesSascha Hauer2017-05-111-118/+169
| | | | | | | | | | | | | | | | | | | | | | | | So far links can only point to files. Implement links to directories. With this all kinds of links are supported: - relative links - absolute links - links including ".." - link loops (are detected, return -EMLINK) Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: drop path_check_prereq()Sascha Hauer2017-05-111-65/+48
|/ | | | | | | | | | | | | | | | | path_check_prereq() has some bugs: - It's called with S_IFLNK, but this is effectively a no-op because this case is not implemented in the function - It uses lstat, but if stat or lstat should be used depends on the usecase: For opendir() stat() must be used, since we are not interested in the link, but in the target. For readlink() lstat() must be used since we are indeed interested in the link, not the target. It's easier and better understandable to open code the functionality where it's needed, so drop path_check_prereq() and do the right thing where called. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* lseek: tighten error checking and allow negative offsets for SEEK_ENDUwe Kleine-König2017-03-031-2/+4
| | | | | Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* lseek: ensure errno is set on failure and return -1Uwe Kleine-König2017-03-021-1/+7
| | | | | | | | All error paths before calling the driver's lseek callback return -1 and set errno. Do the same if the callback returns an error. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Remove O_TRUNC check for devices when open filesTeresa Remmet2017-01-111-1/+1
| | | | | | | | Don't check for the file type here. Devices may have truncate callbacks. Otherwise the caller should check if O_TRUNC is possible. Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Check for correct open modeSascha Hauer2016-07-221-1/+11
| | | | | | | Check that readonly openen files is not written to and writeonly files is not read from. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/include-cleanup'Sascha Hauer2016-05-091-3/+6
|\
| * move make_directory declaration to libfile.hSascha Hauer2016-04-151-0/+1
| | | | | | | | | | | | | | As a utility function for file handling make_directory() is well suited for libfile. Move it there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * string: Fix (v)asprintf prototypesSascha Hauer2016-04-151-3/+4
| | | | | | | | | | | | | | | | | | | | Our asprintf and vasprintf have different prototypes than the glibc functions. This causes trouble when we want to share barebox code with userspace code. Change the prototypes for (v)asprintf to match the glibc prototypes. Since the current (v)asprintf are convenient to use change the existing functions to b(v)asprintf. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * include: move run_command prototype to command.hSascha Hauer2016-04-151-0/+1
| | | | | | | | | | | | run_command fits much better into command.h, move it there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fix erasing/protecting flashes with unspecified sizeSascha Hauer2016-04-191-1/+3
|/ | | | | | | | | | | | | | | | | fixes: 81737c1 mtd: Fix erasing of devices >4GiB Several places erased a complete flash partition passing ~0 as count to erase(). With the above commit count to erase was changed from an unsigned type to a signed type, so the (count > f->size - offset) check in erase() no longer triggers and the ~0 count is no longer adjusted to the whole device size. Among other things this results in saveenv failures on NOR flashes. This patch fixes this by introducing an explicit macro for erasing the whole device which is tested for in erase(). All other negative values are rejected. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reported-by: Giorgio <giorgio.nicole@arcor.de>
* fs: umount based on device path and mount pathMarkus Pargmann2016-04-081-3/+45
| | | | | | | umount on Linux can be used on a mount pathes and device pathes. This patch adds this functionality to barebox. Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
* mtd: Fix erasing of devices >4GiBSascha Hauer2016-02-091-1/+1
| | | | | | | | | When a device >4GiB is erased, not only the offset can be bigger than 4GiB, but also the size. This happens with the simplest command to erase a device: erase /dev/nand0. Make the size argument a 64bit type to make this work. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: automount: Make automountpoints persistentSascha Hauer2016-01-081-3/+4
| | | | | | | Do not remove the automountpoints when they are mounted. This way they can be reused when they have been unmounted. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: pass path directly to cdev_openSascha Hauer2015-10-151-6/+1
| | | | | | | Now that cdev_open handles a path we no longer have to add /dev/ to the name. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* filetype: Use cdev_openSascha Hauer2015-10-151-2/+0
| | | | | | | a cdev has to be opened before usage. Use cdev_open instead of cdev_by_name. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Fix filesystem detection with full pathPeter Mamonov2015-10-131-1/+5
| | | | | | | | | | | | | When mount is given a full path (including /dev/) to the cdev file we can no longer automatically detect the filesystem. This is broken since: e89f1a1 detect_fs: use device instead of file Fix it by dropping the /dev/ component of the path. Signed-off-by: Peter Mamonov <pmamonov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* detect_fs: use device instead of fileVicente Bergas2015-10-021-1/+1
| | | | | | | | detect_fs would usually mount a device on a directory, so, use a device-specific type detection. Signed-off-by: Vicente Bergas <vicencb@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Add device parameter for Linux root= optionSascha Hauer2015-06-181-0/+37
| | | | | | | | | | When registering a filesystem device add a device parameter suitable for the Linux root= option to boot from exactly this filesystem. Currently the fs layer sets this parameter to the root=PARTUUID= mechanism if a partuuid is available. Other filesystems like NFS and UBIFS which do not have a PARTUUID can overwrite this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2015-06-091-8/+5
|\
| * mem: Fix memcpy_sz variable typesSascha Hauer2015-05-151-8/+5
| | | | | | | | | | | | | | | | - Drop usage of 'ulong', use unsigned long - remove unnecessary intermediate casting to unsigned long - Use proper u8/u16/u32 types. Fixes 64bit systems on which ulong is 64bit Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: Add O_RWSIZE_8Sascha Hauer2015-05-281-0/+3
|/ | | | | | To support native 64bit accesses in memcpy_sz. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: make "offset" parameter of erase() and protect() 64 bit safeMarc Kleine-Budde2015-03-031-2/+2
| | | | | Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: implement fstatSascha Hauer2014-10-081-0/+16
| | | | | | | fstat is useful to get information about an already opened file. Add it to barebox. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Store the path in struct filepSascha Hauer2014-10-081-0/+5
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: do not lookup global FILE * when the file is already availableSascha Hauer2014-10-081-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: store pointer to fsdev instead of dev in struct filepSascha Hauer2014-10-081-48/+27
| | | | | | | | The struct device_d * in struct filep is never of interest, instead it is always converted to a struct fs_device_d *, so simplify the code by storing the struct fs_device_d * directly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* move file helper functions to separate fileSascha Hauer2014-08-071-72/+0
| | | | | | | | | | We have our file helper functions in several places. Move them all to lib/libfile.c. With this we no longer have file helpers in fs/fs.c which contains the core fs functions and no functions in lib/libbb.c which are not from busybox. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* automount: check for recursive automountSascha Hauer2014-07-031-1/+9
| | | | | | | | | | | | | automount_mount calls run_command which may trigger an automount again. This results in an endless loop. A simple way to trigger this is: mkdir /x; automount /x false; cd /x; something Use a static variable to detect if we are currently in automount_mount() and bail out if we are. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/nfs'Sascha Hauer2014-03-071-7/+14
|\ | | | | | | | | Conflicts: defaultenv/defaultenv-2-base/bin/ifup
| * run_command: remove unused flag parameterSascha Hauer2014-03-071-1/+1
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * mount: support filesystem options passed via -oUwe Kleine-König2014-02-101-6/+13
| | | | | | | | | | | | | | | | | | | | | | Similar to mount(8) the barebox command mount now supports passing a string to the file system driver via -o. This is used in the next commit to let the user specify port numbers for nfs mounts. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | read_file: Use read_fullSascha Hauer2014-02-131-1/+2
|/ | | | | | | | At least NFS does not fulfill read requests > 1024 bytes at once. Use read_full in read_file as read doesn't guarantee that the whole request can be read at once. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Fix endless loop in automount codeSascha Hauer2013-11-271-0/+2
| | | | | | | | | | A chdir to a path registered as an automount path followed by a 'ls' results in an endless loop. This happens because the command the automounter executes results in another automount request. Fix this by running the automounter from the chdir code before the cwd is actually changed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Add function to get cdev by mountpathSascha Hauer2013-11-051-0/+13
| | | | | | This is useful to know for the bootloader spec implementation. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: ignore O_TRUNC open flag for devicesSascha Hauer2013-10-161-2/+1
| | | | | | | | | | | | | | | | | | The O_TRUNC flag has to be ignored when opening devices. Otherwise cp /somefile /dev/somedev fails. This is broken since: | commit d4f5bb1e011ac653a167031554f0ac9e028e9e36 | Author: Sascha Hauer <s.hauer@pengutronix.de> | Date: Sat Sep 28 13:12:50 2013 +0200 | | copy_file: Add missing O_TRUNC | | Without it, when copying a smaller file over a larger file the | resulting file still has the remaining space from the larger file. | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: add cdev mount helpersSascha Hauer2013-09-301-0/+80
| | | | | | | Introduce helpers to iterate over cdevs and mount them to a known path. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: use bus_for_each_driverSascha Hauer2013-09-291-4/+1
| | | | | | Instead of using for_each_driver and testing for the bus type. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: cleanup backingstore handlingSascha Hauer2013-09-291-8/+20
| | | | | | | | | | | All filesystem drivers which need a backingstore device do the same ignoring of '/dev/' in the backingstore followed by a cdev_open. Add a helper function for it and let the core handle the cdev. As a side effect this makes sure that fsdev->cdev is also set when a device is mounted without the leading '/dev/' which was previously ignored by the mount code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* read_file: Make it work on tftp servers which do not pass sizeSascha Hauer2013-06-201-0/+18
| | | | | | | | Some tftp servers (for example netkit-tftp) do not pass the filesize. Add a workaround for read_file which reads the file into a temporary file which then is copied to a buffer. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: allocate FILE table dynamicallySascha Hauer2013-03-141-4/+7
| | | | | | | | | Some systems are runnignfrom a very limited SRAM, but have a huge malloc space in SDRAM. The bss normally is in SRAM, so we should avoid having big structures there. The FILE table is 5120 bytes big, so allocate it dynamically instead. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: add pread and pwrite functionsAlexander Aring2013-02-201-14/+74
| | | | | | | | | | | | | | | Add pread and pwrite functions. Split read and write functions to save some space. The functions pread and pwrite saves and sets the file position to a given offset and restore them afterwards. This also makes the nandtest command use these function which is necessary to not break compilation for the nandtest command. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: fix return type of readAlexander Aring2013-02-181-1/+1
| | | | | Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>