Commit Graph

937 Commits

Author SHA1 Message Date
Petr Uzel c544aa2c25 libuuid: avoid double open and leaking fd (reworked)
This reverts commit 6126f7a53c
and fixes the double open and leaking descriptor in a different way,
that is by using newly introduced function 'have_random_source()'
to check whether good random source is available while deciding
which uuid type to generate (random/time).

This is better than calling random_get_fd() twice, passing the file
descriptor down the stack and reusing it in next call to
random_get_fd().

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-10 11:43:49 +02:00
Petr Uzel 6126f7a53c libuuid: avoid double open and leaking descriptor
We are opening /dev/urandom twice in uuid_generate(): first to check if
the file is available and then later __uuid_generate_random() again to
actually get the random data. Moreover, descriptor from the first open
is leaking.

Fix by passign the descriptor down the stack and reusing it there.

References: http://marc.info/?l=util-linux-ng&m=133406051131131&w=2

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-04 15:14:24 +02:00
Karel Zak 5ef167714e lib/strutils: add string_to_bitmask()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-03 17:28:44 +02:00
Karel Zak 4a695b1a8b include/tt: remove obsolete stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-03 15:25:23 +02:00
Karel Zak f6efe5024c lib/tt: check for non-printable chars for raw/export format
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-26 09:28:44 +02:00
Karel Zak f8bb6246fd lib/tt: encode data for RAW and EXPORT format
* all tt based utils will properly encode blank chars for raw output
   format and quotes for export output format

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-26 09:22:19 +02:00
Karel Zak 95387b6696 lib/mangle: cleanup, add unhexmangle
* use strchr() rather than for()
 * small refactoring in mangle code
 * add un-hex-mangle

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-26 09:17:44 +02:00
Karel Zak be92327e71 lib/fileutils: add get_fd_tabsize()
as a fallback for the function getdtablesize()

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-23 13:58:39 +02:00
Bernhard Voelker 455fe9a075 Fix typos found by misspellings
The tool misspellings (https://github.com/lyda/misspell-check)
detected several typos. Command used:

  $ git ls-files | grep -v ^po/ | misspellings -f -

* isosize: Fix typo in usage string.
* configure.ac: Fix typo in help string of --enable-most-builds option.
* fdisk: Fix typo in man page.
* libblkid, blkid, mount: Likewise.
* Fix various typos in docs and in source code comments.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-04-23 13:16:35 +02:00
Karel Zak 505abd8434 lib/pager: fix compiler warnings
pager.c: In function ‘start_command’:
pager.c:82:7: warning: unused variable ‘err’ [-Wunused-variable]
pager.c:49:25: warning: unused variable ‘fderr’ [-Wunused-variable]
pager.c:49:15: warning: unused variable ‘fdout’ [-Wunused-variable]
pager.c:48:25: warning: unused variable ‘need_err’ [-Wunused-variable]
pager.c:48:15: warning: unused variable ‘need_out’ [-Wunused-variable]

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-23 11:57:50 +02:00
Davidlohr Bueso 35717a57ac lib: add pager functionality
When some program' output exceeds the terminal's dimensions, it is a nice
feature to call a pager that acts as calling 'less' to allow better user
navigation. This patch adds this functionality, based on what perf and git
have (ie: git log).

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-23 11:52:39 +02:00
Davidlohr Bueso fe72459e41 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>
2012-04-10 13:12:43 +02:00
Karel Zak c344350948 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>
2012-04-10 12:29:10 +02:00
Davidlohr Bueso 958d2b712a strutils: return success on test program
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-10 12:21:30 +02:00
Davidlohr Bueso 64128b705c fdisk: move kernel geometry into blkdev
This is a more generic place for this ioctl.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-10 12:21:16 +02:00
Karel Zak 4f469e588d Merge branch 'eject'
* eject: (47 commits)
  tests: use eject --force
  eject: use BUILD_EJECT, move to sys-utils
  eject: clean up usage()
  eject: clean up man page
  eject: add --force option
  eject: check for hotplug/removable attribute
  eject: remove obsolete code, use EXIT_* macros
  tests: add umount-by-eject tests
  eject: improve work with partitioned devices
  lib/sysfs: improve sysfs_is_partition_dirent()
  eject: call umount <mountpoint> rather than <device>
  eject: use libmount to detect if cdrom is mounted
  eject: make the code robust
  eject: use SG_IO ioctl for scsi
  eject: support CDIOCEJECT ioctl
  eject: new close_tray code from Fedora
  eject: new auto_eject code from Fedora
  eject: add -X from Fedora
  eject: add --manualeject from fedora
  eject: clean up devname usage
  ...
2012-04-05 15:58:28 +02:00
Karel Zak 6219c25ecb lib/loopdev: more robust initialization
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-02 17:33:41 +02:00
Karel Zak a99c913091 lib/strutils: add strtosize_or_err, clean up
* add strtosize_or_err(), we use strtosize() + err() on many places

 * add STRTOXX_EXIT_CODE to overwrite the default EXIT_FAILURE

 * remove else-after-noreturn (e.g. if (foo) err(...); else err(...))

 * clean up indent...

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-30 16:11:31 +02:00
Karel Zak 093b20ba21 lib/sysfs: improve sysfs_is_partition_dirent()
... to work with absolute disk device path too.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-29 12:42:24 +02:00
Michal Luscon 3b66f48e23 sysfs: move blkid_devno_to_wholedisk to sysfs_devno_to_wholedisk
Signed-off-by: Michal Luscon <mluscon@redhat.com>
2012-03-27 13:16:19 +02:00
Karel Zak a36e9a9408 build-sys: move obsolete lib/fsprobe to mount/
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-27 12:23:07 +02:00
Karel Zak 225b804b66 Revert "lib/canonicalize: always remove tailing slash"
It's overkill to modify unknown paths in a generic function like
canonicalize_path().

for example:

 mount -t fuse 'sshfs#marty@thee:/' /media/thee

will be canonicalized to

 mount -t fuse 'sshfs#marty@thee:' /media/thee

and this obvious bug.

Reported-by: Martin Panter <vadmium+floss@gmail.com>

This reverts commit 28074a0952.
2012-03-26 10:08:48 +02:00
Karel Zak a631868639 lib/tt: work more sensitive with large columns
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-20 10:42:03 +01:00
Sami Kerola 7961acce46 fileutils: differentiate xmkstemp and xfmkstemp
Let developer to choose, case by case, what sort of return value is
best in her code.  The xmkstemp() is for users who want file
descriptor as return value of the function, xfmkstemp() will return
FILE pointer.

Proposed-By: Karel Zak <kzak@redhat.com>
CC: Davidlohr Bueso <dave@gnu.org>
Reference: http://marc.info/?l=util-linux-ng&m=133129570124003&w=2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-18 14:29:38 +01:00
Sami Kerola 6f312c8957 xalloc: use xasprintf in all files
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-18 14:28:05 +01:00
Sami Kerola 6b79eb38ba lib: add fileutils function collection
The fileutils contains xmkstemp function will create temporary file
safe and reusable manner.

Reference: http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO.html#TEMPORARY-FILES
CC: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-18 14:28:04 +01:00
Peter Rajnoha 09a71aa1d5 lsblk: add inverse tree support (-s)
$ lsblk --inverse -o NAME /dev/dm-0
NAME
luks-10d813de-fa82-4f67-a86c-23d5d0e7c30e (dm-0)
└─sda6
  └─sda

Signed-off-by: Peter Rajnoha <prajnoha@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-07 13:54:11 +01:00
Karel Zak 4c5bbc5d7e libblkid: fix sysfs context usage
Reported-by: Elan Ruusamäe <glen@delfi.ee>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-06 11:24:54 +01:00
Sami Kerola f06b43285d build-sys: enhance readability of the autotools files
Several horizontal lists are turned to vertical, and sorted to
alphabetical order. Additionally spaces are converted to tabs where
ever possible.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-28 13:29:35 +01:00
Karel Zak 28074a0952 lib/canonicalize: always remove tailing slash
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-24 21:26:11 +01:00
Sami Kerola 7cebf0bb4f docs: corrections to FSF license files, and postal address
The COPYING and Documentation/licenses/COPYING* files are being
replaced by files from GNU web site.

http://www.gnu.org/licenses/gpl-2.0.txt
http://www.gnu.org/licenses/lgpl-2.1.txt

Postal addresses to FSF in other files are updated to match with the
address in license files.

Reference: http://lists.gnu.org/archive/html/freefont-announce/2005-04/msg00001.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-24 14:13:35 +01:00
Chandan B Rajenda 179b923a19 lib/strutils: move array bounds check in string_to_idarray() to appropriate place.
string_to_idarray() will incorrectly exit with an error when the last element
of the passed in array gets filled. However it should only exit with an error
if there is more input. To fix this move the array bounds check.

Signed-off-by: Chandan B Rajenda <chandan@linux.vnet.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2012-02-23 10:54:25 +01:00
Karel Zak bb4f071520 lib/fsprobe: mar this internal API as deprecated
The fsprobe has been added many years ago to provide unified API for

	- built-in libblkid
	- e2fsprogs libblkid
	- udev libvolume_id

these all is unnecessary as we strictly depends on built-in libblkid.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-13 15:10:55 +01:00
Karel Zak 7552258a75 lib/loopdev: remove dead assigment and null deference
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-02 14:48:03 +01:00
Karel Zak 8b04761dc6 lib/loopdev: fix part scan detection code
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-02 14:29:22 +01:00
Karel Zak 5415374ddf lib/sysfs: fix handle leak
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-01 23:02:21 +01:00
Karel Zak 2e566efda3 lib/loopdev: fix possible dir leak on error
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-01 13:06:34 +01:00
Karel Zak 06ae069bc3 lib/sysfs: fix possible fd leak on error
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-01 13:03:58 +01:00
Karel Zak aa1f95c3d0 losetup: make xgetpass more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-17 17:02:34 +01:00
Karel Zak a13e99840d lib,loopdev: remove duplicate includes
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-17 16:21:56 +01:00
Karel Zak 8b470b20d7 libmount: avoid duplicate loopdevs
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-16 11:28:05 +01:00
Karel Zak 6c503d5916 losetup: move xgetpass() to lib/xgetpass.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-11 15:17:06 +01:00
Karel Zak d356c5d238 loopdev: improve debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-09 23:28:50 +01:00
Karel Zak 59d749c331 loopdev: support LO_FLAGS_PARTSCAN flag (kernel 3.2)
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-09 23:28:43 +01:00
Davidlohr Bueso 8150beac7c blkdev: add is_blkdev function
We should have the most basic of checks in this library to see whether or not a block device is being used.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-01-05 17:09:27 +01:00
Davidlohr Bueso 3b622ddd72 fdisk: use CDROM_GET_CAPABILITY ioctl
And replace the current archaic logic of is_ide_cdrom_or_tape().

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-01-02 13:43:06 +01:00
Karel Zak 3ed8b5363d lib,tt: don't trim last line char
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-12-22 13:21:16 +01:00
Karel Zak c7e0925def losetup: rewrite loop setup
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-12-22 12:19:38 +01:00
Karel Zak 6c224de18b lib,loopdev: add missing functions
- improve loop_info usage (don't call ioctl more than once)
 - add functions to get devno and inode of the backing file
 - add function for compare any file with backing file by devno + inode
   or by filename

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-12-22 12:19:38 +01:00
Sami Kerola fbc333fec0 build-sys: check HAVE_ definitions with #ifdef [smatch scan]
Fix to `warning: undefined preprocessor identifier' messages.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-02 18:21:46 +01:00
Karel Zak 1208915521 lib,match: split match_fstype() from libmount
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-15 15:17:19 +01:00
Karel Zak 10b7b6439a lib,tt: fix compiler warning [-Wreturn-type]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-14 13:30:12 +01:00
Karel Zak 7aa69cf2e3 lib,tt: add TT_FL_NOEXTREMES
If you mark a column with TT_FL_NOEXTREMES flag then extremely
large fields will no have effect to column width. Foe example:

 without the TT_FL_NOEXTREMES flag for the 'AAA' column:

	 AAA         BBB CCC  DDD
	 aa          bbb ccc  ddd
	 aaaaaaaaaaa  bb ccc  ddd
	 aa           bb ccc  ddd
	 aa           bb ccc  ddd

 with the flags:

	 AAA  BBB CCC  DDD
	 aa   bbb ccc  dddddddddd
	 aaaaaaaaaaa
	       bb ccc  dddddddd
	 aa    bb ccc  dddddd
	 aa    bb ccc  ddddddddd

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-10 12:39:02 +01:00
Petr Uzel b106d05238 libmount: ignore tailing slash in netfs source paths
Addresses: https://bugzilla.novell.com/show_bug.cgi?id=728480
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-08 16:25:01 +01:00
Karel Zak 0b14bf7af1 lib,loopdev: add LOOP_CTL_GET_FREE support
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-07 16:45:11 +01:00
Karel Zak 52b7b4876c lib: cleanup setproctitle.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-10-26 23:17:15 +02:00
Davidlohr Bueso af7df9ee67 lib,strutils: add default value to parse_range()
This function currently sets the low or high values to 0 when the string doesn't
contain a value, like '123:' or ':123'. In order to make it more flexible, we allow it
to be passed an arbitrary value.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2011-10-17 11:06:48 +02:00
Davidlohr Bueso a883c6349c lib,strutils: share parse_range()
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>
2011-10-12 10:01:26 +02:00
Karel Zak ffbe3270f1 Merge branch 'sys-utils-again' of https://github.com/kerolasa/lelux-utiliteetit
* '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
2011-10-03 15:40:15 +02:00
Karel Zak d568813071 umount: use new lib/loopdev.c code
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-30 11:09:38 +02:00
Karel Zak 8fbbe528a7 mount: use new lib/loopdev.c code
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-30 01:28:02 +02:00
Karel Zak aee31ddc59 lib,loopdev: add debugu messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-29 23:28:36 +02:00
Sami Kerola a9f97001c3 lib: [strutils] add strtod_or_err() function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-29 22:45:27 +02:00
Francesco Cosoleto 82b4082e80 lib,loopdev: fix use of logical '&&' with constant operand
Found by clang.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-09-27 15:04:18 +02:00
Heiko Carstens 25dea0b565 lib,path: use write_all()
From: Heiko Carstens <heiko.carstens@de.ibm.com>

Since write() doesn't necessarily write the complete buffer with
one call we better use write_all() which takes care of this.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2011-09-27 13:37:41 +02:00
Heiko Carstens 9bc2b4b185 chcpu: convert to use lib/path.c
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>
2011-09-27 13:36:54 +02:00
Heiko Carstens 8148217b5b lib,path: move path access functions from lscpu into lib/path.c
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>
2011-09-27 13:36:41 +02:00
Petr Uzel 3a18db62e6 lib: do not attempt to close(0) in sysfs_deinit()
If the 'open' fails we 'goto err' which runs 'sysfs_deinit()' on a 'cxt'
which hasn't been fully initialised. The 'dir_fd' is still 0, so
sysfs_deinit calls "close(0)".

Addresses: https://bugzilla.novell.com/show_bug.cgi?id=714151
Reported-by: Diego Ercolani <diego.ercolani@gmail.com>
Analysed-by: Neil Brown <nfbrown@suse.com>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2011-09-13 11:38:13 +02:00
Karel Zak fc8b1f36fe libmount: potential null derefence [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-12 15:35:33 +02:00
Karel Zak 4e9b3bfda2 lib,cpuset: fix compiler warning [-Wuninitialized]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-10 00:02:00 +02:00
Heiko Carstens 59fb133a02 chcpu,cpuset: reduce code duplication for cpu list parsing
Reduce code duplication and print better error message if an
unsupported cpu number was passed.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2011-09-10 00:00:35 +02:00
Heiko Carstens f27ce0711c lib,cpuset: enforce stricter parsing of cpu lists
The current cpulist_parse() function ignores extra non-parsable characters at
the end of the to be parsed cpu list string.  E.g. it would accept something
like "0bla" and just set bit 0 in the cpu set.  Since such a string is invalid
implement stricter parsing that makes sure that everything of the string has
been succesfully parsed.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2011-09-10 00:00:33 +02:00
Heiko Carstens 72232a267a lib,cpuset: fix stride handling in cpulist_parse()
If cpulist_parse() gets passed a cpu list with a stride value of 0 it will be
stuck in an endless loop.  E.g. the following cpu list will cause an endless
loop: "0-2:0".  Fix this by causing a parse error if the stride value is 0.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2011-09-10 00:00:24 +02:00
Heiko Carstens 289127f52d lib,cpuset: fix odd placed braces in cpulist_parse()
The opening and closing braces for two following if statements within
cpulist_parse() are placed in an odd manner.
Just fix this to prevent broken code in the future.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2011-09-10 00:00:15 +02:00
Heiko Carstens 68845fed01 lib,cpuset: fix comments for cpu mask/list functions
The comments for cpumask_parse() and cpulist_parse() each describe
the wrong function. Just exchange the comments.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
2011-09-10 00:00:14 +02:00
Karel Zak b82c15bd19 Merge branch 'chcpu' of git://git.kernel.org/pub/scm/linux/kernel/git/heiko/util-linux
* 'chcpu' of git://git.kernel.org/pub/scm/linux/kernel/git/heiko/util-linux:
  chcpu: new tool
  cpuset: add option to allow cpulist_parse() to fail
2011-08-31 11:49:27 +02:00
Karel Zak 33487796e7 lib: [loopdev.c] correct qsort compare function
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-23 12:01:12 +02:00
Heiko Carstens b16f615afb cpuset: add option to allow cpulist_parse() to fail
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>
2011-08-15 07:52:44 +02:00
Davidlohr Bueso ad2d0d8587 lib: [loopdev.c] correct trivial typo
Should say "failed to find" instead of "failed to found".

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2011-08-08 13:53:59 +02:00
Karel Zak 8a929ed7c0 lib: [cpuset.c] fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 12:24:22 +02:00
Karel Zak edd1362f8c lib: [mangle.c] fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 12:18:22 +02:00
Karel Zak 3922ef8025 lib: [tt.c] clean up used types
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 12:16:00 +02:00
Karel Zak b28f22673d lib: [strutils.c] fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 12:01:29 +02:00
Karel Zak 6b9166ce06 lib: [sysfs.c] fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 12:01:24 +02:00
Karel Zak 3a2854084e lib: [at.c] fix compiler warnings [-Wunused-parameter]
at.c: In function ‘fstat_at’:
at.c:14:35: warning: unused parameter ‘dirname’ [-Wunused-parameter]
at.c: In function ‘open_at’:
at.c:36:34: warning: unused parameter ‘dirname’ [-Wunused-parameter]
at.c: In function ‘readlink_at’:
at.c:66:42: warning: unused parameter ‘dirname’ [-Wunused-parameter]

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 11:55:11 +02:00
Karel Zak ce75b60528 build-sys: fix 'make checkincludes' warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-07-28 13:21:00 +02:00
Karel Zak c87638ad30 include: [strutils.c] add list parsers
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-07-27 16:41:21 +02:00
Karel Zak bdc3ed6678 include; [tt.c] check for array size in columns parser
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-07-27 16:21:11 +02:00
Karel Zak 9ae45d23de Merge branch 'cramfs' of https://github.com/kerolasa/lelux-utiliteetit
* 'cramfs' of https://github.com/kerolasa/lelux-utiliteetit:
  include: move fsck return values to exitcodes.h
  include: move disk-utils/mkfs.h -> include/exitcodes.h
  mkfs.cramfs: coding style
  mkfs.cramfs: include-what-you-use header check
  mkfs.cramfs: error printing fixes
  mkfs.cramfs: convert spaces to tabs
  mkfs.cramfs: validate numeric user inputs
  mkfs.cramfs: few symbolic exit codes where missing
  md5: use symbolical digest length
  mkfs.cramfs: use program_invocation_short_name
  mkfs.cramfs: use xalloc.h
  fsck.cramfs: add missed strings to translation
  fsck.cramfs: coding style
  fsck.cramfs: use xalloc.h
  fsck.cramfs: retire die function
  cramfs.h: coding style
  cramfs: use stdint.h instead of u{8,16,32}
  cramfs_common: coding style

Conflicts:
	disk-utils/Makefile.am

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-07-26 14:41:28 +02:00
Davidlohr Bueso fb4a9e54fc sysfs: free used resources
In the sysfs lib example, we should be using sysfs_deinit() to free used
resources and for correct usage.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2011-07-26 11:58:38 +02:00
Sami Kerola e429d14106 md5: use symbolical digest length
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>
2011-07-21 23:56:48 +02:00
Karel Zak 24563aea02 include: [tt.c] always truncate if TT_FL_TRUNC
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-07-15 15:35:48 +02:00
Karel Zak c2e05a498c lib: [blkdev.c] remove kernel version check from blkdev_get_sector_size()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-27 16:09:56 +02:00
Karel Zak 6678c06f5d lib: [blkdev.c] more robust blkdev_is_misaligned()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-27 15:57:45 +02:00
Davidlohr Bueso 0e75337c31 lib: [blkdev.c] add blkdev_get_physector_size()
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>
2011-06-27 15:57:31 +02:00
Karel Zak 4ef2674615 lib: [procutils.c] improve robustness
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-20 13:58:41 +02:00
Karel Zak 85d5acb8d2 lib: [linux_version.c] simplify version parsing
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-20 13:48:40 +02:00
Samuel Thibault 4585ec0b29 misc: hurd build fixes
* Make blkdev_is_misaligned return 0 when BLKALIGNOFF is not available.
* Make procutils.c include c.h to get a PATH_MAX replacement.
* Provide agetty.c USE_SYSLOG, DEFAULT_VCTERM and DEFAULT_STERM
  defaults for Hurd.
* Make agetty.c only deal with OFDEL, XCASE and VSWTCH if they are
  available.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-20 12:48:35 +02:00
Josiah Worcester eab0c74daa lib: [tt.c] Fix mbs_width macro for systems without WIDECHAR
Signed-off-by: Josiah Worcester <josiahw@gmail.com>
2011-06-14 13:59:01 +02:00
Karel Zak fd7f0718d4 lib: [loopdev.c] cleanup flags usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-10 15:38:13 +02:00
Karel Zak fa7e0d6d44 lib: [linux_version.c] accommodate two-component linux version (e.g. 3.0)
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-06 12:35:26 +02:00
Sami Kerola e53bc9604c lib: add strtoul_or_err() function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-01 09:57:43 +02:00
Karel Zak 10ee593293 lib: [loopdev.c] add module for work loop devices
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-30 16:37:46 +02:00
Karel Zak 87e77645f5 lib: [sysfs.c] fix double free
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-30 16:37:46 +02:00
Francesco Cosoleto 5d2a98490e This adds a second parameter to size_to_human_string() to return a
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>
2011-05-26 15:32:33 +02:00
Karel Zak e918cca562 build-sys: cleanup lib/ tests
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-25 16:50:44 +02:00
Karel Zak 413993fcb1 lib: [sysfs.c] add sysfs_readlink and name/path functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-18 16:24:37 +02:00
Karel Zak cdc9c4194a lib: [at.c] add readlink_at(), fix semantic for absolute paths
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-18 15:57:16 +02:00
Karel Zak 90e9fcda3b lib: [sysfs.c] make sysfs_read_* function more robust
The functions does not modify result if the requested sysfs attribute
does not exist.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-18 11:57:17 +02:00
Karel Zak 1ddc96ac3c build-sys: disable lib/ at.c tests building
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-18 11:14:32 +02:00
Karel Zak d8a84552fb libblkid: use stuff from sysfs.h and at.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-16 20:22:52 +02:00
Karel Zak 7fe16fdaf4 lib: add generic sysfs utils
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-16 20:22:52 +02:00
Karel Zak bfe695ff5b lib: [tt.c] support key="value" output format
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-10 10:37:39 +02:00
Karel Zak 5b1f031123 lib: [procutils.c]: add missing files. Sorry.
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-04 15:52:39 +02:00
Davidlohr Bueso 9734045d9d lib: [procutils.c]: general purpose procfs parsing functions
We include the following functions as a first approach:

  - proc_open_tasks(): allocate resources and setup basic data
  - proc_next_tid(): iterate over the thread group
  - proc_close_tasks(): free used resources

[kzak@redhat.com: - free() on error in proc_open_tasks(),
                  - always call free() in proc_close_tasks()
                  - ignore non-digit dirs and return 1 on end-of-dir
                    in proc_next_tid()]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-04 15:30:28 +02:00
Karel Zak ce56db8466 lib: [tt.c] support fixed width and multiple tt_print_table() calls
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-04-27 17:15:36 +02:00
Davidlohr Bueso ba32692970 blkdev: add blkdev_is_misaligned()
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>
2011-04-12 13:08:52 +02:00
Karel Zak f9eec41838 lib: [fsprobe.c] fix blkid_evaluate_spec() call
lib/fsprobe.c:56:2: warning: passing argument 2 of ‘blkid_evaluate_spec’ from incompatible pointer type
shlibs/blkid/src/blkid.h:189:14: note: expected ‘struct blkid_struct_cache **’ but argument is of type ‘blkid_cache’

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-22 09:54:57 +01:00
Karel Zak 5298f72839 libblkid: add blkid_evaluate_spec()
The function blkid_evaluate_tag() is useful for tags only (e.g.
LABEL=foo). But we also need to address devices by tags OR paths in
many utils.

The function blkid_evaluate_spec() support this functionality without
extra care about the way how device is addressed. The tags as well as
paths are converted to the standardized device path.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-17 12:51:06 +01:00
Karel Zak 70cc35de73 lib: [fsprobe.c] remove obsolete <blkid/blkid.h>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-16 17:48:47 +01:00
Karel Zak b9eb3c1131 lib: [fsprobe.c] use internal libblkid only
fsck, mount and swapon will be compilable with libblkid from
util-linux package. The old libblkid from e2fsprogs will not be
supported.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-16 16:22:36 +01:00
Karel Zak feb81b6897 lib: [tt.c] use mbs_truncate() from mbsalign.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-11 15:30:27 +01:00
Karel Zak 7b6911e9ae lib: [tt.c] dereferencing data before a null check [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-11 15:00:30 +01:00
Karel Zak 6c7f688b1f umount: segfaults with inconsistent entry in /etc/fstab
Addresses: https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/726283
Reported-by: Greg Brockman <gdb@gregbrockman.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-04 14:44:29 +01:00
Karel Zak 6c7d5ae9a2 move struct option to .rodata
It does not make sense to have writable large arrays of "struct
option" on the stack.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-03 15:00:30 +01:00
Karel Zak 69e433d8d9 lib: [strutils.c] more robust strtol checks
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-21 15:35:04 +01:00
Sami Kerola 94d32126bf strutils: new wrapper function strtoll_or_err
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-02-21 15:32:50 +01:00
Karel Zak 9da2972c15 tests: [cpuset] call free() for range
The free() before exit() is not so important, but let's keep the
example code nice and consistent.

Reported-by: Steve Grubb <sgrubb@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-17 11:26:36 +01:00
Karel Zak 2fa3fbe858 fdisk: more robust whole-disk detection
In lib/wholedisk.c, i is set to 0. If fd was a -1, then at
line 18 geometry.start is used without it being initialized.

Reported-by: Steve Grubb <sgrubb@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-17 11:02:26 +01:00
Dave Reisner f9e05dafd0 lib: [strutils] avoid integer overflow on large values
This is visible on a 2TB disk via lsblk, where a large partition
incorrectly displays as 1.171798692T instead of 1.8T. This is
corrected by using a uint64_t type instead of a simple int --
consistant with the type used in lsblk.c to represent the raw size in
bytes.

[kzak@redhat.com: - add EiB support
                  - add size_to_human_string() to regression tests]

Signed-off-by: Dave Reisner <d@falconindy.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-15 10:13:31 +01:00
Fabian Groffen eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
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>
2011-02-14 17:45:24 +01:00
Sami Kerola 2897f29a10 cfdisk: data type mismatch, and other, compiler warning fixes
Following warnings will longer appear when one will compile with
gcc flags -Wall -Wextra -pedantic

cfdisk.c:475:3: warning: comparison of unsigned expression < 0 is always false
cfdisk.c:487:16: warning: comparison between signed and unsigned integer expressions
cfdisk.c:492:14: warning: comparison between signed and unsigned integer expressions
cfdisk.c:565:19: warning: comparison between signed and unsigned integer expressions
cfdisk.c:569:19: warning: comparison between signed and unsigned integer expressions
cfdisk.c:1070:14: warning: comparison between signed and unsigned integer expressions
cfdisk.c:1568:5: warning: missing initializer
cfdisk.c:1568:5: warning: (near initialization for 'tmp_ext.volume_label')

mbsalign.c:131:2: warning: comparison of unsigned expression >= 0 is always true

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-01-25 10:40:34 +01:00
Karel Zak 1f51db365f include: [tt] enlarge output buffer
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-25 00:24:17 +01:00
Fabian Groffen aabe244176 build-sys: use WORDS_BIGENDIAN to determine platform byte-order
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>
2011-01-17 15:34:45 +01:00
Karel Zak 218f9d3d66 remove duplicate includes
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-04 22:36:09 +01:00
Karel Zak 049caefdcf findmnt: add --submounts option
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-04 14:01:33 +01:00
Karel Zak 013bff51a6 tests: fix strtosize() test
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-03 12:28:48 +01:00
Karel Zak 035507c84b lib: [env] consolidate safe_getenv() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-03 12:28:48 +01:00
Karel Zak 5ac6a13327 libmount: cleanup mangle() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-03 12:28:47 +01:00
Karel Zak dd36965211 libmount: use better format for utab, improve bind mounts
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-03 12:28:46 +01:00
Karel Zak 8f3f6383a5 libmount: rewrite mountinfo/fstab parsers to use sscanf()
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>
2011-01-03 12:28:43 +01:00
Karel Zak 7a539b29af lib: fix mange() and unmangle() to handle NULL
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-03 12:28:40 +01:00
Karel Zak 3c5e4ef888 libmount: add unmangle/mangle() functions to API
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-03 12:28:40 +01:00
Karel Zak 5a5eeb1513 lib: add wrappers for "at" functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-03 12:28:39 +01:00
Karel Zak f872ed1f22 lib: [tt] fix alignment of the last tree child
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-12-16 12:12:43 +01:00
Davidlohr Bueso c4ecaf21d5 partx: complete rewrite
Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-12-09 21:54:17 +01:00
Karel Zak 601d12fb10 rename util-linux-ng back to util-linux
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-30 11:41:59 +01:00
Karel Zak ce877f2d16 lib: [strutils] move strmode() from namei.c to strutils.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-24 17:08:32 +01:00
Karel Zak 3e451589d5 lib: [tt] add TT_FL_RIGHT, add columns list parser
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-24 17:08:31 +01:00
Karel Zak 8c9e72ce2b lib: [ismounted] don't wast time with mtab is /proc/mounts used
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-24 17:08:26 +01:00
Davidlohr Bueso 8abcf29002 lib: [strutils] general purpose string handling functions
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>
2010-11-23 21:06:49 +01:00
Karel Zak f7a29259ee findmnt: follow HAVE_LANGINFO
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-15 16:47:13 +01:00
Karel Zak dc61d398ba lib: add fallback for nl_langinfo()
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>
2010-11-15 16:42:45 +01:00
Davidlohr Bueso 97be4a37e3 lib/tt: fix langinfo build break
When HAVE_LANGINFO_H is not defined we break the compilation in tt.c:

  CC     tt.o
tt.c: In function ‘tt_new_table’:
tt.c:142: warning: implicit declaration of function ‘nl_langinfo’
tt.c:142: error: ‘CODESET’ undeclared (first use in this function)
tt.c:142: error: (Each undeclared identifier is reported only once
tt.c:142: error: for each function it appears in.)
make: *** [tt.o] Error 1

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-15 13:37:27 +01:00
Karel Zak 6cfa971e1b lib: add test program to canonicalize.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-10-25 11:00:15 +02:00
Karel Zak fab1c0463a lib: fix syntax error in blkdev.c
Reported-by: Tuco <tuco.xyz@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-08-23 11:06:08 +02:00
François Revol 9779651e2b portability: fix mntent.h and pty.h usage
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-07-26 11:43:51 +02:00
Samuel Thibault 4951f9b38f build-sys: minor changes for GNU/Hurd
Here is a patch to fix the build on GNU/Hurd.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2010-06-14 11:10:02 +02:00
Karel Zak e7baa97105 lib: remove unwanted debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-03 15:20:13 +02:00
Karel Zak ac3d410c46 lib: tt.c - fix minimal width of column
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-03 15:20:12 +02:00
Karel Zak 46e9ff0aeb lib: tt.c: don't print header for empty table
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-03 15:20:12 +02:00
Karel Zak c15b21e4e3 lib: add tt.c (Tree and Table output)
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-03 15:20:12 +02:00
Karel Zak bae91ecf07 taskset: move NR_CPUS determination to lib/cpuset.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-01 11:11:26 +02:00
Karel Zak ee32c514b5 lib: add fallback for libc (uClibc) without CPU_ALLOC
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-01 11:09:23 +02:00
Karel Zak ff5a6d2067 taskset: use libc based cpu_set_t
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>
2010-06-01 11:06:50 +02:00
Karel Zak 125b6a9191 tests: add cpuset regression test
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-01 11:06:49 +02:00
Karel Zak efcb71f8ff taskset: move bitmap routines to lib/cpuset.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-01 11:04:44 +02:00
Karel Zak 5f94ca33cf cfdisk: support non-ascii characters in input
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>
2010-05-07 14:12:26 +02:00
Karel Zak ca55a451cd mount: revert ugly ENOMEDIUM support
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-04-27 15:15:11 +02:00
Karel Zak cf8de26afe lib: add strtosize() function
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>
2010-03-30 13:51:58 +02:00
Karel Zak abbd79ac35 lib: fix blkdev_find_size()
echo l | fdisk/fdisk /dev/zero

FYI that however now spins forever doing:

offset=3074457345618258603)
    at ../lib/blkdev.c:31
    at ../lib/blkdev.c:151
    at ../lib/blkdev.c:161

Reported-by: Pádraig Brady <P@draigBrady.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-16 17:31:39 +01:00
Pádraig Brady 104b92f848 cal: factor out and update multibyte alignment code
* include/mbsalign.h: New module interface
* lib/mbsalign.c: Updated implementation synced from coreutils
* include/Makefile.am: Add mbsalign.h
* misc-utils/Makefile.am: Make cal dependent on mbsalign module
* misc-utils/cal.c: Call mbsalign()

[kzak@redhat.com: - use min() macro from c.h]

Signed-off-by: Pádraig Brady <P@draigBrady.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-16 15:16:11 +01:00
Jim Meyering 1675ed7819 lib: avoid compilation failure on rawhide
* lib/blkdev.c: Include <sys/stat.h>, for use of S_ISREG.
2010-03-16 14:31:23 +01:00
Karel Zak c6c98f93f5 mount: report ambivalent FS detection, improve brute force detection
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>
2010-03-15 13:46:43 +01:00
Karel Zak 530381d2d5 lib: use fstat() as fallback in blkdev_get_size()
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-11 00:59:04 +01:00
Karel Zak 21169393e3 lib: add mangle.c for mtab (fstab or swaps) encoding
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-10 23:54:11 +01:00
Karel Zak 3069624180 liblkid: move getsize.c code to lib/
.. and cleanup blkdev_get_size() usage in libblkid.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-10 15:41:40 +01:00
Karel Zak a4a1da09cd build-sys: remove duplicate #includes
$ make checkincludes
fsck/fsck.c: errno.h is included more than once.
lib/canonicalize.c: string.h is included more than once.
shlibs/blkid/src/blkidP.h: stdio.h is included more than once.
shlibs/blkid/src/devname.c: string.h is included more than once.
shlibs/blkid/src/devno.c: string.h is included more than once.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-12 10:21:05 +01:00
Karel Zak 6596057175 lib: bug (typo) in function MD5Final()
On Wed, Dec 09, 2009 at 10:08:38PM +0000, Jochen Voss wrote:
> while experimenting with coccinelle, I accidentally found what I
> believe is a bug in util-linux-ng release 2.17-rc2 (downloaded
> today). The problem is the following code in lib/md5.c (around line
> 153):
>
>     void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
>     {
>   [...]
>   memset(ctx, 0, sizeof(ctx));        /* In case it's sensitive */
>     }
>
> The third argument of memset should probably be the size of 'struct
> MD5Context' instead of the size of the pointer.  So my guess is
> that the memset line should be
>
>   memset(ctx, 0, sizeof(*ctx));       /* In case it's sensitive */
>
> instead.  I don't know whether this actually causes a problem,
> but the comment makes it seem possible that it does.

Note, this typo does not have any impact on the utils in the
util-linux-ng project, because we don't use MD5 for any security
sensitive data or cryptographic stuff. The typo also does not have any
impact to the final MD5 hashes.

Reported-by: Jochen Voss <voss@seehuhn.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-12-10 11:59:46 +01:00
Karel Zak 1a70e0cba2 build-sys: add HAVE_LIBBLKID_INTERNAL
It's better to use one macro for all situations where we depends on
in-tree (internal) libblkid.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-27 12:11:37 +01:00
Karel Zak a992137b7b mount: and libblkid: covert /dev/dm-N to /dev/mapper/<name>
* 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>
2009-10-26 13:33:03 +01:00
Karel Zak 2a1dfbad1c libblkid: use BLKSSZGET for GPT sectors
The current implementation uses fixed sector size (512 bytes), that's
wrong. UEFI standard requires real logical sector size -- it means
BLKSSZGET for Linux.

The size of GPT header is not static, but whole sector is allocated
for the header. In theory the HeaderSize field could be greater than
sizeof(struct gpt_header). It means we have to read whole sector with
the header, because the header crc32 checksum is counted according to
HeaderSize.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-22 14:52:39 +02:00
Karel Zak acf6ab6f67 lib: import whole ismounted.c code from e2fsprogs
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-14 01:13:18 +02:00
Karel Zak 2f1a8f2d49 Merge branch 'for_upstream' of git://git.kernel.org/pub/scm/utils/util-linux-ng/tytso/util-linux-ng 2009-10-05 15:23:12 +02:00
Theodore Ts'o fdf08588af lib: fix file descriptor leak in is_mounted()
Remove an extraneous fopen() that leaks memory and a file descriptor.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-03 12:50:06 -04:00
Karel Zak 37ec7366c5 lib: fix lib/Makefile.am (remove pttype.c)
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-09-30 01:14:26 +02:00
Karel Zak a4532e10e3 lib: remove pttype.c
The libblkid library supports partition tables detection now.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-09-29 13:31:32 +02:00
Karel Zak 7176f22db5 lib: add a generic crc32()
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>
2009-09-16 16:17:41 +02:00
Karel Zak 1b780848b0 libblkid: use the new API in whole u-l-ng
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-09-16 10:57:24 +02:00
Karel Zak d5a8c30ceb mount: use TAG parsing function from libblkid
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-05-29 13:20:47 +02:00
Karel Zak d94e8a9ebc mount: (and fsck) remove libvolume_id support
The libvolume_id is deprecated in favor of libblkid. The libblkid from
u-l-ng provides the same functionality as libvolume_id.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-05-22 10:06:15 +02:00
Karel Zak 7c950efa34 build-sys: fix blkid.h include for old e2fsprogs
When building util-linux-ng-2.15, I get this:
   ../lib/fsprobe.c:10:19: error: blkid.h: No such file or directory

Unfortunately, the blkid.pc uses -I${includedir}/blkidi since
e2fsprogs v1.41.2. The old versions use -I${includedir} only.

Reported-by: Robert Schwebel <r.schwebel@pengutronix.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-05-11 15:06:06 +02:00
Karel Zak cee95a9567 blkid: rename blkid_evaluate_spec to blkid_evaluate_tag
"SPEC" is usually used in mount(8) as a generic term for device name or
tag (LABEL, UUID). The function blkid_evaluate_* works with TAGs only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-04-29 15:11:54 +02:00
Aurelien Jarno 89289f1f25 lib: do not include <linux/fd.h> in ismounted.c
<linux/fd.h> is included for no reason in lib/ismounted.c. This
obviously breaks on non-Linux systems.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-04-20 13:22:21 +02:00
Karel Zak 07dfde722b lib: fsprobe - fix gcc warning
lib/fsprobe.c: In function ‘fsprobe_get_fstype_by_devname’:
lib/fsprobe.c:243: warning: return discards qualifiers from pointer target type

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-16 13:08:45 +01:00
Karel Zak dfbc185e53 lib: wholedisk - extend API, add test program
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-12 14:31:50 +01:00
Karel Zak 17c0248447 lib: pttype - extend the API to work with file descriptors
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-12 14:17:59 +01:00
Karel Zak 048ebb85c5 lib: pttype: fix DOS detection
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-12 13:20:51 +01:00
Karel Zak 8f898c578a lib: pttype: add BSD subpartitions support
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-12 13:00:27 +01:00
Karel Zak e85a2a9392 lib: add pttype.c for PT types detection
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>
2009-03-12 10:15:50 +01:00
Karel Zak 929f243f79 lib: add is_whole_disk() from fdisk code
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-11 14:00:21 +01:00
Karel Zak 7926576ec2 lib: fix fsprobe wrapper (const char * is nonsense)
The fsprobe_ functions return newly allocated strings.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-03 16:25:23 +01:00
Karel Zak 4b350e0120 lib: gcc warning in fix fsprobe
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-03 16:10:24 +01:00
Karel Zak efc09ae329 build-sys: add fsck binary to .gitignore
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-02-18 17:20:30 +01:00
Karel Zak 355eceba7e tests: add fsck:ismounted reg.test
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-02-18 16:10:45 +01:00
Karel Zak 33bbc95937 lib: add test_ismounted for regression test
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-02-18 15:43:34 +01:00
Karel Zak fb429f2219 fsck: cosmetic changes (NLS, paths, ...)
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-02-18 15:34:51 +01:00
Karel Zak 84a26f645c lib: make open_device() optional in fsprobe.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-02-18 15:21:55 +01:00
Karel Zak 607c2a7295 fsck: move fsck from e2fsprogs to util-linux-ng
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-02-18 15:09:34 +01:00
Karel Zak d06d028a5a build-sys: use pkg-config for blkid and volume_id
It seems that blkid.pc from e2fsprogs has been fixed:

   $ pkg-config --libs blkid
   -lblkid

and the pkg-config does not return any other extra libraries (such
-luuid or -ldevmapper).

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-02-17 21:28:09 +01:00
Karel Zak 17f29d7bac mount: generic blkid/volume_id wrapper, use blkid_evaluate_*
* 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>
2009-02-17 01:18:22 +01:00
Karel Zak 74a9c6f7b7 mount: move realpath.c code to lib/
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-02-11 23:55:51 +01:00
Karel Zak 6fc2c88210 lib: add __BYTE_ORDER to md5.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-12-08 11:12:30 +01:00
Samuel Thibault 268cefe6cb lib: blkdev.c clean up, non-linux support
[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>
2008-07-24 00:52:52 +02:00
Samuel Thibault ca04a95a3b fdisk: don't use get_linux_version() for non-linux
The get_linux_version() function is Linux-specific.
Work around it in a few places.

[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>
2008-07-24 00:52:52 +02:00
James Youngman c4e1583799 build-sys: ignore a bunch of generated files, mostly binaries
Signed-off-by: James Youngman <jay@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-04-14 14:08:00 +02:00
Karel Zak d00ed8911e tests: move test_bkdev to lib/
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-11-28 12:27:00 +01:00
Stefan Krah 3738a48e08 lib: add blkdev.{c,h}
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>
2007-11-07 12:37:30 +01:00
Stefan Krah 5d2c98e1df lib: add linux_version.{c,h}
Signed-off-by: Stefan Krah <stefan@bytereef.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-11-06 02:40:13 +01:00
Stepan Kasal 2984313a46 build-sys: do not build convenience libraries in lib/
Build lib/*.c individually for each project which uses it, so that the
right set of flags is applied each time.

Signed-off-by: Stepan Kasal <skasal@redhat.com>
2007-05-16 11:43:29 +02:00
Karel Zak 8eeb575c0d build-sys: remove generated autotools stuff from git
The generated autotools stuff shouldn't be maintained by SCM. After check out
from git use ./autogen.sh. For more details see README.devel.

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-01-03 22:20:44 +01:00
Karel Zak cf6d7faebb Imported from util-linux-2.13-pre6 tarball. 2006-12-07 00:27:13 +01:00
Karel Zak ca3ea756e7 Imported from util-linux-2.13-pre4 tarball. 2006-12-07 00:27:06 +01:00
Karel Zak 9cb689775c Imported from util-linux-2.13-pre3 tarball. 2006-12-07 00:27:03 +01:00
Karel Zak baf39af15b Imported from util-linux-2.13-pre2 tarball. 2006-12-07 00:26:58 +01:00
Karel Zak 48d7b13a1e Imported from util-linux-2.13-pre1 tarball. 2006-12-07 00:26:54 +01:00
Karel Zak d03dd60840 Imported from util-linux-2.12a tarball. 2006-12-07 00:26:14 +01:00
Karel Zak df1dddf9ff Imported from util-linux-2.12 tarball. 2006-12-07 00:26:12 +01:00
Karel Zak 95f1bdeee4 Imported from util-linux-2.11x tarball. 2006-12-07 00:26:05 +01:00
Karel Zak 63cccae468 Imported from util-linux-2.11t tarball. 2006-12-07 00:25:58 +01:00
Karel Zak e8f2641919 Imported from util-linux-2.11m tarball. 2006-12-07 00:25:49 +01:00
Karel Zak 364cda4857 Imported from util-linux-2.11f tarball. 2006-12-07 00:25:48 +01:00
Karel Zak c07ebfa1e0 Imported from util-linux-2.11b tarball. 2006-12-07 00:25:46 +01:00
Karel Zak 66ee8158b6 Imported from util-linux-2.10s tarball. 2006-12-07 00:25:44 +01:00
Karel Zak eb63b9b8f4 Imported from util-linux-2.10f tarball. 2006-12-07 00:25:41 +01:00
Karel Zak 7eda085c41 Imported from util-linux-2.9v tarball. 2006-12-07 00:25:39 +01:00
Karel Zak 5c36a0eb7c Imported from util-linux-2.9i tarball. 2006-12-07 00:25:37 +01:00