~ubuntu-branches/ubuntu/quantal/util-linux/quantal

« back to all changes in this revision

Viewing changes to lib/fsprobe.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
static blkid_cache blcache;
22
22
 
23
 
#ifdef HAVE_LIBBLKID_INTERNAL
24
 
/* ask kernel developers why we need such ugly open() method... */
25
 
static int
26
 
open_device(const char *devname)
27
 
{
28
 
        int retries = 0;
29
 
 
30
 
        do {
31
 
                int fd = open(devname, O_RDONLY);
32
 
                if (fd >= 0)
33
 
                        return fd;
34
 
#ifdef ENOMEDIUM
35
 
                /* ENOMEDIUM is Linux-only */
36
 
                if (errno != ENOMEDIUM)
37
 
                        break;
38
 
#else
39
 
                break;
40
 
#endif
41
 
                if (retries >= CRDOM_NOMEDIUM_RETRIES)
42
 
                        break;
43
 
                ++retries;
44
 
                sleep(3);
45
 
        } while(1);
46
 
 
47
 
        return -1;
48
 
}
49
 
#endif
50
 
 
51
23
/*
52
24
 * Parses NAME=value, returns -1 on parse error, 0 success. The success is also
53
25
 * when the 'spec' doesn't contain name=value pair (because the spec could be
104
76
 
105
77
#ifdef HAVE_LIBBLKID_INTERNAL
106
78
/*
107
 
 * libblkid from util-linux-ng
 
79
 * libblkid from util-linux
108
80
 * -- recommended
109
81
 */
110
82
static blkid_probe blprobe;
122
94
 * probing interface
123
95
 */
124
96
static char *
125
 
fsprobe_get_value(const char *name, const char *devname)
 
97
fsprobe_get_value(const char *name, const char *devname, int *ambi)
126
98
{
127
 
        int fd;
 
99
        int fd, rc;
128
100
        const char *data = NULL;
129
101
 
130
102
        if (!devname || !name)
131
103
                return NULL;
132
 
        fd = open_device(devname);
 
104
        fd = open(devname, O_RDONLY);
133
105
        if (fd < 0)
134
106
                return NULL;
135
107
        if (!blprobe)
144
116
        blkid_probe_set_superblocks_flags(blprobe,
145
117
                BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | BLKID_SUBLKS_TYPE);
146
118
 
147
 
        if (blkid_do_safeprobe(blprobe))
148
 
                goto done;
149
 
        if (blkid_probe_lookup_value(blprobe, name, &data, NULL))
150
 
                goto done;
 
119
        rc = blkid_do_safeprobe(blprobe);
 
120
        if (ambi)
 
121
                *ambi = rc == -2 ? 1 : 0;       /* ambivalent probing result */
 
122
        if (!rc)
 
123
                blkid_probe_lookup_value(blprobe, name, &data, NULL);
151
124
done:
152
125
        close(fd);
153
126
        return data ? strdup((char *) data) : NULL;
156
129
char *
157
130
fsprobe_get_label_by_devname(const char *devname)
158
131
{
159
 
        return fsprobe_get_value("LABEL", devname);
 
132
        return fsprobe_get_value("LABEL", devname, NULL);
160
133
}
161
134
 
162
135
char *
163
136
fsprobe_get_uuid_by_devname(const char *devname)
164
137
{
165
 
        return fsprobe_get_value("UUID", devname);
 
138
        return fsprobe_get_value("UUID", devname, NULL);
166
139
}
167
140
 
168
141
char *
169
142
fsprobe_get_fstype_by_devname(const char *devname)
170
143
{
171
 
        return fsprobe_get_value("TYPE", devname);
 
144
        return fsprobe_get_value("TYPE", devname, NULL);
 
145
}
 
146
 
 
147
char *
 
148
fsprobe_get_fstype_by_devname_ambi(const char *devname, int *ambi)
 
149
{
 
150
        return fsprobe_get_value("TYPE", devname, ambi);
172
151
}
173
152
 
174
153
char *
237
216
}
238
217
 
239
218
char *
 
219
fsprobe_get_fstype_by_devname_ambi(const char *devname, int *ambi)
 
220
{
 
221
        if (ambi)
 
222
                *ambi = 0;
 
223
        return fsprobe_get_fstype_by_devname(devname);
 
224
}
 
225
 
 
226
char *
240
227
fsprobe_get_label_by_devname(const char *devname)
241
228
{
242
229
        if (!blcache)