+ char *ptr;
+ char *ipath = NULL;
+ char *defdev = NULL;
+
+ result->dev = NULL;
+ result->part = -1;
+ result->file = NULL;
+
+ if (!imagepath)
+ return 0;
+ else
+ ipath = strdup(imagepath);
+
+ if (defdevice)
+ defdev = strdup(defdevice);
+
+ if (defdev) {
+ if (!strstr(defdev, "ethernet") && !strstr(defdev, "enet")) {
+ if ((ptr = strrchr(defdev, ':')) != NULL)
+ *ptr = 0; /* remove trailing : from defdevice if necessary */
+ }
+ }
+
+ /* if there is no : then there is no filename or partition. must
+ use strrchr() since enet:,10.0.0.1,file is legal */
+
+ if (strchr(ipath, ':') != NULL) {
+ if ((ptr = strrchr(ipath, ',')) != NULL) {
+ char *colon = strrchr(ipath, ':');
+ /* If a ':' occurs *after* a ',', then we assume that there is
+ no filename */
+ if (!colon || colon < ptr) {
+ result->file = strdup(ptr+1);
+ /* Trim the filename off */
+ *ptr = 0;
+ }
+ }
+ }
+
+ if (strstr(ipath, "ethernet") || strstr(ipath, "enet"))
+ if ((ptr = strstr(ipath, "bootp")) != NULL) { /* `n' key booting boots enet:bootp */
+ *ptr = 0;
+ result->dev = strdup(ipath);
+ } else
+ result->dev = strdup(ipath);
+ else if ((ptr = strchr(ipath, ':')) != NULL) {
+ *ptr = 0;
+ result->dev = strdup(ipath);
+ if (*(ptr+1))
+ result->part = simple_strtol(ptr+1, NULL, 10);
+ } else if (!defdev) {
+ result->dev = strdup(ipath);
+ } else if (strlen(ipath)) {
+ result->file = strdup(ipath);
+ } else {
+ return 0;
+ }
+
+ if (!result->dev && defdev)
+ result->dev = strdup(defdev);
+
+ if (result->part < 0)
+ result->part = defpart;
+
+ if (!result->file)
+ result->file = strdup(deffile);
+
+ free(ipath);
+ if (defdev)
+ free(defdev);
+ return 1;