* [PATCH] scriptreplay: fscanf portability fix
From: Sami Kerola @ 2011-07-22 20:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
This is a fix to an issue with llvm clang which I reported
earlier.
http://www.spinics.net/lists/util-linux-ng/msg04331.html
When compiling with clang fscanf format string %[\n] will not
work. For now using %c in format string seems to be best option.
p.s. The llvm people are informed about the issue.
http://llvm.org/bugs/show_bug.cgi?id=10443
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
term-utils/scriptreplay.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/term-utils/scriptreplay.c b/term-utils/scriptreplay.c
index 96993d5..7f1b497 100644
--- a/term-utils/scriptreplay.c
+++ b/term-utils/scriptreplay.c
@@ -203,7 +203,7 @@ main(int argc, char *argv[])
size_t blk;
char nl;
- if ((fscanf(tfile, "%lf %zd%[\n]\n", &delay, &blk, &nl) != 3) ||
+ if ((fscanf(tfile, "%lf %zd%c\n", &delay, &blk, &nl) != 3) ||
(nl != '\n')) {
if (feof(tfile))
break;
--
1.7.6
^ permalink raw reply related
* Re: ionice: requires scheduling since 7ab08ba3e5e6f161b93ff2b3b7d5b18dc7b44510
From: Karel Zak @ 2011-07-22 10:57 UTC (permalink / raw)
To: Voelker, Bernhard; +Cc: util-linux@vger.kernel.org
In-Reply-To: <7856072A9D04C24B82DFE2B1112FE38A08FE2D3B4F@MCHP058A.global-ad.net>
On Fri, Jul 22, 2011 at 12:21:08PM +0200, Voelker, Bernhard wrote:
> Karel Zak wrote:
>
> > Fixed.
> >
> > I've also added support for human readable class names, you can use:
> >
> > ionice -c best-effort /bin/foo
>
> great, thanks!
>
> One last corner case regarding -t (ignoring failure):
>
> $ schedutils/ionice -c 4 -t schedutils/ionice
> ionice: bad prio class 4
> $ schedutils/ionice -n 8 -t schedutils/ionice
> idle
>
> With -c, a bad prio class leads to a failure, while it doesn't with -n.
> Is this intended?
OK. Copy & past from the latest commit:
ionice: make -t more tolerant
* replace errx() with warnx() for unknown -c class
The right place to check I/O scheduler features is in kernel. We should
not try to be more smart than kernel.
* make the code ready (robust) for unknown sched.classes
* fix -t behavior
old version:
$ ionice -c 4 -t bash
ionice: bad prio class 4
new version:
$ ionice -c 4 -t bash
Reported-by: Voelker, Bernhard" <bernhard.voelker@siemens-enterprise.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* RE: ionice: requires scheduling since 7ab08ba3e5e6f161b93ff2b3b7d5b18dc7b44510
From: Voelker, Bernhard @ 2011-07-22 10:21 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux@vger.kernel.org
In-Reply-To: <20110722094304.GQ22568@nb.net.home>
Karel Zak wrote:
> Fixed.
>
> I've also added support for human readable class names, you can use:
>
> ionice -c best-effort /bin/foo
great, thanks!
One last corner case regarding -t (ignoring failure):
$ schedutils/ionice -c 4 -t schedutils/ionice
ionice: bad prio class 4
$ schedutils/ionice -n 8 -t schedutils/ionice
idle
With -c, a bad prio class leads to a failure, while it doesn't with -n.
Is this intended?
Berny
^ permalink raw reply
* Re: ionice: requires scheduling since 7ab08ba3e5e6f161b93ff2b3b7d5b18dc7b44510
From: Karel Zak @ 2011-07-22 9:43 UTC (permalink / raw)
To: Voelker, Bernhard; +Cc: util-linux@vger.kernel.org
In-Reply-To: <7856072A9D04C24B82DFE2B1112FE38A08FE2D3AC2@MCHP058A.global-ad.net>
On Fri, Jul 22, 2011 at 10:57:28AM +0200, Voelker, Bernhard wrote:
> Karel Zak wrote:
>
> > I'll improve the behavior:
>
> great!
>
> > ionice : print the current I/O prio.
> > ionice <COMMAND> : exec command with default (best-effort) class
> > ionice -p PID [...] : return info about the PID(s)
> > ionice -c CLASS COMMAND : exec command with the class
> > ionice -c CLASS -p PID [...] : modify PID(s) class
> >
> > Comments?
Fixed.
I've also added support for human readable class names, you can use:
ionice -c best-effort /bin/foo
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* RE: ionice: requires scheduling since 7ab08ba3e5e6f161b93ff2b3b7d5b18dc7b44510
From: Voelker, Bernhard @ 2011-07-22 8:57 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux@vger.kernel.org
In-Reply-To: <20110722085420.GP22568@nb.net.home>
Karel Zak wrote:
> I'll improve the behavior:
great!
> ionice : print the current I/O prio.
> ionice <COMMAND> : exec command with default (best-effort) class
> ionice -p PID [...] : return info about the PID(s)
> ionice -c CLASS COMMAND : exec command with the class
> ionice -c CLASS -p PID [...] : modify PID(s) class
>
> Comments?
ionice --help : print help
is missing ;-)
Berny
^ permalink raw reply
* Re: ionice: requires scheduling since 7ab08ba3e5e6f161b93ff2b3b7d5b18dc7b44510
From: Karel Zak @ 2011-07-22 8:54 UTC (permalink / raw)
To: Voelker, Bernhard; +Cc: util-linux@vger.kernel.org
In-Reply-To: <7856072A9D04C24B82DFE2B1112FE38A08FE2D3A66@MCHP058A.global-ad.net>
On Fri, Jul 22, 2011 at 10:09:57AM +0200, Voelker, Bernhard wrote:
> Since 7ab08ba3e5e6f161b93ff2b3b7d5b18dc7b44510, ionice requires a "scheduling".
>
> $ schedutils/ionice 123
> ionice: scheduling for the COMMAND not specified
>
> As `ionice` is the sister of `nice`, I question why a certain prio/class is needed.
> What's wrong with not passing a certain prio/class?
Good point, I'll fix it.
> Second, doesn't this break existing scripts which rely on "123" being executed?
It has never been supported:
$ ionice 123
none: prio 4
ionice: ioprio_get failed: No such process
Unfortunately, the 123 has been always interpreted as PID, not as
COMMAND. The another bug is that without -p the ioprio_get() has been
called two times, the "none: prio 4" is for PID=0 ;-)
I'll improve the behavior:
ionice : print the current I/O prio.
ionice <COMMAND> : exec command with default (best-effort) class
ionice -p PID [...] : return info about the PID(s)
ionice -c CLASS COMMAND : exec command with the class
ionice -c CLASS -p PID [...] : modify PID(s) class
Comments?
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* ionice: requires scheduling since 7ab08ba3e5e6f161b93ff2b3b7d5b18dc7b44510
From: Voelker, Bernhard @ 2011-07-22 8:09 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux@vger.kernel.org
Since 7ab08ba3e5e6f161b93ff2b3b7d5b18dc7b44510, ionice requires a "scheduling".
$ schedutils/ionice 123
ionice: scheduling for the COMMAND not specified
As `ionice` is the sister of `nice`, I question why a certain prio/class is needed.
What's wrong with not passing a certain prio/class?
Second, doesn't this break existing scripts which rely on "123" being executed?
Have a nice day,
Berny
^ permalink raw reply
* Re: [git pull] cramfs fixes
From: Sami Kerola @ 2011-07-22 7:56 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
In-Reply-To: <20110721181012.GA6672@nb.net.home>
On Thu, Jul 21, 2011 at 20:10, Karel Zak <kzak@redhat.com> wrote:
>> =A0 =A0 =A0 u32 namelen:6, offset:26;
> =A0 =A0^^^
> =A0uint32_t
Oops. Fixed.
>> +/* Exit codes used by fsck-type programs */
>> +#define FSCK_OK =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A00 =A0 =A0 =
=A0 /* No errors */
>> +#define FSCK_NONDESTRUCT =A0 =A0 1 =A0 =A0 =A0 /* File system errors co=
rrected */
>> +#define FSCK_REBOOT =A0 =A0 =A0 =A0 =A02 =A0 =A0 =A0 /* System should b=
e rebooted */
>> +#define FSCK_UNCORRECTED =A0 =A0 4 =A0 =A0 =A0 /* File system errors le=
ft uncorrected */
>> +#define FSCK_ERROR =A0 =A0 =A0 =A0 =A0 8 =A0 =A0 =A0 /* Operational err=
or */
>> +#define FSCK_USAGE =A0 =A0 =A0 =A0 =A0 16 =A0 =A0 =A0/* Usage or syntax=
error */
>> +#define FSCK_LIBRARY =A0 =A0 =A0 =A0 128 =A0 =A0 /* Shared library erro=
r */
>
> =A0I see magic numbers also in fsck.minix ;-)
>
> =A0What about to add include/exitcodes.h and move this and
> =A0disk-utils/mkfs.h to this file?
True. I added two patches which does exactly that.
include: move disk-utils/mkfs.h -> include/exitcodes.h
include: move fsck return values to exitcodes.h
>> [snip]
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 err(FSCK_ERROR, _("write failed: %s"),
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 path);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 curr =3D next;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 ^^^
>
> the 'if (opt_extract)' block is outsize 'if (size >=3D page_size)'...
Correct, the mistake is fixed.
>> [snip]
>> + =A0 =A0 =A0 =A0 =A0 =A0 if ((S_ISUID | S_ISGID) & i->mode)
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (chmod(path, i->mode) < 0)
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 err(FSCK_ERROR=
, _("chown failed: %s"), path);
>> =A0 =A0 =A0 }
>
> =A0 =A0 =A0if (((S_ISUID | S_ISGID) & i->mode) && chmod(path, i->mode) < =
0)
> =A0 =A0 =A0 =A0 =A0 err(FSCK_ERROR, _("chown failed: %s"), path);
Changed to single if.
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 blksize =3D atoi(optarg);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 blksize =3D strtoll_or_err(opt=
arg, _("blocksize argument failed"));
>
> =A0hmm... "failed to parse blocksize argument" ?
Changed to "failed to parse".
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else if (strcmp(optarg, "hos=
t") =3D=3D 0); =A0/* default */
>> [snip]
>
> =A0 else if (strcmp(optarg, "host") =3D=3D 0)
> =A0 =A0 =A0 =A0; /* default */
This and...
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 case 'V':
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf(_("%s (%s)\n"),
>
> =A0"%s from %s\n" :-)
the version string are in new patch.
mkfs.cramfs: coding style
The fixed & few new patches are available in the git repository at:
https://github.com/kerolasa/lelux-utiliteetit cramfs
--=20
=A0=A0 Sami Kerola
=A0=A0 http://www.iki.fi/kerolasa/
^ permalink raw reply
* Re: [git pull] schedutils
From: Sami Kerola @ 2011-07-21 20:03 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
In-Reply-To: <20110721190328.GH22568@nb.net.home>
On Thu, Jul 21, 2011 at 21:03, Karel Zak <kzak@redhat.com> wrote:
> On Thu, Jul 21, 2011 at 08:37:52PM +0200, Sami Kerola wrote:
>> > =A0* I think that
>> > =A0 =A0 =A0 =A0-c, --class NUM
>> > =A0 is better than
>> > =A0 =A0 =A0 =A0-c, --class=3DNUM
>>
>> With equals sign is FSFism, which seemed like good starting point...
>
> =A0:-)
>
> =A0The '=3D' is required only for optional arguments, the it's probably
> =A0the best to use
>
> =A0 =A0--foo[=3DNUM]
I've already forgot what was the original switch did, but that is
exactly how optional argument should be marked up to make *nix command
line tools to look & feel the same. Which IMHO is important for users.
>> > =A0I have fixed this in ionice man page, but not in usage(). It would =
be
>> > =A0nice to use in all man pages and usage() functions the same syntax.
>> > =A0Maybe we can create any template or so to have it documented.
>>
>> ...but you are absolutely right again. Converting README.devel in
>> small chunks to a Documentation directory might be a way to go.
>
> =A0Good idea!
I'll propose in future something, unless someone else is quicker.
>> BTW what would you think about having a util-linux.h with inline
>
> =A0Should be enough to use c.h ?
Possibly.
>> function to print in usage help & version option descriptions and
>> proper version output function. The first would make translation teams
>> happier when they do not need to write time after time the same
>> translations. Second would simply unify how version is printed, and if
>
> =A0Well, .po files never contains duplicate strings.
Yes and no. What I mean is this:
util-linux/po grep -c 'display this help and exit' util-linux.pot
27
By writing the strings once & reusing the separated stings in usage()
functions should fix the issue.
>> In practice the file would be similar to coreutils system.h.
>
> =A0Hmm... I don't like
>
> =A0#define case_GETOPT_VERSION_CHAR(Program_name, Authors)
> =A0 =A0 =A0 =A0 =A0case GETOPT_VERSION_CHAR:
>
> =A0We don't use the same char everywhere and hide keywords (e.g. case)
> =A0to macros is not nice too.
>
> =A0It would be enough to use
>
> =A0 case 'V':
> =A0 =A0 =A0 =A0ul_print_version();
> =A0 =A0 =A0 =A0break;
>
> =A0The result should be readable C language, not any gnulib meta-language=
:-)
Yup, I agree. Doing the very same as coreutils is possibly not a good
match. Partially copying good ideas seems better, but that just
requires bit of thinking which ideas apply well. Uh, programming is
difficult.
--=20
=A0=A0 Sami Kerola
=A0=A0 http://www.iki.fi/kerolasa/
^ permalink raw reply
* Re: [git pull] schedutils
From: Karel Zak @ 2011-07-21 19:03 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
In-Reply-To: <CAG27Bk1R_fG+SkFd1JfoiEyg7z8saJv4V+=K02Cz8_OHL9tz=w@mail.gmail.com>
On Thu, Jul 21, 2011 at 08:37:52PM +0200, Sami Kerola wrote:
> > * I think that
> > -c, --class NUM
> > is better than
> > -c, --class=NUM
>
> With equals sign is FSFism, which seemed like good starting point...
:-)
The '=' is required only for optional arguments, the it's probably
the best to use
--foo[=NUM]
> > I have fixed this in ionice man page, but not in usage(). It would be
> > nice to use in all man pages and usage() functions the same syntax.
> > Maybe we can create any template or so to have it documented.
>
> ...but you are absolutely right again. Converting README.devel in
> small chunks to a Documentation directory might be a way to go.
Good idea!
> Contents of the directory could have help_and_version.txt for what you
> said above, and I can recall recent minix & kernel headers
> conversation which ought also be documented.
OK.
> BTW what would you think about having a util-linux.h with inline
Should be enough to use c.h ?
> function to print in usage help & version option descriptions and
> proper version output function. The first would make translation teams
> happier when they do not need to write time after time the same
> translations. Second would simply unify how version is printed, and if
Well, .po files never contains duplicate strings.
> it ever needs a modification it's easier to do.
I agree.
> In practice the file would be similar to coreutils system.h.
Hmm... I don't like
#define case_GETOPT_VERSION_CHAR(Program_name, Authors)
case GETOPT_VERSION_CHAR:
We don't use the same char everywhere and hide keywords (e.g. case)
to macros is not nice too.
It would be enough to use
case 'V':
ul_print_version();
break;
The result should be readable C language, not any gnulib meta-language :-)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [git pull] schedutils
From: Sami Kerola @ 2011-07-21 18:37 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
In-Reply-To: <20110721154303.GF22568@nb.net.home>
On Thu, Jul 21, 2011 at 17:43, Karel Zak <kzak@redhat.com> wrote:
> =A0The 'ioprio' in the syscall:
>
> =A0 =A0 syscall(SYS_ioprio_set, which, who, ioprio);
>
> =A0encodes two information:
>
> =A0 =A0IOPRIO_PRIO_CLASS =A0- e.g. realtime, idle, ...
> =A0 =A0IOPRIO_PRIO_DATA =A0 - e.g. 0-7
>
> =A0this is reason why the docs is talking about "class" and "class data".
>
> =A0Anyway, merged with some minor changes and --classdata option :-)
Sounds reasonable.
> =A0Minor notes:
>
> =A0* .PP in man page within .IP block does not have the same meaning
> =A0 like blank line
Oops, that was sloppy from my side. Sorry.
> =A0* I think that
> =A0 =A0 =A0 =A0-c, --class NUM
> =A0 is better than
> =A0 =A0 =A0 =A0-c, --class=3DNUM
With equals sign is FSFism, which seemed like good starting point...
> =A0I have fixed this in ionice man page, but not in usage(). It would be
> =A0nice to use in all man pages and usage() functions the same syntax.
> =A0Maybe we can create any template or so to have it documented.
...but you are absolutely right again. Converting README.devel in
small chunks to a Documentation directory might be a way to go.
Contents of the directory could have help_and_version.txt for what you
said above, and I can recall recent minix & kernel headers
conversation which ought also be documented.
BTW what would you think about having a util-linux.h with inline
function to print in usage help & version option descriptions and
proper version output function. The first would make translation teams
happier when they do not need to write time after time the same
translations. Second would simply unify how version is printed, and if
it ever needs a modification it's easier to do. In practice the file
would be similar to coreutils system.h.
http://git.savannah.gnu.org/gitweb/?p=3Dcoreutils.git;a=3Dblob;f=3Dsrc/syst=
em.h
--=20
=A0=A0 Sami Kerola
=A0=A0 http://www.iki.fi/kerolasa/
^ permalink raw reply
* Re: [git pull] cramfs fixes
From: Karel Zak @ 2011-07-21 18:10 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
In-Reply-To: <CAG27Bk1uKnqR62SRNgTXFPGfTseraC0AUgpAMQ5zhdcsAM-79w@mail.gmail.com>
On Wed, Jul 20, 2011 at 10:55:16PM +0200, Sami Kerola wrote:
> + /*
> + * NAMELEN is the length of the file name, divided by 4 and
> + * rounded up. (cramfs doesn't support hard links.)
> + *
> + * OFFSET: For symlinks and non-empty regular files, this
> + * contains the offset (divided by 4) of the file data in
> + * compressed form (starting with an array of block pointers;
> + * see README). For non-empty directories it is the offset
> + * (divided by 4) of the inode of the first file in that
> + * directory. For anything else, offset is zero.
> + */
> u32 namelen:6, offset:26;
^^^
uint32_t
> +/* Exit codes used by fsck-type programs */
> +#define FSCK_OK 0 /* No errors */
> +#define FSCK_NONDESTRUCT 1 /* File system errors corrected */
> +#define FSCK_REBOOT 2 /* System should be rebooted */
> +#define FSCK_UNCORRECTED 4 /* File system errors left uncorrected */
> +#define FSCK_ERROR 8 /* Operational error */
> +#define FSCK_USAGE 16 /* Usage or syntax error */
> +#define FSCK_LIBRARY 128 /* Shared library error */
I see magic numbers also in fsck.minix ;-)
What about to add include/exitcodes.h and move this and
disk-utils/mkfs.h to this file?
> if (size >= page_size) {
> - if (out != page_size) {
> - die(FSCK_UNCORRECTED, 0, _("non-block (%ld) bytes"), out);
> - }
> - } else {
> - if (out != size) {
> - die(FSCK_UNCORRECTED, 0, _("non-size (%ld vs %ld) bytes"), out, size);
> - }
> - }
> - size -= out;
> - if (opt_extract) {
> - if (write(fd, outbuffer, out) < 0) {
> - die(FSCK_ERROR, 1, _("write failed: %s"), path);
> - }
> + if (out != page_size)
> + errx(FSCK_UNCORRECTED,
> + _("non-block (%ld) bytes"), out);
> + else if (out != size)
} else if (out != size)
^^^
> + errx(FSCK_UNCORRECTED,
> + _("non-size (%ld vs %ld) bytes"), out,
> + size);
> + size -= out;
> + if (opt_extract)
> + if (write(fd, outbuffer, out) < 0)
> + err(FSCK_ERROR, _("write failed: %s"),
> + path);
> + curr = next;
> }
^^^
the 'if (opt_extract)' block is outsize 'if (size >= page_size)'...
> - curr = next;
> } while (size);
> }
> - if ((S_ISUID | S_ISGID) & i->mode) {
> - if (chmod(path, i->mode) < 0) {
> - die(FSCK_ERROR, 1, _("chown failed: %s"), path);
> - }
> - }
> + if ((S_ISUID | S_ISGID) & i->mode)
> + if (chmod(path, i->mode) < 0)
> + err(FSCK_ERROR, _("chown failed: %s"), path);
> }
if (((S_ISUID | S_ISGID) & i->mode) && chmod(path, i->mode) < 0)
err(FSCK_ERROR, _("chown failed: %s"), path);
[...]
> while ((c = getopt(argc, argv, "hb:Ee:i:n:N:psVvz")) != EOF) {
> switch (c) {
> case 'h':
> - usage(0);
> + usage(MKFS_OK);
> case 'b':
> - blksize = atoi(optarg);
> + blksize = strtoll_or_err(optarg, _("blocksize argument failed"));
hmm... "failed to parse blocksize argument" ?
[...]
> else if (strcmp(optarg, "host") == 0); /* default */
> - else {
> - perror("invalid endianness given. Must be 'big', 'little', or 'host'");
> - exit(MKFS_USAGE);
> - }
> + else
> + errx(MKFS_USAGE, _("invalid endianness given."
> + " Must be 'big', 'little', or 'host'"));
else if (strcmp(optarg, "host") == 0)
; /* default */
else {
....
}
> case 'V':
> printf(_("%s (%s)\n"),
"%s from %s\n" :-)
> - progname, PACKAGE_STRING);
> + program_invocation_short_name, PACKAGE_STRING);
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] swapon: use xalloc lib
From: Karel Zak @ 2011-07-21 16:54 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1311117475.3215.5.camel@offbook>
On Tue, Jul 19, 2011 at 07:17:55PM -0400, Davidlohr Bueso wrote:
> mount/swapon.c | 15 +++++----------
> 1 files changed, 5 insertions(+), 10 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] whereis: search in path variable
From: Karel Zak @ 2011-07-21 16:51 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1311137185.3077.1.camel@offbook>
On Wed, Jul 20, 2011 at 12:46:25AM -0400, Davidlohr Bueso wrote:
> From: Davidlohr Bueso <dave@gnu.org>
> Date: Wed, 20 Jul 2011 00:39:10 -0400
>
> Currently this tool only uses the hardcoded paths for looking up
> strings for binaries, man pages and source code, adding those
> directories found in $PATH makes a nice little enhancement.
Finally someone who is not lazy to implement it correctly :-)
> +char **dirp, **pathdir = NULL;
It's unnecessary to initialize global variables to 0 or NULL.
> main(int argc, char **argv)
> {
> + int i;
variable not used
> setlocale(LC_ALL, "");
> bindtextdomain(PACKAGE, LOCALEDIR);
> textdomain(PACKAGE);
> @@ -179,6 +185,9 @@ main(int argc, char **argv)
> argc--, argv++;
> if (argc == 0)
> usage(stderr);
> +
> + fillpath();
> + dirp = pathdir;
it would be better to hide 'dirp = pathdir' to fillpath().
> do
> if (argv[0][0] == '-') {
> @@ -232,9 +241,51 @@ main(int argc, char **argv)
> } else
> lookup(*argv++);
> while (--argc > 0);
> +
> + free(pathdir);
add freepath()
>
> +int inpath(const char *str)
> +{
> + int i;
> +
> + for (i = 0; i < sizeof(bindirs)/sizeof(char *) - 1 ; i++)
^^^^^^^^^^^^^^^^^^^
We have ARRAY_SIZE() in c.h, or you can use the fact that arrays are
terminated by zero.
> + if (!strcmp(bindirs[i], str))
> + return 1;
> +
> + for (i = 0; i < sizeof(mandirs)/sizeof(char *) - 1; i++)
> + if (!strcmp(mandirs[i], str))
> + return 1;
> +
> + for (i = 0; i < sizeof(srcdirs)/sizeof(char *) - 1; i++)
> + if (!strcmp(srcdirs[i], str))
> + return 1;
> +
> + return 0;
> +}
> +
> +void fillpath(void)
> +{
> + char *key=NULL, *tmp=NULL, *tok=NULL, *path = getenv("PATH");
> + int i = 0;
> +
> + if (!path)
> + return;
> +
> + for (tmp = path; ;tmp = NULL) {
> + tok = strtok_r(tmp, ":", &key);
man getenv, you should not modify the result from getenv().
> + if (!tok)
> + break;
> + if (inpath(tok)) /* make sure we don't repeat the search path */
> + continue;
> +
> + pathdir = xrealloc(pathdir, (i + 1) * sizeof(char *));
> + pathdir[i++] = tok;
> + }
here is bug, see below to gdb backtrace...
> +
> void
> getlist(int *argcp, char ***argvp, char ***flagp, int *cntp)
> {
> @@ -356,6 +407,8 @@ find(char **dirs, char *cp)
> {
> while (*dirs)
> findin(*dirs++, cp);
> + while(*dirp)
^^^^^^
> + findin(*dirp++, cp);
... this code expects that the array is terminated by zero.
Note that find() is called always for all dir lists.
Maybe it would be better to add lookpathenv() and call it from
print_again(). You can also add -p options to control this behavior.
See how {s,b,m}flags work.
BTW, the whole whereis code is horrible, for example find() is completely
unnecessary if there is also findv() and all lists of the directories are
static. It should be possible to use
findv(ary, ARRAY_SIZE(ary), str);
everywhere instead of find(ary, str);
Karel
Starting program: /home/projects/util-linux/util-linux/misc-utils/whereis lsblk
Program received signal SIGSEGV, Segmentation fault.
0x0000003cbae7edfa in __strchr_sse2 () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.14-4.x86_64
(gdb) bt
#0 0x0000003cbae7edfa in __strchr_sse2 () from /lib64/libc.so.6
#1 0x00000000004013c8 in findin (dir=0x1ff41 <Address 0x1ff41 out of bounds>,
cp=0x7fffffffe477 "lsblk") at whereis.c:434
#2 0x0000000000401623 in find (dirs=<optimized out>,
cp=0x7fffffffe477 "lsblk") at whereis.c:421
#3 0x00000000004017a8 in print_again (cp=0x7fffffffe477 "lsblk")
at whereis.c:327
#4 0x0000000000401870 in lookup (cp=0x7fffffffe477 "lsblk") at whereis.c:374
#5 0x0000000000400c9b in main (argc=1, argv=0x7fffffffe148) at whereis.c:242
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] partx: get partition number with sysfs lib
From: Karel Zak @ 2011-07-21 16:54 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1311117428.3215.4.camel@offbook>
On Tue, Jul 19, 2011 at 07:17:08PM -0400, Davidlohr Bueso wrote:
> partx/Makefile.am | 1 +
> partx/partx.c | 22 +++++-----------------
> 2 files changed, 6 insertions(+), 17 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [git pull] schedutils
From: Karel Zak @ 2011-07-21 15:43 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
In-Reply-To: <CAG27Bk3vs54m7b6y_M_uq4RuyPBn-yhAEt2GhicsyY8F_+jJfw@mail.gmail.com>
On Wed, Jul 20, 2011 at 10:15:13AM +0200, Sami Kerola wrote:
> >> - ioprio = strtol_or_err(optarg, _("failed to parse class data"));
> >> + ioprio = strtol_or_err(optarg, _("failed to parse priority"));
> >
> > well, the original kernel Documentation/block/ioprio.txt is talking
> > about "class data" and I think it would be better to follow kernel
> > here. Maybe one day the mask for the syscall will used for a different
> > things than only for priority...
>
> I read kernel documentation using priority, class data and level as
> synonyms. To me the `class data' is most confusing because it gets
> mixed up with `class'. As you did not like `priority' I do my last
> attempt to change the word and used `level'. How that would sound?
The 'ioprio' in the syscall:
syscall(SYS_ioprio_set, which, who, ioprio);
encodes two information:
IOPRIO_PRIO_CLASS - e.g. realtime, idle, ...
IOPRIO_PRIO_DATA - e.g. 0-7
this is reason why the docs is talking about "class" and "class data".
Anyway, merged with some minor changes and --classdata option :-)
Minor notes:
* .PP in man page within .IP block does not have the same meaning
like blank line
* I think that
-c, --class NUM
is better than
-c, --class=NUM
I have fixed this in ionice man page, but not in usage(). It would be
nice to use in all man pages and usage() functions the same syntax.
Maybe we can create any template or so to have it documented.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] minix: v3 super-block does not have s_state field
From: Karel Zak @ 2011-07-21 11:21 UTC (permalink / raw)
To: kerolasa; +Cc: Davidlohr Bueso, util-linux
In-Reply-To: <CAG27Bk3pxKEUPVE92=rZwA-FDHqA81TSM71J0Ati3mFXcGvE3g@mail.gmail.com>
On Wed, Jul 20, 2011 at 08:53:11PM +0200, Sami Kerola wrote:
> disk-utils/Makefile.am | 4 +-
> disk-utils/fsck.minix.c | 99 ++++++++++---------
> disk-utils/minix.h | 202 --------------------------------------
> disk-utils/minix_programs.h | 113 +++++++++++++++++++++
> disk-utils/mkfs.minix.c | 77 +++++++-------
> include/Makefile.am | 1 +
> include/minix.h | 97 ++++++++++++++++++
> libblkid/src/partitions/minix.c | 6 +-
> libblkid/src/superblocks/minix.c | 33 +------
Merged. I have removed the "static" variables from the
minix_programs.h file. It's better to use normal global variables.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* [git pull] cramfs fixes
From: Sami Kerola @ 2011-07-20 20:55 UTC (permalink / raw)
To: util-linux
The following changes since commit 608d45015f78d85510b22181e7afd189876ac6c6:
dmesg: allow to print time delta without timestamp (2011-07-20 17:03:24 +0200)
are available in the git repository at:
https://github.com/kerolasa/lelux-utiliteetit cramfs
Sami Kerola (15):
cramfs_common: coding style
cramfs: use stdint.h instead of u{8,16,32}
cramfs.h: coding style
fsck.cramfs: retire die function
fsck.cramfs: use xalloc.h
fsck.cramfs: coding style
fsck.cramfs: add missed strings to translation
mkfs.cramfs: use xalloc.h
mkfs.cramfs: use program_invocation_short_name
md5: use symbolical digest length
mkfs.cramfs: few symbolic exit codes where missing
mkfs.cramfs: validate numeric user inputs
mkfs.cramfs: convert spaces to tabs
mkfs.cramfs: error printing fixes
mkfs.cramfs: include-what-you-use header check
disk-utils/Makefile.am | 2 +-
disk-utils/cramfs.h | 67 +++---
disk-utils/cramfs_common.c | 46 ++--
disk-utils/fsck.cramfs.c | 538 ++++++++++++++++++----------------------
disk-utils/mkfs.cramfs.c | 280 +++++++++-------------
include/md5.h | 4 +-
lib/md5.c | 4 +-
libblkid/src/superblocks/hfs.c | 6 +-
misc-utils/mcookie.c | 4 +-
tests/helpers/test_md5.c | 4 +-
10 files changed, 423 insertions(+), 532 deletions(-)
diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am
index a7c2eaa..4f26b90 100644
--- a/disk-utils/Makefile.am
+++ b/disk-utils/Makefile.am
@@ -64,7 +64,7 @@ if BUILD_CRAMFS
cramfs_common = $(utils_common) cramfs.h cramfs_common.c
sbin_PROGRAMS += fsck.cramfs mkfs.cramfs
fsck_cramfs_SOURCES = fsck.cramfs.c $(cramfs_common)
-mkfs_cramfs_SOURCES = mkfs.cramfs.c mkfs.h $(cramfs_common)
$(top_srcdir)/lib/md5.c
+mkfs_cramfs_SOURCES = mkfs.cramfs.c mkfs.h $(cramfs_common)
$(top_srcdir)/lib/md5.c $(top_srcdir)/lib/strutils.c
fsck_cramfs_LDADD = -lz
mkfs_cramfs_LDADD = -lz
endif
diff --git a/disk-utils/cramfs.h b/disk-utils/cramfs.h
index ba4ba7f..fcfae56 100644
--- a/disk-utils/cramfs.h
+++ b/disk-utils/cramfs.h
@@ -19,9 +19,7 @@
#ifndef __CRAMFS_H
#define __CRAMFS_H
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
+#include <stdint.h>
#define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
#define CRAMFS_SIGNATURE "Compressed ROMFS"
@@ -49,47 +47,50 @@ typedef unsigned int u32;
* Reasonably terse representation of the inode data.
*/
struct cramfs_inode {
- u32 mode:16, uid:16;
+ uint32_t mode:16, uid:16;
/* SIZE for device files is i_rdev */
- u32 size:24, gid:8;
- /* NAMELEN is the length of the file name, divided by 4 and
- rounded up. (cramfs doesn't support hard links.) */
- /* OFFSET: For symlinks and non-empty regular files, this
- contains the offset (divided by 4) of the file data in
- compressed form (starting with an array of block pointers;
- see README). For non-empty directories it is the offset
- (divided by 4) of the inode of the first file in that
- directory. For anything else, offset is zero. */
+ uint32_t size:24, gid:8;
+ /*
+ * NAMELEN is the length of the file name, divided by 4 and
+ * rounded up. (cramfs doesn't support hard links.)
+ *
+ * OFFSET: For symlinks and non-empty regular files, this
+ * contains the offset (divided by 4) of the file data in
+ * compressed form (starting with an array of block pointers;
+ * see README). For non-empty directories it is the offset
+ * (divided by 4) of the inode of the first file in that
+ * directory. For anything else, offset is zero.
+ */
u32 namelen:6, offset:26;
};
struct cramfs_info {
- u32 crc;
- u32 edition;
- u32 blocks;
- u32 files;
+ uint32_t crc;
+ uint32_t edition;
+ uint32_t blocks;
+ uint32_t files;
};
/*
* Superblock information at the beginning of the FS.
*/
struct cramfs_super {
- u32 magic; /* 0x28cd3d45 - random number */
- u32 size; /* Not used. mkcramfs currently
- writes a constant 1<<16 here. */
- u32 flags; /* 0 */
- u32 future; /* 0 */
- u8 signature[16]; /* "Compressed ROMFS" */
+ uint32_t magic; /* 0x28cd3d45 - random number */
+ uint32_t size; /* Not used. mkcramfs currently
+ writes a constant 1<<16 here. */
+ uint32_t flags; /* 0 */
+ uint32_t future; /* 0 */
+ uint8_t signature[16]; /* "Compressed ROMFS" */
struct cramfs_info fsid;/* unique filesystem info */
- u8 name[16]; /* user-defined name */
+ uint8_t name[16]; /* user-defined name */
struct cramfs_inode root; /* Root inode data */
};
-#define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */
-#define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */
-#define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */
-#define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */
-#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */
+#define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */
+#define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */
+#define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */
+#define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */
+#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */
/*
* Valid values in super.flags. Currently we refuse to mount
@@ -103,9 +104,11 @@ int cramfs_uncompress_block(void *dst, int
dstlen, void *src, int srclen);
int cramfs_uncompress_init(void);
int cramfs_uncompress_exit(void);
-u32 u32_toggle_endianness(int big_endian, u32 what);
+uint32_t u32_toggle_endianness(int big_endian, uint32_t what);
void super_toggle_endianness(int from_big_endian, struct cramfs_super *super);
-void inode_to_host(int from_big_endian, struct cramfs_inode
*inode_in, struct cramfs_inode *inode_out);
-void inode_from_host(int to_big_endian, struct cramfs_inode
*inode_in, struct cramfs_inode *inode_out);
+void inode_to_host(int from_big_endian, struct cramfs_inode *inode_in,
+ struct cramfs_inode *inode_out);
+void inode_from_host(int to_big_endian, struct cramfs_inode *inode_in,
+ struct cramfs_inode *inode_out);
#endif
diff --git a/disk-utils/cramfs_common.c b/disk-utils/cramfs_common.c
index 4f679cb..f4a257d 100644
--- a/disk-utils/cramfs_common.c
+++ b/disk-utils/cramfs_common.c
@@ -20,7 +20,7 @@
#include "cramfs.h"
#include "../include/bitops.h"
-u32 u32_toggle_endianness(int big_endian, u32 what)
+uint32_t u32_toggle_endianness(int big_endian, uint32_t what)
{
return big_endian == HOST_IS_BIG_ENDIAN ? what : swab32(what);
}
@@ -35,16 +35,17 @@ void super_toggle_endianness(int big_endian,
struct cramfs_super *super)
super->fsid.crc = swab32(super->fsid.crc);
super->fsid.edition = swab32(super->fsid.edition);
super->fsid.blocks = swab32(super->fsid.blocks);
- super->fsid.files = swab32(super->fsid.files);
+ super->fsid.files = swab32(super->fsid.files);
}
}
-void inode_toggle_endianness(int input_big_endian, int
output_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode
*inode_out)
+void inode_toggle_endianness(int input_big_endian, int output_big_endian,
+ struct cramfs_inode *inode_in,
+ struct cramfs_inode *inode_out)
{
if (input_big_endian == output_big_endian) {
memmove(inode_out, inode_in, sizeof(*inode_out));
- }
- else {
+ } else {
unsigned char inode_out_buf[sizeof(*inode_in)];
unsigned char *inode_in_buf = (unsigned char*)inode_in;
@@ -52,7 +53,7 @@ void inode_toggle_endianness(int input_big_endian,
int output_big_endian, struct
inode_out_buf[1] = inode_in_buf[0];
inode_out_buf[2] = inode_in_buf[3]; /* 16 bit: uid */
- inode_out_buf[3] = inode_in_buf[2];
+ inode_out_buf[3] = inode_in_buf[2];
inode_out_buf[4] = inode_in_buf[6]; /* 24 bit: size */
inode_out_buf[5] = inode_in_buf[5];
@@ -60,11 +61,12 @@ void inode_toggle_endianness(int input_big_endian,
int output_big_endian, struct
inode_out_buf[7] = inode_in_buf[7]; /* 8 bit: gid width */
- /* Stop the madness! Outlaw C bitfields! They are unportable and nasty!
- See for yourself what a mess this is: */
-
+ /*
+ * Stop the madness! Outlaw C bitfields! They are unportable
+ * and nasty! See for yourself what a mess this is:
+ */
if (output_big_endian) {
- inode_out_buf[ 8] = ( (inode_in_buf[ 8]&0x3F) << 2 ) |
+ inode_out_buf[ 8] = ( (inode_in_buf[ 8]&0x3F) << 2 ) |
( (inode_in_buf[11]&0xC0) >> 6 );
inode_out_buf[ 9] = ( (inode_in_buf[11]&0x3F) << 2 ) |
@@ -75,31 +77,33 @@ void inode_toggle_endianness(int input_big_endian,
int output_big_endian, struct
inode_out_buf[11] = ( (inode_in_buf[ 9]&0x3F) << 2 ) |
( (inode_in_buf[ 8]&0xC0) >> 6 );
- }
- else {
- inode_out_buf[ 8] = ( (inode_in_buf[ 8]&0xFD) >> 2 ) |
+ } else {
+ inode_out_buf[ 8] = ( (inode_in_buf[ 8]&0xFD) >> 2 ) |
( (inode_in_buf[11]&0x03) << 6 );
- inode_out_buf[ 9] = ( (inode_in_buf[11]&0xFD) >> 2 ) |
+ inode_out_buf[ 9] = ( (inode_in_buf[11]&0xFD) >> 2 ) |
( (inode_in_buf[10]&0x03) << 6 );
- inode_out_buf[10] = ( (inode_in_buf[10]&0xFD) >> 2 ) |
+ inode_out_buf[10] = ( (inode_in_buf[10]&0xFD) >> 2 ) |
( (inode_in_buf[ 9]&0x03) << 6 );
- inode_out_buf[11] = ( (inode_in_buf[ 9]&0xFD) >> 2 ) |
+ inode_out_buf[11] = ( (inode_in_buf[ 9]&0xFD) >> 2 ) |
( (inode_in_buf[ 8]&0x03) << 6 );
}
-
memmove(inode_out, inode_out_buf, sizeof(*inode_out));
}
}
-void inode_to_host(int from_big_endian, struct cramfs_inode
*inode_in, struct cramfs_inode *inode_out)
+void inode_to_host(int from_big_endian, struct cramfs_inode *inode_in,
+ struct cramfs_inode *inode_out)
{
- inode_toggle_endianness(from_big_endian, HOST_IS_BIG_ENDIAN,
inode_in, inode_out);
+ inode_toggle_endianness(from_big_endian, HOST_IS_BIG_ENDIAN, inode_in,
+ inode_out);
}
-void inode_from_host(int to_big_endian, struct cramfs_inode
*inode_in, struct cramfs_inode *inode_out)
+void inode_from_host(int to_big_endian, struct cramfs_inode *inode_in,
+ struct cramfs_inode *inode_out)
{
- inode_toggle_endianness(HOST_IS_BIG_ENDIAN, to_big_endian, inode_in,
inode_out);
+ inode_toggle_endianness(HOST_IS_BIG_ENDIAN, to_big_endian, inode_in,
+ inode_out);
}
diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c
index 3d0c3e5..181c113 100644
--- a/disk-utils/fsck.cramfs.c
+++ b/disk-utils/fsck.cramfs.c
@@ -36,8 +36,18 @@
/* compile-time options */
//#define INCLUDE_FS_TESTS /* include cramfs checking and extraction */
+/* Exit codes used by fsck-type programs */
+#define FSCK_OK 0 /* No errors */
+#define FSCK_NONDESTRUCT 1 /* File system errors corrected */
+#define FSCK_REBOOT 2 /* System should be rebooted */
+#define FSCK_UNCORRECTED 4 /* File system errors left uncorrected */
+#define FSCK_ERROR 8 /* Operational error */
+#define FSCK_USAGE 16 /* Usage or syntax error */
+#define FSCK_LIBRARY 128 /* Shared library error */
+
#include <stdio.h>
#include <stdarg.h>
+#include <stdint.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
@@ -56,6 +66,10 @@
#include "cramfs.h"
#include "nls.h"
#include "blkdev.h"
+#include "c.h"
+
+#define XALLOC_EXIT_CODE FSCK_ERROR
+#include "xalloc.h"
static const char *progname = "cramfsck";
@@ -65,16 +79,7 @@ struct cramfs_super super; /* just find the cramfs
superblock once */
static int cramfs_is_big_endian = 0; /* source is big endian */
static int opt_verbose = 0; /* 1 = verbose (-v), 2+ = very verbose (-vv) */
-char *extract_dir = ""; /* extraction directory (-x) */
-
-/* Exit codes used by fsck-type programs */
-#define FSCK_OK 0 /* No errors */
-#define FSCK_NONDESTRUCT 1 /* File system errors corrected */
-#define FSCK_REBOOT 2 /* System should be rebooted */
-#define FSCK_UNCORRECTED 4 /* File system errors left uncorrected */
-#define FSCK_ERROR 8 /* Operational error */
-#define FSCK_USAGE 16 /* Usage or syntax error */
-#define FSCK_LIBRARY 128 /* Shared library error */
+char *extract_dir = ""; /* extraction directory (-x) */
#define PAD_SIZE 512
@@ -82,19 +87,19 @@ char *extract_dir = ""; /* extraction directory (-x) */
static int opt_extract = 0; /* extract cramfs (-x) */
-static uid_t euid; /* effective UID */
+static uid_t euid; /* effective UID */
/* (cramfs_super + start) <= start_dir < end_dir <= start_data <= end_data */
-static unsigned long start_dir = ~0UL; /* start of first non-root inode */
-static unsigned long end_dir = 0; /* end of the directory structure */
-static unsigned long start_data = ~0UL; /* start of the data
(256 MB = max) */
-static unsigned long end_data = 0; /* end of the data */
+static unsigned long start_dir = ~0UL; /* start of first non-root inode */
+static unsigned long end_dir = 0; /* end of the directory structure */
+static unsigned long start_data = ~0UL; /* start of the data (256 MB = max) */
+static unsigned long end_data = 0; /* end of the data */
/* Guarantee access to at least 8kB at a time */
#define ROMBUFFER_BITS 13
#define ROMBUFFERSIZE (1 << ROMBUFFER_BITS)
-#define ROMBUFFERMASK (ROMBUFFERSIZE-1)
+#define ROMBUFFERMASK (ROMBUFFERSIZE - 1)
static char read_buffer[ROMBUFFERSIZE * 2];
static unsigned long read_buffer_block = ~0UL;
@@ -122,169 +127,138 @@ static void usage(int status)
exit(status);
}
-static void die(int status, int syserr, const char *fmt, ...)
-{
- va_list arg_ptr;
- int save = errno;
-
- fflush(0);
- va_start(arg_ptr, fmt);
- fprintf(stderr, "%s: ", progname);
- vfprintf(stderr, fmt, arg_ptr);
- if (syserr) {
- fprintf(stderr, ": %s", strerror(save));
- }
- fprintf(stderr, "\n");
- va_end(arg_ptr);
- exit(status);
-}
-
-int get_superblock_endianness(u32 magic)
+int get_superblock_endianness(uint32_t magic)
{
if (magic == CRAMFS_MAGIC) {
cramfs_is_big_endian = HOST_IS_BIG_ENDIAN;
return 0;
- }
- else if (magic == u32_toggle_endianness(!HOST_IS_BIG_ENDIAN, CRAMFS_MAGIC)) {
+ } else if (magic ==
+ u32_toggle_endianness(!HOST_IS_BIG_ENDIAN, CRAMFS_MAGIC)) {
cramfs_is_big_endian = !HOST_IS_BIG_ENDIAN;
return 0;
- }
- else {
+ } else
return -1;
- }
}
-static void test_super(int *start, size_t *length) {
+static void test_super(int *start, size_t * length)
+{
struct stat st;
/* find the physical size of the file or block device */
- if (stat(filename, &st) < 0) {
- die(FSCK_ERROR, 1, _("stat failed: %s"), filename);
- }
+ if (stat(filename, &st) < 0)
+ err(FSCK_ERROR, _("stat failed: %s"), filename);
+
fd = open(filename, O_RDONLY);
- if (fd < 0) {
- die(FSCK_ERROR, 1, _("open failed: %s"), filename);
- }
+ if (fd < 0)
+ err(FSCK_ERROR, _("open failed: %s"), filename);
+
if (S_ISBLK(st.st_mode)) {
unsigned long long bytes;
- if (blkdev_get_size(fd, &bytes)) {
- die(FSCK_ERROR, 1, _("ioctl failed: unable to determine device
size: %s"), filename);
- }
+ if (blkdev_get_size(fd, &bytes))
+ err(FSCK_ERROR,
+ _("ioctl failed: unable to determine device size: %s"),
+ filename);
*length = bytes;
- }
- else if (S_ISREG(st.st_mode)) {
+ } else if (S_ISREG(st.st_mode))
*length = st.st_size;
- }
- else {
- die(FSCK_ERROR, 0, _("not a block device or file: %s"), filename);
- }
+ else
+ errx(FSCK_ERROR, _("not a block device or file: %s"), filename);
- if (*length < sizeof(struct cramfs_super)) {
- die(FSCK_UNCORRECTED, 0, _("file length too short"));
- }
+ if (*length < sizeof(struct cramfs_super))
+ errx(FSCK_UNCORRECTED, _("file length too short"));
/* find superblock */
- if (read(fd, &super, sizeof(super)) != sizeof(super)) {
- die(FSCK_ERROR, 1, _("read failed: %s"), filename);
- }
- if (get_superblock_endianness(super.magic) != -1) {
+ if (read(fd, &super, sizeof(super)) != sizeof(super))
+ err(FSCK_ERROR, _("read failed: %s"), filename);
+ if (get_superblock_endianness(super.magic) != -1)
*start = 0;
- }
else if (*length >= (PAD_SIZE + sizeof(super))) {
lseek(fd, PAD_SIZE, SEEK_SET);
- if (read(fd, &super, sizeof(super)) != sizeof(super)) {
- die(FSCK_ERROR, 1, _("read failed: %s"), filename);
- }
- if (get_superblock_endianness(super.magic) != -1) {
+ if (read(fd, &super, sizeof(super)) != sizeof(super))
+ err(FSCK_ERROR, _("read failed: %s"), filename);
+ if (get_superblock_endianness(super.magic) != -1)
*start = PAD_SIZE;
- }
- else {
- die(FSCK_UNCORRECTED, 0, "superblock magic not found");
- }
- }
- else {
- die(FSCK_UNCORRECTED, 0, _("superblock magic not found"));
- }
+ else
+ errx(FSCK_UNCORRECTED, _("superblock magic not found"));
+ } else
+ errx(FSCK_UNCORRECTED, _("superblock magic not found"));
- if (opt_verbose) {
- printf("cramfs endianness is %s\n", cramfs_is_big_endian ? "big" : "little");
- }
+ if (opt_verbose)
+ printf(_("cramfs endianness is %s\n"),
+ cramfs_is_big_endian ? _("big") : _("little"));
super_toggle_endianness(cramfs_is_big_endian, &super);
- if (super.flags & ~CRAMFS_SUPPORTED_FLAGS) {
- die(FSCK_ERROR, 0, _("unsupported filesystem features"));
- }
- if (super.size < page_size) {
- die(FSCK_UNCORRECTED, 0, _("superblock size (%d) too small"), super.size);
- }
+ if (super.flags & ~CRAMFS_SUPPORTED_FLAGS)
+ errx(FSCK_ERROR, _("unsupported filesystem features"));
+
+ if (super.size < page_size)
+ errx(FSCK_UNCORRECTED, _("superblock size (%d) too small"),
+ super.size);
+
if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {
- if (super.fsid.files == 0) {
- die(FSCK_UNCORRECTED, 0, _("zero file count"));
- }
- if (*length < super.size) {
- die(FSCK_UNCORRECTED, 0, _("file length too short"));
- }
- else if (*length > super.size) {
- fprintf(stderr, _("warning: file extends past end of filesystem\n"));
- }
- }
- else {
+ if (super.fsid.files == 0)
+ errx(FSCK_UNCORRECTED, _("zero file count"));
+ if (*length < super.size)
+ errx(FSCK_UNCORRECTED, _("file length too short"));
+ else if (*length > super.size)
+ fprintf(stderr,
+ _("warning: file extends past end of filesystem\n"));
+ } else
fprintf(stderr, _("warning: old cramfs format\n"));
- }
}
static void test_crc(int start)
{
void *buf;
- u32 crc;
+ uint32_t crc;
if (!(super.flags & CRAMFS_FLAG_FSID_VERSION_2)) {
#ifdef INCLUDE_FS_TESTS
return;
-#else /* not INCLUDE_FS_TESTS */
- die(FSCK_USAGE, 0, _("unable to test CRC: old cramfs format"));
-#endif /* not INCLUDE_FS_TESTS */
+#else
+ errx(FSCK_USAGE, _("unable to test CRC: old cramfs format"));
+#endif
}
crc = crc32(0L, Z_NULL, 0);
- buf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+ buf =
+ mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if (buf == MAP_FAILED) {
- buf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE |
MAP_ANONYMOUS, -1, 0);
+ buf =
+ mmap(NULL, super.size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (buf != MAP_FAILED) {
lseek(fd, 0, SEEK_SET);
if (read(fd, buf, super.size) < 0)
- die(FSCK_ERROR, 1, _("read failed: %s"), filename);
+ err(FSCK_ERROR, _("read failed: %s"), filename);
}
}
if (buf != MAP_FAILED) {
- ((struct cramfs_super *) (buf+start))->fsid.crc = crc32(0L, Z_NULL, 0);
- crc = crc32(crc, buf+start, super.size-start);
+ ((struct cramfs_super *)(buf + start))->fsid.crc =
+ crc32(0L, Z_NULL, 0);
+ crc = crc32(crc, buf + start, super.size - start);
munmap(buf, super.size);
- }
- else {
+ } else {
int retval;
size_t length = 0;
- buf = malloc(4096);
- if (!buf) {
- die(FSCK_ERROR, 1, _("malloc failed"));
- }
+ buf = xmalloc(4096);
lseek(fd, start, SEEK_SET);
for (;;) {
retval = read(fd, buf, 4096);
- if (retval < 0) {
- die(FSCK_ERROR, 1, _("read failed: %s"), filename);
- }
- else if (retval == 0) {
+ if (retval < 0)
+ err(FSCK_ERROR, _("read failed: %s"), filename);
+ else if (retval == 0)
break;
- }
- if (length == 0) {
- ((struct cramfs_super *) buf)->fsid.crc = crc32(0L, Z_NULL, 0);
- }
+ if (length == 0)
+ ((struct cramfs_super *)buf)->fsid.crc =
+ crc32(0L, Z_NULL, 0);
length += retval;
- if (length > (super.size-start)) {
- crc = crc32(crc, buf, retval - (length - (super.size-start)));
+ if (length > (super.size - start)) {
+ crc = crc32(crc, buf,
+ retval - (length -
+ (super.size - start)));
break;
}
crc = crc32(crc, buf, retval);
@@ -292,9 +266,8 @@ static void test_crc(int start)
free(buf);
}
- if (crc != super.fsid.crc) {
- die(FSCK_UNCORRECTED, 0, _("crc error"));
- }
+ if (crc != super.fsid.crc)
+ errx(FSCK_UNCORRECTED, _("crc error"));
}
#ifdef INCLUDE_FS_TESTS
@@ -302,14 +275,12 @@ static void print_node(char type, struct
cramfs_inode *i, char *name)
{
char info[10];
- if (S_ISCHR(i->mode) || (S_ISBLK(i->mode))) {
+ if (S_ISCHR(i->mode) || (S_ISBLK(i->mode)))
/* major/minor numbers can be as high as 2^12 or 4096 */
snprintf(info, 10, "%4d,%4d", major(i->size), minor(i->size));
- }
- else {
+ else
/* size be as high as 2^24 or 16777216 */
snprintf(info, 10, "%9d", i->size);
- }
printf("%c %04o %s %5d:%-3d %s\n",
type, i->mode & ~S_IFMT, info, i->uid, i->gid,
@@ -330,13 +301,10 @@ static void *romfs_read(unsigned long offset)
return read_buffer + (offset & ROMBUFFERMASK);
}
-static struct cramfs_inode *cramfs_iget(struct cramfs_inode * i)
+static struct cramfs_inode *cramfs_iget(struct cramfs_inode *i)
{
- struct cramfs_inode *inode = malloc(sizeof(struct cramfs_inode));
+ struct cramfs_inode *inode = xmalloc(sizeof(struct cramfs_inode));
- if (!inode) {
- die(FSCK_ERROR, 1, _("malloc failed"));
- }
inode_to_host(cramfs_is_big_endian, i, inode);
return inode;
}
@@ -356,16 +324,15 @@ static void iput(struct cramfs_inode *inode)
*/
static struct cramfs_inode *read_super(void)
{
- struct cramfs_inode * root = cramfs_iget(&super.root);
+ struct cramfs_inode *root = cramfs_iget(&super.root);
unsigned long offset = root->offset << 2;
if (!S_ISDIR(root->mode))
- die(FSCK_UNCORRECTED, 0, _("root inode is not directory"));
+ errx(FSCK_UNCORRECTED, _("root inode is not directory"));
if (!(super.flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) &&
((offset != sizeof(struct cramfs_super)) &&
- (offset != PAD_SIZE + sizeof(struct cramfs_super))))
- {
- die(FSCK_UNCORRECTED, 0, _("bad root offset (%lu)"), offset);
+ (offset != PAD_SIZE + sizeof(struct cramfs_super)))) {
+ errx(FSCK_UNCORRECTED, _("bad root offset (%lu)"), offset);
}
return root;
}
@@ -377,68 +344,68 @@ static int uncompress_block(void *src, int len)
stream.next_in = src;
stream.avail_in = len;
- stream.next_out = (unsigned char *) outbuffer;
- stream.avail_out = page_size*2;
+ stream.next_out = (unsigned char *)outbuffer;
+ stream.avail_out = page_size * 2;
inflateReset(&stream);
- if (len > page_size*2) {
- die(FSCK_UNCORRECTED, 0, _("data block too large"));
- }
+ if (len > page_size * 2)
+ errx(FSCK_UNCORRECTED, _("data block too large"));
+
err = inflate(&stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- die(FSCK_UNCORRECTED, 0, _("decompression error %p(%d): %s"),
- zError(err), src, len);
- }
+ if (err != Z_STREAM_END)
+ errx(FSCK_UNCORRECTED, _("decompression error %p(%d): %s"),
+ zError(err), src, len);
return stream.total_out;
}
#if !HAVE_LCHOWN
#define lchown chown
#endif
-static void do_uncompress(char *path, int fd, unsigned long offset,
unsigned long size)
+
+static void do_uncompress(char *path, int fd, unsigned long offset,
+ unsigned long size)
{
unsigned long curr = offset + 4 * ((size + page_size - 1) / page_size);
do {
unsigned long out = page_size;
- unsigned long next = u32_toggle_endianness(cramfs_is_big_endian,
*(u32 *) romfs_read(offset));
+ unsigned long next = u32_toggle_endianness(cramfs_is_big_endian,
+ *(uint32_t *)
+ romfs_read(offset));
- if (next > end_data) {
+ if (next > end_data)
end_data = next;
- }
offset += 4;
if (curr == next) {
- if (opt_verbose > 1) {
- printf(_(" hole at %ld (%zd)\n"), curr, page_size);
- }
+ if (opt_verbose > 1)
+ printf(_(" hole at %ld (%zd)\n"), curr,
+ page_size);
if (size < page_size)
out = size;
memset(outbuffer, 0x00, out);
- }
- else {
- if (opt_verbose > 1) {
- printf(_(" uncompressing block at %ld to %ld (%ld)\n"), curr,
next, next - curr);
- }
+ } else {
+ if (opt_verbose > 1)
+ printf(_(" uncompressing block at %ld to %ld (%ld)\n"),
+ curr, next, next - curr);
out = uncompress_block(romfs_read(curr), next - curr);
}
if (size >= page_size) {
- if (out != page_size) {
- die(FSCK_UNCORRECTED, 0, _("non-block (%ld) bytes"), out);
- }
- } else {
- if (out != size) {
- die(FSCK_UNCORRECTED, 0, _("non-size (%ld vs %ld) bytes"), out, size);
- }
- }
- size -= out;
- if (opt_extract) {
- if (write(fd, outbuffer, out) < 0) {
- die(FSCK_ERROR, 1, _("write failed: %s"), path);
- }
+ if (out != page_size)
+ errx(FSCK_UNCORRECTED,
+ _("non-block (%ld) bytes"), out);
+ else if (out != size)
+ errx(FSCK_UNCORRECTED,
+ _("non-size (%ld vs %ld) bytes"), out,
+ size);
+ size -= out;
+ if (opt_extract)
+ if (write(fd, outbuffer, out) < 0)
+ err(FSCK_ERROR, _("write failed: %s"),
+ path);
+ curr = next;
}
- curr = next;
} while (size);
}
@@ -447,22 +414,18 @@ static void change_file_status(char *path,
struct cramfs_inode *i)
struct utimbuf epoch = { 0, 0 };
if (euid == 0) {
- if (lchown(path, i->uid, i->gid) < 0) {
- die(FSCK_ERROR, 1, _("lchown failed: %s"), path);
- }
+ if (lchown(path, i->uid, i->gid) < 0)
+ err(FSCK_ERROR, _("lchown failed: %s"), path);
if (S_ISLNK(i->mode))
return;
- if ((S_ISUID | S_ISGID) & i->mode) {
- if (chmod(path, i->mode) < 0) {
- die(FSCK_ERROR, 1, _("chown failed: %s"), path);
- }
- }
+ if ((S_ISUID | S_ISGID) & i->mode)
+ if (chmod(path, i->mode) < 0)
+ err(FSCK_ERROR, _("chown failed: %s"), path);
}
if (S_ISLNK(i->mode))
return;
- if (utime(path, &epoch) < 0) {
- die(FSCK_ERROR, 1, _("utime failed: %s"), path);
- }
+ if (utime(path, &epoch) < 0)
+ err(FSCK_ERROR, _("utime failed: %s"), path);
}
static void do_directory(char *path, struct cramfs_inode *i)
@@ -470,28 +433,26 @@ static void do_directory(char *path, struct
cramfs_inode *i)
int pathlen = strlen(path);
int count = i->size;
unsigned long offset = i->offset << 2;
- char *newpath = malloc(pathlen + 256);
+ char *newpath = xmalloc(pathlen + 256);
- if (!newpath) {
- die(FSCK_ERROR, 1, _("malloc failed"));
- }
- if (offset == 0 && count != 0) {
- die(FSCK_UNCORRECTED, 0, _("directory inode has zero offset and
non-zero size: %s"), path);
- }
- if (offset != 0 && offset < start_dir) {
+ if (offset == 0 && count != 0)
+ errx(FSCK_UNCORRECTED,
+ _("directory inode has zero offset and non-zero size: %s"),
+ path);
+
+ if (offset != 0 && offset < start_dir)
start_dir = offset;
- }
+
/* TODO: Do we need to check end_dir for empty case? */
memcpy(newpath, path, pathlen);
newpath[pathlen] = '/';
pathlen++;
- if (opt_verbose) {
+ if (opt_verbose)
print_node('d', i, path);
- }
+
if (opt_extract) {
- if (mkdir(path, i->mode) < 0) {
- die(FSCK_ERROR, 1, _("mkdir failed: %s"), path);
- }
+ if (mkdir(path, i->mode) < 0)
+ err(FSCK_ERROR, _("mkdir failed: %s"), path);
change_file_status(path, i);
}
while (count > 0) {
@@ -506,23 +467,19 @@ static void do_directory(char *path, struct
cramfs_inode *i)
memcpy(newpath + pathlen, romfs_read(offset), newlen);
newpath[pathlen + newlen] = 0;
- if (newlen == 0) {
- die(FSCK_UNCORRECTED, 0, _("filename length is zero"));
- }
- if ((pathlen + newlen) - strlen(newpath) > 3) {
- die(FSCK_UNCORRECTED, 0, _("bad filename length"));
- }
+ if (newlen == 0)
+ errx(FSCK_UNCORRECTED, _("filename length is zero"));
+ if ((pathlen + newlen) - strlen(newpath) > 3)
+ errx(FSCK_UNCORRECTED, _("bad filename length"));
expand_fs(newpath, child);
offset += newlen;
- if (offset <= start_dir) {
- die(FSCK_UNCORRECTED, 0, _("bad inode offset"));
- }
- if (offset > end_dir) {
+ if (offset <= start_dir)
+ errx(FSCK_UNCORRECTED, _("bad inode offset"));
+ if (offset > end_dir)
end_dir = offset;
- }
- iput(child); /* free(child) */
+ iput(child); /* free(child) */
}
free(newpath);
}
@@ -532,27 +489,23 @@ static void do_file(char *path, struct cramfs_inode *i)
unsigned long offset = i->offset << 2;
int fd = 0;
- if (offset == 0 && i->size != 0) {
- die(FSCK_UNCORRECTED, 0, _("file inode has zero offset and non-zero size"));
- }
- if (i->size == 0 && offset != 0) {
- die(FSCK_UNCORRECTED, 0, _("file inode has zero size and non-zero offset"));
- }
- if (offset != 0 && offset < start_data) {
+ if (offset == 0 && i->size != 0)
+ errx(FSCK_UNCORRECTED,
+ _("file inode has zero offset and non-zero size"));
+ if (i->size == 0 && offset != 0)
+ errx(FSCK_UNCORRECTED,
+ _("file inode has zero size and non-zero offset"));
+ if (offset != 0 && offset < start_data)
start_data = offset;
- }
- if (opt_verbose) {
+ if (opt_verbose)
print_node('f', i, path);
- }
if (opt_extract) {
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, i->mode);
- if (fd < 0) {
- die(FSCK_ERROR, 1, _("open failed: %s"), path);
- }
+ if (fd < 0)
+ err(FSCK_ERROR, _("open failed: %s"), path);
}
- if (i->size) {
+ if (i->size)
do_uncompress(path, fd, offset, i->size);
- }
if (opt_extract) {
close(fd);
change_file_status(path, i);
@@ -563,42 +516,38 @@ static void do_symlink(char *path, struct cramfs_inode *i)
{
unsigned long offset = i->offset << 2;
unsigned long curr = offset + 4;
- unsigned long next = u32_toggle_endianness(cramfs_is_big_endian,
*(u32 *) romfs_read(offset));
+ unsigned long next =
+ u32_toggle_endianness(cramfs_is_big_endian,
+ *(uint32_t *) romfs_read(offset));
unsigned long size;
- if (offset == 0) {
- die(FSCK_UNCORRECTED, 0, _("symbolic link has zero offset"));
- }
- if (i->size == 0) {
- die(FSCK_UNCORRECTED, 0, _("symbolic link has zero size"));
- }
+ if (offset == 0)
+ errx(FSCK_UNCORRECTED, _("symbolic link has zero offset"));
+ if (i->size == 0)
+ errx(FSCK_UNCORRECTED, _("symbolic link has zero size"));
- if (offset < start_data) {
+ if (offset < start_data)
start_data = offset;
- }
- if (next > end_data) {
+ if (next > end_data)
end_data = next;
- }
size = uncompress_block(romfs_read(curr), next - curr);
- if (size != i->size) {
- die(FSCK_UNCORRECTED, 0, _("size error in symlink: %s"), path);
- }
+ if (size != i->size)
+ errx(FSCK_UNCORRECTED, _("size error in symlink: %s"), path);
outbuffer[size] = 0;
if (opt_verbose) {
char *str;
asprintf(&str, "%s -> %s", path, outbuffer);
print_node('l', i, str);
- if (opt_verbose > 1) {
- printf(_(" uncompressing block at %ld to %ld (%ld)\n"), curr,
next, next - curr);
- }
+ if (opt_verbose > 1)
+ printf(_(" uncompressing block at %ld to %ld (%ld)\n"),
+ curr, next, next - curr);
free(str);
}
if (opt_extract) {
- if (symlink(outbuffer, path) < 0) {
- die(FSCK_ERROR, 1, _("symlink failed: %s"), path);
- }
+ if (symlink(outbuffer, path) < 0)
+ err(FSCK_ERROR, _("symlink failed: %s"), path);
change_file_status(path, i);
}
}
@@ -608,60 +557,52 @@ static void do_special_inode(char *path, struct
cramfs_inode *i)
dev_t devtype = 0;
char type;
- if (i->offset) { /* no need to shift offset */
- die(FSCK_UNCORRECTED, 0, _("special file has non-zero offset: %s"), path);
- }
+ if (i->offset)
+ /* no need to shift offset */
+ errx(FSCK_UNCORRECTED,
+ _("special file has non-zero offset: %s"), path);
+
if (S_ISCHR(i->mode)) {
devtype = i->size;
type = 'c';
- }
- else if (S_ISBLK(i->mode)) {
+ } else if (S_ISBLK(i->mode)) {
devtype = i->size;
type = 'b';
- }
- else if (S_ISFIFO(i->mode)) {
- if (i->size != 0) {
- die(FSCK_UNCORRECTED, 0, _("fifo has non-zero size: %s"), path);
- }
+ } else if (S_ISFIFO(i->mode)) {
+ if (i->size != 0)
+ errx(FSCK_UNCORRECTED, _("fifo has non-zero size: %s"),
+ path);
type = 'p';
- }
- else if (S_ISSOCK(i->mode)) {
- if (i->size != 0) {
- die(FSCK_UNCORRECTED, 0, _("socket has non-zero size: %s"), path);
- }
+ } else if (S_ISSOCK(i->mode)) {
+ if (i->size != 0)
+ errx(FSCK_UNCORRECTED,
+ _("socket has non-zero size: %s"), path);
type = 's';
- }
- else {
- die(FSCK_UNCORRECTED, 0, _("bogus mode: %s (%o)"), path, i->mode);
+ } else {
+ errx(FSCK_UNCORRECTED, _("bogus mode: %s (%o)"), path, i->mode);
return; /* not reached */
}
- if (opt_verbose) {
+ if (opt_verbose)
print_node(type, i, path);
- }
if (opt_extract) {
- if (mknod(path, i->mode, devtype) < 0) {
- die(FSCK_ERROR, 1, _("mknod failed: %s"), path);
- }
+ if (mknod(path, i->mode, devtype) < 0)
+ err(FSCK_ERROR, _("mknod failed: %s"), path);
change_file_status(path, i);
}
}
static void expand_fs(char *path, struct cramfs_inode *inode)
{
- if (S_ISDIR(inode->mode)) {
+ if (S_ISDIR(inode->mode))
do_directory(path, inode);
- }
- else if (S_ISREG(inode->mode)) {
+ else if (S_ISREG(inode->mode))
do_file(path, inode);
- }
- else if (S_ISLNK(inode->mode)) {
+ else if (S_ISLNK(inode->mode))
do_symlink(path, inode);
- }
- else {
+ else
do_special_inode(path, inode);
- }
}
static void test_fs(int start)
@@ -677,18 +618,19 @@ static void test_fs(int start)
expand_fs(extract_dir, root);
inflateEnd(&stream);
if (start_data != ~0UL) {
- if (start_data < (sizeof(struct cramfs_super) + start)) {
- die(FSCK_UNCORRECTED, 0, _("directory data start (%ld) <
sizeof(struct cramfs_super) + start (%ld)"), start_data, sizeof(struct
cramfs_super) + start);
- }
- if (end_dir != start_data) {
- die(FSCK_UNCORRECTED, 0, _("directory data end (%ld) != file data
start (%ld)"), end_dir, start_data);
- }
- }
- if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {
- if (end_data > super.size) {
- die(FSCK_UNCORRECTED, 0, _("invalid file data offset"));
- }
- }
+ if (start_data < (sizeof(struct cramfs_super) + start))
+ errx(FSCK_UNCORRECTED,
+ _("directory data start (%ld) < sizeof(struct cramfs_super) +
start (%ld)"),
+ start_data, sizeof(struct cramfs_super) + start);
+ if (end_dir != start_data)
+ errx(FSCK_UNCORRECTED,
+ _("directory data end (%ld) != file data start (%ld)"),
+ end_dir, start_data);
+ }
+ if (super.flags & CRAMFS_FLAG_FSID_VERSION_2)
+ if (end_data > super.size)
+ errx(FSCK_UNCORRECTED, _("invalid file data offset"));
+
iput(root); /* free(root) */
}
#endif /* INCLUDE_FS_TESTS */
@@ -708,12 +650,10 @@ int main(int argc, char **argv)
if (argc)
progname = argv[0];
- outbuffer = malloc(page_size * 2);
- if (!outbuffer)
- die(FSCK_ERROR, 1, _("failed to allocate outbuffer"));
+ outbuffer = xmalloc(page_size * 2);
/* command line options */
- while ((c = getopt(argc, argv, "hx:v")) != EOF) {
+ while ((c = getopt(argc, argv, "hx:v")) != EOF)
switch (c) {
case 'h':
usage(FSCK_OK);
@@ -722,14 +662,13 @@ int main(int argc, char **argv)
opt_extract = 1;
extract_dir = optarg;
break;
-#else /* not INCLUDE_FS_TESTS */
- die(FSCK_USAGE, 0, _("compiled without -x support"));
-#endif /* not INCLUDE_FS_TESTS */
+#else
+ errx(FSCK_USAGE, _("compiled without -x support"));
+#endif
case 'v':
opt_verbose++;
break;
}
- }
if ((argc - optind) != 1)
usage(FSCK_USAGE);
@@ -739,11 +678,10 @@ int main(int argc, char **argv)
test_crc(start);
#ifdef INCLUDE_FS_TESTS
test_fs(start);
-#endif /* INCLUDE_FS_TESTS */
+#endif
- if (opt_verbose) {
- printf("%s: OK\n", filename);
- }
+ if (opt_verbose)
+ printf(_("%s: OK\n"), filename);
exit(FSCK_OK);
}
diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c
index 6767ba3..1446a57 100644
--- a/disk-utils/mkfs.cramfs.c
+++ b/disk-utils/mkfs.cramfs.c
@@ -30,22 +30,26 @@
#include <sys/mman.h>
#include <fcntl.h>
#include <dirent.h>
+#include <stddef.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <getopt.h>
-#include <stdarg.h>
+#include <zconf.h>
#include <zlib.h>
+#include "c.h"
#include "cramfs.h"
#include "md5.h"
#include "nls.h"
#include "mkfs.h"
+#include "strutils.h"
+#define XALLOC_EXIT_CODE MKFS_ERROR
+#include "xalloc.h"
/* The kernel only supports PAD_SIZE of 0 and 512. */
#define PAD_SIZE 512
-static const char *progname = "mkcramfs";
static int verbose = 0;
static unsigned int blksize; /* settable via -b option */
@@ -88,14 +92,14 @@ struct entry {
/* stats */
unsigned char *name;
unsigned int mode, size, uid, gid;
- unsigned char md5sum[16];
+ unsigned char md5sum[MD5LENGTH];
unsigned char flags; /* CRAMFS_EFLAG_* */
/* FS data */
char *path;
int fd; /* temporarily open files while mmapped */
- struct entry *same; /* points to other identical file */
- unsigned int offset; /* pointer to compressed data in archive */
+ struct entry *same; /* points to other identical file */
+ unsigned int offset; /* pointer to compressed data in archive */
unsigned int dir_offset; /* offset of directory entry in archive */
/* organization */
@@ -135,22 +139,11 @@ usage(int status) {
" -z make explicit holes (requires >= 2.3.39)\n"
" dirname root of the filesystem to be compressed\n"
" outfile output file\n"),
- progname, PAD_SIZE);
+ program_invocation_short_name, PAD_SIZE);
exit(status);
}
-/* malloc or die */
-static void *
-xmalloc (size_t size) {
- void *t = malloc(size);
- if (t == NULL) {
- perror(NULL);
- exit(MKFS_ERROR); /* out of memory */
- }
- return t;
-}
-
static char *
do_mmap(char *path, unsigned int size, unsigned int mode){
int fd;
@@ -177,10 +170,8 @@ do_mmap(char *path, unsigned int size, unsigned int mode){
}
start = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (-1 == (int) (long) start) {
- perror("mmap");
- exit(MKFS_ERROR);
- }
+ if (-1 == (int) (long) start)
+ err(MKFS_ERROR, "mmap");
close(fd);
return start;
@@ -244,11 +235,11 @@ identical_file(struct entry *e1, struct entry *e2){
static int find_identical_file(struct entry *orig, struct entry *new,
loff_t *fslen_ub)
{
- if (orig == new)
+ if (orig == new)
return 1;
- if (!orig)
+ if (!orig)
return 0;
- if (orig->size == new->size && orig->path) {
+ if (orig->size == new->size && orig->path) {
if (!orig->flags)
mdfile(orig);
if (!new->flags)
@@ -256,24 +247,24 @@ static int find_identical_file(struct entry
*orig, struct entry *new, loff_t *fs
if ((orig->flags & CRAMFS_EFLAG_MD5) &&
(new->flags & CRAMFS_EFLAG_MD5) &&
- !memcmp(orig->md5sum, new->md5sum, 16) &&
+ !memcmp(orig->md5sum, new->md5sum, MD5LENGTH) &&
identical_file(orig, new)) {
new->same = orig;
*fslen_ub -= new->size;
return 1;
}
- }
- return find_identical_file(orig->child, new, fslen_ub) ||
- find_identical_file(orig->next, new, fslen_ub);
+ }
+ return find_identical_file(orig->child, new, fslen_ub) ||
+ find_identical_file(orig->next, new, fslen_ub);
}
static void eliminate_doubles(struct entry *root, struct entry *orig,
loff_t *fslen_ub) {
- if (orig) {
- if (orig->size && orig->path)
+ if (orig) {
+ if (orig->size && orig->path)
find_identical_file(root,orig, fslen_ub);
- eliminate_doubles(root,orig->child, fslen_ub);
- eliminate_doubles(root,orig->next, fslen_ub);
- }
+ eliminate_doubles(root,orig->child, fslen_ub);
+ eliminate_doubles(root,orig->next, fslen_ub);
+ }
}
/*
@@ -300,13 +291,11 @@ static unsigned int parse_directory(struct entry
*root_entry, const char *name,
*endpath = '/';
endpath++;
- /* read in the directory and sort */
- dircount = scandir(name, &dirlist, 0, cramsort);
+ /* read in the directory and sort */
+ dircount = scandir(name, &dirlist, 0, cramsort);
- if (dircount < 0) {
- perror(name);
- exit(MKFS_ERROR);
- }
+ if (dircount < 0)
+ err(MKFS_ERROR, _("could not read directory %s"), name);
/* process directory */
for (dirindex = 0; dirindex < dircount; dirindex++) {
@@ -329,14 +318,12 @@ static unsigned int parse_directory(struct entry
*root_entry, const char *name,
}
}
namelen = strlen(dirent->d_name);
- if (namelen > MAX_INPUT_NAMELEN) {
- fprintf(stderr,
+ if (namelen > MAX_INPUT_NAMELEN)
+ errx(MKFS_ERROR,
_("Very long (%zu bytes) filename `%s' found.\n"
" Please increase MAX_INPUT_NAMELEN in "
- "mkcramfs.c and recompile. Exiting.\n"),
+ "mkcramfs.c and recompile. Exiting."),
namelen, dirent->d_name);
- exit(MKFS_ERROR);
- }
memcpy(endpath, dirent->d_name, namelen + 1);
if (lstat(path, &st) < 0) {
@@ -344,16 +331,8 @@ static unsigned int parse_directory(struct entry
*root_entry, const char *name,
warn_skip = 1;
continue;
}
- entry = calloc(1, sizeof(struct entry));
- if (!entry) {
- perror(NULL);
- exit(MKFS_ERROR);
- }
- entry->name = (unsigned char *)strdup(dirent->d_name);
- if (!entry->name) {
- perror(NULL);
- exit(MKFS_ERROR);
- }
+ entry = xcalloc(1, sizeof(struct entry));
+ entry->name = (unsigned char *)xstrdup(dirent->d_name);
if (namelen > 255) {
/* Can't happen when reading from ext2fs. */
@@ -370,17 +349,17 @@ static unsigned int parse_directory(struct entry
*root_entry, const char *name,
entry->gid = st.st_gid;
if (entry->gid >= 1 << CRAMFS_GID_WIDTH)
/* TODO: We ought to replace with a default
- gid instead of truncating; otherwise there
- are security problems. Maybe mode should
- be &= ~070. Same goes for uid once Linux
- supports >16-bit uids. */
+ gid instead of truncating; otherwise there
+ are security problems. Maybe mode should
+ be &= ~070. Same goes for uid once Linux
+ supports >16-bit uids. */
warn_gid = 1;
size = sizeof(struct cramfs_inode) + ((namelen + 3) & ~3);
*fslen_ub += size;
if (S_ISDIR(st.st_mode)) {
entry->size = parse_directory(root_entry, path, &entry->child, fslen_ub);
} else if (S_ISREG(st.st_mode)) {
- entry->path = strdup(path);
+ entry->path = xstrdup(path);
if (entry->size) {
if (entry->size >= (1 << CRAMFS_SIZE_WIDTH)) {
warn_size = 1;
@@ -388,7 +367,7 @@ static unsigned int parse_directory(struct entry
*root_entry, const char *name,
}
}
} else if (S_ISLNK(st.st_mode)) {
- entry->path = strdup(path);
+ entry->path = xstrdup(path);
} else if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {
/* maybe we should skip sockets */
entry->size = 0;
@@ -404,7 +383,7 @@ static unsigned int parse_directory(struct entry
*root_entry, const char *name,
/* block pointers & data expansion allowance + data */
if (entry->size)
*fslen_ub += (4+26)*blocks + entry->size + 3;
- }
+ }
/* Link it into the list */
*prev = entry;
@@ -462,10 +441,8 @@ static void set_data_offset(struct entry *entry,
char *base, unsigned long offse
{
struct cramfs_inode *inode = (struct cramfs_inode *) (base +
entry->dir_offset);
inode_to_host(cramfs_is_big_endian, inode, inode);
- if (offset >= (1 << (2 + CRAMFS_OFFSET_WIDTH))) {
- fprintf(stderr, _("filesystem too big. Exiting.\n"));
- exit(MKFS_ERROR);
- }
+ if (offset >= (1 << (2 + CRAMFS_OFFSET_WIDTH)))
+ errx(MKFS_ERROR, _("filesystem too big. Exiting."));
inode->offset = (offset >> 2);
inode_from_host(cramfs_is_big_endian, inode, inode);
}
@@ -517,11 +494,7 @@ static unsigned int
write_directory_structure(struct entry *entry, char *base, u
if (entry->child) {
if (stack_entries >= stack_size) {
stack_size *= 2;
- entry_stack = realloc(entry_stack, stack_size * sizeof(struct entry *));
- if (!entry_stack) {
- perror(NULL);
- exit(MKFS_ERROR); /* out of memory */
- }
+ entry_stack = xrealloc(entry_stack, stack_size * sizeof(struct entry *));
}
entry_stack[stack_entries] = entry;
stack_entries++;
@@ -532,9 +505,9 @@ static unsigned int
write_directory_structure(struct entry *entry, char *base, u
/*
* Reverse the order the stack entries pushed during
- * this directory, for a small optimization of disk
- * access in the created fs. This change makes things
- * `ls -UR' order.
+ * this directory, for a small optimization of disk
+ * access in the created fs. This change makes things
+ * `ls -UR' order.
*/
{
struct entry **lo = entry_stack + dir_start;
@@ -634,7 +607,7 @@ do_compress(char *base, unsigned int offset,
unsigned char const *name,
exit(MKFS_ERROR);
}
- *(u32 *) (base + offset) = u32_toggle_endianness(cramfs_is_big_endian, curr);
+ *(uint32_t *) (base + offset) =
u32_toggle_endianness(cramfs_is_big_endian, curr);
offset += 4;
} while (size);
@@ -665,15 +638,15 @@ write_data(struct entry *entry, char *base,
unsigned int offset) {
for (e = entry; e; e = e->next) {
if (e->path) {
- if (e->same) {
- set_data_offset(e, base, e->same->offset);
- e->offset = e->same->offset;
- } else if (e->size) {
- set_data_offset(e, base, offset);
- e->offset = offset;
- offset = do_compress(base, offset, e->name,
+ if (e->same) {
+ set_data_offset(e, base, e->same->offset);
+ e->offset = e->same->offset;
+ } else if (e->size) {
+ set_data_offset(e, base, offset);
+ e->offset = offset;
+ offset = do_compress(base, offset, e->name,
e->path, e->size,e->mode);
- }
+ }
} else if (e->child)
offset = write_data(e->child, base, offset);
}
@@ -686,14 +659,13 @@ static unsigned int write_file(char *file, char
*base, unsigned int offset)
char *buf;
fd = open(file, O_RDONLY);
- if (fd < 0) {
- perror(file);
- exit(MKFS_ERROR);
- }
+ if (fd < 0)
+ err(MKFS_ERROR, _("cannot open file %s"), file);
buf = mmap(NULL, image_length, PROT_READ, MAP_PRIVATE, fd, 0);
memcpy(base + offset, buf, image_length);
munmap(buf, image_length);
- close (fd);
+ if (close (fd) < 0)
+ err(MKFS_ERROR, _("closing file %s"), file);
/* Pad up the image_length to a 4-byte boundary */
while (image_length & 3) {
*(base + offset + image_length) = '\0';
@@ -736,20 +708,13 @@ int main(int argc, char **argv)
loff_t fslen_ub = sizeof(struct cramfs_super);
unsigned int fslen_max;
char const *dirname, *outfile;
- u32 crc = crc32(0L, Z_NULL, 0);
+ uint32_t crc = crc32(0L, Z_NULL, 0);
int c;
cramfs_is_big_endian = HOST_IS_BIG_ENDIAN; /* default is to use host order */
blksize = getpagesize();
total_blocks = 0;
- if (argc) {
- char *p;
- progname = argv[0];
- if ((p = strrchr(progname, '/')) != NULL)
- progname = p+1;
- }
-
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -758,17 +723,17 @@ int main(int argc, char **argv)
while ((c = getopt(argc, argv, "hb:Ee:i:n:N:psVvz")) != EOF) {
switch (c) {
case 'h':
- usage(0);
+ usage(MKFS_OK);
case 'b':
- blksize = atoi(optarg);
+ blksize = strtoll_or_err(optarg, _("blocksize argument failed"));
if (blksize <= 0)
- usage(1);
+ usage(MKFS_USAGE);
break;
case 'E':
opt_errors = 1;
break;
case 'e':
- opt_edition = atoi(optarg);
+ opt_edition = strtoll_or_err(optarg, _("edition number argument failed"));
break;
case 'N':
if (strcmp(optarg, "big") == 0) {
@@ -778,18 +743,15 @@ int main(int argc, char **argv)
cramfs_is_big_endian = 0;
}
else if (strcmp(optarg, "host") == 0); /* default */
- else {
- perror("invalid endianness given. Must be 'big', 'little', or 'host'");
- exit(MKFS_USAGE);
- }
+ else
+ errx(MKFS_USAGE, _("invalid endianness given."
+ " Must be 'big', 'little', or 'host'"));
break;
case 'i':
opt_image = optarg;
- if (lstat(opt_image, &st) < 0) {
- perror(opt_image);
- exit(MKFS_USAGE);
- }
+ if (lstat(opt_image, &st) < 0)
+ err(MKFS_USAGE, _("cannot stat %s"), opt_image);
image_length = st.st_size; /* may be padded later */
fslen_ub += (image_length + 3); /* 3 is for padding */
break;
@@ -805,7 +767,7 @@ int main(int argc, char **argv)
break;
case 'V':
printf(_("%s (%s)\n"),
- progname, PACKAGE_STRING);
+ program_invocation_short_name, PACKAGE_STRING);
exit(MKFS_OK);
case 'v':
verbose = 1;
@@ -817,21 +779,17 @@ int main(int argc, char **argv)
}
if ((argc - optind) != 2)
- usage(16);
+ usage(MKFS_USAGE);
dirname = argv[optind];
outfile = argv[optind + 1];
- if (stat(dirname, &st) < 0) {
- perror(dirname);
- exit(MKFS_USAGE);
- }
+ if (stat(dirname, &st) < 0)
+ err(MKFS_USAGE, _("cannot stat %s"), dirname);
fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd < 0)
+ err(MKFS_USAGE, _("cannot open %s"), outfile);
- root_entry = calloc(1, sizeof(struct entry));
- if (!root_entry) {
- perror(NULL);
- exit(MKFS_ERROR);
- }
+ root_entry = xcalloc(1, sizeof(struct entry));
root_entry->mode = st.st_mode;
root_entry->uid = st.st_uid;
root_entry->gid = st.st_gid;
@@ -839,42 +797,39 @@ int main(int argc, char **argv)
root_entry->size = parse_directory(root_entry, dirname,
&root_entry->child, &fslen_ub);
/* always allocate a multiple of blksize bytes because that's
- what we're going to write later on */
+ what we're going to write later on */
fslen_ub = ((fslen_ub - 1) | (blksize - 1)) + 1;
fslen_max = maxfslen();
if (fslen_ub > fslen_max) {
- fprintf(stderr,
- _("warning: guestimate of required size (upper bound) "
+ warnx( _("warning: guestimate of required size (upper bound) "
"is %lldMB, but maximum image size is %uMB. "
- "We might die prematurely.\n"),
+ "We might die prematurely."),
(long long)fslen_ub >> 20,
fslen_max >> 20);
fslen_ub = fslen_max;
}
- /* find duplicate files */
- eliminate_doubles(root_entry,root_entry, &fslen_ub);
+ /* find duplicate files */
+ eliminate_doubles(root_entry,root_entry, &fslen_ub);
/* TODO: Why do we use a private/anonymous mapping here
- followed by a write below, instead of just a shared mapping
- and a couple of ftruncate calls? Is it just to save us
- having to deal with removing the file afterwards? If we
- really need this huge anonymous mapping, we ought to mmap
- in smaller chunks, so that the user doesn't need nn MB of
- RAM free. If the reason is to be able to write to
- un-mmappable block devices, then we could try shared mmap
- and revert to anonymous mmap if the shared mmap fails. */
+ followed by a write below, instead of just a shared mapping
+ and a couple of ftruncate calls? Is it just to save us
+ having to deal with removing the file afterwards? If we
+ really need this huge anonymous mapping, we ought to mmap
+ in smaller chunks, so that the user doesn't need nn MB of
+ RAM free. If the reason is to be able to write to
+ un-mmappable block devices, then we could try shared mmap
+ and revert to anonymous mmap if the shared mmap fails. */
rom_image = mmap(NULL,
fslen_ub?fslen_ub:1,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
- if (-1 == (int) (long) rom_image) {
- perror(_("ROM image map"));
- exit(MKFS_ERROR);
- }
+ if (-1 == (int) (long) rom_image)
+ err(MKFS_ERROR, _("ROM image map"));
/* Skip the first opt_pad bytes for boot loader code */
offset = opt_pad;
@@ -897,7 +852,7 @@ int main(int argc, char **argv)
offset = write_data(root_entry, rom_image, offset);
/* We always write a multiple of blksize bytes, so that
- losetup works. */
+ losetup works. */
offset = ((offset - 1) | (blksize - 1)) + 1;
if (verbose)
printf(_("Everything: %zd kilobytes\n"), offset >> 10);
@@ -915,56 +870,45 @@ int main(int argc, char **argv)
printf(_("CRC: %x\n"), crc);
/* Check to make sure we allocated enough space. */
- if (fslen_ub < offset) {
- fprintf(stderr,
+ if (fslen_ub < offset)
+ errx(MKFS_ERROR,
_("not enough space allocated for ROM image "
- "(%lld allocated, %zu used)\n"),
+ "(%lld allocated, %zu used)"),
(long long) fslen_ub, offset);
- exit(MKFS_ERROR);
- }
written = write(fd, rom_image, offset);
- if (written < 0) {
- perror(_("ROM image"));
- exit(MKFS_ERROR);
- }
- if (offset != written) {
- fprintf(stderr, _("ROM image write failed (%zd %zd)\n"),
+ if (written < 0)
+ err(MKFS_ERROR, _("ROM image"));
+ if (offset != written)
+ errx(MKFS_ERROR, _("ROM image write failed (%zd %zd)"),
written, offset);
- exit(MKFS_ERROR);
- }
/* (These warnings used to come at the start, but they scroll off the
- screen too quickly.) */
+ screen too quickly.) */
if (warn_namelen) /* (can't happen when reading from ext2fs) */
- fprintf(stderr, /* bytes, not chars: think UTF8. */
- _("warning: filenames truncated to 255 bytes.\n"));
+ warnx(/* bytes, not chars: think UTF8. */
+ _("warning: filenames truncated to 255 bytes."));
if (warn_skip)
- fprintf(stderr,
- _("warning: files were skipped due to errors.\n"));
+ warnx( _("warning: files were skipped due to errors."));
if (warn_size)
- fprintf(stderr,
- _("warning: file sizes truncated to %luMB "
- "(minus 1 byte).\n"),
+ warnx( _("warning: file sizes truncated to %luMB "
+ "(minus 1 byte)."),
1L << (CRAMFS_SIZE_WIDTH - 20));
if (warn_uid) /* (not possible with current Linux versions) */
- fprintf(stderr,
- _("warning: uids truncated to %u bits. "
- "(This may be a security concern.)\n"),
+ warnx( _("warning: uids truncated to %u bits. "
+ "(This may be a security concern.)"),
CRAMFS_UID_WIDTH);
if (warn_gid)
- fprintf(stderr,
- _("warning: gids truncated to %u bits. "
- "(This may be a security concern.)\n"),
+ warnx( _("warning: gids truncated to %u bits. "
+ "(This may be a security concern.)"),
CRAMFS_GID_WIDTH);
if (warn_dev)
- fprintf(stderr,
- _("WARNING: device numbers truncated to %u bits. "
+ warnx( _("WARNING: device numbers truncated to %u bits. "
"This almost certainly means\n"
- "that some device files will be wrong.\n"),
+ "that some device files will be wrong."),
CRAMFS_OFFSET_WIDTH);
if (opt_errors &&
(warn_namelen|warn_skip|warn_size|warn_uid|warn_gid|warn_dev))
exit(MKFS_ERROR);
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/include/md5.h b/include/md5.h
index d598e81..1222cf0 100644
--- a/include/md5.h
+++ b/include/md5.h
@@ -7,6 +7,8 @@
typedef unsigned int uint32_t;
#endif
+#define MD5LENGTH 16
+
struct MD5Context {
uint32_t buf[4];
uint32_t bits[2];
@@ -16,7 +18,7 @@ struct MD5Context {
void MD5Init(struct MD5Context *context);
void MD5Update(struct MD5Context *context, unsigned char const *buf,
unsigned len);
-void MD5Final(unsigned char digest[16], struct MD5Context *context);
+void MD5Final(unsigned char digest[MD5LENGTH], struct MD5Context *context);
void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
/*
diff --git a/lib/md5.c b/lib/md5.c
index 071630f..26ec4bb 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -107,7 +107,7 @@ void MD5Update(struct MD5Context *ctx, unsigned
char const *buf, unsigned len)
* Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
-void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
+void MD5Final(unsigned char digest[MD5LENGTH], struct MD5Context *ctx)
{
unsigned count;
unsigned char *p;
@@ -144,7 +144,7 @@ void MD5Final(unsigned char digest[16], struct
MD5Context *ctx)
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
- memcpy(digest, ctx->buf, 16);
+ memcpy(digest, ctx->buf, MD5LENGTH);
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
}
diff --git a/libblkid/src/superblocks/hfs.c b/libblkid/src/superblocks/hfs.c
index e043994..6d960e9 100644
--- a/libblkid/src/superblocks/hfs.c
+++ b/libblkid/src/superblocks/hfs.c
@@ -130,17 +130,17 @@ struct hfsplus_vol_header {
static int hfs_set_uuid(blkid_probe pr, unsigned char const
*hfs_info, size_t len)
{
- static unsigned char const hash_init[16] = {
+ static unsigned char const hash_init[MD5LENGTH] = {
0xb3, 0xe2, 0x0f, 0x39, 0xf2, 0x92, 0x11, 0xd6,
0x97, 0xa4, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac
};
- unsigned char uuid[16];
+ unsigned char uuid[MD5LENGTH];
struct MD5Context md5c;
if (memcmp(hfs_info, "\0\0\0\0\0\0\0\0", len) == 0)
return -1;
MD5Init(&md5c);
- MD5Update(&md5c, hash_init, 16);
+ MD5Update(&md5c, hash_init, MD5LENGTH);
MD5Update(&md5c, hfs_info, len);
MD5Final(uuid, &md5c);
uuid[6] = 0x30 | (uuid[6] & 0x0f);
diff --git a/misc-utils/mcookie.c b/misc-utils/mcookie.c
index 61896e1..1e6b64b 100644
--- a/misc-utils/mcookie.c
+++ b/misc-utils/mcookie.c
@@ -79,7 +79,7 @@ int main(int argc, char **argv)
{
size_t i;
struct MD5Context ctx;
- unsigned char digest[16];
+ unsigned char digest[MD5LENGTH];
unsigned char buf[BUFFERSIZE];
int fd;
int c;
@@ -178,7 +178,7 @@ int main(int argc, char **argv)
}
MD5Final(digest, &ctx);
- for (i = 0; i < 16; i++)
+ for (i = 0; i < MD5LENGTH; i++)
printf("%02x", digest[i]);
putchar('\n');
diff --git a/tests/helpers/test_md5.c b/tests/helpers/test_md5.c
index b99882b..7f1e4f3 100644
--- a/tests/helpers/test_md5.c
+++ b/tests/helpers/test_md5.c
@@ -9,7 +9,7 @@ main(int argc, char *argv[])
{
int i, ret;
struct MD5Context ctx;
- unsigned char digest[16];
+ unsigned char digest[MD5LENGTH];
unsigned char buf[BUFSIZ];
MD5Init( &ctx );
@@ -23,7 +23,7 @@ main(int argc, char *argv[])
fclose(stdin);
MD5Final( digest, &ctx );
- for (i = 0; i < 16; i++)
+ for (i = 0; i < MD5LENGTH; i++)
printf( "%02x", digest[i] );
printf(" -\n");
return 0;
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply related
* Re: [PATCH] minix: v3 super-block does not have s_state field
From: Sami Kerola @ 2011-07-20 18:53 UTC (permalink / raw)
To: Karel Zak; +Cc: Davidlohr Bueso, util-linux
In-Reply-To: <20110718221926.GE4354@nb.redhat.com>
On Tue, Jul 19, 2011 at 00:19, Karel Zak <kzak@redhat.com> wrote:
> On Thu, Jul 14, 2011 at 05:47:39PM +0200, Sami Kerola wrote:
>> +++ b/include/minix.h
>> @@ -1,69 +1,65 @@
>> =A0#ifndef __MINIX_H__
>> =A0#define __MINIX_H__
>
> =A0we usually use UTIL_LINUX prefix, so #ifndef UTIL_LINUX_MINIX_H.
Changed.
>> =A0#define BLOCK_SIZE_BITS 10
>> =A0#define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
>
> =A0This is too generic. Please, use MINIX_ prefix.
Adding MINIX_ prefix will cause a greater change, but as you wish I did tha=
t.
>> =A0#define Inode (((struct minix_inode *) inode_buffer)-1)
>> =A0#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
>>
>> =A0#define INODE_SIZE (sizeof(struct minix_inode))
>> =A0#define INODE2_SIZE (sizeof(struct minix2_inode))
>>
>> -int fs_version =3D 1; /* this default value needs to change in a near f=
uture */
>> -char *super_block_buffer, *inode_buffer =3D NULL;
>> +static int fs_version =3D 1; /* this default value needs to change in a
>> near future */
>> +static char *super_block_buffer, *inode_buffer =3D NULL;
>>
>> =A0static char *inode_map;
>> =A0static char *zone_map;
>
> =A0The global variables don't belong to this generic header file. The
> =A0stuff around inode_buffer, fs_version and the inline functions are
> =A0specific to the disk-utils/ utils. Please, add
> =A0disk-utils/minix_programs.h and use it in {mkfs,fsck}.minix.
Done.
The following changes since commit 872a1575e81f5ed1e871d4ed9558f43effe96423=
:
dmesg: fix typo in usage() (2011-07-14 13:46:13 +0200)
are available in the git repository at:
https://github.com/kerolasa/lelux-utiliteetit minix
Sami Kerola (7):
include: minix.h: use data types from stdint.h
include: remove kernel headers from minix.h
include: move minix.h to include directory
libblkid: use superblock structure from minix.h
libblkid: use MINIX_BLOCK_SIZE from minix.h
minix: move globals and inline functions to minix_programs.h
libblkid: move MINIX_MAXPARTITIONS to minix.h
disk-utils/Makefile.am | 4 +-
disk-utils/fsck.minix.c | 99 ++++++++++---------
disk-utils/minix.h | 202 ----------------------------------=
----
disk-utils/minix_programs.h | 113 +++++++++++++++++++++
disk-utils/mkfs.minix.c | 77 +++++++-------
include/Makefile.am | 1 +
include/minix.h | 97 ++++++++++++++++++
libblkid/src/partitions/minix.c | 6 +-
libblkid/src/superblocks/minix.c | 33 +------
9 files changed, 304 insertions(+), 328 deletions(-)
delete mode 100644 disk-utils/minix.h
create mode 100644 disk-utils/minix_programs.h
create mode 100644 include/minix.h
--=20
=A0=A0 Sami Kerola
=A0=A0 http://www.iki.fi/kerolasa/
^ permalink raw reply
* RE: [PATCH] dmesg.c: print human readable timestamp
From: Voelker, Bernhard @ 2011-07-20 14:25 UTC (permalink / raw)
To: Karel Zak; +Cc: corentin.labbe, util-linux@vger.kernel.org
In-Reply-To: <20110720135137.GB22568@nb.net.home>
Karel Zak wrote:
> On Wed, Jul 20, 2011 at 03:33:04PM +0200, Voelker, Bernhard wrote:
>> Karel Zak wrote:
>>=20
>> > The latest dmesg(1) changes:
>> >
>> > * -T, --ctime : print human readable timestamps
>>=20
>> shouln'd -T and -t or -r be mutually exclusive?
>>=20
>> Currently, -T wins over -t, and -r wins over -T.
>
> Should be fixed now. Thanks!
It works. Thanks!
Have a nice day,
Berny=
^ permalink raw reply
* Re: [PATCH] dmesg.c: print human readable timestamp
From: Karel Zak @ 2011-07-20 13:51 UTC (permalink / raw)
To: Voelker, Bernhard; +Cc: corentin.labbe, util-linux@vger.kernel.org
In-Reply-To: <7856072A9D04C24B82DFE2B1112FE38A08FE26DD8A@MCHP058A.global-ad.net>
On Wed, Jul 20, 2011 at 03:33:04PM +0200, Voelker, Bernhard wrote:
> Karel Zak wrote:
>
> > The latest dmesg(1) changes:
> >
> > * -T, --ctime : print human readable timestamps
>
> shouln'd -T and -t or -r be mutually exclusive?
>
> Currently, -T wins over -t, and -r wins over -T.
Should be fixed now. Thanks!
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* RE: [PATCH] dmesg.c: print human readable timestamp
From: Voelker, Bernhard @ 2011-07-20 13:33 UTC (permalink / raw)
To: Karel Zak, corentin.labbe; +Cc: util-linux@vger.kernel.org
In-Reply-To: <20110720124826.GA22568@nb.net.home>
Karel Zak wrote:
> The latest dmesg(1) changes:
>
> * -T, --ctime : print human readable timestamps
shouln'd -T and -t or -r be mutually exclusive?
Currently, -T wins over -t, and -r wins over -T.
Have a nice day,
Berny=
^ permalink raw reply
* Re: [PATCH] dmesg.c: print human readable timestamp
From: Karel Zak @ 2011-07-20 12:48 UTC (permalink / raw)
To: corentin.labbe; +Cc: util-linux
In-Reply-To: <4E2449B6.1070105@geomatys.fr>
On Mon, Jul 18, 2011 at 04:56:54PM +0200, corentin.labbe wrote:
> Perhaps we could keep my patch and add a warning about "problem with
> suspend/resume" (both at first line when -H is used and in
> manpages). Like "Warning timestamp could be inaccurate if you have
> used SUSPEND/RESUME"
I agree.
> If you are agree with that I will update my patch accordingly.
I have already added this feature to the code.
The latest dmesg(1) changes:
* -T, --ctime : print human readable timestamps
[Mon Jul 18 22:30:51 2011] Bluetooth: L2CAP ver 2.15
[Mon Jul 18 22:30:51 2011] Bluetooth: L2CAP socket layer initialized
[Mon Jul 18 22:30:51 2011] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
* -d, --show-delta : display the time spent between messages.
(based on kernel scripts/show_delat).
[ 37.727490 < 0.157379>] Bluetooth: L2CAP ver 2.15
[ 37.729090 < 0.001600>] Bluetooth: L2CAP socket layer initialized
[ 37.964308 < 0.235218>] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
It's possible to mix the options (dmesg -d -T):
[Mon Jul 18 22:30:51 2011 < 0.157379>] Bluetooth: L2CAP ver 2.15
[Mon Jul 18 22:30:51 2011 < 0.001600>] Bluetooth: L2CAP socket layer initialized
[Mon Jul 18 22:30:51 2011 < 0.235218>] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [git pull] schedutils
From: Sami Kerola @ 2011-07-20 8:15 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
In-Reply-To: <20110718221751.GD4354@nb.redhat.com>
On Tue, Jul 19, 2011 at 00:17, Karel Zak <kzak@redhat.com> wrote:
> On Sun, Jul 17, 2011 at 08:37:58PM +0200, Sami Kerola wrote:
>> =A0 =A0 =A0 default:
>> - =A0 =A0 =A0 =A0 =A0 =A0 printf(_("unknown\n"));
>> + =A0 =A0 =A0 =A0 =A0 =A0 printf(_("unknown scheduling policy\n"));
>
> =A0what about warnx() ?
You are right. Change is done.
>> + =A0 =A0 printf(_("policy =A0 =A0 =A0 =A0 =A0: min/max priority\n"
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0"----------------+-----------------\n"));
>
> =A0oh...
>
>> =A0 =A0 =A0 for (i =3D 0; i < ARRAY_SIZE(policies); i++) {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 int max =3D sched_get_priority_max(policies[=
i]);
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 int min =3D sched_get_priority_min(policies[=
i]);
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (max >=3D 0 && min >=3D 0)
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf(_("SCHED_%s min/max pri=
ority\t: %d/%d\n"),
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf(_("SCHED_%-10s: %d/%d\n=
"),
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 names[i], min, max);
>
> =A0...this is not backwardly compatible.
>
> =A0If you really want to have nice output then use include/tt.c (see for
> =A0example partx, findmnt or lsblk) and add a new option for such
> =A0functionality.
This change is dropped for now.
>> =A0.SH SYNOPSIS
>> =A0.B ionice
>> -.RB [[ \-c
>> -.IR class ]
>> -.RB [ \-n
>> -.IR classdata ]
>> -.RB [ \-t ]]
>> -.BI \-p \ PID
>> -.RI [ PID =A0]...
>> +[OPTION] \fB\-p\fR PID [PID...]
>> =A0.br
>> =A0.B ionice
>> -.RB [ \-c
>> -.IR class ]
>> -.RB [ \-n
>> -.IR classdata ]
>> -.RB [ \-t ]
>> -.IR COMMAND\ =A0[ ARG =A0]...
>> +[OPTION] COMMAND
>
> hmm.. don't forget that people love examples, IMHO the old version
> seems more readable.
I put the longer synopsis back in place.
>> =A0 =A0 =A0 textdomain(PACKAGE);
>>
>> - =A0 =A0 while ((c =3D getopt(argc, argv, "+n:c:p:th")) !=3D EOF) {
>> + =A0 =A0 while ((c =3D getopt_long(argc, argv, "+n:c:p:tVh", longopts, =
NULL)) !=3D EOF)
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 switch (c) {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 case 'n':
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ioprio =3D strtol_or_err(optar=
g, _("failed to parse class data"));
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ioprio =3D strtol_or_err(optar=
g, _("failed to parse priority"));
>
> well, the original kernel Documentation/block/ioprio.txt is talking
> about "class data" and I think it would be better to follow kernel
> here. Maybe one day the mask for the syscall will used for a different
> things than only for priority...
I read kernel documentation using priority, class data and level as
synonyms. To me the `class data' is most confusing because it gets
mixed up with `class'. As you did not like `priority' I do my last
attempt to change the word and used `level'. How that would sound?
IMHO it is a clarity enhancement, which should lead to greater
usability (that admittedly very difficult to measure).
>> + =A0 =A0 =A0 =A0 =A0 =A0 case 'V':
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf(_("%s (%s)\n"),
>
> =A0"%s from %s" ;-)
Chanced to all of these three utilities.
The fixes are available in the git repository at:
https://github.com/kerolasa/lelux-utiliteetit schedutils
--=20
=A0=A0 Sami Kerola
=A0=A0 http://www.iki.fi/kerolasa/
^ permalink raw reply
* [PATCH] whereis: search in path variable
From: Davidlohr Bueso @ 2011-07-20 4:46 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Date: Wed, 20 Jul 2011 00:39:10 -0400
Currently this tool only uses the hardcoded paths for looking up strings for binaries, man pages and source code,
adding those directories found in $PATH makes a nice little enhancement.
dave@offbook:~/projects/util-linux/misc-utils$ export PATH=$PATH:/home/dave/whereis-test
dave@offbook:~/projects/util-linux/misc-utils$ ./whereis stdlib
stdlib: /home/dave/whereis-test/stdlib.h /usr/include/stdlib.h
dave@offbook:~/projects/util-linux/misc-utils$ whereis-old stdlib
stdlib: /usr/include/stdlib.h
This feature was also discussed previously here (http://www.spinics.net/lists/util-linux-ng/msg03429.html)
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
misc-utils/whereis.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index 4f841f9..ec75057 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -45,6 +45,8 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+
+#include "xalloc.h"
#include "nls.h"
#include "c.h"
@@ -58,6 +60,7 @@ void findv(char **, int, char *);
void find(char **, char *);
void findin(char *, char *);
int itsit(char *, char *);
+void fillpath(void);
static char *bindirs[] = {
"/bin",
@@ -144,6 +147,7 @@ int Bcnt;
char **Mflag;
int Mcnt;
char uflag;
+char **dirp, **pathdir = NULL;
static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
@@ -172,6 +176,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
int
main(int argc, char **argv)
{
+ int i;
+
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -179,6 +185,9 @@ main(int argc, char **argv)
argc--, argv++;
if (argc == 0)
usage(stderr);
+
+ fillpath();
+ dirp = pathdir;
do
if (argv[0][0] == '-') {
@@ -232,9 +241,51 @@ main(int argc, char **argv)
} else
lookup(*argv++);
while (--argc > 0);
+
+ free(pathdir);
+
return EXIT_SUCCESS;
}
+int inpath(const char *str)
+{
+ int i;
+
+ for (i = 0; i < sizeof(bindirs)/sizeof(char *) - 1 ; i++)
+ if (!strcmp(bindirs[i], str))
+ return 1;
+
+ for (i = 0; i < sizeof(mandirs)/sizeof(char *) - 1; i++)
+ if (!strcmp(mandirs[i], str))
+ return 1;
+
+ for (i = 0; i < sizeof(srcdirs)/sizeof(char *) - 1; i++)
+ if (!strcmp(srcdirs[i], str))
+ return 1;
+
+ return 0;
+}
+
+void fillpath(void)
+{
+ char *key=NULL, *tmp=NULL, *tok=NULL, *path = getenv("PATH");
+ int i = 0;
+
+ if (!path)
+ return;
+
+ for (tmp = path; ;tmp = NULL) {
+ tok = strtok_r(tmp, ":", &key);
+ if (!tok)
+ break;
+ if (inpath(tok)) /* make sure we don't repeat the search path */
+ continue;
+
+ pathdir = xrealloc(pathdir, (i + 1) * sizeof(char *));
+ pathdir[i++] = tok;
+ }
+}
+
void
getlist(int *argcp, char ***argvp, char ***flagp, int *cntp)
{
@@ -356,6 +407,8 @@ find(char **dirs, char *cp)
{
while (*dirs)
findin(*dirs++, cp);
+ while(*dirp)
+ findin(*dirp++, cp);
}
void
--
1.7.4.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox