From e342b75ef9e22f0a96583639ba61c6629df7993b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 15 Feb 2011 11:05:08 +0100 Subject: [PATCH 1/9] 2.19-2; fix #677569 Signed-off-by: Karel Zak --- util-linux-ng-2.19-lsblk-SIZE.patch | 35 +++++++++++++++++++++++++++++ util-linux.spec | 10 ++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 util-linux-ng-2.19-lsblk-SIZE.patch diff --git a/util-linux-ng-2.19-lsblk-SIZE.patch b/util-linux-ng-2.19-lsblk-SIZE.patch new file mode 100644 index 0000000..d580c93 --- /dev/null +++ b/util-linux-ng-2.19-lsblk-SIZE.patch @@ -0,0 +1,35 @@ +diff -up util-linux-2.19/lib/strutils.c.kzak util-linux-2.19/lib/strutils.c +--- util-linux-2.19/lib/strutils.c.kzak 2011-01-31 16:43:47.000000000 +0100 ++++ util-linux-2.19/lib/strutils.c 2011-02-15 10:58:15.000000000 +0100 +@@ -245,8 +245,9 @@ static int get_exp(uint64_t n) + char *size_to_human_string(uint64_t bytes) + { + char buf[32]; +- int dec, frac, exp; +- const char *letters = "BKMGTP"; ++ int dec, exp; ++ uint64_t frac; ++ const char *letters = "BKMGTPE"; + char c; + + exp = get_exp(bytes); +@@ -254,6 +255,10 @@ char *size_to_human_string(uint64_t byte + dec = exp ? bytes / (1ULL << exp) : bytes; + frac = exp ? bytes % (1ULL << exp) : 0; + ++ /* fprintf(stderr, "exp: %d, c: %c, dec: %d, frac: %jd\n", ++ * exp, c, dec, frac); ++ */ ++ + if (frac) { + /* round */ + frac = (frac / (1ULL << (exp - 10)) + 50) / 100; +@@ -267,7 +272,7 @@ char *size_to_human_string(uint64_t byte + + if (!dp || !*dp) + dp = "."; +- snprintf(buf, sizeof(buf), "%d%s%d%c", dec, dp, frac, c); ++ snprintf(buf, sizeof(buf), "%d%s%jd%c", dec, dp, frac, c); + } else + snprintf(buf, sizeof(buf), "%d%c", dec, c); + diff --git a/util-linux.spec b/util-linux.spec index 490dd5b..87d9e50 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -2,7 +2,7 @@ Summary: A collection of basic system utilities Name: util-linux Version: 2.19 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: ftp://ftp.kernel.org/pub/linux/utils/util-linux @@ -84,6 +84,11 @@ Patch7: util-linux-ng-2.13-login-lastlog.patch # 231192 - ipcs is not printing correct values on pLinux Patch8: util-linux-ng-2.15-ipcs-32bit.patch +### Upstream patches, backports to Fedora +### +# 677569 - lsblk: SIZE integer overflow on large values +Patch9: util-linux-ng-2.19-lsblk-SIZE.patch + %description The util-linux package contains a large variety of low-level system utilities that are necessary for a Linux system to function. Among @@ -197,6 +202,7 @@ cp %{SOURCE8} %{SOURCE9} . %patch5 -p1 %patch7 -p1 %patch8 -p1 +%patch9 -p1 %build unset LINGUAS || : @@ -742,6 +748,8 @@ fi %changelog +* Tue Feb 15 2011 Karel Zak 2.19-2 +- fix #677569 - lsblk: SIZE integer overflow on large values * Thu Feb 10 2011 Karel Zak 2.19-1 - upgrade to the release 2.19 From f3bea18c63d1378f0e45bb0bfbf46ec8e0d130d0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 24 Feb 2011 14:35:25 +0100 Subject: [PATCH 2/9] 2.19-3: fix #679799 Signed-off-by: Karel Zak --- util-linux-ng-2.16-blkid-wipe.patch | 219 ++++++++++++++++++++++++++++ util-linux.spec | 8 +- 2 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 util-linux-ng-2.16-blkid-wipe.patch diff --git a/util-linux-ng-2.16-blkid-wipe.patch b/util-linux-ng-2.16-blkid-wipe.patch new file mode 100644 index 0000000..151e6ca --- /dev/null +++ b/util-linux-ng-2.16-blkid-wipe.patch @@ -0,0 +1,219 @@ +From 8b7eae458ccb04befb579dc87bdbfc1b6cbd5553 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Thu, 24 Feb 2011 14:03:44 +0100 +Subject: [PATCH] libblkid: try to detect if PT is newer than LVM + +LVM (pvcreate) wipes the begin of the device. If there is a PT in the +wiped area then LVM signature is obsolete. + + # pvcreate /dev/sdb + # fdisk /dev/sdb + +old version: + # blkid -p -o udev /dev/sdb + ID_FS_TYPE=LVM2_member + +new version: + # blkid -p -o udev /dev/sdb + ID_PART_TABLE_TYPE=dos + +Reported-by: Matej Cepl +Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=679799 +Signed-off-by: Karel Zak +--- + shlibs/blkid/src/blkidP.h | 10 ++++ + shlibs/blkid/src/partitions/dos.c | 3 + + shlibs/blkid/src/partitions/gpt.c | 2 + + shlibs/blkid/src/partitions/partitions.c | 2 +- + shlibs/blkid/src/probe.c | 78 ++++++++++++++++++++++++++++++ + shlibs/blkid/src/superblocks/lvm.c | 6 ++ + 6 files changed, 100 insertions(+), 1 deletions(-) + +diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h +index 5bf9cca..94709a5 100644 +--- a/shlibs/blkid/src/blkidP.h ++++ b/shlibs/blkid/src/blkidP.h +@@ -198,6 +198,10 @@ struct blkid_struct_probe + int flags; /* private libray flags */ + int prob_flags; /* always zeroized by blkid_do_*() */ + ++ blkid_loff_t wipe_off; /* begin of the wiped area */ ++ blkid_loff_t wipe_size; /* size of the wiped area */ ++ struct blkid_chain *wipe_chain; /* superblock, partition, ... */ ++ + struct list_head buffers; /* list of buffers */ + + struct blkid_chain chains[BLKID_NCHAINS]; /* array of chains */ +@@ -428,6 +432,12 @@ extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name, + extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len); + extern size_t blkid_rtrim_whitespace(unsigned char *str); + ++extern void blkid_probe_set_wiper(blkid_probe pr, blkid_loff_t off, ++ blkid_loff_t size); ++extern int blkid_probe_is_wiped(blkid_probe pr, struct blkid_chain **chn, ++ blkid_loff_t off, blkid_loff_t size); ++extern void blkid_probe_use_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size); ++ + /* filter bitmap macros */ + #define blkid_bmp_wordsize (8 * sizeof(unsigned long)) + #define blkid_bmp_idx_bit(item) (1UL << ((item) % blkid_bmp_wordsize)) +diff --git a/shlibs/blkid/src/partitions/dos.c b/shlibs/blkid/src/partitions/dos.c +index c961ef7..72ac778 100644 +--- a/shlibs/blkid/src/partitions/dos.c ++++ b/shlibs/blkid/src/partitions/dos.c +@@ -177,6 +177,9 @@ static int probe_dos_pt(blkid_probe pr, const struct blkid_idmag *mag) + } + } + ++ blkid_probe_use_wiper(pr, BLKID_MSDOS_PT_OFFSET, ++ 512 - BLKID_MSDOS_PT_OFFSET); ++ + /* + * Well, all checks pass, it's MS-DOS partiton table + */ +diff --git a/shlibs/blkid/src/partitions/gpt.c b/shlibs/blkid/src/partitions/gpt.c +index 12100e0..8259c2f 100644 +--- a/shlibs/blkid/src/partitions/gpt.c ++++ b/shlibs/blkid/src/partitions/gpt.c +@@ -303,6 +303,8 @@ static int probe_gpt_pt(blkid_probe pr, const struct blkid_idmag *mag) + if (!h) + goto nothing; + ++ blkid_probe_use_wiper(pr, lba * blkid_probe_get_size(pr), 8); ++ + if (blkid_partitions_need_typeonly(pr)) + /* caller does not ask for details about partitions */ + return 0; +diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c +index fb2e015..4fa826b 100644 +--- a/shlibs/blkid/src/partitions/partitions.c ++++ b/shlibs/blkid/src/partitions/partitions.c +@@ -556,7 +556,7 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn) + if (chn->binary) + partitions_init_data(pr, chn); + +- if (pr->prob_flags & BLKID_PARTS_IGNORE_PT) ++ if (!pr->wipe_size && (pr->prob_flags & BLKID_PARTS_IGNORE_PT)) + goto details_only; + + DBG(DEBUG_LOWPROBE, +diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c +index 677b32f..3429277 100644 +--- a/shlibs/blkid/src/probe.c ++++ b/shlibs/blkid/src/probe.c +@@ -752,6 +752,7 @@ static inline void blkid_probe_start(blkid_probe pr) + if (pr) { + pr->cur_chain = NULL; + pr->prob_flags = 0; ++ blkid_probe_set_wiper(pr, 0, 0); + } + } + +@@ -760,6 +761,7 @@ static inline void blkid_probe_end(blkid_probe pr) + if (pr) { + pr->cur_chain = NULL; + pr->prob_flags = 0; ++ blkid_probe_set_wiper(pr, 0, 0); + } + } + +@@ -1338,3 +1340,79 @@ size_t blkid_rtrim_whitespace(unsigned char *str) + return i; + } + ++/* ++ * Some mkfs-like utils wipe some parts (usually begin) of the device. ++ * For example LVM (pvcreate) or mkswap(8). This information could be used ++ * for later resolution to conflicts between superblocks. ++ * ++ * For example we found valid LVM superblock, LVM wipes 8KiB at the begin of ++ * the device. If we found another signature (for example MBR) this wiped area ++ * then the signature has been added later and LVM superblock should be ignore. ++ * ++ * Note that this heuristic is not 100% reliable, for example "pvcreate --zero ++ * n" allows to keep the begin of the device unmodified. It's probably better ++ * to use this heuristic for conflicts between superblocks and partition tables ++ * than for conflicts between filesystem superblocks -- existence of unwanted ++ * partition table is very unusual, because PT is pretty visible (parsed and ++ * interpreted by kernel). ++ */ ++void blkid_probe_set_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size) ++{ ++ struct blkid_chain *chn; ++ ++ if (!pr) ++ return; ++ ++ if (!size) { ++ DBG(DEBUG_LOWPROBE, printf("zeroize wiper\n")); ++ pr->wipe_size = pr->wipe_off = 0; ++ pr->wipe_chain = NULL; ++ return; ++ } ++ ++ chn = pr->cur_chain; ++ ++ if (!chn || !chn->driver || ++ chn->idx < 0 || chn->idx >= chn->driver->nidinfos) ++ return; ++ ++ pr->wipe_size = size; ++ pr->wipe_off = off; ++ pr->wipe_chain = chn; ++ ++ DBG(DEBUG_LOWPROBE, ++ printf("wiper set to %s::%s off=%jd size=%jd\n", ++ chn->driver->name, ++ chn->driver->idinfos[chn->idx]->name, ++ pr->wipe_off, pr->wipe_size)); ++ return; ++} ++ ++/* ++ * Returns 1 if the <@off,@size> area was wiped ++ */ ++int blkid_probe_is_wiped(blkid_probe pr, struct blkid_chain **chn, ++ blkid_loff_t off, blkid_loff_t size) ++{ ++ if (!pr || !size) ++ return 0; ++ ++ if (pr->wipe_off <= off && off + size <= pr->wipe_off + pr->wipe_size) { ++ if (chn) ++ *chn = pr->wipe_chain; ++ return 1; ++ } ++ return 0; ++} ++ ++void blkid_probe_use_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size) ++{ ++ struct blkid_chain *chn = NULL; ++ ++ if (blkid_probe_is_wiped(pr, &chn, off, size) && chn) { ++ DBG(DEBUG_LOWPROBE, printf("wiped area detected -- ignore previous results\n")); ++ blkid_probe_set_wiper(pr, 0, 0); ++ blkid_probe_chain_reset_vals(pr, chn); ++ } ++} ++ +diff --git a/shlibs/blkid/src/superblocks/lvm.c b/shlibs/blkid/src/superblocks/lvm.c +index facf703..3a9807c 100644 +--- a/shlibs/blkid/src/superblocks/lvm.c ++++ b/shlibs/blkid/src/superblocks/lvm.c +@@ -112,6 +112,12 @@ static int probe_lvm2(blkid_probe pr, const struct blkid_idmag *mag) + /* the mag->magic is the same string as label->type, + * but zero terminated */ + blkid_probe_set_version(pr, mag->magic); ++ ++ /* LVM (pvcreate) wipes begin of the device -- let's remember this ++ * to resolve conflicts bettween LVM and partition tables, ... ++ */ ++ blkid_probe_set_wiper(pr, 0, 8 * 1024); ++ + return 0; + } + +-- +1.7.3.4 + diff --git a/util-linux.spec b/util-linux.spec index 87d9e50..5a60d4a 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -2,7 +2,7 @@ Summary: A collection of basic system utilities Name: util-linux Version: 2.19 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: ftp://ftp.kernel.org/pub/linux/utils/util-linux @@ -88,6 +88,8 @@ Patch8: util-linux-ng-2.15-ipcs-32bit.patch ### # 677569 - lsblk: SIZE integer overflow on large values Patch9: util-linux-ng-2.19-lsblk-SIZE.patch +# 679799 - blkid reports partitioned disk sdc as being an LVM PV +Patch10: util-linux-ng-2.16-blkid-wipe.patch %description The util-linux package contains a large variety of low-level system @@ -203,6 +205,7 @@ cp %{SOURCE8} %{SOURCE9} . %patch7 -p1 %patch8 -p1 %patch9 -p1 +%patch10 -p1 %build unset LINGUAS || : @@ -748,6 +751,9 @@ fi %changelog +* Thu Feb 24 2011 Karel Zak 2.19-3 +- fix #679799 - blkid reports partitioned disk sdc as being an LVM PV + * Tue Feb 15 2011 Karel Zak 2.19-2 - fix #677569 - lsblk: SIZE integer overflow on large values From 6bb4e20fb33cf78c458ccd7a5169652e91013259 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 7 Mar 2011 10:23:50 +0100 Subject: [PATCH 3/9] update URLs in spec file Signed-off-by: Karel Zak --- util-linux.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util-linux.spec b/util-linux.spec index 5a60d4a..d850dc3 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -5,7 +5,7 @@ Version: 2.19 Release: 3%{?dist} License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base -URL: ftp://ftp.kernel.org/pub/linux/utils/util-linux +URL: http://kernel.org/~kzak/util-linux/ %define upstream_version %{version} @@ -41,7 +41,7 @@ Source4: util-linux-60-raw.rules Source8: nologin.c Source9: nologin.8 Source10: uuidd.init -Source11: http://dl.sourceforge.net/floppyutil/floppy-%{floppyver}.tar.bz2 +Source11: http://downloads.sourceforge.net/floppyutil/floppy-%{floppyver}.tar.bz2 ### Obsoletes & Conflicts & Provides # old versions of e2fsprogs contain fsck, uuidgen From b21024ce79531dfbdc6e688cd2b0ddef86ca5fd8 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 21 Apr 2011 10:46:35 +0200 Subject: [PATCH 4/9] 2.19-4: fix mountinfo parsing Signed-off-by: Karel Zak --- util-linux-2.19-libmount-uuid.patch | 78 +++++++++++++++++++++++++++++ util-linux.spec | 9 +++- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 util-linux-2.19-libmount-uuid.patch diff --git a/util-linux-2.19-libmount-uuid.patch b/util-linux-2.19-libmount-uuid.patch new file mode 100644 index 0000000..0487c73 --- /dev/null +++ b/util-linux-2.19-libmount-uuid.patch @@ -0,0 +1,78 @@ +From 307fb169ce47dff7fe01d99c25ed69752582ebce Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 5 Apr 2011 14:17:51 +0200 +Subject: [PATCH] libmount: fix parsing of mountinfo from 2.6.39 + +The /proc/self/mountinfo file uses " - " field as a separator between +optional fields and next fields in the file. The '-' char could be +used in the fields (for example in UUIDs), so it's necessary to check +for whole " - " string rather than for '-' char only. + +Reported-by: "Aneesh Kumar K. V" +Signed-off-by: Karel Zak +--- + shlibs/mount/src/tab_parse.c | 29 +++++++++++++++++++++-------- + 1 files changed, 21 insertions(+), 8 deletions(-) + +diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c +index b0007fa..e285c65 100644 +--- a/shlibs/mount/src/tab_parse.c ++++ b/shlibs/mount/src/tab_parse.c +@@ -113,9 +113,9 @@ static int mnt_parse_table_line(struct libmnt_fs *fs, char *s) + */ + static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) + { +- int rc; ++ int rc, end = 0; + unsigned int maj, min; +- char *fstype, *src; ++ char *fstype, *src, *p; + + rc = sscanf(s, "%u " /* (1) id */ + "%u " /* (2) parent */ +@@ -123,11 +123,7 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) + "%ms " /* (4) mountroot */ + "%ms " /* (5) target */ + "%ms" /* (6) vfs options (fs-independent) */ +- "%*[^-]" /* (7) optional fields */ +- "- " /* (8) separator */ +- "%ms " /* (9) FS type */ +- "%ms " /* (10) source */ +- "%ms", /* (11) fs options (fs specific) */ ++ "%n", /* number of read bytes */ + + &fs->id, + &fs->parent, +@@ -135,11 +131,28 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) + &fs->root, + &fs->target, + &fs->vfs_optstr, ++ &end); ++ ++ if (rc >= 7 && end > 0) ++ s += end; ++ ++ /* (7) optional fields, terminated by " - " */ ++ p = strstr(s, " - "); ++ if (!p) { ++ DBG(TAB, mnt_debug("mountinfo parse error: not found separator")); ++ return -EINVAL; ++ } ++ s = p + 3; ++ ++ rc += sscanf(s, "%ms " /* (8) FS type */ ++ "%ms " /* (9) source */ ++ "%ms", /* (10) fs options (fs specific) */ ++ + &fstype, + &src, + &fs->fs_optstr); + +- if (rc == 10) { ++ if (rc >= 10) { + fs->flags |= MNT_FS_KERNEL; + fs->devno = makedev(maj, min); + +-- +1.7.3.4 + diff --git a/util-linux.spec b/util-linux.spec index d850dc3..08b9127 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -2,7 +2,7 @@ Summary: A collection of basic system utilities Name: util-linux Version: 2.19 -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: http://kernel.org/~kzak/util-linux/ @@ -90,6 +90,8 @@ Patch8: util-linux-ng-2.15-ipcs-32bit.patch Patch9: util-linux-ng-2.19-lsblk-SIZE.patch # 679799 - blkid reports partitioned disk sdc as being an LVM PV Patch10: util-linux-ng-2.16-blkid-wipe.patch +# Fix /proc/self/mouninfo parsing on kernel >= 2.6.39 +Patch11: util-linux-2.19-libmount-uuid.patch %description The util-linux package contains a large variety of low-level system @@ -206,6 +208,7 @@ cp %{SOURCE8} %{SOURCE9} . %patch8 -p1 %patch9 -p1 %patch10 -p1 +%patch11 -p1 %build unset LINGUAS || : @@ -751,6 +754,10 @@ fi %changelog +* Thu Apr 21 2011 Karel Zak 2.19-4 +- fix /proc/self/mountinfo parsing in libmount + https://lkml.org/lkml/2011/4/12/485 + * Thu Feb 24 2011 Karel Zak 2.19-3 - fix #679799 - blkid reports partitioned disk sdc as being an LVM PV From ca854f7da382fa2d032c354913350e9037ebb7aa Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 6 May 2011 14:03:12 +0200 Subject: [PATCH 5/9] 2.19.1-1: upgrade Signed-off-by: Karel Zak --- .gitignore | 1 + sources | 2 +- util-linux-2.19-libmount-uuid.patch | 78 ---------- util-linux-ng-2.16-blkid-wipe.patch | 219 ---------------------------- util-linux-ng-2.19-lsblk-SIZE.patch | 35 ----- util-linux.spec | 20 +-- 6 files changed, 8 insertions(+), 347 deletions(-) delete mode 100644 util-linux-2.19-libmount-uuid.patch delete mode 100644 util-linux-ng-2.16-blkid-wipe.patch delete mode 100644 util-linux-ng-2.19-lsblk-SIZE.patch diff --git a/.gitignore b/.gitignore index 912a99f..b85fc35 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /util-linux-2.19-rc2.tar.bz2 /util-linux-2.19-rc3.tar.bz2 /util-linux-2.19.tar.bz2 +/util-linux-2.19.1.tar.bz2 diff --git a/sources b/sources index 83b415d..489116c 100644 --- a/sources +++ b/sources @@ -1,2 +1,2 @@ +3eab06f05163dfa65479c44e5231932c util-linux-2.19.1.tar.bz2 7eeb9a6f7a258174bf0fa80f1370788d floppy-0.16.tar.bz2 -590ca71aad0b254e2631d84401f28255 util-linux-2.19.tar.bz2 diff --git a/util-linux-2.19-libmount-uuid.patch b/util-linux-2.19-libmount-uuid.patch deleted file mode 100644 index 0487c73..0000000 --- a/util-linux-2.19-libmount-uuid.patch +++ /dev/null @@ -1,78 +0,0 @@ -From 307fb169ce47dff7fe01d99c25ed69752582ebce Mon Sep 17 00:00:00 2001 -From: Karel Zak -Date: Tue, 5 Apr 2011 14:17:51 +0200 -Subject: [PATCH] libmount: fix parsing of mountinfo from 2.6.39 - -The /proc/self/mountinfo file uses " - " field as a separator between -optional fields and next fields in the file. The '-' char could be -used in the fields (for example in UUIDs), so it's necessary to check -for whole " - " string rather than for '-' char only. - -Reported-by: "Aneesh Kumar K. V" -Signed-off-by: Karel Zak ---- - shlibs/mount/src/tab_parse.c | 29 +++++++++++++++++++++-------- - 1 files changed, 21 insertions(+), 8 deletions(-) - -diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c -index b0007fa..e285c65 100644 ---- a/shlibs/mount/src/tab_parse.c -+++ b/shlibs/mount/src/tab_parse.c -@@ -113,9 +113,9 @@ static int mnt_parse_table_line(struct libmnt_fs *fs, char *s) - */ - static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) - { -- int rc; -+ int rc, end = 0; - unsigned int maj, min; -- char *fstype, *src; -+ char *fstype, *src, *p; - - rc = sscanf(s, "%u " /* (1) id */ - "%u " /* (2) parent */ -@@ -123,11 +123,7 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) - "%ms " /* (4) mountroot */ - "%ms " /* (5) target */ - "%ms" /* (6) vfs options (fs-independent) */ -- "%*[^-]" /* (7) optional fields */ -- "- " /* (8) separator */ -- "%ms " /* (9) FS type */ -- "%ms " /* (10) source */ -- "%ms", /* (11) fs options (fs specific) */ -+ "%n", /* number of read bytes */ - - &fs->id, - &fs->parent, -@@ -135,11 +131,28 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) - &fs->root, - &fs->target, - &fs->vfs_optstr, -+ &end); -+ -+ if (rc >= 7 && end > 0) -+ s += end; -+ -+ /* (7) optional fields, terminated by " - " */ -+ p = strstr(s, " - "); -+ if (!p) { -+ DBG(TAB, mnt_debug("mountinfo parse error: not found separator")); -+ return -EINVAL; -+ } -+ s = p + 3; -+ -+ rc += sscanf(s, "%ms " /* (8) FS type */ -+ "%ms " /* (9) source */ -+ "%ms", /* (10) fs options (fs specific) */ -+ - &fstype, - &src, - &fs->fs_optstr); - -- if (rc == 10) { -+ if (rc >= 10) { - fs->flags |= MNT_FS_KERNEL; - fs->devno = makedev(maj, min); - --- -1.7.3.4 - diff --git a/util-linux-ng-2.16-blkid-wipe.patch b/util-linux-ng-2.16-blkid-wipe.patch deleted file mode 100644 index 151e6ca..0000000 --- a/util-linux-ng-2.16-blkid-wipe.patch +++ /dev/null @@ -1,219 +0,0 @@ -From 8b7eae458ccb04befb579dc87bdbfc1b6cbd5553 Mon Sep 17 00:00:00 2001 -From: Karel Zak -Date: Thu, 24 Feb 2011 14:03:44 +0100 -Subject: [PATCH] libblkid: try to detect if PT is newer than LVM - -LVM (pvcreate) wipes the begin of the device. If there is a PT in the -wiped area then LVM signature is obsolete. - - # pvcreate /dev/sdb - # fdisk /dev/sdb - -old version: - # blkid -p -o udev /dev/sdb - ID_FS_TYPE=LVM2_member - -new version: - # blkid -p -o udev /dev/sdb - ID_PART_TABLE_TYPE=dos - -Reported-by: Matej Cepl -Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=679799 -Signed-off-by: Karel Zak ---- - shlibs/blkid/src/blkidP.h | 10 ++++ - shlibs/blkid/src/partitions/dos.c | 3 + - shlibs/blkid/src/partitions/gpt.c | 2 + - shlibs/blkid/src/partitions/partitions.c | 2 +- - shlibs/blkid/src/probe.c | 78 ++++++++++++++++++++++++++++++ - shlibs/blkid/src/superblocks/lvm.c | 6 ++ - 6 files changed, 100 insertions(+), 1 deletions(-) - -diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h -index 5bf9cca..94709a5 100644 ---- a/shlibs/blkid/src/blkidP.h -+++ b/shlibs/blkid/src/blkidP.h -@@ -198,6 +198,10 @@ struct blkid_struct_probe - int flags; /* private libray flags */ - int prob_flags; /* always zeroized by blkid_do_*() */ - -+ blkid_loff_t wipe_off; /* begin of the wiped area */ -+ blkid_loff_t wipe_size; /* size of the wiped area */ -+ struct blkid_chain *wipe_chain; /* superblock, partition, ... */ -+ - struct list_head buffers; /* list of buffers */ - - struct blkid_chain chains[BLKID_NCHAINS]; /* array of chains */ -@@ -428,6 +432,12 @@ extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name, - extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len); - extern size_t blkid_rtrim_whitespace(unsigned char *str); - -+extern void blkid_probe_set_wiper(blkid_probe pr, blkid_loff_t off, -+ blkid_loff_t size); -+extern int blkid_probe_is_wiped(blkid_probe pr, struct blkid_chain **chn, -+ blkid_loff_t off, blkid_loff_t size); -+extern void blkid_probe_use_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size); -+ - /* filter bitmap macros */ - #define blkid_bmp_wordsize (8 * sizeof(unsigned long)) - #define blkid_bmp_idx_bit(item) (1UL << ((item) % blkid_bmp_wordsize)) -diff --git a/shlibs/blkid/src/partitions/dos.c b/shlibs/blkid/src/partitions/dos.c -index c961ef7..72ac778 100644 ---- a/shlibs/blkid/src/partitions/dos.c -+++ b/shlibs/blkid/src/partitions/dos.c -@@ -177,6 +177,9 @@ static int probe_dos_pt(blkid_probe pr, const struct blkid_idmag *mag) - } - } - -+ blkid_probe_use_wiper(pr, BLKID_MSDOS_PT_OFFSET, -+ 512 - BLKID_MSDOS_PT_OFFSET); -+ - /* - * Well, all checks pass, it's MS-DOS partiton table - */ -diff --git a/shlibs/blkid/src/partitions/gpt.c b/shlibs/blkid/src/partitions/gpt.c -index 12100e0..8259c2f 100644 ---- a/shlibs/blkid/src/partitions/gpt.c -+++ b/shlibs/blkid/src/partitions/gpt.c -@@ -303,6 +303,8 @@ static int probe_gpt_pt(blkid_probe pr, const struct blkid_idmag *mag) - if (!h) - goto nothing; - -+ blkid_probe_use_wiper(pr, lba * blkid_probe_get_size(pr), 8); -+ - if (blkid_partitions_need_typeonly(pr)) - /* caller does not ask for details about partitions */ - return 0; -diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c -index fb2e015..4fa826b 100644 ---- a/shlibs/blkid/src/partitions/partitions.c -+++ b/shlibs/blkid/src/partitions/partitions.c -@@ -556,7 +556,7 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn) - if (chn->binary) - partitions_init_data(pr, chn); - -- if (pr->prob_flags & BLKID_PARTS_IGNORE_PT) -+ if (!pr->wipe_size && (pr->prob_flags & BLKID_PARTS_IGNORE_PT)) - goto details_only; - - DBG(DEBUG_LOWPROBE, -diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c -index 677b32f..3429277 100644 ---- a/shlibs/blkid/src/probe.c -+++ b/shlibs/blkid/src/probe.c -@@ -752,6 +752,7 @@ static inline void blkid_probe_start(blkid_probe pr) - if (pr) { - pr->cur_chain = NULL; - pr->prob_flags = 0; -+ blkid_probe_set_wiper(pr, 0, 0); - } - } - -@@ -760,6 +761,7 @@ static inline void blkid_probe_end(blkid_probe pr) - if (pr) { - pr->cur_chain = NULL; - pr->prob_flags = 0; -+ blkid_probe_set_wiper(pr, 0, 0); - } - } - -@@ -1338,3 +1340,79 @@ size_t blkid_rtrim_whitespace(unsigned char *str) - return i; - } - -+/* -+ * Some mkfs-like utils wipe some parts (usually begin) of the device. -+ * For example LVM (pvcreate) or mkswap(8). This information could be used -+ * for later resolution to conflicts between superblocks. -+ * -+ * For example we found valid LVM superblock, LVM wipes 8KiB at the begin of -+ * the device. If we found another signature (for example MBR) this wiped area -+ * then the signature has been added later and LVM superblock should be ignore. -+ * -+ * Note that this heuristic is not 100% reliable, for example "pvcreate --zero -+ * n" allows to keep the begin of the device unmodified. It's probably better -+ * to use this heuristic for conflicts between superblocks and partition tables -+ * than for conflicts between filesystem superblocks -- existence of unwanted -+ * partition table is very unusual, because PT is pretty visible (parsed and -+ * interpreted by kernel). -+ */ -+void blkid_probe_set_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size) -+{ -+ struct blkid_chain *chn; -+ -+ if (!pr) -+ return; -+ -+ if (!size) { -+ DBG(DEBUG_LOWPROBE, printf("zeroize wiper\n")); -+ pr->wipe_size = pr->wipe_off = 0; -+ pr->wipe_chain = NULL; -+ return; -+ } -+ -+ chn = pr->cur_chain; -+ -+ if (!chn || !chn->driver || -+ chn->idx < 0 || chn->idx >= chn->driver->nidinfos) -+ return; -+ -+ pr->wipe_size = size; -+ pr->wipe_off = off; -+ pr->wipe_chain = chn; -+ -+ DBG(DEBUG_LOWPROBE, -+ printf("wiper set to %s::%s off=%jd size=%jd\n", -+ chn->driver->name, -+ chn->driver->idinfos[chn->idx]->name, -+ pr->wipe_off, pr->wipe_size)); -+ return; -+} -+ -+/* -+ * Returns 1 if the <@off,@size> area was wiped -+ */ -+int blkid_probe_is_wiped(blkid_probe pr, struct blkid_chain **chn, -+ blkid_loff_t off, blkid_loff_t size) -+{ -+ if (!pr || !size) -+ return 0; -+ -+ if (pr->wipe_off <= off && off + size <= pr->wipe_off + pr->wipe_size) { -+ if (chn) -+ *chn = pr->wipe_chain; -+ return 1; -+ } -+ return 0; -+} -+ -+void blkid_probe_use_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size) -+{ -+ struct blkid_chain *chn = NULL; -+ -+ if (blkid_probe_is_wiped(pr, &chn, off, size) && chn) { -+ DBG(DEBUG_LOWPROBE, printf("wiped area detected -- ignore previous results\n")); -+ blkid_probe_set_wiper(pr, 0, 0); -+ blkid_probe_chain_reset_vals(pr, chn); -+ } -+} -+ -diff --git a/shlibs/blkid/src/superblocks/lvm.c b/shlibs/blkid/src/superblocks/lvm.c -index facf703..3a9807c 100644 ---- a/shlibs/blkid/src/superblocks/lvm.c -+++ b/shlibs/blkid/src/superblocks/lvm.c -@@ -112,6 +112,12 @@ static int probe_lvm2(blkid_probe pr, const struct blkid_idmag *mag) - /* the mag->magic is the same string as label->type, - * but zero terminated */ - blkid_probe_set_version(pr, mag->magic); -+ -+ /* LVM (pvcreate) wipes begin of the device -- let's remember this -+ * to resolve conflicts bettween LVM and partition tables, ... -+ */ -+ blkid_probe_set_wiper(pr, 0, 8 * 1024); -+ - return 0; - } - --- -1.7.3.4 - diff --git a/util-linux-ng-2.19-lsblk-SIZE.patch b/util-linux-ng-2.19-lsblk-SIZE.patch deleted file mode 100644 index d580c93..0000000 --- a/util-linux-ng-2.19-lsblk-SIZE.patch +++ /dev/null @@ -1,35 +0,0 @@ -diff -up util-linux-2.19/lib/strutils.c.kzak util-linux-2.19/lib/strutils.c ---- util-linux-2.19/lib/strutils.c.kzak 2011-01-31 16:43:47.000000000 +0100 -+++ util-linux-2.19/lib/strutils.c 2011-02-15 10:58:15.000000000 +0100 -@@ -245,8 +245,9 @@ static int get_exp(uint64_t n) - char *size_to_human_string(uint64_t bytes) - { - char buf[32]; -- int dec, frac, exp; -- const char *letters = "BKMGTP"; -+ int dec, exp; -+ uint64_t frac; -+ const char *letters = "BKMGTPE"; - char c; - - exp = get_exp(bytes); -@@ -254,6 +255,10 @@ char *size_to_human_string(uint64_t byte - dec = exp ? bytes / (1ULL << exp) : bytes; - frac = exp ? bytes % (1ULL << exp) : 0; - -+ /* fprintf(stderr, "exp: %d, c: %c, dec: %d, frac: %jd\n", -+ * exp, c, dec, frac); -+ */ -+ - if (frac) { - /* round */ - frac = (frac / (1ULL << (exp - 10)) + 50) / 100; -@@ -267,7 +272,7 @@ char *size_to_human_string(uint64_t byte - - if (!dp || !*dp) - dp = "."; -- snprintf(buf, sizeof(buf), "%d%s%d%c", dec, dp, frac, c); -+ snprintf(buf, sizeof(buf), "%d%s%jd%c", dec, dp, frac, c); - } else - snprintf(buf, sizeof(buf), "%d%c", dec, c); - diff --git a/util-linux.spec b/util-linux.spec index 08b9127..f7b1a1e 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -1,8 +1,8 @@ ### Header Summary: A collection of basic system utilities Name: util-linux -Version: 2.19 -Release: 4%{?dist} +Version: 2.19.1 +Release: 1%{?dist} License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: http://kernel.org/~kzak/util-linux/ @@ -84,15 +84,6 @@ Patch7: util-linux-ng-2.13-login-lastlog.patch # 231192 - ipcs is not printing correct values on pLinux Patch8: util-linux-ng-2.15-ipcs-32bit.patch -### Upstream patches, backports to Fedora -### -# 677569 - lsblk: SIZE integer overflow on large values -Patch9: util-linux-ng-2.19-lsblk-SIZE.patch -# 679799 - blkid reports partitioned disk sdc as being an LVM PV -Patch10: util-linux-ng-2.16-blkid-wipe.patch -# Fix /proc/self/mouninfo parsing on kernel >= 2.6.39 -Patch11: util-linux-2.19-libmount-uuid.patch - %description The util-linux package contains a large variety of low-level system utilities that are necessary for a Linux system to function. Among @@ -206,9 +197,6 @@ cp %{SOURCE8} %{SOURCE9} . %patch5 -p1 %patch7 -p1 %patch8 -p1 -%patch9 -p1 -%patch10 -p1 -%patch11 -p1 %build unset LINGUAS || : @@ -754,6 +742,10 @@ fi %changelog +* Fri May 6 2011 Karel Zak 2.19.1-1 +- upgrade to the release 2.19.1 + ftp://ftp.kernel.org/pub/linux/utils/util-linux/v2.19/v2.19.1-ReleaseNotes + * Thu Apr 21 2011 Karel Zak 2.19-4 - fix /proc/self/mountinfo parsing in libmount https://lkml.org/lkml/2011/4/12/485 From 3d7bc453eb13114585c56649b6a0382c5e5cde52 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 14 Jun 2011 11:09:02 +0200 Subject: [PATCH 6/9] 2.19.1-1.1: fix mount -a - fix #709319 - 'mount -a' mounts already mounted directories - fix kernel version parsing Signed-off-by: Karel Zak --- util-linux-2.19-kernel-version.patch | 32 +++ util-linux-2.19-libmount-mounted.patch | 290 +++++++++++++++++++++++++ util-linux-2.19-mount-a-bind.patch | 105 +++++++++ util-linux.spec | 19 +- 4 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 util-linux-2.19-kernel-version.patch create mode 100644 util-linux-2.19-libmount-mounted.patch create mode 100644 util-linux-2.19-mount-a-bind.patch diff --git a/util-linux-2.19-kernel-version.patch b/util-linux-2.19-kernel-version.patch new file mode 100644 index 0000000..c15b93f --- /dev/null +++ b/util-linux-2.19-kernel-version.patch @@ -0,0 +1,32 @@ +From fa7e0d6d442de9f5940f99fd93f4522602439131 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Mon, 6 Jun 2011 12:35:26 +0200 +Subject: [PATCH] lib: [linux_version.c] accommodate two-component linux + version (e.g. 3.0) + +Signed-off-by: Karel Zak +--- + lib/linux_version.c | 6 +++--- + 1 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/lib/linux_version.c b/lib/linux_version.c +index f9fbd8d..ada566a 100644 +--- a/lib/linux_version.c ++++ b/lib/linux_version.c +@@ -16,10 +16,10 @@ get_linux_version (void) + return kver; + if (uname (&uts)) + kver = 0; +- else if (sscanf (uts.release, "%d.%d.%d", &major, &minor, &teeny) != 3) +- kver = 0; +- else ++ else if (sscanf (uts.release, "%d.%d.%d", &major, &minor, &teeny) == 3) + kver = KERNEL_VERSION (major, minor, teeny); ++ else if (sscanf (uts.release, "%d.%d", &major, &minor) == 2) ++ kver = KERNEL_VERSION (major, minor, 0); + + return kver; + } +-- +1.7.5.2 + diff --git a/util-linux-2.19-libmount-mounted.patch b/util-linux-2.19-libmount-mounted.patch new file mode 100644 index 0000000..99b8e38 --- /dev/null +++ b/util-linux-2.19-libmount-mounted.patch @@ -0,0 +1,290 @@ +From 5c60a0eab5155043f58fa88909d89e0b06cad2f8 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 31 May 2011 18:01:36 +0200 +Subject: [PATCH] libmount: add mnt_table_is_mounted() + +Signed-off-by: Karel Zak +--- + shlibs/mount/src/libmount.h.in | 3 + + shlibs/mount/src/libmount.sym | 1 + + shlibs/mount/src/tab.c | 210 ++++++++++++++++++++++++++++++++++++++++ + shlibs/mount/src/tab_update.c | 2 +- + 4 files changed, 215 insertions(+), 1 deletions(-) + +diff --git a/shlibs/mount/src/libmount.h.in b/shlibs/mount/src/libmount.h.in +index 3ea2f92..1522208 100644 +--- a/shlibs/mount/src/libmount.h.in ++++ b/shlibs/mount/src/libmount.h.in +@@ -308,6 +308,9 @@ extern int mnt_table_find_next_fs(struct libmnt_table *tb, + int (*match_func)(struct libmnt_fs *, void *), void *userdata, + struct libmnt_fs **fs); + ++extern int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs); ++ ++ + /* tab_update.c */ + extern struct libmnt_update *mnt_new_update(void); + extern void mnt_free_update(struct libmnt_update *upd); +diff --git a/shlibs/mount/src/libmount.sym b/shlibs/mount/src/libmount.sym +index 0b7c560..a498916 100644 +--- a/shlibs/mount/src/libmount.sym ++++ b/shlibs/mount/src/libmount.sym +@@ -195,6 +195,7 @@ global: + mnt_update_is_ready; + mnt_update_set_fs; + mnt_update_table; ++ mnt_table_is_fs_mounted; + local: + *; + }; +diff --git a/shlibs/mount/src/tab.c b/shlibs/mount/src/tab.c +index 2a6a235..38a5d5b 100644 +--- a/shlibs/mount/src/tab.c ++++ b/shlibs/mount/src/tab.c +@@ -712,6 +712,175 @@ struct libmnt_fs *mnt_table_find_pair(struct libmnt_table *tb, const char *sourc + return NULL; + } + ++/* ++ * @tb: /proc/self/mountinfo ++ * @fs: filesystem ++ * @mountflags: MS_BIND or 0 ++ * @fsroot: fs-root that will be probably used in the mountinfo file ++ * for @fs after mount(2) ++ * ++ * For btrfs subvolumes this function returns NULL, but @fsroot properly set. ++ * ++ * Returns: entry from @tb that will be used as a source for @fs if the @fs is ++ * bindmount. ++ */ ++struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb, ++ struct libmnt_fs *fs, ++ unsigned long mountflags, ++ char **fsroot) ++{ ++ char *root = NULL, *mnt = NULL; ++ const char *fstype; ++ struct libmnt_fs *src_fs = NULL; ++ ++ assert(tb); ++ assert(fs); ++ assert(fsroot); ++ ++ DBG(TAB, mnt_debug("lookup fs-root for %s", mnt_fs_get_source(fs))); ++ ++ fstype = mnt_fs_get_fstype(fs); ++ ++ if (mountflags & MS_BIND) { ++ const char *src, *src_root; ++ ++ DBG(TAB, mnt_debug("fs-root for bind")); ++ ++ src = mnt_resolve_spec(mnt_fs_get_source(fs), tb->cache); ++ if (!src) ++ goto err; ++ ++ mnt = mnt_get_mountpoint(src); ++ if (!mnt) ++ goto err; ++ ++ root = mnt_get_fs_root(src, mnt); ++ ++ src_fs = mnt_table_find_target(tb, mnt, MNT_ITER_BACKWARD); ++ if (!src_fs) { ++ DBG(TAB, mnt_debug("not found '%s' in mountinfo -- using default", mnt)); ++ goto dflt; ++ } ++ ++ /* on btrfs the subvolume is used as fs-root in ++ * /proc/self/mountinfo, so we have to get the original subvolume ++ * name from src_fs and prepend the subvolume name to the ++ * fs-root path ++ */ ++ src_root = mnt_fs_get_root(src_fs); ++ if (src_root && !startswith(root, src_root)) { ++ size_t sz = strlen(root) + strlen(src_root) + 1; ++ char *tmp = malloc(sz); ++ ++ if (!tmp) ++ goto err; ++ snprintf(tmp, sz, "%s%s", src_root, root); ++ free(root); ++ root = tmp; ++ } ++ } ++ ++ /* ++ * btrfs-subvolume mount -- get subvolume name and use it as a root-fs path ++ */ ++ else if (fstype && !strcmp(fstype, "btrfs")) { ++ char *vol = NULL, *p; ++ size_t sz, volsz = 0; ++ ++ if (mnt_fs_get_option(fs, "subvol", &vol, &volsz)) ++ goto dflt; ++ ++ DBG(TAB, mnt_debug("setting FS root: btrfs subvol")); ++ ++ sz = volsz; ++ if (*vol != '/') ++ sz++; ++ root = malloc(sz + 1); ++ if (!root) ++ goto err; ++ p = root; ++ if (*vol != '/') ++ *p++ = '/'; ++ memcpy(p, vol, volsz); ++ *(root + sz) = '\0'; ++ } ++dflt: ++ if (!root) { ++ root = strdup("/"); ++ if (!root) ++ goto err; ++ } ++ *fsroot = root; ++ ++ DBG(TAB, mnt_debug("FS root result: %s", root)); ++ ++ free(mnt); ++ return src_fs; ++err: ++ free(root); ++ free(mnt); ++ return NULL; ++} ++ ++/** ++ * mnt_table_is_mounted: ++ * @tb: /proc/self/mountinfo file ++ * @fstab_fs: /etc/fstab entry ++ * ++ * Checks if the @fstab_fs entry is already in the @tb table. The "swap" ++ * is ignored. ++ * ++ * TODO: check for loopdev (see mount/mount.c is_fstab_entry_mounted(). ++ * ++ * Returns: 0 or 1 ++ */ ++int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) ++{ ++ char *root = NULL; ++ struct libmnt_fs *src_fs; ++ const char *src, *tgt; ++ int flags = 0, rc = 0; ++ ++ assert(tb); ++ assert(fstab_fs); ++ ++ if (fstab_fs->flags & MNT_FS_SWAP) ++ return 0; ++ ++ if (mnt_fs_get_option(fstab_fs, "bind", NULL, NULL) == 0) ++ flags = MS_BIND; ++ ++ src_fs = mnt_table_get_fs_root(tb, fstab_fs, flags, &root); ++ if (src_fs) ++ src = mnt_fs_get_srcpath(src_fs); ++ else ++ src = mnt_resolve_spec(mnt_fs_get_source(fstab_fs), tb->cache); ++ ++ tgt = mnt_fs_get_target(fstab_fs); ++ ++ if (tgt || src || root) { ++ struct libmnt_iter itr; ++ struct libmnt_fs *fs; ++ ++ mnt_reset_iter(&itr, MNT_ITER_FORWARD); ++ ++ while(mnt_table_next_fs(tb, &itr, &fs) == 0) { ++ const char *s = mnt_fs_get_srcpath(fs), ++ *t = mnt_fs_get_target(fs), ++ *r = mnt_fs_get_root(fs); ++ ++ if (s && t && r && !strcmp(t, tgt) && ++ !strcmp(s, src) && !strcmp(r, root)) ++ break; ++ } ++ if (fs) ++ rc = 1; /* success */ ++ } ++ ++ free(root); ++ return rc; ++} ++ + #ifdef TEST_PROGRAM + + static int parser_errcb(struct libmnt_table *tb, const char *filename, int line) +@@ -869,6 +1038,46 @@ done: + return rc; + } + ++static int test_is_mounted(struct libmnt_test *ts, int argc, char *argv[]) ++{ ++ struct libmnt_table *tb = NULL, *fstab = NULL; ++ struct libmnt_fs *fs; ++ struct libmnt_iter *itr = NULL; ++ int rc; ++ ++ tb = mnt_new_table_from_file("/proc/self/mountinfo"); ++ if (!tb) { ++ fprintf(stderr, "failed to parse mountinfo\n"); ++ return -1; ++ } ++ ++ fstab = create_table(argv[1]); ++ if (!fstab) ++ goto done; ++ ++ itr = mnt_new_iter(MNT_ITER_FORWARD); ++ if (!itr) ++ goto done; ++ ++ while(mnt_table_next_fs(fstab, itr, &fs) == 0) { ++ if (mnt_table_is_fs_mounted(tb, fs)) ++ printf("%s already mounted on %s\n", ++ mnt_fs_get_source(fs), ++ mnt_fs_get_target(fs)); ++ else ++ printf("%s not mounted on %s\n", ++ mnt_fs_get_source(fs), ++ mnt_fs_get_target(fs)); ++ } ++ ++ rc = 0; ++done: ++ mnt_free_table(tb); ++ mnt_free_table(fstab); ++ mnt_free_iter(itr); ++ return rc; ++} ++ + int main(int argc, char *argv[]) + { + struct libmnt_test tss[] = { +@@ -877,6 +1086,7 @@ int main(int argc, char *argv[]) + { "--find-backward", test_find_bw, " " }, + { "--find-pair", test_find_pair, " " }, + { "--copy-fs", test_copy_fs, " copy root FS from the file" }, ++ { "--is-mounted", test_is_mounted, " check what from are already mounted" }, + { NULL } + }; + +diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c +index 5abb566..9817f20 100644 +--- a/shlibs/mount/src/tab_update.c ++++ b/shlibs/mount/src/tab_update.c +@@ -410,7 +410,7 @@ static int set_fs_root(struct libmnt_fs *result, struct libmnt_fs *fs, unsigned + mnt_fs_set_fstype(result, mnt_fs_get_fstype(src_fs)); + + /* on btrfs the subvolume is used as fs-root in +- * /proc/self/mountinfo, so we have get the original subvolume ++ * /proc/self/mountinfo, so we have to get the original subvolume + * name from src_fs and prepend the subvolume name to the + * fs-root path + */ +-- +1.7.5.2 + diff --git a/util-linux-2.19-mount-a-bind.patch b/util-linux-2.19-mount-a-bind.patch new file mode 100644 index 0000000..5d6eb59 --- /dev/null +++ b/util-linux-2.19-mount-a-bind.patch @@ -0,0 +1,105 @@ +From 0cac8948216a298deaf5fd30837ed9cc80618f80 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 31 May 2011 18:02:29 +0200 +Subject: [PATCH] mount: use libmount to detect already mounted bind mounts + +It's pretty tricky to detect that a bind mount from fstab is already +mounted on system without /etc/mtab. Let's use functionality from +libmount. + +Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=701176 +Signed-off-by: Karel Zak +--- + mount/mount.c | 42 ++++++++++++++++++++++++++++++++++++++---- + 1 files changed, 38 insertions(+), 4 deletions(-) + +diff --git a/mount/mount.c b/mount/mount.c +index 29963c2..3ba705f 100644 +--- a/mount/mount.c ++++ b/mount/mount.c +@@ -212,7 +212,7 @@ static const char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_sizelimit, + *opt_encryption, *opt_speed, *opt_comment, *opt_uhelper; + + static int is_readonly(const char *node); +-static int mounted (const char *spec0, const char *node0); ++static int mounted (const char *spec0, const char *node0, struct mntentchn *fstab_mc); + static int check_special_mountprog(const char *spec, const char *node, + const char *type, int flags, char *extra_opts, int *status); + +@@ -1562,7 +1562,7 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, + /* The "mount -f" checks for for existing record in /etc/mtab (with + * regular non-fake mount this is usually done by kernel) + */ +- if (!(flags & MS_REMOUNT) && fake && mounted (spec, node)) ++ if (!(flags & MS_REMOUNT) && fake && mounted (spec, node, NULL)) + die(EX_USAGE, _("mount: according to mtab, " + "%s is already mounted on %s\n"), + spec, node); +@@ -2016,13 +2016,46 @@ mount_one (const char *spec, const char *node, const char *types, + return try_mount_one (spec, node, types, opts, freq, pass, 0); + } + ++#ifdef HAVE_LIBMOUNT_MOUNT ++static struct libmnt_table *minfo; /* parsed mountinfo file */ ++#endif ++ + /* Check if an fsname/dir pair was already in the old mtab. */ + static int +-mounted (const char *spec0, const char *node0) { ++mounted (const char *spec0, const char *node0, struct mntentchn *fstab_mc) { + struct mntentchn *mc, *mc0; + const char *spec, *node; + int ret = 0; + ++#ifdef HAVE_LIBMOUNT_MOUNT ++ /* ++ * Use libmount to check for already mounted bind mounts on systems ++ * without mtab. ++ */ ++ if (fstab_mc && fstab_mc->m.mnt_opts && ++ mtab_is_a_symlink() && strstr(fstab_mc->m.mnt_opts, "bind")) { ++ ++ struct libmnt_fs *fs = mnt_new_fs(); ++ int rc = fs ? 0 : -1; ++ ++ if (!rc) ++ rc = mnt_fs_set_fstype(fs, fstab_mc->m.mnt_type); ++ if (!rc) ++ rc = mnt_fs_set_source(fs, fstab_mc->m.mnt_fsname); ++ if (!rc) ++ rc = mnt_fs_set_target(fs, fstab_mc->m.mnt_dir); ++ if (!rc) ++ rc = mnt_fs_set_options(fs, fstab_mc->m.mnt_opts); ++ if (!rc && !minfo) ++ minfo = mnt_new_table_from_file("/proc/self/mountinfo"); ++ if (!rc && minfo) ++ rc = mnt_table_is_fs_mounted(minfo, fs); ++ ++ mnt_free_fs(fs); ++ if (rc == 1) ++ return 1; ++ } ++#endif + /* Handle possible UUID= and LABEL= in spec */ + spec = spec_to_devname(spec0); + if (!spec) +@@ -2030,6 +2063,7 @@ mounted (const char *spec0, const char *node0) { + + node = canonicalize(node0); + ++ + mc0 = mtab_head(); + for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) + if (streq (spec, mc->m.mnt_fsname) && +@@ -2050,7 +2084,7 @@ is_fstab_entry_mounted(struct mntentchn *mc, int verbose) + { + struct stat st; + +- if (mounted(mc->m.mnt_fsname, mc->m.mnt_dir)) ++ if (mounted(mc->m.mnt_fsname, mc->m.mnt_dir, mc)) + goto yes; + + /* extra care for loop devices */ +-- +1.7.5.2 + diff --git a/util-linux.spec b/util-linux.spec index f7b1a1e..74eb0a2 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -2,7 +2,7 @@ Summary: A collection of basic system utilities Name: util-linux Version: 2.19.1 -Release: 1%{?dist} +Release: 1.1%{?dist} License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: http://kernel.org/~kzak/util-linux/ @@ -84,6 +84,15 @@ Patch7: util-linux-ng-2.13-login-lastlog.patch # 231192 - ipcs is not printing correct values on pLinux Patch8: util-linux-ng-2.15-ipcs-32bit.patch +### Upstream patches +### +# kernel "3.0" +Patch9: util-linux-2.19-kernel-version.patch +# 709319 - 'mount -a' mounts already mounted directories +Patch10: util-linux-2.19-libmount-mounted.patch +Patch11: util-linux-2.19-mount-a-bind.patch + + %description The util-linux package contains a large variety of low-level system utilities that are necessary for a Linux system to function. Among @@ -197,6 +206,10 @@ cp %{SOURCE8} %{SOURCE9} . %patch5 -p1 %patch7 -p1 %patch8 -p1 +%patch9 -p1 +%patch10 -p1 +%patch11 -p1 + %build unset LINGUAS || : @@ -742,6 +755,10 @@ fi %changelog +* Tue Jun 14 2011 Karel Zak 2.19.1-1.1 +- fix #709319 - 'mount -a' mounts already mounted directories +- fix kernel version parsing + * Fri May 6 2011 Karel Zak 2.19.1-1 - upgrade to the release 2.19.1 ftp://ftp.kernel.org/pub/linux/utils/util-linux/v2.19/v2.19.1-ReleaseNotes From d6ea7f6451dbbc03911fb2fbab8045b316f238a2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 14 Jun 2011 11:43:44 +0200 Subject: [PATCH 7/9] 2.19.1-1.2: fix #709681 Signed-off-by: Karel Zak --- util-linux-2.19-mount-fsname.patch | 33 ++++++++++++++++++++++++++++++ util-linux.spec | 9 ++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 util-linux-2.19-mount-fsname.patch diff --git a/util-linux-2.19-mount-fsname.patch b/util-linux-2.19-mount-fsname.patch new file mode 100644 index 0000000..686d7fb --- /dev/null +++ b/util-linux-2.19-mount-fsname.patch @@ -0,0 +1,33 @@ +From aab72640daa7ee2db3d42fc8278ab86e3aef2d71 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Thu, 2 Jun 2011 14:53:42 +0200 +Subject: [PATCH] mount: canonicalize fstab mnt_dir + +Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=709681 +Signed-off-by: Karel Zak +--- + mount/fstab.c | 8 +++++++- + 1 files changed, 7 insertions(+), 1 deletions(-) + +diff --git a/mount/fstab.c b/mount/fstab.c +index 8ce733b..4fa26b4 100644 +--- a/mount/fstab.c ++++ b/mount/fstab.c +@@ -455,7 +455,13 @@ getfs_by_dir (const char *dir) { + + cdir = canonicalize(dir); + for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) { +- if (streq(mc->m.mnt_dir, cdir)) { ++ int ok = streq(mc->m.mnt_dir, cdir); ++ if (!ok) { ++ char *dr = canonicalize(mc->m.mnt_dir); ++ ok = dr ? streq(dr, cdir) : 0; ++ free(dr); ++ } ++ if (ok) { + free(cdir); + return mc; + } +-- +1.7.5.2 + diff --git a/util-linux.spec b/util-linux.spec index 74eb0a2..00d7e8e 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -2,7 +2,7 @@ Summary: A collection of basic system utilities Name: util-linux Version: 2.19.1 -Release: 1.1%{?dist} +Release: 1.2%{?dist} License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: http://kernel.org/~kzak/util-linux/ @@ -91,7 +91,8 @@ Patch9: util-linux-2.19-kernel-version.patch # 709319 - 'mount -a' mounts already mounted directories Patch10: util-linux-2.19-libmount-mounted.patch Patch11: util-linux-2.19-mount-a-bind.patch - +# 709681 - failure to mount if a mount point ends with a slash in /etc/fstab +Patch12: util-linux-2.19-mount-fsname.patch %description The util-linux package contains a large variety of low-level system @@ -209,6 +210,7 @@ cp %{SOURCE8} %{SOURCE9} . %patch9 -p1 %patch10 -p1 %patch11 -p1 +%patch12 -p1 %build @@ -755,6 +757,9 @@ fi %changelog +* Tue Jun 14 2011 Karel Zak 2.19.1-1.2 +- fix #709681 - failure to mount if a mount point ends with a slash in /etc/fstab + * Tue Jun 14 2011 Karel Zak 2.19.1-1.1 - fix #709319 - 'mount -a' mounts already mounted directories - fix kernel version parsing From 52a02ebeb9af7e9ad3c1716c7584ff33a5181822 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 4 Jul 2011 23:45:38 +0200 Subject: [PATCH 8/9] 2.19.1-1.3: #716483 Signed-off-by: Karel Zak --- util-linux-2.19-mount-mountpoint.patch | 76 ++++++++++++++++++++++++++ util-linux.spec | 8 ++- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 util-linux-2.19-mount-mountpoint.patch diff --git a/util-linux-2.19-mount-mountpoint.patch b/util-linux-2.19-mount-mountpoint.patch new file mode 100644 index 0000000..bd97aa7 --- /dev/null +++ b/util-linux-2.19-mount-mountpoint.patch @@ -0,0 +1,76 @@ +From 067e9b4934372f72b89b2c0442a3d28290834537 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Wed, 29 Jun 2011 09:02:50 +0200 +Subject: [PATCH] mount: first look for mountpoint + + # mount + +The current code looks for a device and then for a mountpoint in +/etc/fstab. This is not user friendly solution. People usually use + + # mount /dir + +to mount any filesystem. It makes more sense to check for mountpoint +and if not found then for device. + +This is also important for bind mounts, for example if you have in +your fstab: + + /dev/sda1 /mnt/foo auto defaults + /mnt/foo /mnt/bar none bind + +then + # mount /mnt/foo + +should be interpreted as the first entry and /dev/sda1 should be +mounted. + +Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=716483 +Signed-off-by: Karel Zak +--- + mount/mount.8 | 11 +++++++++++ + mount/mount.c | 4 ++-- + 2 files changed, 13 insertions(+), 2 deletions(-) + +diff --git a/mount/mount.8 b/mount/mount.8 +index 8982537..e9a52dd 100644 +--- a/mount/mount.8 ++++ b/mount/mount.8 +@@ -101,6 +101,17 @@ the pathname + refers to the root of the filesystem on + .IR device . + ++If only directory or device is given, for example: ++.RS ++ ++.br ++.BI "mount /dir" ++.br ++ ++.RE ++then mount looks for a mountpoint and if not found then for a device in the ++/etc/fstab file. ++ + .B The listing and help. + .RS + Three forms of invocation do not actually mount anything: +diff --git a/mount/mount.c b/mount/mount.c +index 3ba705f..00637f5 100644 +--- a/mount/mount.c ++++ b/mount/mount.c +@@ -2347,10 +2347,10 @@ getfs(const char *spec, const char *uuid, const char *label) + else if (label) + mc = getfs_by_label(label); + else { +- mc = getfs_by_spec(spec); ++ mc = getfs_by_dir(spec); + + if (!mc) +- mc = getfs_by_dir(spec); ++ mc = getfs_by_spec(spec); + } + if (mc) + return mc; +-- +1.7.5.4 + diff --git a/util-linux.spec b/util-linux.spec index 00d7e8e..01175fb 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -2,7 +2,7 @@ Summary: A collection of basic system utilities Name: util-linux Version: 2.19.1 -Release: 1.2%{?dist} +Release: 1.3%{?dist} License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: http://kernel.org/~kzak/util-linux/ @@ -93,6 +93,8 @@ Patch10: util-linux-2.19-libmount-mounted.patch Patch11: util-linux-2.19-mount-a-bind.patch # 709681 - failure to mount if a mount point ends with a slash in /etc/fstab Patch12: util-linux-2.19-mount-fsname.patch +# 716483 - /var/tmp --(BIND-mounted)--> /tmp disrupts/hangs bootup +Patch13: util-linux-2.19-mount-mountpoint.patch %description The util-linux package contains a large variety of low-level system @@ -211,6 +213,7 @@ cp %{SOURCE8} %{SOURCE9} . %patch10 -p1 %patch11 -p1 %patch12 -p1 +%patch13 -p1 %build @@ -757,6 +760,9 @@ fi %changelog +* Mon Jul 4 2011 Karel Zak 2.19.1-1.3 +- fix #716483 - /var/tmp --(BIND-mounted)--> /tmp disrupts/hangs bootup + * Tue Jun 14 2011 Karel Zak 2.19.1-1.2 - fix #709681 - failure to mount if a mount point ends with a slash in /etc/fstab From ccfa199c64911e3eee517e4c2db24ed1db91a91e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 11 Jul 2011 13:27:49 +0200 Subject: [PATCH 9/9] 2.19.1-1.4: fix #707035 Signed-off-by: Karel Zak --- util-linux-2.19-mount-doublefree.patch | 66 ++++++++++++++++++++++++++ util-linux.spec | 9 +++- 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 util-linux-2.19-mount-doublefree.patch diff --git a/util-linux-2.19-mount-doublefree.patch b/util-linux-2.19-mount-doublefree.patch new file mode 100644 index 0000000..db8d0d4 --- /dev/null +++ b/util-linux-2.19-mount-doublefree.patch @@ -0,0 +1,66 @@ +From 400459e897045b40eb3711fa4814176f7422a76a Mon Sep 17 00:00:00 2001 +From: Kirill Elagin +Date: Mon, 11 Jul 2011 12:53:43 +0200 +Subject: [PATCH] mount: fix double free in mount.c with SELinux enabled + +append_context reallocates memory, invalidating extra_opts1. As a +result my_free(extra_opts1) crashes. + +Signed-off-by: Kirill Elagin +Signed-off-by: Nikita Ofitserov +Signed-off-by: Karel Zak +--- + mount/mount.c | 15 ++++++++------- + 1 files changed, 8 insertions(+), 7 deletions(-) + +diff --git a/mount/mount.c b/mount/mount.c +index cb04d9d..ea2c478 100644 +--- a/mount/mount.c ++++ b/mount/mount.c +@@ -1535,7 +1535,7 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, + struct stat statbuf; + + /* copies for freeing on exit */ +- const char *opts1, *spec1, *node1, *types1, *extra_opts1; ++ const char *opts1, *spec1, *node1, *types1; + + if (verbose > 2) { + printf("mount: spec: \"%s\"\n", spec0); +@@ -1550,8 +1550,7 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, + opts = opts1 = xstrdup(opts0); + + parse_opts (opts, &flags, &extra_opts); +- extra_opts1 = extra_opts; +- mount_opts = extra_opts; ++ mount_opts = xstrdup(extra_opts); + + /* quietly succeed for fstab entries that don't get mounted automatically */ + if (mount_all && (flags & MS_NOAUTO)) +@@ -1592,8 +1591,11 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, + /* + * Linux kernel does not accept any selinux context option on remount + */ +- if (mount_opts) ++ if (mount_opts) { ++ char *tmp = mount_opts; + mount_opts = remove_context_options(mount_opts); ++ my_free(tmp); ++ } + + } else if (types && strcmp(types, "tmpfs") == 0 && is_selinux_enabled() > 0 && + !has_context_option(mount_opts)) { +@@ -1922,9 +1924,8 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, + } + #endif + +- if (extra_opts1 != mount_opts) +- my_free(mount_opts); +- my_free(extra_opts1); ++ my_free(mount_opts); ++ my_free(extra_opts); + my_free(spec1); + my_free(node1); + my_free(opts1); +-- +1.7.6 + diff --git a/util-linux.spec b/util-linux.spec index 01175fb..4a76f45 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -2,7 +2,7 @@ Summary: A collection of basic system utilities Name: util-linux Version: 2.19.1 -Release: 1.3%{?dist} +Release: 1.4%{?dist} License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain Group: System Environment/Base URL: http://kernel.org/~kzak/util-linux/ @@ -95,6 +95,8 @@ Patch11: util-linux-2.19-mount-a-bind.patch Patch12: util-linux-2.19-mount-fsname.patch # 716483 - /var/tmp --(BIND-mounted)--> /tmp disrupts/hangs bootup Patch13: util-linux-2.19-mount-mountpoint.patch +# 707035 - /bin/mount: double free glibc detected +Patch14: util-linux-2.19-mount-doublefree.patch %description The util-linux package contains a large variety of low-level system @@ -214,7 +216,7 @@ cp %{SOURCE8} %{SOURCE9} . %patch11 -p1 %patch12 -p1 %patch13 -p1 - +%patch14 -p1 %build unset LINGUAS || : @@ -760,6 +762,9 @@ fi %changelog +* Mon Jul 11 2011 Karel Zak 2.19.1-1.4 +- fix #707035 - /bin/mount: double free glibc detected + * Mon Jul 4 2011 Karel Zak 2.19.1-1.3 - fix #716483 - /var/tmp --(BIND-mounted)--> /tmp disrupts/hangs bootup