9
0
Fork 0
Commit Graph

75 Commits

Author SHA1 Message Date
Sascha Hauer 55aca0a48c Merge branch 'for-next/include-cleanup' 2016-05-09 08:49:42 +02:00
Sascha Hauer cb8cf33ce8 fix erasing/protecting flashes with unspecified size
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>
2016-04-19 08:26:51 +02:00
Sascha Hauer 70bbeea7b2 fs: move libc function prototypes to their correct locations
This moves the function prototypes in include/fs.h which also exist
in the libc to the locations they would have in libc.

With this it becomes easier to share code between barebox and userspace
since the usual libc include files will exist. Also users of the libc
functions no longer have to include the barebox internal fs.h header.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-15 12:21:45 +02:00
Sascha Hauer e1385b3399 move unlink_recursive declaration to libfile.h
unlink_recursive is a file utility function, so move the prototype to
libfile.h

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-15 12:21:45 +02:00
Sascha Hauer 69858c74b2 move make_directory declaration to libfile.h
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>
2016-04-15 12:21:45 +02:00
Markus Pargmann 38eae8b2ca fs: umount based on device path and mount path
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>
2016-04-08 13:34:45 +02:00
Markus Pargmann 0a3795dd0e fs: Add for_each_fs_device_safe()
We need to be able to umount specific filesystems while iterating all of
them. This helper gives us a safe macro to do so.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
2016-04-08 13:34:45 +02:00
Sascha Hauer 81737c1d43 mtd: Fix erasing of devices >4GiB
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>
2016-02-09 09:32:29 +01:00
Yegor Yefremov 00dd903055 fs: use linux/fs.h for file system related definitions
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-02-01 09:16:13 +01:00
Sascha Hauer e9db2079a5 fs: Add device parameter for Linux root= option
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>
2015-06-18 09:01:01 +02:00
Sascha Hauer ac1bffb220 Merge branch 'for-next/fs' 2015-03-09 08:30:24 +01:00
Sascha Hauer 6977292a34 fs: rename inode member of struct filep to priv
Because that's what it is. 'inode' will become confusing
once we support real inodes.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-03-09 08:06:41 +01:00
Marc Kleine-Budde 89fc8c31ff fs: make "offset" parameter of erase() and protect() 64 bit safe
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-03-03 08:23:46 +01:00
Sascha Hauer a3993a38da fs: implement fstat
fstat is useful to get information about an already opened file. Add
it to barebox.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-10-08 16:11:06 +02:00
Sascha Hauer 4f7a18cdb5 fs: Store the path in struct filep
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-10-08 16:09:17 +02:00
Sascha Hauer bfef6cd5f2 fs: store pointer to fsdev instead of dev in struct filep
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>
2014-10-08 16:06:21 +02:00
Sascha Hauer 3cfa4bc00c move file helper functions to separate file
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>
2014-08-07 06:13:51 +02:00
Uwe Kleine-König f97f4b6571 mount: support filesystem options passed via -o
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>
2014-02-10 09:02:21 +01:00
Sascha Hauer b7a66554dc fs: Add function to get cdev by mountpath
This is useful to know for the bootloader spec implementation.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-05 08:37:55 +01:00
Sascha Hauer cd16227383 fs: add cdev mount helpers
Introduce helpers to iterate over cdevs and mount them to a known
path.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-09-30 16:03:02 +02:00
Sascha Hauer 7a1c5027f9 mount: implement -v option to print available filesystems
It's useful to know which filesystems a barebox binary supports.
Add a -v option to the mount command to find it out.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-09-29 12:11:14 +02:00
Sascha Hauer d915fcbc6d fs: remove unused field 'name' from struct fs_driver_d
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-09-29 12:11:14 +02:00
Sascha Hauer ecb3aaa23b fs: cleanup backingstore handling
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>
2013-09-29 12:11:14 +02:00
Sascha Hauer 2d2ec6619b read_file: Make it work on tftp servers which do not pass size
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>
2013-06-20 08:42:46 +02:00
Alexander Aring 9d8a20592f fs: add pread and pwrite functions
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>
2013-02-20 08:22:42 +01:00
Alexander Aring e48b144071 fs: fix return type of read
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-02-18 11:09:46 +01:00
Sascha Hauer a886dac94e Add write_file function
write_file() will write a buffer to a file. The file is created
if necessary.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-01-19 11:48:17 +01:00
Sascha Hauer 5a9d53c47e rm: implement -r
To recursively remove files and directories.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-11-29 20:21:29 +01:00
Sascha Hauer e5a927883e Merge branch 'for-next/link' 2012-09-05 12:59:29 +02:00
Jean-Christophe PLAGNIOL-VILLARD 1483f45879 fs: introduce get_mounted_path to get the path where a file is mounted
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
2012-09-05 03:22:14 +08:00
Jean-Christophe PLAGNIOL-VILLARD 2d7ac4aa33 fs: implement stat
stat() stats the file pointed to by path and fills in buf.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
2012-09-05 03:22:13 +08:00
Jean-Christophe PLAGNIOL-VILLARD 65d4f485eb fs: add symlink support
Limit it's support to existing file only

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
2012-09-05 03:22:13 +08:00
Jean-Christophe PLAGNIOL-VILLARD 99684498ec fs: rename stat to lstat as we implement lstat
For compatibility put a inline on lstat for stat until we have the symlink
support.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
2012-09-05 03:22:13 +08:00
Jean-Christophe PLAGNIOL-VILLARD 2f17f1a22f fs: add readlink support
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
2012-09-05 03:22:13 +08:00
Jean-Christophe PLAGNIOL-VILLARD a1b1aec6af fs/mount: add autodetection type support
if NULL is pass as type mount will try to autodetect the filesystem type

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
2012-09-04 09:08:39 +02:00
Sascha Hauer 8d064097eb fs: fix standard zero, full devices
The standard devices are currently broken since they have
the size ~0. As now files use loff_t as file size which is a signed
type the read implementation gets confused and now returns -1.

