This function is currently only being used by partx(8), but it's handy and
generic enough that we can use it elsewhere as well.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Without the check libmount builds on systems that has older than 2.7
glibc are silently unsuccessful. The missing %ms modifier will, at
least, result on such system missing output of findmnt and lsblk
commands. If either %ms or %as modifiers are present the libmount
build is disabled.
Based on patch from: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Definition name is changed to UL_BUILD_BUG_ON_ZERO to avoid collision
with a system header.
../include/c.h:72:1: warning: "BUILD_BUG_ON_ZERO" redefined
In file included from /usr/include/sys/sysinfo.h:25,
from dmesg.c:16:
/usr/include/linux/kernel.h:34:1: warning: this is the location of the previous definition
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* 'sys-utils-again' of https://github.com/kerolasa/lelux-utiliteetit:
cytune: fix printf type warning
docs: mention long options in cytune.8
cytune: coding style fixes
cytune: refactor main(), new function query_tty_stats()
cytune: use libc error printing facilities
cytune: check numeric user inputs
cytune: add long options and usage()
docs: restructure flock.1 manual page
flock: simplify strtotimeval()
lib: [strutils] add strtod_or_err() function
flock: use strutils.h to check numeric user input
flock: use sysexit.h for all exit values
flock: use function attributes
flock: align with howto-usage-function.txt
flock: use libc error printing facilities
flock: move long_options struct to function scope
flock: fix coding style
docs: align fallocate.1 with howto-man-page.txt
This fixes a segfault in mount (and possibly elsewhere) when invoked
without a -t parameter.
Broken in 7ef9fd7 when the common xalloc.h libs were introduced.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Use the common path access functions. In order to simplify chcpu also implement
and use path_writestr() which writes a string to the path specified.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
A couple of these functions already have been copied to chcpu.c,
so it makes sense to move these functions into an own file.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
* 'sys-utils' of https://github.com/kerolasa/lelux-utiliteetit: (29 commits)
docs: add non-return function and if shorthand tips
build-sys: fixes to USAGE_* macros
ipcrm: check IPC syscalls
ipcrm: add --verbose option
ipcmk: allow high speed ipc creation
ipcrm: add --all option
docs: add long options to ipcs.1 man page
docs: add long options to ipcrm.1 man page
docs: add long options to ipcmk.1 man page
docs: add --version to setarch.8
docs: mention long options in ctrlaltdel.8
ctrlaltdel: add version & help options
docs: mention long options in pivot_root.8
pivot_root: add version & help option
ipcs: comment & white space clean up
ipcs: include-what-you-use header check
ipcs: add long options
ipcrm: include-what-you-use header check
ipcrm: refactor new and old main to share code
ipcrm: exit if unknown error occurs
...
The USAGE_BEGIN_TAIL is removed as unnecessary.
In between command specific options and --help & --version
USAGE_SEPARATOR is inserted. For now the separator is empty line.
The USAGE_MAN_TAIL is changed to take an argument.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The arch command is hijacked to be example of howto write usage
as defined in Documentation/howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This is a preparation patch for chcpu. If a cpu should be added to
a cpu_set where the cpu doesn't fit into the cpu_set this got silently
ignored.
Since the cpu-list is user space provided it should be checked if cpus
are specified that are completely out of range of the system.
In order to do that add a parameter which specifies if cpulist_parse()
should fail if it parses a cpu-list with "impossible" cpus.
The current callers have been converted so they behave like before.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
fixes:
../include/c.h: In function ‘errmsg’:
../include/c.h:111:26: error: ‘program_invocation_short_name’ undeclared
(first use in this function)
../include/c.h:111:26: note: each undeclared identifier is reported only
once for each function it appears in
Signed-off-by: maximilian attems <max@stro.at>
Magic hash lenght number 16 is turned to a definition MD5LENGTH,
and put into use everywhere where md5 checksum is in use.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Global variables and inline functions are moved from minix.h to
minix_programs.h which is included in mkfs.minix and fsck.minix.
The minix.h will have only struct definitions etc generic
contents which is reasonable to share with utilities and
libraries.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
In the minix.h two definitions where renamed, so that the single
definition is reusable in fsck.minix, mkfs.minix and libblkid.
BLOCK_SIZE_BITS -> MINIX_BLOCK_SIZE_BITS
BLOCK_SIZE -> MINIX_BLOCK_SIZE
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This function uses the BLKPBSZGET ioctl to get the physical block size
of the device.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
string with a different format based on the following flags:
SIZE_SUFFIX_1LETTER = "1K"
SIZE_SUFFIX_3LETTER = "1KiB",
SIZE_SUFFIX_SPACE = "1 KiB" or "1 K"
[kzak@redhat.com: - rename flags to SIZE_SUFFIX_* format,
- fix suffix[] buffer size
- add 3 letter version to the test]
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Next cleanup, that is split off special character parsing in do_prompt()
and parse_args(), handle name of line of virtual console and use it in
utmp update as well as the session id. Also move the initial TERM
variable to open_tty() as we use this later in open_tty(). Use writeall()
but avoid repeat to often for EAGAIN (compare with info page of the
(g)libc, description of the macro EAGAIN).
Signed-off-by: Werner Fink <werner@suse.de>
To be able to use DIR we need to include the dirent.h header. This fixes issues such as:
../include/procutils.h:5: error: syntax error before "DIR"
../include/procutils.h:5: warning: no semicolon at end of struct or union
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
This functions returns the status of the device's alignment. It will
be 0 when aligned, otherwise return the offset.
[kzak@redhat.com: - returns 0 if the ioctl failed]
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
Solaris lacks err, errx, warn and warnx. This also means the err.h header
doesn't exist. Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
unfortunately, gcc 4.6
void fn (void) {
int foo;
foo = bar ();
}
evaluates that foo is never used. The __attribute__((unused)) is
necessary...
Signed-off-by: Karel Zak <kzak@redhat.com>
xalloc.h needs string.h for declaration of strdup(). Otherwise we
can get implicit declaration warning. This patch prevents it.
Signed-off-by: Marek Polacek <mpolacek@redhat.com>
Try some replacements, such as getexecname() on Solaris and __progname
on BSDs and Darwin. When not found, base program_invocation_short_name
on the source filename it is used in, as not to require argv[0] to be
passed along. This latter approach is not dynamic, but doesn't require
code changes for all places where program_invocation_short_name is used
now.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
dirfd is not available on Solaris 10, it is available on latest
OpenSolaris releases though. Do some autoconf trickery to determine if
providing an alternative dirfd function is necessary and possible.
shlibs/blkid/src/read.c: Do not define _XOPEN_SOURCE to 600, or DIR will
lose it's dd_fd member again. Rearrange defines and includes to make
sense per comments, and not conflict on Solaris.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
The _IO macro is defined in sys/ioccom.h on various platforms. However,
on Solaris it isn't included by ioctl.h, so include it explicitly if
available.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Autoconf contains the right magic to determine the endianness on many
platforms next to Linux. This reverses previous commits to move away
from WORDS_BIGENDIAN:
"use __BYTE_ORDER rather than AC specific WORDS_BIGENDIAN"
This is necessary to compile on non Linux platforms like Darwin and
Solaris.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Simple replacement code with hardcoded y/n responses to allow
compilation on systems without rpmatch() such as Cygwin.
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
The old solution (without scanf()) was based on old code from
mount(8). It seems that the modern libc is able to provide all
necessary functionality by sscanf() and %ms directive.
Signed-off-by: Karel Zak <kzak@redhat.com>
The basic loopdev attributes are available in sysfs since kernel
2.6.37. This patch uses the backing_file attribute from sysfs for very
long filenames (the LOOP_GET_STATUS ioctl uses only 64 bytes for the
filename).
old version:
# losetup -a
/dev/loop0: [0804]:12865322 (/home/images/filesystems/this_is_really_really_long_directory_*)
new version:
# losetup -a
/dev/loop0: [0804]:12865322 (/home/images/filesystems/this_is_really_really_long_directory_name/ext2.img)
Signed-off-by: Karel Zak <kzak@redhat.com>
This patch replaces a few functions used throughout the source:
* Renames getnum (from schedutils) to strtol_or_err
* Moves strtosize (from lib/strtosize.c)
* Moves xstrncpy (from include/xstrncpy.h)
* Adds strnlen, strnchr and strndup if not available (remove it from libmount utils)
A few Makefile.am files were modified to compile accordingly along with trivial renaming
in schedutils source code.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
The fallback ignores locales and returns hardcoded static strings. It
should be enough to include "nls.h" to work with nl_langinfo() on all
systems.
Signed-off-by: Karel Zak <kzak@redhat.com>
- move all FAT code to superblocks/vfat.c only
- add a generic function to verify FAT superblock and use it
in FAT prober as well as in MBR parser
- add a more robust FAT cluster_count check
(it seems that iPod contains an "almost valid" FAT superblock before MBR)
Reported-by: Davidlohr Bueso <dave.bueso@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
The glibc already supports dynamically allocated CPU sets. We don't
have to maintains our private non-compatible implementation.
Signed-off-by: Karel Zak <kzak@redhat.com>
[kzak@redhat.com: - cleanup
- add long options
- add note about DM to the man page
- use err.h and nls.h]
Signed-off-by: Hajime Taira <htaira@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
On Sat, Apr 03, 2010 at 12:58:48PM +0000, Jorge wrote:
> When you want to write changes to disk you're asked for a
> confirmation, like this one:
>
> Are you sure you want to write the partition table to disk? (yes
> or no)
>
> There is no problem on the English version, but when you launch the
> program in Spanish you get this:
>
> ¿Está seguro de que desea escribir la tabla de particiones en el
> disco?
> (sí o no):
>
> You can't type the "í" character. Trying to do so will end in no
> input at all. That is, typing in my keyboard "´" then "i" leads to
> nothing. So you can't write changes to disk, and you must launch the
> program in English for it to operate.
Reported-by: Jorge <yo@jorgesuarezdelis.name>
Addresses: https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/205327
Signed-off-by: Karel Zak <kzak@redhat.com>
Print or change the label / UUID of a swap area.
[kzak@redhat.com: - code refactoring
- add long options
- clean up Makefile.am]
Signed-off-by: Jason Borden <jborden@bluehost.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
This function
int strtosize(const char *str, uintmax_t *res)
supports {K,M,G,T,E,P}iB and {K,M,G,T,E,P}B suffixes.
Signed-off-by: Karel Zak <kzak@redhat.com>
The ambivalent probing result should be properly reported and user
should be informed that the problem is possible to bypass by "-t
<type>" or resolved by wipefs(8).
The mount(8) command uses a brute force stage (calls mount(2) for all
/{proc,etc}/fylesystems) if there is not any other way how to detect
the filesystem type. The brute force stage should not be restricted by
libblkid. It's possible that libblkid is not able to detect slightly
corrupted filesystem, but kernel is able to mount such filesystem.
Note that the brute force stage should not be used if libblkid returns
ambivalent probing result. In this case user's intervention is required
(e.g. mount -t <type>).
Reported-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
The libblkid probing is based on devices from /proc/partitions by
default. This file usually does not contain removable devices (e.g.
CDROMs) and this kind of devices are invisible for libblkid.
The blkid_probe_all_removable() function adds removable block devices
to blkid cache. The probing is based on information from the /sys
directory. The devices which were detected by this function won't be
written to blkid.tab cache file.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=533874
Signed-off-by: Karel Zak <kzak@redhat.com>
* mount(8) uses private device-mapper names in mtab
* libblkid returns private device-mapper names when evaluate udev
/dev/disk-by symlinks.
* on systems where DM is fully integrated with udev the /dev/mapper/<name>
files are symlinks to /dev/dm-N. It means we need a special care to hide
private device-mapper names.
Signed-off-by: Karel Zak <kzak@redhat.com>
Add:
* ARRAY_SIZE with array type check
* PATH_MAX, TRUE and FALSE macros
* dummy __attribute__ for non-gcc compilers
Signed-off-by: Karel Zak <kzak@redhat.com>
This bug has been introduced by commit
95356e8b74.
The fsck.minix code assumes that isset() macro returns boolean,
unfortunately the generic implementation from libc returns integer.
This patch also add a fallback for the bitmap macros to include/bitops.h.
Reported-by: "Andries E. Brouwer" <Andries.Brouwer@cwi.nl>
Signed-off-by: Karel Zak <kzak@redhat.com>
new options:
--getpbsz get physical block (sector) size
--getiomin get minimum I/O size
--getioopt get optimal I/O size
--getalignoff get alignment offset
--getmaxsect get max sectors per request
Signed-off-by: Karel Zak <kzak@redhat.com>
This is public domain implementation, based on static crc32_table[].
This implementation is used on may places (libparted, FreeBSD kernel,
PostgreSQL, ...). The Linux kernel uses on-the-fly generated and
allocated tables. That's useless in shared libraries.
Signed-off-by: Karel Zak <kzak@redhat.com>
Based on patch from
Piergiorgio Sartor <piergiorgio.sartor@nexgo.de>
at
https://bugzilla.redhat.com/show_bug.cgi?id=449115
Piergiorgio's note about S5:
> According to the ACPI specifications, chapter 4.7.2.4 "Real Time
> Clock Alarm", the wakeup from RTC, when supported, should work from
> *sleep* state S1-S3 and, optionally, from S4.
>
> Note 3 (same chapter) says that S5 is *not* a sleep state and should
> not be supported. Actually it also says that: "The OS will disable
> the RTC_EN bit prior to entering the G2/S5 or G3 states regardless."
>
> Nevertheless, on all PC supporting the RTC wakeup I tested, all were
> able to wake from S5.
Signed-off-by: Karel Zak <kzak@redhat.com>
This function is marked obsolete in POSIX.1-2001 and removed in
POSIX.1-2008.
Conditionally replaced with nanosleep().
Signed-off-by: Daniel Mierswa <impulze@impulze.org>
This is a small fragment from libdisk (from xfsprogs). The final
solution will be to move the library to util-linux-ng.
Signed-off-by: Karel Zak <kzak@redhat.com>
* moves the generic libblkid/libvolume_id wrapper (fsprobe.c) from
mount/ to lib/. We'll use the wrapper in cfdisk and fsck.
The wrapper supports:
- obsolete volume_id (udev)
- obsolete libblkid (e2fsprogs)
- libblkid (util-linux-ng)
* mount, umount and swapon when linked against the new libblkid use
- low-level probing code to read LABEL, UUID or FSTYPE from a device
- high-level blkid_evaluate_spec() to convert LABEL/UUID to devname
Signed-off-by: Karel Zak <kzak@redhat.com>
This patch replaces scandir-based implementation with readdir(). The
readdir(3) is less expensive and more portable (to non-glibc environment).
The patch also replaces sysfs-based solution with simpler /proc/partitions
parsing. The /proc/partitions includes all used loop devices on all systems
(include 2.4). This solution seems faster than scandir(/sys/block/) too.
Summary, the losetup (with this patch) uses three methods to found a
loop device:
a) parse /proc/partitions to found already used loop devices (for
loserup -a)
b) stat(2) for all loop[0-7] devices (default number of loop devices).
This is classic method from util-linux <= 2.13. This method is good
enough for standard Linux machines with default number of loop
devices.
c) scan all /dev or /dev/loop/ for loop devices. This is useful for
crazy people who need more than 8 loop devices.
Signed-off-by: Karel Zak <kzak@redhat.com>
Due to a change in kernel behaviour when opening CDROM devices,
we need to retry the open/mount call when ENOMEDIUM is returned.
Explanation from Tejun Heo:
Okay, the difference is from the addition of cdrom_get_media_event()
call to both sr_drive_status() and ide_cdrom_drive_status().
Previously, the cdrom driver can't differentiate between tray closed
w/ no media and tray open and always returned tray open, which
triggers close and retry in the open logic which probably have delayed
things enough to get the media recognized.
Now the cdrom driver can discern between tray closed w/o media and
device not ready for other reasons and returns -ENOMEDIUM on the
former. This is all good and dandy but the problem seems that some
drives report no media right after the tray is closed but it hasn't
properly detected the media yet.
It seems the only way to work around the problem is via sensible
retries (e.g. try three times 5 secs apart) and I don't think we can
add that type of retry logic into cdrom open path. Please note that
the previous logic wasn't water proof. Some drives can take longer to
recognize the media is there and could have failed the in-kernel retry
too. Also, reading the media can take quite some time and during that
period the drive reports media present but device not ready. The
driver will retry the command (e.g. READ TOC for open) five times but
all of them can fail w/ EMEDIUMTYPE.
[kzak@redhat.com: - add CRDOM_NOMEDIUM_RETRIES to blkdev.h
- add verbose message to mount.c]
Signed-off-by: Matthias Koenig <mkoenig@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
[kzak@redhat.com: split the original patch to small patches]
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
Now we duplicate BLK* ioctls on many places... This patch also
fix BLKGETSIZE64 usage in dependence on kernel version.
Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Stefan Krah <stefan@bytereef.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
On Monday 03 September 2007, Karel Zak wrote:
> http://thread.gmane.org/gmane.linux.utilities.util-linux-ng/590/focus=592
>
> I agree that we need a better support for compilation without
> locales, but from my point of view NLS != all locales stuff. The NLS
> support is subset only.
thinking about the input from everyone, i'd propose the attached ...
Only pull in locale.h as needed and move it to the common nls.h.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Compiling utils fail when disable NLS with the --disable-nls switch.
"mkfs.c:46: error: 'LC_ALL' undeclared (first use in this function)"
It is due to a missing locale.h header : When enabling NLS, nls.h
includes libintl.h, which in turn includes locale.h. When disabling NLS,
libintl.h isn't anymore included nor locale.h, which is needed for the
setlocale() calls.
Signed-off-by: Gabriel Barazer <gabriel@oxeva.fr>
Signed-off-by: Karel Zak <kzak@redhat.com>
The original newgrp command doesn't expect group pasword in /etc/gshadow
although almost all distributions use this file (and the gpasswd command).
The newgrp from util-linux is deprecated and better is use shadow-utils only.
Unfortunately, shadow-utils are broken too (see RH version where is bugfix).
In this case it's better fix util-linux version at least...
Signed-off-by: Karel Zak <kzak@redhat.com>
There has been unexpected mix of HAVE_WIDECHAR and ENABLE_WIDECHAR macros. The
ENABLE_WIDECHAR is old version and has to be replaced everywhere otherwise we
will see bugs with multibyte stuff.
Signed-off-by: Karel Zak <kzak@redhat.com>