static void createline(char *line) { char *w; char *ep; for (w=dl_next(line); w!=line; w=dl_next(w)) { if (strncasecmp(w, "auto=", 5) == 0) createinfo.autof = parse_auto(w+5, "auto=", 1); else if (strncasecmp(w, "owner=", 6) == 0) { if (w[6] == 0) { pr_err("missing owner name\n"); continue; } createinfo.uid = strtoul(w+6, &ep, 10); if (*ep != 0) { struct passwd *pw; /* must be a name */ pw = getpwnam(w+6); if (pw) createinfo.uid = pw->pw_uid; else pr_err("CREATE user %s not found\n", w+6); } } else if (strncasecmp(w, "group=", 6) == 0) { if (w[6] == 0) { pr_err("missing group name\n"); continue; } createinfo.gid = strtoul(w+6, &ep, 10); if (*ep != 0) { struct group *gr; /* must be a name */ gr = getgrnam(w+6); if (gr) createinfo.gid = gr->gr_gid; else pr_err("CREATE group %s not found\n", w+6); } } else if (strncasecmp(w, "mode=", 5) == 0) { if (w[5] == 0) { pr_err("missing CREATE mode\n"); continue; } createinfo.mode = strtoul(w+5, &ep, 8); if (*ep != 0) { createinfo.mode = 0600; pr_err("unrecognised CREATE mode %s\n", w+5); } } else if (strncasecmp(w, "metadata=", 9) == 0) { /* style of metadata to use by default */ int i; for (i=0; superlist[i] && !createinfo.supertype; i++) createinfo.supertype = superlist[i]->match_metadata_desc(w+9); if (!createinfo.supertype) pr_err("metadata format %s unknown, ignoring\n", w+9); } else if (strncasecmp(w, "symlinks=yes", 12) == 0) createinfo.symlinks = 1; else if (strncasecmp(w, "symlinks=no", 11) == 0) createinfo.symlinks = 0; else if (strncasecmp(w, "names=yes", 12) == 0) createinfo.names = 1; else if (strncasecmp(w, "names=no", 11) == 0) createinfo.names = 0; else { pr_err("unrecognised word on CREATE line: %s\n", w); } } }
void arrayline(char *line) { char *w; struct mddev_ident mis; struct mddev_ident *mi; mis.uuid_set = 0; mis.super_minor = UnSet; mis.level = UnSet; mis.raid_disks = UnSet; mis.spare_disks = 0; mis.devices = NULL; mis.devname = NULL; mis.spare_group = NULL; mis.autof = 0; mis.next = NULL; mis.st = NULL; mis.bitmap_fd = -1; mis.bitmap_file = NULL; mis.name[0] = 0; mis.container = NULL; mis.member = NULL; for (w=dl_next(line); w!=line; w=dl_next(w)) { if (w[0] == '/' || strchr(w, '=') == NULL) { /* This names the device, or is '<ignore>'. * The rules match those in create_mddev. * 'w' must be: * /dev/md/{anything} * /dev/mdNN * /dev/md_dNN * <ignore> * or anything that doesn't start '/' or '<' */ if (strcasecmp(w, "<ignore>") == 0 || strncmp(w, "/dev/md/", 8) == 0 || (w[0] != '/' && w[0] != '<') || (strncmp(w, "/dev/md", 7) == 0 && is_number(w+7)) || (strncmp(w, "/dev/md_d", 9) == 0 && is_number(w+9)) ) { /* This is acceptable */; if (mis.devname) pr_err("only give one " "device per ARRAY line: %s and %s\n", mis.devname, w); else mis.devname = w; }else { pr_err("%s is an invalid name for " "an md device - ignored.\n", w); } } else if (strncasecmp(w, "uuid=", 5)==0 ) { if (mis.uuid_set) pr_err("only specify uuid once, %s ignored.\n", w); else { if (parse_uuid(w+5, mis.uuid)) mis.uuid_set = 1; else pr_err("bad uuid: %s\n", w); } } else if (strncasecmp(w, "super-minor=", 12)==0 ) { if (mis.super_minor != UnSet) pr_err("only specify super-minor once, %s ignored.\n", w); else { char *endptr; int minor = strtol(w+12, &endptr, 10); if (w[12]==0 || endptr[0]!=0 || minor < 0) pr_err("invalid super-minor number: %s\n", w); else mis.super_minor = minor; } } else if (strncasecmp(w, "name=", 5)==0) { if (mis.name[0]) pr_err("only specify name once, %s ignored.\n", w); else if (strlen(w+5) > 32) pr_err("name too long, ignoring %s\n", w); else strcpy(mis.name, w+5); } else if (strncasecmp(w, "bitmap=", 7) == 0) { if (mis.bitmap_file) pr_err("only specify bitmap file once. %s ignored\n", w); else mis.bitmap_file = xstrdup(w+7); } else if (strncasecmp(w, "devices=", 8 ) == 0 ) { if (mis.devices) pr_err("only specify devices once (use a comma separated list). %s ignored\n", w); else mis.devices = xstrdup(w+8); } else if (strncasecmp(w, "spare-group=", 12) == 0 ) { if (mis.spare_group) pr_err("only specify one spare group per array. %s ignored.\n", w); else mis.spare_group = xstrdup(w+12); } else if (strncasecmp(w, "level=", 6) == 0 ) { /* this is mainly for compatability with --brief output */ mis.level = map_name(pers, w+6); } else if (strncasecmp(w, "disks=", 6) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+6); } else if (strncasecmp(w, "num-devices=", 12) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+12); } else if (strncasecmp(w, "spares=", 7) == 0 ) { /* for warning if not all spares present */ mis.spare_disks = atoi(w+7); } else if (strncasecmp(w, "metadata=", 9) == 0) { /* style of metadata on the devices. */ int i; for(i=0; superlist[i] && !mis.st; i++) mis.st = superlist[i]->match_metadata_desc(w+9); if (!mis.st) pr_err("metadata format %s unknown, ignored.\n", w+9); } else if (strncasecmp(w, "auto=", 5) == 0 ) { /* whether to create device special files as needed */ mis.autof = parse_auto(w+5, "auto type", 0); } else if (strncasecmp(w, "member=", 7) == 0) { /* subarray within a container */ mis.member = xstrdup(w+7); } else if (strncasecmp(w, "container=", 10) == 0) { /* the container holding this subarray. Either a device name * or a uuid */ mis.container = xstrdup(w+10); } else { pr_err("unrecognised word on ARRAY line: %s\n", w); } } if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0 && (mis.container == NULL || mis.member == NULL)) pr_err("ARRAY line %s has no identity information.\n", mis.devname); else { mi = xmalloc(sizeof(*mi)); *mi = mis; mi->devname = mis.devname ? xstrdup(mis.devname) : NULL; mi->next = NULL; *mddevlp = mi; mddevlp = &mi->next; } }
void arrayline(char *line) { char *w; struct mddev_ident_s mis; mddev_ident_t mi; mis.uuid_set = 0; mis.super_minor = UnSet; mis.level = UnSet; mis.raid_disks = UnSet; mis.spare_disks = 0; mis.devices = NULL; mis.devname = NULL; mis.spare_group = NULL; mis.autof = 0; mis.next = NULL; mis.st = NULL; mis.bitmap_fd = -1; mis.bitmap_file = NULL; mis.name[0] = 0; for (w=dl_next(line); w!=line; w=dl_next(w)) { if (w[0] == '/') { if (mis.devname) fprintf(stderr, Name ": only give one device per ARRAY line: %s and %s\n", mis.devname, w); else mis.devname = w; } else if (strncasecmp(w, "uuid=", 5)==0 ) { if (mis.uuid_set) fprintf(stderr, Name ": only specify uuid once, %s ignored.\n", w); else { if (parse_uuid(w+5, mis.uuid)) mis.uuid_set = 1; else fprintf(stderr, Name ": bad uuid: %s\n", w); } } else if (strncasecmp(w, "super-minor=", 12)==0 ) { if (mis.super_minor != UnSet) fprintf(stderr, Name ": only specify super-minor once, %s ignored.\n", w); else { char *endptr; mis.super_minor= strtol(w+12, &endptr, 10); if (w[12]==0 || endptr[0]!=0 || mis.super_minor < 0) { fprintf(stderr, Name ": invalid super-minor number: %s\n", w); mis.super_minor = UnSet; } } } else if (strncasecmp(w, "name=", 5)==0) { if (mis.name[0]) fprintf(stderr, Name ": only specify name once, %s ignored.\n", w); else if (strlen(w+5) > 32) fprintf(stderr, Name ": name too long, ignoring %s\n", w); else strcpy(mis.name, w+5); } else if (strncasecmp(w, "bitmap=", 7) == 0) { if (mis.bitmap_file) fprintf(stderr, Name ": only specify bitmap file once. %s ignored\n", w); else mis.bitmap_file = strdup(w+7); } else if (strncasecmp(w, "devices=", 8 ) == 0 ) { if (mis.devices) fprintf(stderr, Name ": only specify devices once (use a comma separated list). %s ignored\n", w); else mis.devices = strdup(w+8); } else if (strncasecmp(w, "spare-group=", 12) == 0 ) { if (mis.spare_group) fprintf(stderr, Name ": only specify one spare group per array. %s ignored.\n", w); else mis.spare_group = strdup(w+12); } else if (strncasecmp(w, "level=", 6) == 0 ) { /* this is mainly for compatability with --brief output */ mis.level = map_name(pers, w+6); } else if (strncasecmp(w, "disks=", 6) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+6); } else if (strncasecmp(w, "num-devices=", 12) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+12); } else if (strncasecmp(w, "spares=", 7) == 0 ) { /* for warning if not all spares present */ mis.spare_disks = atoi(w+7); } else if (strncasecmp(w, "metadata=", 9) == 0) { /* style of metadata on the devices. */ int i; for(i=0; superlist[i] && !mis.st; i++) mis.st = superlist[i]->match_metadata_desc(w+9); if (!mis.st) fprintf(stderr, Name ": metadata format %s unknown, ignored.\n", w+9); } else if (strncasecmp(w, "auto=", 5) == 0 ) { /* whether to create device special files as needed */ mis.autof = parse_auto(w+5, "auto type", 0); } else { fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n", w); } } if (mis.devname == NULL) fprintf(stderr, Name ": ARRAY line with no device\n"); else if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0) fprintf(stderr, Name ": ARRAY line %s has no identity information.\n", mis.devname); else { mi = malloc(sizeof(*mi)); *mi = mis; mi->devname = strdup(mis.devname); mi->next = NULL; *mddevlp = mi; mddevlp = &mi->next; } }