#include "md_p.h"
#include <sys/utsname.h>
#include <ctype.h>
+#include <linux/blkpg.h>
/*
* Parse a 128 bit uuid in 4 integers
return (a*1000000)+(b*1000)+c;
}
+void remove_partitions(int fd)
+{
+ /* remove partitions from this block devices.
+ * This is used for components added to an array
+ */
+#ifdef BLKPG_DEL_PARTITION
+ struct blkpg_ioctl_arg a;
+ struct blkpg_partition p;
+
+ a.op = BLKPG_DEL_PARTITION;
+ a.data = (void*)&p;
+ a.datalen = sizeof(p);
+ a.flags = 0;
+ memset(a.data, 0, a.datalen);
+ for (p.pno=0; p.pno < 16; p.pno++)
+ ioctl(fd, BLKPG, &a);
+#endif
+}
+
int enough(int level, int raid_disks, int layout,
char *avail, int avail_disks)
{
} *devlist = NULL;
int devlist_ready = 0;
-#ifdef UCLIBC
-int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
-{
- return 0;
-}
-char *map_dev(int major, int minor, int create)
-{
-#if 0
- fprintf(stderr, "Warning - fail to map %d,%d to a device name\n",
- major, minor);
-#endif
- return NULL;
-}
-#else
-
-#ifdef __dietlibc__
-int add_dev_1(const char *name, const struct stat *stb, int flag)
-{
- return add_dev(name, stb, flag, NULL);
-}
-int nftw(const char *path, int (*han)(const char *name, const struct stat *stb, int flag, struct FTW *s), int nopenfd, int flags)
-{
- return ftw(path, add_dev_1, nopenfd);
-}
-#endif
-
int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
{
struct stat st;
return 0;
}
+#ifndef HAVE_NFTW
+#ifdef HAVE_FTW
+int add_dev_1(const char *name, const struct stat *stb, int flag)
+{
+ return add_dev(name, stb, flag, NULL);
+}
+int nftw(const char *path, int (*han)(const char *name, const struct stat *stb, int flag, struct FTW *s), int nopenfd, int flags)
+{
+ return ftw(path, add_dev_1, nopenfd);
+}
+#else
+int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
+{
+ return 0;
+}
+int nftw(const char *path, int (*han)(const char *name, const struct stat *stb, int flag, struct FTW *s), int nopenfd, int flags)
+{
+ return 0;
+}
+#endif /* HAVE_FTW */
+#endif /* HAVE_NFTW */
+
/*
* Find a block device with the right major/minor number.
* If we find multiple names, choose the shortest.
struct devmap *p;
char *std = NULL, *nonstd=NULL;
int did_check = 0;
+
+ if (major == 0 && minor == 0)
+ return NULL;
+
retry:
if (!devlist_ready) {
char *dev = "/dev";
struct stat stb;
+ while(devlist) {
+ struct devmap *d = devlist;
+ devlist = d->next;
+ free(d->name);
+ free(d);
+ }
if (lstat(dev, &stb)==0 &&
S_ISLNK(stb.st_mode))
dev = "/dev/.";
return nonstd ? nonstd : std;
}
-#endif
-
unsigned long calc_csum(void *super, int bytes)
{
unsigned long long newcsum = 0;
char *e;
int fd = -1;
char devname[32];
- int major = strtoul(dev, &e, 0);
+ int major;
int minor;
+
+ if (!dev) return -1;
+
+ major = strtoul(dev, &e, 0);
if (e > dev && *e == ':' && e[1] &&
(minor = strtoul(e+1, &e, 0)) >= 0 &&
*e == 0) {