The current implementation also has the (somewhat theorical) problem
that we do not have real streaming devices, so /dev/zero went out
of zeroes after reading 4GB (or now LLONG_MAX).

This patch introduces a new cdev flag DEVFS_IS_CHARACTER_DEV and a new
file size flag FILE_SIZE_STREAM which makes it possible to create
real stream devices instead.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-07-04 08:38:22 +02:00
Sascha Hauer 3e503822c7 use loff_t for file offsets
This is a first step for 64bit file support: Make the file sizes/offsets
64bit.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-06-30 16:53:24 +02:00
Sascha Hauer b5e5b06d8b Add automount support
This patch adds an automount command which makes it possible
to execute a script when a certain directory is first accessed.
It's the commands responsibility to make this directory available
(bringing devices up and mounting it). This results in automount
support which makes sure that from the shell every file can
be accessed without having to care for device bringup. Bringing
up devices may be expensive (USB, dhcp). The automount support
makes it easy for the environment to bringup devices when they
are actually needed.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-03-18 15:03:26 +01:00
Sascha Hauer b55fbf7f5f fs: drop struct mtab_entry
every struct fs_device_d contains a struct mtab_entry, so they
have a 1:1 relationship. Instead of having to use container_of
to get from a struct mtab_entry to a struct fs_device_d we can
better embed the members of struct mtab_entry into struct fs_device_d
directly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-03-17 18:16:03 +01:00
Sascha Hauer 3a92711511 fs: get fs device using container_of
This reduces the usage of dev->type_data.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-02-25 14:03:56 +01:00
Sascha Hauer 76c7f90a54 fs: get fs driver using container_of
This reduces the usage of dev->type_data.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-02-25 14:03:56 +01:00
Sascha Hauer 9bf08d582a fs: put fs devices on its own bus
By putting the fs devices/drivers on a bus on its own we can hook
into the bus remove function to cleanup the fs device. This way
we can unmount a device by simply unregistering the device which
is useful for for example USB mass storage devices. These can now
unregister the assoiated filesystems by unregistering their child
devices.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-02-17 10:27:15 +01:00
Sascha Hauer 33b5ead7e6 fs: remove fs devices list
We store the fs devices in a list only because we want to
check if the fs driver needs a backingstore or not. The
driver will bail out anyway if it needs a backingstore and
doesn't find one. So we can remove this check and thus remove
the list of fs devices.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-02-17 10:27:15 +01:00
Sascha Hauer fcec314b09 fs: remove unused function fsdev_get_mountpoint
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-02-17 10:27:15 +01:00
Sascha Hauer ec1d29e61c fs: Store mtab path in allocated string
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-02-17 10:27:15 +01:00
Sascha Hauer 2c2fb6a947 fs: make locally used function get_mtab_entry_by_path static
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-02-17 10:27:15 +01:00
Sascha Hauer 8a81eab846 fs: Store mtab entries in list
To make the code a bit easier to read. Also, do not allow
to umount / when something else is mounted.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-02-17 10:27:15 +01:00
Sascha Hauer f1bb89fd9e fs: implement flush function
Once we have caching in file functions we need a way to sync
the the underlying devices.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2011-04-11 12:36:07 +02:00
Sascha Hauer 5c44e3af24 fs: remove unused field 'type' from struct fs_driver_d
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2011-04-11 12:36:07 +02:00
Sascha Hauer 2baeaf38f3 fs: replace broken dev_protect with protect_file function
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2009-10-02 15:23:22 +02:00