fsck: don't free fstab table on parse failure

Even if we fail parsing, fstab gets referenced later in the code (and
will subsequently crash via heap corruption). Take the easy way out and
simply avoid deallocating this table, as it will be freed for us on
program exit regardless.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
fdisk: move kernel geometry into blkdev

This is a more generic place for this ioctl.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
eject: constify array

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
eject(1): fix typo in mount(1) reference

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
eject: use CDROM_DRIVE_STATUS if available for tray toggling

One some platforms, the -T option can be unreliable (see reference bug
report for some examples).  Instead, if the kernel supports the cdrom
status ioctl, use that to ask explicitly for the current tray status
and then open/close accordingly.

The eject_cdrom() func was reworked slightly, but none of the existing
callers care about the explicit normalization to [0,1] values, so have
it return the raw value so we can convert toggle_tray() over to using
that.

Finally, now that toggle_tray() uses a lot of helper functions, drop
the check on CDROMCLOSETRAY.  The sub-functions take care of that.

Reference: https://bugs.gentoo.org/261880
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
strutils: return success on test program

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
eject: inform why open failed

Mostly to cover common case when user does not have permission to use
eject.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
eject: close open file [cppcheck]

[eject.c:498]: (error) Resource leak: f

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
docs: eject.1: align with Documentation/howto-man-page.txt

* Add spaces after dots (English spacing).
* Add line break macros.
* Use URL and email macros where appropriate.
* Fix typo at the end of the manual (s/lsblk/eject/).

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sfdisk: fix calculation due to type mismatch (ix86)

Instructing sfdisk to create one partition spanning
across entire disk (",,") on 32bit system, if the disk
is sufficiently large (~2TB) leads to wrong calculation
in compute_start_sect() due to type mismatch.

Can be reproduced as:

--------------------------
linux-3ln5:~ # modprobe scsi_debug virtual_gb=2000
linux-3ln5:~ # sfdisk /dev/sda <<< ',,'
Checking that no-one is using this disk right now ...
OK

Disk /dev/sda: 261083 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
sfdisk:  /dev/sda: unrecognized partition table type

Old situation:
sfdisk: No partitions found

no room for partition descriptor
sfdisk: bad input
--------------------------

Addresses: https://bugzilla.novell.com/show_bug.cgi?id=754789
Reported-by: Dan Mares <dan.mares@norcrossgroup.com>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
lib/blkdev: fix compiler warning [-Wreturn-type]

../lib/blkdev.c: In function ‘blkdev_get_geometry’:
../lib/blkdev.c:287:1: warning: control reaches end of non-void function [-Wreturn-type]

Signed-off-by: Karel Zak <kzak@redhat.com>
lib: random utilities

Add a random number(s) generator specific file. The intial functions are based
on what libuuid provide. I did some modifications like avoid WIN32 checks - this
is util-LINUX.

[kzak@redhat.com: - move jrand_seed to lib/randutils.c
                  - use TLS for jrand_seed (like original code from libuuid)
                  - use size_t for buffer sizes
                  - add close() to random_get_bytes]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisk: use randutils for mbr signature creation

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
libuuid: use randutils

Signed-off-by: Davidlohr Bueso <dave@gnu.org>