- /* check major number is correct */
- num = -1;
- std = is_standard(dev, &num);
- if (std>0) major = get_mdp_major();
- switch(autof) {
- case 2: /* only create is_standard names */
- if (!std && !stb.st_mode) {
- fprintf(stderr, Name ": --auto=yes requires a 'standard' md device name, not %s\n", dev);
- return -1;
- }
- break;
- case 3: /* create md, reject std>0 */
- if (std > 0) {
- fprintf(stderr, Name ": that --auto option not compatable with device named %s\n", dev);
- return -1;
- }
- break;
- case 4: /* create mdp, reject std<0 */
- if (std < 0) {
- fprintf(stderr, Name ": that --auto option not compatable with device named %s\n", dev);
- return -1;
- }
- break;
- case 5: /* default to md if not standard */
- break;
- case 6: /* default to mdp if not standard */
- if (std == 0) major = get_mdp_major();
- break;
- }
- /* major is final. num is -1 if not standard */
- if (stb.st_mode && major(stb.st_rdev) != major)
- must_remove = 1;
- if (stb.st_mode && !must_remove) {
- mdu_array_info_t array;
- /* looks ok, see if it is available */
- mdfd = open(dev, O_RDWR, 0);
- if (mdfd < 0) {
- fprintf(stderr, Name ": error opening %s: %s\n",
- dev, strerror(errno));
- return -1;
- } else if (md_get_version(mdfd) <= 0) {
- fprintf(stderr, Name ": %s does not appear to be an md device\n",
- dev);
- close(mdfd);
- return -1;
- }
- if (ioctl(mdfd, GET_ARRAY_INFO, &array)==0) {
- /* already active */
- close(mdfd);
- fprintf(stderr, Name ": %s is already active.\n",
- dev);
- return -1;
- } else {
- if (major != MD_MAJOR && parts > 0)
- make_parts(dev, parts);
- return mdfd;
- }
- }
- /* Ok, need to find a minor that is not in use.
- * If the device name is in a 'standard' format,
- * intuit the minor from that, else
- * easiest to read /proc/mdstat, and hunt through for
- * an unused number
- */