Commit Graph

344 Commits

Author SHA1 Message Date
Jeff Mahoney 293714c0d1 loopdev: sync capacity after setting it
I recently tried to mount an hfsplus file system from an image file with
a partition table by using the loop offset and sizelimit options to specify
the location of the file system.

hfsplus stores some metadata at a set offset from the end of the partition,
so it's sensitive to the device size reported by the kernel.

It worked with this:

But failed with this:

/dev/loop0: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000
/dev/loop1: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000

/proc/partitions shows the correct number of blocks to match the sizelimit.

But if I set a breakpoint in mount before the mount syscall, I could see:
102400000
102432768

The kernel loop driver will set the gendisk capacity of the device at
LOOP_SET_STATUS64 but won't sync it to the block device until one of two
conditions are met: All open file descriptors referring to the device are
closed (and it will sync when re-opened) or if the LOOP_SET_CAPACITY ioctl
is called to sync it. Since mount opens the device and passes it directly
to the mount syscall after LOOP_SET_STATUS64 without closing and reopening
it, the sizelimit argument is effectively ignroed. The capacity needs to
be synced immediately for it to work as expected.

This patch adds the LOOP_SET_CAPACITY call to loopctx_setup_device since
the device isn't yet released to the user, so it's safe to sync the capacity
immediately.

