From: Theodore Ts'o Date: Sat, 25 Jan 2003 05:26:48 +0000 (-0500) Subject: Fix gcc -Wall nits. X-Git-Tag: E2FSPROGS-1_33-WIP-0306~23 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=d3f917989badf78d1f97654e46d60d1f3d25cd17;p=tools%2Fe2fsprogs.git Fix gcc -Wall nits. --- diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog index 6791e98..af99d46 100644 --- a/lib/blkid/ChangeLog +++ b/lib/blkid/ChangeLog @@ -1,3 +1,8 @@ +2003-01-25 Theodore Ts'o + + * 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 * save.c (blkid_save_cache): Use mkstemp() instead mktemp(). diff --git a/lib/blkid/blkid.h b/lib/blkid/blkid.h index 4d7ec25..349bd9d 100644 --- a/lib/blkid/blkid.h +++ b/lib/blkid/blkid.h @@ -215,7 +215,7 @@ int blkid_read_cache(blkid_cache **cache, const char *filename); * 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 diff --git a/lib/blkid/cache.c b/lib/blkid/cache.c index 83d28d4..7432144 100644 --- a/lib/blkid/cache.c +++ b/lib/blkid/cache.c @@ -14,9 +14,9 @@ #ifdef DEBUG_CACHE #include -#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) @@ -37,7 +37,7 @@ void blkid_free_cache(blkid_cache *cache) 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)) { @@ -54,8 +54,8 @@ void blkid_free_cache(blkid_cache *cache) 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); diff --git a/lib/blkid/dev.c b/lib/blkid/dev.c index 1904c31..c428256 100644 --- a/lib/blkid/dev.c +++ b/lib/blkid/dev.c @@ -16,9 +16,9 @@ #ifdef DEBUG_DEV #include -#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) @@ -39,7 +39,7 @@ void blkid_free_dev(blkid_dev *dev) 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); @@ -73,7 +73,7 @@ void blkid_free_dev(blkid_dev *dev) #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; @@ -97,14 +97,14 @@ static int add_tag_to_cache(blkid_cache *cache, blkid_tag *tag) 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); @@ -157,7 +157,7 @@ blkid_dev *blkid_add_dev_to_cache(blkid_cache *cache, blkid_dev *dev) /* 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); @@ -177,7 +177,7 @@ blkid_dev *blkid_add_dev_to_cache(blkid_cache *cache, blkid_dev *dev) * (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) && @@ -195,7 +195,7 @@ blkid_dev *blkid_add_dev_to_cache(blkid_cache *cache, blkid_dev *dev) 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; @@ -210,7 +210,7 @@ blkid_dev *blkid_add_dev_to_cache(blkid_cache *cache, blkid_dev *dev) } 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; @@ -222,7 +222,7 @@ exit_new: 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; } diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c index 43c34ef..cbbf50d 100644 --- a/lib/blkid/devname.c +++ b/lib/blkid/devname.c @@ -37,9 +37,9 @@ /* #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 /* @@ -59,7 +59,7 @@ blkid_dev *blkid_find_devname(blkid_cache *cache, const char *devname) 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; } @@ -149,15 +149,15 @@ static int lvm_get_devno(const char *lvm_device, int *major, int *minor, *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) { @@ -179,7 +179,7 @@ static void lvm_probe_all(blkid_cache **cache) 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; @@ -222,8 +222,8 @@ static void lvm_probe_all(blkid_cache **cache) 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); } @@ -279,12 +279,12 @@ int blkid_probe_all(blkid_cache **cache) 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); @@ -304,9 +304,9 @@ int blkid_probe_all(blkid_cache **cache) 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], @@ -317,9 +317,9 @@ int blkid_probe_all(blkid_cache **cache) } 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; diff --git a/lib/blkid/devno.c b/lib/blkid/devno.c index 56f754d..c1175fb 100644 --- a/lib/blkid/devno.c +++ b/lib/blkid/devno.c @@ -34,9 +34,9 @@ #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 { @@ -138,8 +138,8 @@ static int scan_dir(char *dirname, dev_t devno, struct dir_list **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; @@ -181,7 +181,7 @@ char *blkid_devno_to_devname(dev_t devno) 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); @@ -200,9 +200,10 @@ char *blkid_devno_to_devname(dev_t devno) 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; } @@ -234,8 +235,8 @@ blkid_dev *blkid_find_devno(blkid_cache *cache, dev_t devno) } 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; } diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c index d58e050..c6791bf 100644 --- a/lib/blkid/probe.c +++ b/lib/blkid/probe.c @@ -33,9 +33,9 @@ /* #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 /* @@ -94,8 +94,8 @@ static int probe_default(int fd, blkid_dev **dev_p, const char *devname, 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: @@ -116,10 +116,10 @@ static int probe_ext2(int fd, blkid_dev **dev_p, const char *devname, 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") && @@ -147,7 +147,7 @@ static int probe_ext2(int fd, blkid_dev **dev_p, const char *devname, } 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)); } @@ -234,10 +234,10 @@ static int probe_vfat(int fd, blkid_dev **dev_p, const char *devname, 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; @@ -278,10 +278,10 @@ static int probe_msdos(int fd, blkid_dev **dev_p, const char *devname, 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; @@ -369,7 +369,7 @@ static int probe_reiserfs(int fd, blkid_dev **dev_p, const char *devname, } 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)); } @@ -449,7 +449,7 @@ static int probe_mdraid(int fd, blkid_dev **dev_p, const char *devname, /* 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); @@ -558,7 +558,7 @@ struct blkid_magic type_array[] = { */ 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; @@ -577,16 +577,16 @@ static unsigned char *read_one_buf(int fd, blkid_loff_t offset) 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); @@ -679,8 +679,8 @@ blkid_dev *blkid_devname_to_dev(const char *devname, blkid_loff_t size) 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) { @@ -696,9 +696,9 @@ blkid_dev *blkid_devname_to_dev(const char *devname, blkid_loff_t size) 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)) { @@ -711,9 +711,9 @@ blkid_dev *blkid_devname_to_dev(const char *devname, blkid_loff_t size) } 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) / @@ -743,7 +743,7 @@ blkid_dev *blkid_verify_devname(blkid_cache *cache, blkid_dev *dev) 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; @@ -757,7 +757,7 @@ blkid_dev *blkid_verify_devname(blkid_cache *cache, blkid_dev *dev) 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) { @@ -767,7 +767,7 @@ blkid_dev *blkid_verify_devname(blkid_cache *cache, blkid_dev *dev) 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; } @@ -779,7 +779,7 @@ blkid_dev *blkid_verify_devname(blkid_cache *cache, blkid_dev *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))) { diff --git a/lib/blkid/probe.h b/lib/blkid/probe.h index 9312a5f..8471fd6 100644 --- a/lib/blkid/probe.h +++ b/lib/blkid/probe.h @@ -27,7 +27,7 @@ struct blkid_magic { 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 */ @@ -55,7 +55,7 @@ struct ext2_super_block { __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 @@ -69,7 +69,7 @@ struct xfs_super_block { __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; @@ -89,7 +89,7 @@ struct reiserfs_super_block { 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 */ @@ -117,7 +117,7 @@ struct vfat_super_block { /* 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]; @@ -141,7 +141,7 @@ struct msdos_super_block { /* 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]; diff --git a/lib/blkid/read.c b/lib/blkid/read.c index 222e233..fcecf4d 100644 --- a/lib/blkid/read.c +++ b/lib/blkid/read.c @@ -24,9 +24,9 @@ #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 @@ -146,7 +146,7 @@ static int parse_start(char **cp) return 0; if (!strncmp(p, "", 9)) { - DEB_CACHE("found device trailer %9s\n", *cp); + DBG(printf("found device trailer %9s\n", *cp)); *cp += 9; return 0; } @@ -196,7 +196,7 @@ static int parse_dev(blkid_dev **dev, char **cp) 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; @@ -228,7 +228,7 @@ static int parse_dev(blkid_dev **dev, char **cp) 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; } @@ -344,7 +344,7 @@ static int parse_tag(blkid_cache *cache, blkid_dev *dev, blkid_tag **tag, * 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; @@ -355,7 +355,7 @@ int blkid_parse_line(blkid_cache *cache, blkid_dev **dev_p, char *cp) *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; @@ -447,7 +447,7 @@ int blkid_read_cache(blkid_cache **cache, const char *filename) 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) && diff --git a/lib/blkid/resolve.c b/lib/blkid/resolve.c index 88acc66..6b7d147 100644 --- a/lib/blkid/resolve.c +++ b/lib/blkid/resolve.c @@ -22,9 +22,9 @@ #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 @@ -38,7 +38,7 @@ char *blkid_get_tagname_devname(blkid_cache *cache, const char *tagname, 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; @@ -47,7 +47,7 @@ char *blkid_get_tagname_devname(blkid_cache *cache, const char *tagname, 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))) @@ -74,8 +74,8 @@ char *blkid_get_token(blkid_cache *cache, const char *token, 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) diff --git a/lib/blkid/save.c b/lib/blkid/save.c index 0b3f1ae..932cb51 100644 --- a/lib/blkid/save.c +++ b/lib/blkid/save.c @@ -26,9 +26,9 @@ #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) @@ -38,12 +38,12 @@ 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, - "bid_type, dev->bid_devno, - dev->bid_id, (long long)dev->bid_time); + "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")) @@ -83,10 +83,10 @@ int blkid_save_cache_file(blkid_cache *cache, FILE *file) /* * 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; @@ -95,7 +95,7 @@ int blkid_save_cache(blkid_cache *cache, char *filename) 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; } @@ -110,7 +110,7 @@ int blkid_save_cache(blkid_cache *cache, char *filename) /* 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; } @@ -122,11 +122,14 @@ int blkid_save_cache(blkid_cache *cache, char *filename) * 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; + } } } @@ -135,10 +138,12 @@ int blkid_save_cache(blkid_cache *cache, char *filename) 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; } } @@ -150,20 +155,25 @@ int blkid_save_cache(blkid_cache *cache, char *filename) 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; } diff --git a/lib/blkid/tag.c b/lib/blkid/tag.c index 0ccd9e0..0f4c65a 100644 --- a/lib/blkid/tag.c +++ b/lib/blkid/tag.c @@ -16,9 +16,9 @@ #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) @@ -39,7 +39,7 @@ void blkid_free_tag(blkid_tag *tag) 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 */ @@ -64,7 +64,7 @@ blkid_tag *blkid_find_tv_tags(blkid_tag *head, const char *value) 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); @@ -119,7 +119,7 @@ blkid_tag *blkid_find_head_cache(blkid_cache *cache, blkid_tag *tag) 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; } @@ -135,7 +135,7 @@ blkid_tag *blkid_find_tag_cache(blkid_cache *cache, blkid_tag *tag) { 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); @@ -153,7 +153,7 @@ blkid_tag *blkid_get_tag_cache(blkid_cache *cache, blkid_tag *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); @@ -181,7 +181,7 @@ static void add_tag_to_dev(blkid_dev *dev, blkid_tag *tag) 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; @@ -247,7 +247,7 @@ blkid_tag *blkid_token_to_tag(const char *token) 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; diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index bd5b9e3..2a1bce2 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,7 @@ +2003-01-25 Theodore Ts'o + + * dirhash.c: Fix gcc -Wall nits. + 2003-01-22 Theodore Ts'o * unix_io.c (unix_write_blk): Fix up GCC -Wall nits. diff --git a/lib/ext2fs/dirhash.c b/lib/ext2fs/dirhash.c index 5e18d14..4d18593 100644 --- a/lib/ext2fs/dirhash.c +++ b/lib/ext2fs/dirhash.c @@ -12,6 +12,7 @@ */ #include +#include #include "ext2_fs.h" #include "ext2fs.h"