Age | Commit message (Collapse) | Author |
|
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
|
|
Fix warnings abot PRIdoff_t in libmtd.c, in mtd_read (and mtd_write):
In file included from ../git/lib/libmtd.c:40:0:
../git/lib/libmtd.c: In function 'mtd_read':
../git/include/common.h:110:18: warning: format '%ld' expects argument of
type 'long int', but argument 5 has type 'off_t {aka long long int}'
[-Wformat=]
../git/include/common.h:120:2: note: in expansion of macro 'errmsg'
errmsg(fmt, ##__VA_ARGS__); \
^~~~~~
../git/lib/libmtd.c:1082:10: note: in expansion of macro 'sys_errmsg'
return sys_errmsg("cannot seek mtd%d to offset %"PRIdoff_t,
^~~~~~~~~~
/usr/lib/klibc/include/inttypes.h:28:17: note: format string is defined here
#define PRId32 "d"
Signed-off-by: Thorsten Glaser <tg@mirbsd.org>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
|
|
mtd_debug: Remove a duplicate if case. MTD_CAP_NANDFLASH has only one
flag set (MTD_WRITEABLE). Directly below, we had a check for
MTD_WRITEABLE in the else branch which can't possible ever have
triggered. Checking for MTD_WRITEABLE in addition to the CAP constants
was probably not intended anyway, given the check for the individual
flags if all else fails.
integck: We already established that "r" is less than the number of
elements in the list, so the loop condition doesn't need to check
if w is NULL in addition. At least this way, the compiler "gets"
that w cannot be NULL below and doesn't issue warnings.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
|
|
Now that C++17 introduced a special fallthrough keyword for
explicitly tagging switch cases that are supposed to fall
through, newer gcc versions also implement a feature request
from 2002 to warn about maybe unwanted fall-throughs in switch
cases in other languages (like C).
For C code, we can either add a gcc specific attribute at the
end of the switch case, or use a special comment that gcc checks
for, indicating that the fall-through behaviour is indeed
intended.
This patch adds a "/* fall-through */" comment at the end of
various case blocks to silence gcc warnings and in some cases
a break, where fall-through was probably not intended.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
|
|
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
|
|
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
|
|
This patch eliminates warnings generated by the -Wmissing-prototypes
option. With this flag set, we are now forced to have prototypes for
all global, exported functions, that have to be made visible to the
definitions and we are forced to mark all local functions as static.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
|
|
AC_CHECK_HEADERS already makes sure our config header contains a
HAVE_$FOO_H macro if a header was found. There is no need to
awkwardly set our own Automake conditionals and check for it all
over the place in the Automake files.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
|
|
The tools in question will quit with an exit code 0 if the command
line option was not recognized. By returning an error code a calling
script has the possibility to distinguish between a real success and
an invalid invocation.
We need to return -1 instead of EXIT_FAILURE to be consistent with the
other exit code places.
Signed-off-by: Daniel Wagner <daniel.wagner@siemens.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
|
|
This patch adds a libmissing library to mtd-utils, containing
implementations of functionality found in glibc but typically
missing from embedded C libraries such as uclibc ot musl.
For now, the library only contains stub implementations of
the backtrace*() family of functions.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>
|
|
When a program does sophisticated enough command line processing
(i.e. getopt), make sure it responds to -V and --version.
When a program prints a version string, make sure it uses the
common_print_version macro to print out its name, that it is part
of mtd-utils and the mtd-utils version from the build system in a
fashion similar to common program packages like the GNU coreutils.
When a program responds to -V/--version or -h/--help, make sure it
reports success exit status.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>
|
|
Add automake files for the test binaries. If configured to do so,
install the test binaries to libexec/mtd-utils and use autoconf to
fix the paths in the test scripts.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>
|
|
In commit ca7a5eda221d("integck.c: Fix buffer overflow in save_file")
we started including header <bits/stdio_lim.h>.
But with musl C library, we get following build error
integck.c:37:28: fatal error: bits/stdio_lim.h: No such file or directory
#include <bits/stdio_lim.h>
^
compilation terminated.
make[2]: *** [integck] Error 1
Header <bits/stdio_lim.h> is not available in musl C library. However
<stdio.h> has all definition that <bits/stdio_lim.h> supposed to be
providing. Moreover <bits/stdio_lim.h> shouldn't be included directly
instead we should be using <stdio.h>.
Since we already include <stdio.h> and in case of uClibc or glibc
<bits/stdio_lim.h> gets included internally, we can safely remove it.
This build issue is found by Buildroot autobuilder
http://autobuild.buildroot.net/results/175/1754861457af520480cc34d7d2d0edff2868ff66/
Fixes: ca7a5eda221d("integck.c: Fix buffer overflow in save_file")
Signed-off-by: Rahul Bedarkar <rahul.bedarkar@imgtec.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
|
|
Test integck requires a parameter but run_all.sh did no pass any to it.
Then:
integck: error!: test file-system was not specified (use -h for help)
Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Reviewed-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
|
|
Not using the macros may be a problem when cross-compiling.
Signed-off-by: Mats Karrman <mats.karrman@tritech.se>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
In the problem above I've spend several hours waiting for the issue to
appear, only to had the 'luck' that it was found in a file whose name was
256 bytes in length, resulting in the write to fail. Closer examination
showed that the buffer to store the path was 256 bytes in length, but this
buffer also includes /tmp and the read/write suffix and should be able to
contain a filename which is up to 255 bytes (NAME_MAX in linux/limits.h)
in size which is a bad fit. So that array is modified to FILENAME_MAX
(stdio_lim.h) and some checking is added to truncate the filename should
it cause an overflow.
The following log shows the first patch in action (see the correct seed),
and shows why this third patch is needed:
<quote>
integck: File Data:
integck: Offset: 0 Size: 1 Seed: 5008310 R.Off: 0
integck: 1 writes
integck: ============================================
integck: Write Info:
integck: Offset: 0 Size: 1 Seed: 5008310 R.Off: 0
integck: Offset: 0 Size: 1 Seed: 8246352 R.Off: 0
integck: Offset: 0 Size: 1 Seed: 5078796 R.Off: 0
integck: Offset: 0 Size: 1 Seed: 2267087 R.Off: 0
integck: Offset: 0 Size: 1 Seed: 3602680 R.Off: 0
integck: 5 writes or truncations
integck: ============================================
integck: Saving /tmp/yqcnfygfitaatyeyvffrguegcdttamcnyhowhgieljfuxfipiljsjcbluaeaghwyinkggommsbwnmvekihgnwgiibccpbwfrpxuxwkmnyghnutrudienngxwgorudbskedaaekiuiyqksfazrwzfwbfhzjjqoiulebtlpbfiuffmsnguqkjzqjqizimsmhbqqagaebjdhqwmzdxghiavtcxubegawlgtvstuqurkurpnrckjfkgostdtpg.integ.sav.readn
integck: error!: condition 'w_fd != -1' failed in save_file() at integck.c:1445
integck: error 36 (File name too long)
</quote>
Signed-off-by: Elie De Brauwer <eliedebrauwer@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
the errors
See my problem description int the previous commit, the point is that integck
in file_check_data reads a buffer, and then checks if the data is correct, it
will do a seek(0), and reread from the same fd. The point is that in the
scenario I observed integck failed (due to a buffer mismatch) but the it saved
(and what was in flash) was actually correct. So I modified this function to
dump the buffers to stderr at the moment an error is found.
Signed-off-by: Elie De Brauwer <eliedebrauwer@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
<quote>
integck: File Data:
integck: Offset: 0 Size: 196 Seed: 5999877 R.Off: 0
integck: Offset: 196 Size: 33 Seed: 4160795 R.Off: 0
integck: Offset: 229 Size: 1252 Seed: 8070052 R.Off: 0
integck: Offset: 1481 Size: 612 Seed: 4160795 R.Off: 1285
integck: Offset: 2093 Size: 6 Seed: 6946586 R.Off: 0
integck: Offset: 2099 Size: 536 Seed: 4160795 R.Off: 1903
integck: Offset: 2635 Size: 1562 Seed: 9845455 R.Off: 0
integck: Offset: 4197 Size: 80 Seed: 702818 R.Off: 0
integck: Offset: 4277 Size: 115 Seed: 9845455 R.Off: 1642
integck: 9 writes
integck: ============================================
integck: Write Info:
integck: Offset: 826 Size: 357 Seed: 5908448 R.Off: 0
integck: Offset: 4197 Size: 80 Seed: 702818 R.Off: 0
...
</quote>
And I would expect the file data listing to include at offset 826 something
with a size of 357 and a seed of 5908448. Clearly it is not there (which
is already extremely confusing). The point is that file_write_info first
updates the raw_write, then verifies the data (passing the new write)
and only after that updates the write structure. But in file_check_data
only the newly written data is verified (passed as an argument) whilst
the save_file() function to dump the file uses the raw_writes to recreate
the written data (while raw_writes is only updated after after this check
would have succeeded). Several lines to say that in this patch the verify
only gets called _after_ the datastructures are updated.
Signed-off-by: Elie De Brauwer <eliedebrauwer@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
We should use the off_t type instead of off64_t or u_int32_t as its
length is controlled by the WITHOUT_LARGEFILE flag.
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
The ioctl UBI_IOCATT has been extended with max_beb_per1024 parameter.
This parameter is used for adjusting the "maximum expected number of
bad blocks per 1024 blocks" for each mtd device.
The number of physical erase blocks (PEB) that UBI will reserve for bad
block handling is now:
whole_flash_chipset__PEB_number * max_beb_per1024 / 1024
This means that for a 4096 PEB NAND device with 3 MTD partitions:
mtd0: 512 PEB
mtd1: 1536 PEB
mtd2: 2048 PEB
the commands:
ubiattach -m 0 -d 0 -b 20 /dev/ubi_ctrl
ubiattach -m 1 -d 1 -b 20 /dev/ubi_ctrl
ubiattach -m 2 -d 2 -b 20 /dev/ubi_ctrl
will attach mtdx to UBIx and reserve:
80 PEB for bad block handling on UBI0
80 PEB for bad block handling on UBI1
80 PEB for bad block handling on UBI2
=> for the whole device, 240 PEB will be reserved for bad block
handling.
This may seems a waste of space, but as far as the bad blocks can appear
every where on a flash device, in the worst case scenario they can
all appear in one MTD partition.
So the maximum number of expected erase blocks given by the NAND
manufacturer should be reserve on each MTD partition.
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
First, the top-level Makefile should not tell git to ignore sub-level
.gitignore files.
Second, add simple .gitignores to ignore the executables generated under
the various `tests' subdirectories.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
|
|
The ubi-utils/src/ subdir is tossed as it just complicates things for no
real gain. The dictionary.h header is relocated to the ubi-utils/include/
since other headers in there need it.
The top level clean is replaced with a `find -delete` on objects, so it
might prune more than necessary, but many projects now do this sort of
thing and no one complained there.
A "mkdep" helper generates the actual rule, and the variables are used
with "foreach" to expand these automatically.
The tests subdir is updated only to reflect the ubi-utils source move.
Otherwise, it is left untouched as making that non-recursive isn't really
worth the effort.
While we're gutting things, also through in kbuild style output while
building to make things more legible.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
|
|
Need to include <linux/fs.h>, at least for my build system. Otherwise,
you can't build the 'tests'.
integck.c: In function ‘parse_mount_options’:
integck.c:2862: error: ‘MS_DIRSYNC’ undeclared (first use in this
function)
integck.c:2862: error: (Each undeclared identifier is reported only once
integck.c:2862: error: for each function it appears in.)
integck.c:2872: error: ‘MS_RELATIME’ undeclared (first use in this
function)
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Currently pcv macro print the error message only if we are not doing power cut
testing or if we have -v flag. But if we run without -v and an error happen
and the error code is not EROFS/EIO, pcv() does not print anything. This patch
makes it print the error message in that case as well.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
The 'file_new()' function should create a file but should not keep it
open. There is a different path to open files and keep them open. This
patch makes 'file_new()' close newly created files.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
This patch makes the directory checking in case of power cut emulation
actually work. There were many bugs. Basically, we cannot rely on anything
unless the directory is marked as clean.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Make -v switch control verbose integck output.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Check the clean data after every emulated power cut, not only when
'create_test_data()'/'update_test_data()' succeed. This required some minor
re-work.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Add a helper 'sync_directory()' function to synchronize directories.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
In 'dir_check()' print name of the directory if we fail to open it.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Currently when we are doing UBIFS power cut emulation testing we assume that
EROFS is returned in case of an emulated power cut event. However, this is
not true and sometimes Linux returns EIO to user-space instead. Namely, this
happens when we are waiting for write-back to finish. Here is a call trace
form kernel 2.6.39-rc7:
Call Trace:
[<ffffffff810aaa77>] filemap_write_and_wait_range+0x78/0xb1
[<ffffffff8110f34d>] vfs_fsync_range+0x38/0xd3
[<ffffffff8110f42b>] generic_write_sync+0x43/0x65
[<ffffffff810ab0c9>] generic_file_aio_write+0xaa/0xf2
[<ffffffffa02224c9>] ubifs_aio_write+0x13a/0x1a1 [ubifs]
[<ffffffff810ed71f>] do_sync_write+0xcb/0x141
[<ffffffff810ee016>] vfs_write+0xb0/0x150
[<ffffffff810ee175>] sys_write+0x48/0x72
[<ffffffff813e0692>] system_call_fastpath+0x16/0x1b
'filemap_fdatawait_range()' returns hard-coded -EIO if a page write-back
happens with whatever error code.
Thus, this patch teaches integck to handle EIO when doing power cut emulation
testing.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
This patch adds -m <mtdnum> option to integck and teaches integck to re-attach
the MTD device to UBI in case of an emulated power cut event. This is needed
for the new UBI power cut and unstable bits emulation infrastructure: when UBI
emulates a power cut the only way to recover form this is to re-attach the MTD
device.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
When we are in power cut mode read all files after re-mounting. This will
check that FS recovery worked well and all files are readable after recovery.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Currently we always verify holes when truncating, but we have -v switch for
this and should do this only if -v was given.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Call 'fsync()' for directories sometimes as well, and check synchronized
directories after re-mount - cound of directory entries has to be correct.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
If 'fsync()' or 'fdatasync()' fail we have to return an error, but we by
mistake were returning 0 (success).
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Currently integck calls 'fsync()' very rarely - with 0.1% probability. Make
this happen more often - with 1% probability.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Allow verification for clean files, i.e. the files which had been fsync()'ed
before the emulated power cut happened.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Make the verify option -v work with power cut emulation option -e. We can
verify all operations except of writing to the file, because of write-back.
Indeed, even if we write successfully, the pages may still be in the page-cache
and if an emulated power cut happens they will be dropped, and our verification
will fail.
I am not 100% sure it is save to verify non-write operation in other FSes, but
only UBIFS has power cut emulation mode now, so we do not really care about
other FSes at this point.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Enable directory entry checking in power cut mode. This means that with this
patch integck will check that all directory entries in the file-system were
created by integck.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
All errors but write errors have corresponding CHECK(), so if something
gets wrong we fail. But in case of I/O errors we do not fail if an
unexpected error happens, which makes it difficult to trace issues.
Inject the errno checking to the pvc macro to make sure we fail if
errno is not EROFS.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Commit 1394a46213e8180e1233ca6d4811e7c77d49b1e0 was a good idea, but it
introduced a segfault - files can be unlinked and 'file->links' is NULL, it is
bad idea to unconditionally dereference it with 'file->links->name'. This patch
introduces a helper function which takes care of the situation with unlinked
files, plus it adds few assertions.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Introduce per-file "clean" flag which tells whether the file is synchronized or
not. This flag is not really used so far.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
In pcv() messages also print the error number - this is useful when
an error happens and it is not because of EROFS.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
This is just a preparation - re-structure 'file_write()' to make one "success"
return point - we'll add synchronization stuff there. Also, while on it, make
it delete the file errored in truncation, not only in write. Also, move
the fsync() call to this function because it is common to all write paths.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
I observes segfaults in integck test, and unfortunately I do not have the core
file to investigate the problem. But I see one possibility for the test to
segfault - it has unbounded recursion. Limit the maximum recursion depth.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
If we are not in power cut testing mode (-p was not used) and we get an
unexpected EROFS, we silently exit. This patch fixes this behavior and make
the test loudly fail instead.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
The test sometimes dies due to SIGBUS because a power cut event happens when
we are writing to an mmap()'ed area. SIGBUS is very difficult to ignore, so
fix the issue simply by avoiding doing 'mmap()' operations when in power cut
testing mode.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|