[kzak@redhat.com: - port to the current git HEAD,
                  - use uint64_t]

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-09 14:32:50 +02:00
Sami Kerola 3acc206d39 various: fix variable and function declarations [smatch scan]
disk-utils/fsck.minix.c:511:9: warning: mixing declarations and code
fdisks/sfdisk.c:982:5: warning: mixing declarations and code
fdisks/sfdisk.c:1254:5: warning: mixing declarations and code
fdisks/sfdisk.c:1564:5: warning: mixing declarations and code
lib/mbsalign.c:279:7: warning: mixing declarations and code
libblkid/src/devname.c:378:17: warning: mixing declarations and code
libfdisk/src/alignment.c:219:9: warning: mixing declarations and code
term-utils/wall.c:111:9: warning: mixing declarations and code
text-utils/col.c:418:19: warning: non-ANSI function declaration of function 'flush_blanks'
text-utils/col.c:553:12: warning: non-ANSI function declaration of function 'alloc_line'
text-utils/rev.c:105:9: warning: mixing declarations and code
text-utils/tailf.c:245:9: warning: mixing declarations and code

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-09 12:17:20 +02:00
Karel Zak b1fa3e2234 lib: use O_CLOEXEC in libcommon
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-03 16:13:06 +02:00
Karel Zak 4e5262e450 lib/canonicalize: don't use /dev/mapper/<name> if the node does not exist
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-03 13:32:39 +02:00
Karel Zak 88a6006bc8 lsblk: fix hctl buffer usage [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 14:18:22 +01:00
Pádraig Brady 36c7f78524 lib/mbsalign: correct license header from GPLv[23] to LGPLv2+
* lib/mbsalign.c: s/GPLv3/LGPLv2+/
* include/mbsalign.h: s/GPLv2/LGPLv2+/
* README.licensing: Remove mention GPLv3 as it's not actually used.
2013-03-20 14:03:28 +01:00
Karel Zak 5aaee63cdf dmesg: more colors, more fun
* colorize subsystem prefix
 * colorize time
 * colorize by keywords (now "segfault" only)

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-18 12:28:32 +01:00
Karel Zak 477254da93 lib/strutils: add strtotimeval_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-13 11:51:15 +01:00
Karel Zak 13377dd64a lib/procutils: add simple API to scan /proc/PID/*
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-12 17:24:14 +01:00
Karel Zak 1bb53a5435 lib/procutils: test refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-12 15:45:59 +01:00
Karel Zak 23106a29b0 lib/strutils: simplify strtosize(), return info about suffix
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-11 13:00:54 +01:00
Karel Zak 416c43a9a5 fdisk: add callback for ask-numbers API
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-11 13:00:54 +01:00
Karel Zak d48f6c5db8 Merge branch 'patch-1' of https://github.com/dtrebbien/util-linux
* 'patch-1' of https://github.com/dtrebbien/util-linux:
  Implement mempcpy() in terms of memcpy() if mempcpy() is unavailable
2013-02-20 13:07:07 +01:00
Karel Zak 3785056ca8 lib/tty: don't truncate output on non-terminals
for example:

	$ findmnt | cat
	$ lslocks > foo

 the output should not be truncated.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-19 14:10:24 +01:00
Zbigniew Jędrzejewski-Szmek 5758069426 unshare,nsenter: spawn shell by default
The behaviour mimics chroot.

Possibly it would have been nicer to to query the password database in
the new namepace and run the shell of the user there, but it's hard to
do correctly. getpwuid() might need to load nss plugins, and the arch
in the new namespace might be different (in case of NEWNS mounts), or
the hostname might be different, etc. So in general it's not possible
to do it reliably.

Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2013-02-14 14:42:35 +01:00
Cristian Rodríguez 075f4bfd34 build-sys: test for secure_getenv() too.
In current glibc versions, internal __secure_getenv
no longer exists and was replaced by secure_getenv()

Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
2013-02-06 12:03:22 +01:00
Sami Kerola f8bd089b1d a pointer should not be compared to zero [coccinelle]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-02-06 11:51:15 +01:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00
Daniel Trebbien 02887b73eb Implement mempcpy() in terms of memcpy() if mempcpy() is unavailable 2013-01-30 18:53:00 -05:00
Karel Zak 0f23ee0c85 include: cleanup copyright headers
We use the code from include/ and lib/ on many places, so use public
domain if possible or LGPL for code copied from libs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-08 15:10:17 +01:00
Karel Zak a73f59fa03 sulogin: remove consoles.c from libcommon
- move struct chardata to include/ttyutils.h
- move console.{h,c} to login-utils/sulogin-* (it's sulogin specific)
- fix sulogin and agetty includes

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-23 22:14:21 +01:00
Karel Zak 45ddc110ac lib/ismounted: improve loopdev support
... to make it usable for situations when the same backing
file is mapped to more loop devices.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-19 14:34:01 +01:00
Karel Zak ca4f6229b0 lib/ismounted: basic support for loop devices
# losetup -a /dev/loop0
 /dev/loop0: [2053]:1048578 (/home/fs-images/filesystems/ext2.img)

 # findmnt /dev/loop0
 TARGET    SOURCE     FSTYPE OPTIONS
 /mnt/test /dev/loop0 ext3   rw,relatime,data=ordered

old version:

 ./test_ismounted /home/fs-images/filesystems/ext2.img
 not mounted

new version:

 ./test_ismounted /home/fs-images/filesystems/ext2.img
 mounted on /mnt/test

Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-19 12:40:32 +01:00
Karel Zak 06f588f7d1 lib/loopdev: fix loopdev_find_by_backing_file()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-19 12:40:19 +01:00
Werner Fink ab6478ef2d sulogin: mount temporary /dev and /proc if not found
This is very usefull if initrd can not loaded that is no /dev and no
/proc is found.  Also if the /etc/shadow and /etc/passwd is copied into
the initrd the sulogin can be used in initrd even before /dev and/or /proc
are mounted.

Signed-off-by: Werner Fink <werner@suse.de>
2012-12-18 15:45:33 +01:00
Werner Fink cae29b3717 sulogin: use the linked lists from list.h for consoles list
with this the double linked list feature from util-linux is used
instead of the single linked list.

[kzak@redhat.com: use list_last_entry() and list INIT macros]

Signed-off-by: Werner Fink <werner@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-18 15:02:35 +01:00
Karel Zak 59da1544ce include/list: add list_last_entry()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-18 15:00:03 +01:00
Karel Zak 33c5fd0c5a lib/canonicalize: add canonicalize_path_restricted() to canonicalize without suid permisssions
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-26 16:24:28 +01:00
Karel Zak 37a5c7ee41 lib/path: add path_read_u64()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-23 14:58:21 +01:00
Karel Zak ca01695b77 lib/path: rename functions to be more explicit
... and to have names compatible with lib/sysfs.c

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-23 14:58:21 +01:00
Karel Zak 1ef28920f8 lib/ttyutils: add get_terminal_name()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-22 14:40:14 +01:00
Karel Zak 5f247c8bcd lib/ttyutils: add test program
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-22 14:32:21 +01:00
Karel Zak 4e76adb0e1 lib/ttyutils: create .c file
Well, now all tty stuff are incline functions in include/ttyutils.h.
It's seems more elegant to create regular lib/ttyutils.c for libcommon
and write test program.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-22 14:26:41 +01:00
Karel Zak b481b622c5 lib/loopdev: make loopcxt_get_device() more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-12 12:10:52 +01:00
Karel Zak 874dbb9c92 lib/console: fix possible fd leak
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 12:59:33 +01:00
Karel Zak 27a76b7bd0 lib/consoles: try another methods before go to fallback
The current code goes immediately to the fallback section if any
detection method fails. It seems better to try another methods before
the fallback solution.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 12:52:33 +01:00
Karel Zak b25343bbbc lib/consoles: add debug messages
- may be enabled by CONSOLES_DEBUG env. variable

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 12:48:33 +01:00
Karel Zak 6ea0921e16 lib/consoles: TIOCGDEV code refactoring
- add missing scandev() otherwise TIOCGDEV make no sense
 - use this method independent on /proc/cmdline code

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 12:18:31 +01:00
Karel Zak 4fcee23da5 lib/consoles: cmdline code refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 11:52:11 +01:00
Karel Zak 615eada9b2 lib/consoles: sysfs code refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 11:17:23 +01:00
Karel Zak aded518ae1 lib/consoles: /proc/consoles code refactoring
- move to separate function
 - cleanup code
 - fix fscanf() usage to avoid buffer overflow

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 11:15:50 +01:00
Karel Zak 97909f6131 lib/consoles: small cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 10:30:14 +01:00
Karel Zak f0d6004ce7 lib/consoles: don't call perror()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 10:18:49 +01:00
Karel Zak 82d11fbd0f lib/consoles: add test program
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 10:12:35 +01:00
Karel Zak cf987d0aa7 lib/consoles: remove global variable consoles
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 10:06:23 +01:00
Karel Zak 6c7c1eaf2a lib/consolas: remove global variable concount, fix linked list
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-09 09:52:35 +01:00
Karel Zak 53e0a68806 lib/consoles: remove global variable initcp
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-08 17:25:09 +01:00
Karel Zak e0e5974fde lib/consoles: remove global variable comparedev
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-08 17:22:45 +01:00
Karel Zak 95226b5522 lib/consoles: minor clean ups
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-08 17:04:01 +01:00
Werner Fink 3a08f74f1d lib/consoles: add code to detect all system consoles
Signed-off-by: Werner Fink <werner@suse.de>
2012-11-08 15:55:48 +01:00