summaryrefslogtreecommitdiffstats
path: root/libblkid
diff options
context:
space:
mode:
authorKarel Zak2012-01-25 12:56:39 +0100
committerKarel Zak2012-01-25 13:20:37 +0100
commitb82590ad46acf9fe8d332b53875e24c3c31e2482 (patch)
tree6e2f7e53424393b1925a896a309d2913ae48c136 /libblkid
parentblkid: remove -w option from man page and usage() output (diff)
downloadkernel-qcow2-util-linux-b82590ad46acf9fe8d332b53875e24c3c31e2482.tar.gz
kernel-qcow2-util-linux-b82590ad46acf9fe8d332b53875e24c3c31e2482.tar.xz
kernel-qcow2-util-linux-b82590ad46acf9fe8d332b53875e24c3c31e2482.zip
blkid: move cache to /run on new systems
Why? * read-only root * /etc is pretty bad place for caches * all is usually cached by udev in /dev/disk/by-* and libblkid is able to use these symlinks * boot persistent cache is attractive for very small subset of Linux machines (and they already need extra udev tunning otherwise udev will probe all block devices during boot) * the default is possible to override in /etc/blkid.conf The systems without /run directory will not be affected by this change. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libblkid')
-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
5 files changed, 47 insertions, 40 deletions
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;
}