+2003-01-25 Theodore Ts'o <tytso@mit.edu>
+
+ * blkid.h, cache.c, dev.c, devname.c, devno.c, probe.c, probe.h,
+ read.c, resolve.c, save.c, tag.c: Fix gcc -Wall nits.
+
2003-01-24 Theodore Ts'o <tytso@mit.edu>
* save.c (blkid_save_cache): Use mkstemp() instead mktemp().
* Save data to the cache file: save.c
*/
int blkid_save_cache_file(blkid_cache *cache, FILE *file);
-int blkid_save_cache(blkid_cache *cache, char *filename);
+int blkid_save_cache(blkid_cache *cache, const char *filename);
/*
* Identify a device by inode name: probe.c
#ifdef DEBUG_CACHE
#include <stdio.h>
-#define DEB_CACHE(fmt, arg...) printf("cache: " fmt, ## arg)
+#define DBG(x) x
#else
-#define DEB_CACHE(fmt, arg...) do {} while (0)
+#define DBG(x)
#endif
blkid_cache *blkid_new_cache(void)
if (!cache)
return;
- DEB_CACHE("freeing cache struct\n");
+ DBG(printf("freeing cache struct\n"));
/* DEB_DUMP_CACHE(cache); */
while (!list_empty(&cache->bic_devs)) {
blkid_tag *bad = list_entry(tag->bit_names.next,
blkid_tag, bit_names);
- DEB_CACHE("warning: unfreed tag %s=%s\n",
- bad->bit_name, bad->bit_val);
+ DBG(printf("warning: unfreed tag %s=%s\n",
+ bad->bit_name, bad->bit_val));
blkid_free_tag(bad);
}
blkid_free_tag(tag);
#ifdef DEBUG_DEV
#include <stdio.h>
-#define DEB_DEV(fmt, arg...) printf("dev: " fmt, ## arg)
+#define DBG(x) x
#else
-#define DEB_DEV(fmt, arg...) do {} while (0)
+#define DBG(x)
#endif
blkid_dev *blkid_new_dev(void)
if (!dev)
return;
- DEB_DEV(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type);
+ DBG(printf(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type));
DEB_DUMP_DEV(dev);
list_del(&dev->bid_devs);
#define SC_NONE 0x0003
#define SC_SAME 0x0002
-int string_compare(char *s1, char *s2)
+static int string_compare(char *s1, char *s2)
{
if (!s1 && !s2)
return SC_NONE;
if (!cache || !tag)
return 0;
- DEB_DEV(" adding tag %s=%s to cache\n", tag->bit_name, tag->bit_val);
+ DBG(printf(" adding tag %s=%s to cache\n", tag->bit_name, tag->bit_val));
if (!(head = blkid_find_head_cache(cache, tag))) {
head = blkid_new_tag();
if (!head)
return -BLKID_ERR_MEM;
- DEB_DEV(" creating new cache tag head %s\n",tag->bit_name);
+ DBG(printf(" creating new cache tag head %s\n",tag->bit_name));
head->bit_name = string_copy(tag->bit_name);
if (!head->bit_name) {
blkid_free_tag(head);
/* If the UUIDs are the same but one is unverified discard it */
if (dup_uuid == SC_SAME) {
- DEB_DEV(" duplicate uuid %s\n", dev->bid_uuid);
+ DBG(printf(" duplicate uuid %s\n", dev->bid_uuid));
if (!(odev->bid_flags & BLKID_BID_FL_VERIFIED)) {
dev->bid_id = odev->bid_id; /* keep old id */
blkid_free_dev(odev);
* (prefer one that has been validated, or the first one).
*/
if (dup_name == SC_SAME) {
- DEB_DEV(" duplicate devname %s\n", dev->bid_name);
+ DBG(printf(" duplicate devname %s\n", dev->bid_name));
if (odev->bid_flags & BLKID_BID_FL_VERIFIED ||
!(dev->bid_flags & BLKID_BID_FL_VERIFIED)) {
if ((dup_uuid & SC_SAME) &&
dup_type = string_compare(odev->bid_type, dev->bid_type);
if (dup_label == SC_SAME && dup_type == SC_SAME) {
- DEB_DEV(" duplicate label %s\n", dev->bid_label);
+ DBG(printf(" duplicate label %s\n", dev->bid_label));
if (!(odev->bid_flags & BLKID_BID_FL_VERIFIED)) {
blkid_free_dev(odev);
goto exit_new;
}
exit_new:
- DEB_DEV(" adding new devname %s to cache\n", dev->bid_name);
+ DBG(printf(" adding new devname %s to cache\n", dev->bid_name));
cache->bic_flags |= BLKID_BIC_FL_CHANGED;
return dev;
exit_old:
- DEB_DEV(" using old devname %s from cache\n", dev->bid_name);
+ DBG(printf(" using old devname %s from cache\n", dev->bid_name));
return dev;
}
/* #define DEBUG_DEVNAME */
#ifdef DEBUG_DEVNAME
-#define DEB_DEV(fmt, arg...) printf("devname: " fmt, ## arg)
+#define DBG(x) x
#else
-#define DEB_DEV(fmt, arg...) do {} while (0)
+#define DBG(x)
#endif
/*
if (strcmp(tmp->bid_name, devname))
continue;
- DEB_DEV("found devname %s in cache\n", tmp->bid_name);
+ DBG(printf("found devname %s in cache\n", tmp->bid_name));
dev = blkid_verify_devname(cache, tmp);
break;
}
*major = *minor = 0;
*size = 0;
- DEB_DEV("opening %s\n", lvm_device);
+ DBG(printf("opening %s\n", lvm_device));
if ((lvf = fopen(lvm_device, "r")) == NULL) {
ret = errno;
- DEB_DEV("%s: (%d) %s\n", lvm_device, ret, strerror(ret));
+ DBG(printf("%s: (%d) %s\n", lvm_device, ret, strerror(ret)));
return -ret;
}
while (fgets(buf, sizeof(buf), lvf)) {
- if (sscanf(buf, "size: %Ld", size) == 1) { /* sectors */
+ if (sscanf(buf, "size: %llu", size) == 1) { /* sectors */
*size <<= 9;
}
if (sscanf(buf, "device: %d:%d", major, minor) == 2) {
if ((vg_list = opendir(VG_DIR)) == NULL)
return;
- DEB_DEV("probing LVM devices under %s\n", VG_DIR);
+ DBG(printf("probing LVM devices under %s\n", VG_DIR));
while ((vg_iter = readdir(vg_list)) != NULL) {
DIR *lv_list;
continue;
}
sprintf(lvm_device, "%s/%s", vg_name, lv_name);
- DEB_DEV("LVM dev %s: devno 0x%02X%02X, size %Ld\n",
- lvm_device, major, minor, size);
+ DBG(printf("LVM dev %s: devno 0x%02X%02X, size %Ld\n",
+ lvm_device, major, minor, size));
probe_one(*cache, lvm_device, major, minor, size);
free(lvm_device);
}
last = which;
which ^= 1;
- if (sscanf(line, " %d %d %Ld %128[^\n ]",
+ if (sscanf(line, " %d %d %lld %128[^\n ]",
&majors[which], &minors[which],
&sizes[which], ptnames[which]) != 4)
continue;
- DEB_DEV("read partition name %s\n", ptnames[which]);
+ DBG(printf("read partition name %s\n", ptnames[which]));
/* look only at md devices on first pass */
handleOnFirst = !strncmp(ptnames[which], "md", 2);
lens[which] = strlen(ptnames[which]);
if (isdigit(ptnames[which][lens[which] - 1])) {
- DEB_DEV("partition dev %s, devno 0x%02X%02X\n",
- ptnames[which], majors[which],
- minors[which]);
+ DBG(printf("partition dev %s, devno 0x%02X%02X\n",
+ ptnames[which], majors[which],
+ minors[which]));
if (sizes[which] > 1)
probe_one(*cache, ptnames[which],
} else if (lens[last] &&
strncmp(ptnames[last], ptnames[which],
lens[last])) {
- DEB_DEV("whole dev %s, devno 0x%02X%02X\n",
- ptnames[last], majors[last],
- minors[last]);
+ DBG(printf("whole dev %s, devno 0x%02X%02X\n",
+ ptnames[last], majors[last],
+ minors[last]));
probe_one(*cache, ptnames[last], majors[last],
minors[last], sizes[last] << 10);
lens[last] = 0;
#include "blkid/blkid.h"
#ifdef DEBUG_DEVNO
-#define DEB_DEVNO(fmt, arg...) printf("devno: " fmt, ## arg)
+#define DBG(x) x
#else
-#define DEB_DEVNO(fmt, arg...) do {} while (0)
+#define DBG(x)
#endif
struct dir_list {
add_to_dirlist(path, list);
else if (S_ISBLK(st.st_mode) && st.st_rdev == devno) {
*devname = string_copy(path);
- DEB_DEVNO("found 0x%Lx at %s (%p)\n", devno,
- *devname, *devname);
+ DBG(printf("found 0x%Lx at %s (%p)\n", devno,
+ *devname, *devname));
if (!*devname)
ret = -BLKID_ERR_MEM;
break;
struct dir_list *current = list;
list = list->next;
- DEB_DEVNO("directory %s\n", current->name);
+ DBG(printf("directory %s\n", current->name));
scan_dir(current->name, devno, &new_list, &devname);
string_free(current->name);
free(current);
free_dirlist(&new_list);
if (!devname)
- fprintf(stderr, "blkid: couldn't find devno 0x%04Lx\n", devno);
+ fprintf(stderr, "blkid: couldn't find devno 0x%04lx\n",
+ (unsigned long) devno);
else
- DEB_DEVNO("found devno 0x%04Lx as %s\n", devno, devname);
+ DBG(printf("found devno 0x%04Lx as %s\n", devno, devname));
return devname;
}
}
if (dev)
- DEB_DEVNO("found devno 0x%04LX in cache as %s\n",
- devno, dev->bid_name);
+ DBG(printf("found devno 0x%04LX in cache as %s\n",
+ devno, dev->bid_name));
return dev;
}
/* #define DEBUG_PROBE */
#ifdef DEBUG_PROBE
-#define DEB_PROBE(fmt, arg...) printf("probe: " fmt, ## arg)
+#define DBG(x) x
#else
-#define DEB_PROBE(fmt, arg...) do {} while (0)
+#define DBG(x)
#endif
/*
blkid_create_tag(dev, NULL, "TYPE", id->bim_type,
strlen(id->bim_type));
- DEB_PROBE("%s: devno 0x%04Lx, type %s\n", devname,
- st.st_rdev, id->bim_type);
+ DBG(printf("%s: devno 0x%04Lx, type %s\n", devname,
+ st.st_rdev, id->bim_type));
return 0;
exit_dev:
es = (struct ext2_super_block *)buf;
- DEB_PROBE("size = %Ld, ext2_sb.compat = %08X:%08X:%08X\n", size,
- le32_to_cpu(es->s_feature_compat),
- le32_to_cpu(es->s_feature_incompat),
- le32_to_cpu(es->s_feature_ro_compat));
+ DBG(printf("size = %Ld, ext2_sb.compat = %08X:%08X:%08X\n", size,
+ le32_to_cpu(es->s_feature_compat),
+ le32_to_cpu(es->s_feature_incompat),
+ le32_to_cpu(es->s_feature_ro_compat)));
/* Make sure we don't keep re-probing as ext2 for a journaled fs */
if (!strcmp(id->bim_type, "ext2") &&
}
if (!uuid_is_null(es->s_uuid)) {
- unsigned char uuid[37];
+ char uuid[37];
uuid_unparse(es->s_uuid, uuid);
blkid_create_tag(dev, NULL, "UUID", uuid, sizeof(uuid));
}
sectors = vs->vs_total_sect;
cluster_size = ((vs->vs_sector_size[1] << 8) | vs->vs_sector_size[0]);
dev->bid_size = sectors * cluster_size;
- DEB_PROBE("%Ld %d byte sectors\n", sectors, cluster_size);
+ DBG(printf("%lld %d byte sectors\n", sectors, cluster_size));
if (strncmp(vs->vs_label, "NO NAME", 7)) {
- unsigned char *end = vs->vs_label + sizeof(vs->vs_label) - 1;
+ char *end = vs->vs_label + sizeof(vs->vs_label) - 1;
while (*end == ' ' && end >= vs->vs_label)
--end;
sectors = ms->ms_total_sect;
cluster_size = ((ms->ms_sector_size[1] << 8) | ms->ms_sector_size[0]);
dev->bid_size = sectors * cluster_size;
- DEB_PROBE("%Ld %d byte sectors\n", sectors, cluster_size);
+ DBG(printf("%Ld %d byte sectors\n", sectors, cluster_size));
if (strncmp(ms->ms_label, "NO NAME", 7)) {
- unsigned char *end = ms->ms_label + sizeof(ms->ms_label) - 1;
+ char *end = ms->ms_label + sizeof(ms->ms_label) - 1;
while (*end == ' ' && end >= ms->ms_label)
--end;
}
if (!uuid_is_null(rs->rs_uuid)) {
- unsigned char uuid[37];
+ char uuid[37];
uuid_unparse(rs->rs_uuid, uuid);
blkid_create_tag(dev, NULL, "UUID", uuid, sizeof(uuid));
}
/* The MD UUID is not contiguous in the superblock, make it so */
if (md->set_uuid0 || md->set_uuid1 || md->set_uuid2 || md->set_uuid3) {
unsigned char md_uuid[16];
- unsigned char uuid[37];
+ char uuid[37];
memcpy(md_uuid, &md->set_uuid0, 4);
memcpy(md_uuid + 4, &md->set_uuid1, 12);
*/
static unsigned char *read_one_buf(int fd, blkid_loff_t offset)
{
- char *buf;
+ unsigned char *buf;
if (lseek(fd, offset, SEEK_SET) < 0)
return NULL;
static unsigned char *read_sb_buf(int fd, unsigned char **bufs, int kboff,
blkid_loff_t start)
{
- int index = kboff >> BLKID_BLK_KBITS;
+ int idx = kboff >> BLKID_BLK_KBITS;
unsigned char **buf;
- if (index > BLKID_BLK_OFFS || index < -BLKID_BLK_OFFS) {
+ if (idx > BLKID_BLK_OFFS || idx < -BLKID_BLK_OFFS) {
fprintf(stderr, "reading from invalid offset %d (%d)!\n",
- kboff, index);
+ kboff, idx);
return NULL;
}
- buf = bufs + index;
+ buf = bufs + idx;
if (!*buf)
*buf = read_one_buf(fd, start);
int new_sb;
blkid_loff_t diff_dev;
- DEB_PROBE("found type %s (#%d) on %s, probing\n",
- id->bim_type, id - type_array, devname);
+ DBG(printf("found type %s (#%d) on %s, probing\n",
+ id->bim_type, id - type_array, devname));
new_sb = id->bim_kbsize << 10;
if (sb_size < new_sb) {
continue;
diff_dev = size - dev->bid_size;
- DEB_PROBE("size = %Lu, fs size = %Lu\n", size, dev->bid_size);
- DEB_PROBE("checking best match: old %Ld, new %Ld\n",
- diff_last, diff_dev);
+ DBG(printf("size = %Lu, fs size = %Lu\n", size, dev->bid_size));
+ DBG(printf("checking best match: old %Ld, new %Ld\n",
+ diff_last, diff_dev));
/* See which type is a better match by checking size */
if ((diff_last < 0 && diff_dev > diff_last) ||
(diff_last > 0 && diff_dev >= 0 && diff_dev < diff_last)) {
}
if (!last)
- DEB_PROBE("unknown device type on %s\n", devname);
+ DBG(printf("unknown device type on %s\n", devname));
else
- DEB_DUMP_DEV(last);
+ DBG(printf(last));
/* Free up any buffers we allocated */
for (bufs = buf_array; bufs - buf_array < sizeof(buf_array) /
blkid_loff_t size;
struct blkid_magic *id;
blkid_dev *new = NULL;
- char *sb_buf = NULL;
+ unsigned char *sb_buf = NULL;
int sb_size = 0;
time_t diff;
int fd;
diff < BLKID_PROBE_INTERVAL))
return dev;
- DEB_PROBE("need to revalidate %s\n", dev->bid_name);
+ DBG(printf("need to revalidate %s\n", dev->bid_name));
if ((fd = open(dev->bid_name, O_RDONLY)) < 0) {
if (errno == ENXIO || errno == ENODEV) {
return NULL;
}
/* We don't have read permission, just return cache data. */
- DEB_PROBE("returning unverified data for %s\n", dev->bid_name);
+ DBG(printf("returning unverified data for %s\n", dev->bid_name));
return dev;
}
int new_sb = id->bim_kbsize << 10;
/* See if we need to allocate a larger sb buffer */
if (sb_size < new_sb) {
- char *sav = sb_buf;
+ unsigned char *sav = sb_buf;
/* We can't revalidate, return old dev */
if (!(sb_buf = realloc(sb_buf, new_sb))) {
long bim_kboff; /* kilobyte offset of superblock */
unsigned bim_sboff; /* byte offset within superblock */
unsigned bim_len; /* length of magic */
- unsigned char *bim_magic; /* magic string */
+ const char *bim_magic; /* magic string */
unsigned bim_align; /* byte alignment of superblock */
unsigned bim_kbsize; /* size of superblock in kilobytes */
blkid_probe_t bim_probe; /* probe function */
__u32 s_feature_incompat;
__u32 s_feature_ro_compat;
unsigned char s_uuid[16];
- unsigned char s_volume_name[16];
+ char s_volume_name[16];
};
#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x00000004
#define EXT3_FEATURE_INCOMPAT_RECOVER 0x00000004
__u32 xs_dummy1[8];
unsigned char xs_uuid[16];
__u32 xs_dummy2[15];
- unsigned char xs_fname[12];
+ char xs_fname[12];
__u32 xs_dummy3[2];
__u64 xs_icount;
__u64 xs_ifree;
unsigned char rs_magic[12];
__u32 rs_dummy4[5];
unsigned char rs_uuid[16];
- unsigned char rs_label[16];
+ char rs_label[16];
};
/* Yucky misaligned values */
/* 34*/ __u16 vs_reserved2[6];
/* 40*/ unsigned char vs_unknown[3];
/* 43*/ unsigned char vs_serno[4];
-/* 47*/ unsigned char vs_label[11];
+/* 47*/ char vs_label[11];
/* 52*/ unsigned char vs_magic[8];
/* 5a*/ unsigned char vs_dummy2[164];
/*1fe*/ unsigned char vs_pmagic[2];
/* 20*/ __u32 ms_total_sect;
/* 24*/ unsigned char ms_unknown[3];
/* 27*/ unsigned char ms_serno[4];
-/* 2b*/ unsigned char ms_label[11];
+/* 2b*/ char ms_label[11];
/* 36*/ unsigned char ms_magic[8];
/* 3d*/ unsigned char ms_dummy2[192];
/*1fe*/ unsigned char ms_pmagic[2];
#include "uuid/uuid.h"
#ifdef DEBUG_CACHE
-#define DEB_CACHE(fmt, arg...) printf("cache:" fmt, ##arg)
+#define DBG(x) x
#else
-#define DEB_CACHE(fmt, arg...) do {} while (0)
+#define DBG(x)
#endif
#ifdef HAVE_STRTOULL
return 0;
if (!strncmp(p, "<device", 7)) {
- DEB_CACHE("found device header: %8s\n", p);
+ DBG(printf("found device header: %8s\n", p));
p += 7;
*cp = p;
*cp = skip_over_blank(*cp);
if (!strncmp(*cp, "</device>", 9)) {
- DEB_CACHE("found device trailer %9s\n", *cp);
+ DBG(printf("found device trailer %9s\n", *cp));
*cp += 9;
return 0;
}
start = skip_over_blank(start + 1);
end = skip_over_word(start);
- DEB_CACHE("device should be %*s\n", end - start, start);
+ DBG(printf("device should be %*s\n", end - start, start));
if (**cp == '>')
*cp = end;
memcpy(*name, start, end - start);
(*name)[end - start] = '\0';
- DEB_CACHE("found dev %s\n", *name);
+ DBG(printf("found dev %s\n", *name));
return 1;
}
* If a valid device was read, *dev_p is non-NULL, otherwise it is NULL
* (e.g. comment lines, unknown XML content, etc).
*/
-int blkid_parse_line(blkid_cache *cache, blkid_dev **dev_p, char *cp)
+static int blkid_parse_line(blkid_cache *cache, blkid_dev **dev_p, char *cp)
{
blkid_dev *dev;
blkid_tag *tag;
*dev_p = NULL;
- DEB_CACHE("line: %s\n", cp);
+ DBG(printf("line: %s\n", cp));
if ((ret = parse_dev(dev_p, &cp)) <= 0)
return ret;
if (!filename || !strlen(filename))
filename = BLKID_CACHE_FILE;
- DEB_CACHE("cache file %s\n", filename);
+ DBG(printf("cache file %s\n", filename));
/* If we read the standard cache file, do not do so again */
if (!strcmp(filename, BLKID_CACHE_FILE) && (*cache) &&
#include "probe.h"
#ifdef DEBUG_RESOLVE
-#define DEB_RESOLVE(fmt, arg...) printf("resolve: " fmt, ## arg)
+#define DBG(x) x
#else
-#define DEB_RESOLVE(fmt, arg...) do {} while (0)
+#define DBG(x)
#endif
blkid_dev *dev;
char *ret = NULL;
- DEB_RESOLVE("looking for %s on %s\n", tagname, devname);
+ DBG(printf("looking for %s on %s\n", tagname, devname));
if (!devname)
return NULL;
return NULL;
if (!cache)
- DEB_RESOLVE("no cache given, direct device probe\n");
+ DBG(printf("no cache given, direct device probe\n"));
if ((dev = blkid_get_devname(cache, devname)) &&
(found = blkid_find_tag_dev(dev, tag)))
blkid_cache *c = cache;
char *name = NULL;
- DEB_RESOLVE("looking for %s%c%s %s\n", token, value ? '=' : ' ',
- value ? value : "", cache ? "in cache" : "from disk");
+ DBG(printf("looking for %s%c%s %s\n", token, value ? '=' : ' ',
+ value ? value : "", cache ? "in cache" : "from disk"));
if (!(tag = blkid_token_to_tag(token))) {
if (!value)
#include "blkid/blkid.h"
#ifdef DEBUG_SAVE
-#define DEB_SAVE(fmt, arg...) printf("save: " fmt, ## arg)
+#define DBG(x) x
#else
-#define DEB_SAVE(fmt, arg...) do {} while (0)
+#define DBG(x)
#endif
static int save_dev(blkid_dev *dev, FILE *file)
if (!dev)
return 0;
- DEB_SAVE("device %s, type %s\n", dev->bid_name, dev->bid_type);
+ DBG(printf("device %s, type %s\n", dev->bid_name, dev->bid_type));
fprintf(file,
- "<device TYPE=\"%s\" DEVNO=\"0x%04Lx\" ID=\"%d\" TIME=\"%Ld\"",
- dev->bid_type, dev->bid_devno,
- dev->bid_id, (long long)dev->bid_time);
+ "<device TYPE=\"%s\" DEVNO=\"0x%04lx\" ID=\"%d\" TIME=\"%lu\"",
+ dev->bid_type, (unsigned long) dev->bid_devno,
+ dev->bid_id, dev->bid_time);
list_for_each(p, &dev->bid_tags) {
blkid_tag *tag = list_entry(p, blkid_tag, bit_tags);
if (strcmp(tag->bit_name, "TYPE"))
/*
* Write out the cache struct to the cache file on disk.
*/
-int blkid_save_cache(blkid_cache *cache, char *filename)
+int blkid_save_cache(blkid_cache *cache, const char *filename)
{
- char tmp[4096] = { '\0', };
- char *opened = NULL;
+ char *tmp = NULL;
+ const char *opened = NULL;
FILE *file = NULL;
int fd, ret;
if (list_empty(&cache->bic_devs) ||
!(cache->bic_flags & BLKID_BIC_FL_CHANGED)) {
- DEB_SAVE("empty cache, not saving\n");
+ DBG(printf("empty cache, not saving\n"));
return 0;
}
/* If we can't write to the cache file, then don't even try */
if (((ret = stat(filename, &st)) < 0 && errno != ENOENT) ||
(ret == 0 && access(filename, W_OK) < 0)) {
- DEB_SAVE("can't write to cache file %s\n", filename);
+ DBG(printf("can't write to cache file %s\n", filename));
return 0;
}
* a temporary file then we open it directly.
*/
if (ret == 0 && S_ISREG(st.st_mode)) {
- snprintf(tmp, sizeof(tmp) - 1, "%s-XXXXXX", filename);
- fd = mkstemp(tmp);
- if (fd >= 0) {
- file = fdopen(fd, "w");
- opened = tmp;
+ tmp = malloc(strlen(filename) + 8);
+ if (tmp) {
+ sprintf(tmp, "%s-XXXXXX", filename);
+ fd = mkstemp(tmp);
+ if (fd >= 0) {
+ file = fdopen(fd, "w");
+ opened = tmp;
+ }
}
}
opened = filename;
}
- DEB_SAVE("cache file %s (really %s)\n", filename, opened);
+ DBG(printf("cache file %s (really %s)\n", filename, opened));
if (!file) {
perror(opened);
+ if (tmp)
+ free(tmp);
return errno;
}
}
if (opened != filename) {
if (ret < 0) {
unlink(opened);
- DEB_SAVE("unlinked temp cache %s\n", opened);
+ DBG(printf("unlinked temp cache %s\n", opened));
} else {
- char backup[4096];
-
- snprintf(backup, sizeof(backup) - 1, "%s.old",
- filename);
- unlink(backup);
- link(filename, backup);
+ char *backup;
+
+ backup = malloc(strlen(filename) + 5);
+ if (backup) {
+ sprintf(backup, "%s.old", filename);
+ unlink(backup);
+ link(filename, backup);
+ free(backup);
+ }
rename(opened, filename);
- DEB_SAVE("moved temp cache %s\n", opened);
+ DBG(printf("moved temp cache %s\n", opened));
}
}
}
+ if (tmp)
+ free(tmp);
return ret;
}
#include "blkid/blkid.h"
#ifdef DEBUG_TAG
-#define DEB_TAG(fmt, arg...) printf("tag: " fmt, ## arg)
+#define DBG(x) x
#else
-#define DEB_TAG(fmt, arg...) do {} while (0)
+#define DBG(x)
#endif
blkid_tag *blkid_new_tag(void)
if (!tag)
return;
- DEB_TAG(" freeing tag %s=%s\n", tag->bit_name, tag->bit_val);
+ DBG(printf(" freeing tag %s=%s\n", tag->bit_name, tag->bit_val));
DEB_DUMP_TAG(tag);
list_del(&tag->bit_tags); /* list of tags for this device */
if (!head || !value)
return NULL;
- DEB_TAG("looking for %s in %s list\n", value, head->bit_name);
+ DBG(printf("looking for %s in %s list\n", value, head->bit_name));
list_for_each(p, &head->bit_names) {
blkid_tag *tmp = list_entry(p, blkid_tag, bit_names);
blkid_tag *tmp = list_entry(p, blkid_tag, bit_tags);
if (!strcmp(tmp->bit_name, tag->bit_name)) {
- DEB_TAG(" found cache tag head %s\n", tag->bit_name);
+ DBG(printf(" found cache tag head %s\n", tag->bit_name));
head = tmp;
break;
}
{
blkid_tag *head;
- DEB_TAG("looking for %s=%s in cache\n", tag->bit_name, tag->bit_val);
+ DBG(printf("looking for %s=%s in cache\n", tag->bit_name, tag->bit_val));
head = blkid_find_head_cache(cache, tag);
if (!tag || !cache)
return NULL;
- DEB_TAG("looking for %s=%s in cache\n", tag->bit_name, tag->bit_val);
+ DBG(printf("looking for %s=%s in cache\n", tag->bit_name, tag->bit_val));
head = blkid_find_head_cache(cache, tag);
found = blkid_find_tv_tags(head, tag->bit_val);
if (!dev)
return;
- DEB_TAG("adding tag %s=%s\n", tag->bit_name, tag->bit_val);
+ DBG(printf("adding tag %s=%s\n", tag->bit_name, tag->bit_val));
tag->bit_dev = dev;
blkid_tag *tag = NULL;
int len;
- DEB_TAG("trying to make '%s' into a tag\n", token);
+ DBG(printf("trying to make '%s' into a tag\n", token));
if (!token || !(cp = strchr(token, '=')))
return NULL;
+2003-01-25 Theodore Ts'o <tytso@mit.edu>
+
+ * dirhash.c: Fix gcc -Wall nits.
+
2003-01-22 Theodore Ts'o <tytso@mit.edu>
* unix_io.c (unix_write_blk): Fix up GCC -Wall nits.
*/
#include <stdio.h>
+#include <string.h>
#include "ext2_fs.h"
#include "ext2fs.h"