summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/blkid.txt10
-rw-r--r--Documentation/howto-debug.txt5
-rw-r--r--libblkid/libblkid.338
-rw-r--r--libblkid/src/blkidP.h10
-rw-r--r--libblkid/src/cache.c16
-rw-r--r--libblkid/src/read.c2
-rw-r--r--libblkid/src/save.c21
-rw-r--r--libmount/src/cache.c2
-rw-r--r--misc-utils/blkid.834
-rw-r--r--misc-utils/blkid.c3
10 files changed, 89 insertions, 52 deletions
diff --git a/Documentation/blkid.txt b/Documentation/blkid.txt
index 4fa9be1f7..c58b04f67 100644
--- a/Documentation/blkid.txt
+++ b/Documentation/blkid.txt
@@ -58,7 +58,7 @@ type, or label, or uuid for a particular device:
}
If a program needs to call multiple blkid functions, then passing in a
-cache value of NULL is not recommended, since the /etc/blkid.tab file
+cache value of NULL is not recommended, since the blkid.tab file
will be repeatedly parsed over and over again, with memory allocated
and deallocated. To initialize the blkid cache, blkid_get_cache()
function is used:
@@ -66,9 +66,11 @@ function is used:
if (blkid_get_cache(&cache, NULL) < 0)
goto errout;
-The second parameter of blkid_get_cache (if non-zero) is the alternate
-filename of the blkid cache file (where the default is
-/etc/blkid.tab). Normally, programs should just pass in NULL.
+The second parameter of blkid_get_cache (if non-zero) is the alternate filename
+of the blkid cache file (see blkid man page for more information about the
+default cach file location).
+
+Normally, programs should just pass in NULL.
If you have called blkid_get_cache(), you should call blkid_put_cache()
when you are done using the blkid library functions. This will save the
diff --git a/Documentation/howto-debug.txt b/Documentation/howto-debug.txt
index 28c6e2252..99e2755d4 100644
--- a/Documentation/howto-debug.txt
+++ b/Documentation/howto-debug.txt
@@ -58,8 +58,9 @@ The libblkid reads by default /etc/blkid.conf which can be overriden by the
environment variable BLKID_CONF. See manual libblkid/libblkid.3 for details
about the configuration file.
-Block device information is normally kept in a cache file /etc/blkid.tab that
-can be overridden by the environment variable BLKID_FILE.
+Block device information is normally kept in a cache file (see blkid man page
+for more information about the cache file location) that can be overridden by
+the environment variable BLKID_FILE.
To libmount uses three paths, which can be override by using environment
variables. Notice that these environment variables are ignored for non-root
diff --git a/libblkid/libblkid.3 b/libblkid/libblkid.3
index a9291e2cc..7f1c04522 100644
--- a/libblkid/libblkid.3
+++ b/libblkid/libblkid.3
@@ -26,10 +26,8 @@ specific block device names into configuration files.
The low-level part of the library also allows to extract infomation about
partitions and block device topology.
.P
-The high-level part of the library keeps information about block devices
-in a cache file
-.I /etc/blkid.tab
-and is verified to still be valid before being returned to the user
+The high-level part of the library keeps information about block devices in a
+cache file and is verified to still be valid before being returned to the user
(if the user has read permission on the raw block device, otherwise not).
The cache file also allows unprivileged users (normally anyone other
than root, or those not in the "disk" group) to locate devices by label/id.
@@ -58,40 +56,16 @@ in this situation.
.SH CONFIGURATION FILE
The standard location of the
.I /etc/blkid.conf
-config file can be overridden by the environment variable BLKID_CONF.
-The following options control the libblkid library:
-.TP
-.I SEND_UEVENT=<yes|not>
-Sends uevent when
-.I /dev/disk/by-{label,uuid}/
-symlink does not match with LABEL or UUID on the device. Default is "yes".
-.TP
-.I CACHE_FILE=<path>
-Overrides the standard location of the cache file. This setting can be
-overridden by the environment variable BLKID_FILE. Default is
-.I /etc/blkid.tab.
-.TP
-.I EVALUATE=<methods>
-Defines LABEL and UUID evaluation method(s). Currently, the libblkid library
-supports "udev" and "scan" methods. More than one methods may be specified in
-a comma separated list. Default is "udev,scan". The "udev" method uses udev
-.I /dev/disk/by-*
-symlinks and the "scan" method scans all block devices from the
-.I /proc/partitions
-file.
+config file can be overridden by the environment variable BLKID_CONF. For more
+details about the config file see
+.BR blkid (8)
+man page.
.SH AUTHOR
.B libblkid
was written by Andreas Dilger for the ext2 filesystem utilties, with input
from Ted Ts'o. The library was subsequently heavily modified by Ted Ts'o.
The low-level probing code was rewritten by Karel Zak.
-.SH FILES
-.TP 18
-.I /etc/blkid.tab
-caches data extracted from each recognized block device
-.TP
-.I /etc/blkid.conf
-configuration file
.SH AVAILABILITY
.B libblkid
is part of the util-linux package since version 2.15 and is available from
diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h
index 00689e827..b6c2bc607 100644
--- a/libblkid/src/blkidP.h
+++ b/libblkid/src/blkidP.h
@@ -286,9 +286,17 @@ extern char *blkid_strdup(const char *s);
extern char *blkid_strndup(const char *s, const int length);
extern char *blkid_strconcat(const char *a, const char *b, const char *c);
-#define BLKID_CACHE_FILE "/etc/blkid.tab"
+/* config file */
#define BLKID_CONFIG_FILE "/etc/blkid.conf"
+/* cache file on systemds with /run */
+#define BLKID_RUNTIME_TOPDIR "/run"
+#define BLKID_RUNTIME_DIR BLKID_RUNTIME_TOPDIR "/blkid"
+#define BLKID_CACHE_FILE BLKID_RUNTIME_DIR "/blkid.tab"
+
+/* old systems */
+#define BLKID_CACHE_FILE_OLD "/etc/blkid.tab"
+
#define BLKID_ERR_IO 5
#define BLKID_ERR_PROC 9
#define BLKID_ERR_MEM 12
diff --git a/libblkid/src/cache.c b/libblkid/src/cache.c
index c100cfa20..2eab2d329 100644
--- a/libblkid/src/cache.c
+++ b/libblkid/src/cache.c
@@ -31,7 +31,7 @@ int blkid_debug_mask = 0;
* @title: Cache
* @short_description: basic routines to work with libblkid cache
*
- * Block device information is normally kept in a cache file /etc/blkid.tab and is
+ * Block device information is normally kept in a cache file blkid.tab and is
* verified to still be valid before being returned to the user (if the user has
* read permission on the raw block device, otherwise not). The cache file also
* allows unprivileged users (normally anyone other than root, or those not in the
@@ -95,6 +95,16 @@ void blkid_init_debug(int mask)
}
#endif
+static const char *get_default_cache_filename(void)
+{
+ struct stat st;
+
+ if (stat(BLKID_RUNTIME_TOPDIR, &st) == 0 && S_ISDIR(st.st_mode))
+ return BLKID_CACHE_FILE; /* cache in /run */
+
+ return BLKID_CACHE_FILE_OLD; /* cache in /etc */
+}
+
/* returns allocated path to cache */
char *blkid_get_cache_filename(struct blkid_config *conf)
{
@@ -108,7 +118,7 @@ char *blkid_get_cache_filename(struct blkid_config *conf)
else {
struct blkid_config *c = blkid_read_config(NULL);
if (!c)
- filename = blkid_strdup(BLKID_CACHE_FILE);
+ filename = blkid_strdup(get_default_cache_filename());
else {
filename = c->cachefile; /* already allocated */
c->cachefile = NULL;
@@ -244,7 +254,7 @@ int main(int argc, char** argv)
if ((ret = blkid_get_cache(&cache, argv[1])) < 0) {
fprintf(stderr, "error %d parsing cache file %s\n", ret,
- argv[1] ? argv[1] : BLKID_CACHE_FILE);
+ argv[1] ? argv[1] : blkid_get_cache_filename(NULL));
exit(1);
}
if ((ret = blkid_get_cache(&cache, "/dev/null")) != 0) {
diff --git a/libblkid/src/read.c b/libblkid/src/read.c
index b9fda3aae..97fd4b4a2 100644
--- a/libblkid/src/read.c
+++ b/libblkid/src/read.c
@@ -489,7 +489,7 @@ int main(int argc, char**argv)
}
if ((ret = blkid_get_cache(&cache, argv[1])) < 0)
fprintf(stderr, "error %d reading cache file %s\n", ret,
- argv[1] ? argv[1] : BLKID_CACHE_FILE);
+ argv[1] ? argv[1] : blkid_get_cache_filename(NULL));
blkid_put_cache(cache);
diff --git a/libblkid/src/save.c b/libblkid/src/save.c
index a71b06878..7673ab42e 100644
--- a/libblkid/src/save.c
+++ b/libblkid/src/save.c
@@ -57,8 +57,8 @@ int blkid_flush_cache(blkid_cache cache)
{
struct list_head *p;
char *tmp = NULL;
- const char *opened = NULL;
- const char *filename;
+ char *opened = NULL;
+ char *filename;
FILE *file = NULL;
int fd, ret = 0;
struct stat st;
@@ -72,7 +72,20 @@ int blkid_flush_cache(blkid_cache cache)
return 0;
}
- filename = cache->bic_filename ? cache->bic_filename: BLKID_CACHE_FILE;
+ filename = cache->bic_filename ? cache->bic_filename :
+ blkid_get_cache_filename(NULL);
+
+ if (filename && strncmp(filename,
+ BLKID_RUNTIME_DIR "/", sizeof(BLKID_RUNTIME_DIR)) == 0) {
+
+ /* default destination, create the directory if necessary */
+ if (stat(BLKID_RUNTIME_DIR, &st) && errno == ENOENT) {
+
+ mkdir(BLKID_RUNTIME_DIR, S_IWUSR|
+ S_IRUSR|S_IRGRP|S_IROTH|
+ S_IXUSR|S_IXGRP|S_IXOTH);
+ }
+ }
/* If we can't write to the cache file, then don't even try */
if (((ret = stat(filename, &st)) < 0 && errno != ENOENT) ||
@@ -157,6 +170,8 @@ int blkid_flush_cache(blkid_cache cache)
errout:
free(tmp);
+ if (filename != cache->bic_filename)
+ free(filename);
return ret;
}
diff --git a/libmount/src/cache.c b/libmount/src/cache.c
index cf319ca25..1b3e94d00 100644
--- a/libmount/src/cache.c
+++ b/libmount/src/cache.c
@@ -54,7 +54,7 @@ struct libmnt_cache {
* 1/ all tags are evaluated by udev /dev/disk/by-* symlinks,
* then the blkid_cache is NULL.
*
- * 2/ all tags are read from /etc/blkid.tab and verified by /dev
+ * 2/ all tags are read from blkid.tab and verified by /dev
* scanning, then the blkid_cache is not NULL and then it's
* better to reuse the blkid_cache.
*/
diff --git a/misc-utils/blkid.8 b/misc-utils/blkid.8
index 31805c611..c8a31210a 100644
--- a/misc-utils/blkid.8
+++ b/misc-utils/blkid.8
@@ -76,10 +76,9 @@ same meaning as "KiB") or decimal (10^N) suffixes KB, MB, GB, PB and EB.
.BI \-c " cachefile"
Read from
.I cachefile
-instead of reading from the default cache file
-.IR /etc/blkid.tab .
-If you want to start with a clean cache (i.e. don't report devices previously
-scanned but not necessarily available at this time), specify
+instead of reading from the default cache file (see CONFIGURATION FILE section
+for more details). If you want to start with a clean cache (i.e. don't report
+devices previously scanned but not necessarily available at this time), specify
.IR /dev/null .
.TP
.B \-d
@@ -255,6 +254,33 @@ For usage or other errors, an exit code of 4 is returned.
If the ambivalent low-level probing result was detected, an exit code of 8 is
returned.
+.SH CONFIGURATION FILE
+The standard location of the
+.I /etc/blkid.conf
+config file can be overridden by the environment variable BLKID_CONF.
+The following options control the libblkid library:
+.TP
+.I SEND_UEVENT=<yes|not>
+Sends uevent when
+.I /dev/disk/by-{label,uuid}/
+symlink does not match with LABEL or UUID on the device. Default is "yes".
+.TP
+.I CACHE_FILE=<path>
+Overrides the standard location of the cache file. This setting can be
+overridden by the environment variable BLKID_FILE. Default is
+.I /run/blkid/blkid.tab
+or
+.I /etc/blkid.tab
+on systems without /run direcotry
+.TP
+.I EVALUATE=<methods>
+Defines LABEL and UUID evaluation method(s). Currently, the libblkid library
+supports "udev" and "scan" methods. More than one methods may be specified in
+a comma separated list. Default is "udev,scan". The "udev" method uses udev
+.I /dev/disk/by-*
+symlinks and the "scan" method scans all block devices from the
+.I /proc/partitions
+file.
.SH AUTHOR
.B blkid
was written by Andreas Dilger for libblkid and improved by Theodore Ts'o
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index 2976bca02..463fad3c0 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -67,7 +67,8 @@ static void usage(int error)
" [-o <format>] <dev> ...\n\n"
" %1$s -i [-s <tag>] [-o <format>] <dev> ...\n\n"
"Options:\n"
- " -c <file> cache file (default: /etc/blkid.tab, /dev/null = none)\n"
+ " -c <file> read from <file> instead of reading from the default\n"
+ " cache file (-c /dev/null means no cache)\n"
" -d don't encode non-printing characters\n"
" -h print this usage message and exit\n"
" -g garbage collect the blkid cache\n"