/* * Ask prom to open a disk file given either the OBP device path, or the * device path representing the target drive/partition and the fs-relative * path of the file. Handle file pathnames with or without leading '/'. * if fs points to a null char, it indicates that we are opening a device. */ int cpr_statefile_open(char *path, char *fs_dev) { int plen, dlen; int handle; char fs_pkg[OBP_MAXPATHLEN]; char fs_name[OBP_MAXDRVNAME]; /* * instead of using specialstate, we use fs as the flag */ if (*fs_dev == '\0') { /* device open */ statefile_special = 1; handle = prom_open(path); /* IEEE1275 prom_open returns 0 on failure; we return -1 */ return (handle ? handle : -1); } /* * No cif for $open-package, so we have to use interpret */ if (prom_getprop(chosen, "fs-package", fs_pkg) == -1) { prom_printf("Missing fs-package name\n"); return (-1); } plen = prom_strlen(fs_pkg); dlen = prom_strlen(fs_dev); prom_interpret("$open-package swap l!", plen, (uintptr_t)fs_pkg, dlen, (uintptr_t)fs_dev, (uintptr_t)&cb_rih); if (cb_rih == OBP_BADNODE || cb_rih == 0) { prom_printf("Can't open %s\n", fs_pkg); return (-1); } if (volname) { return (cpr_fs_volopen(volname)); } /* * Prepend '/' if it's not there already */ if (*path != '/') { (void) prom_sprintf(fs_name, "/%s", path); return (cpr_fs_open(fs_name)); } else return (cpr_fs_open(path)); }
/* * prom_decode_composite_string: * * Returns successive strings in a composite string property. * A composite string property is a buffer containing one or more * NULL terminated strings contained within the length of the buffer. * * Always call with the base address and length of the property buffer. * On the first call, call with prev == 0, call successively * with prev == to the last value returned from this function * until the routine returns zero which means no more string values. */ char * prom_decode_composite_string(void *buf, size_t buflen, char *prev) { if ((buf == 0) || (buflen == 0) || ((int)buflen == -1)) return ((char *)0); if (prev == 0) return ((char *)buf); prev += prom_strlen(prev) + 1; if (prev >= ((char *)buf + buflen)) return ((char *)0); return (prev); }
/* * strstr() locates the first occurrence in the string s1 of * the sequence of characters (excluding the terminating null * character) in the string s2. strstr() returns a pointer * to the located string, or a null pointer if the string is * not found. If s2 is "", the function returns s1. */ char * prom_strstr(register char *s1, register char *s2) { register char *p = s1; register int32_t len = prom_strlen(s2); if ((s2 == NULL) || (*s2 == '\0')) return ((char *)s1); for (; (p = (char *)prom_strchr(p, *s2)) != 0; p++) { if (prom_strncmp(p, s2, len) == 0) { return (p); } } return (NULL); }
/* * Returns 0 on error. Otherwise returns a handle. */ int prom_open(char *path) { cell_t ci[5]; promif_owrap_t *ow; #ifdef PROM_32BIT_ADDRS char *opath = NULL; size_t len; if ((uintptr_t)path > (uint32_t)-1) { opath = path; len = prom_strlen(opath) + 1; /* include terminating NUL */ path = promplat_alloc(len); if (path == NULL) return (0); (void) prom_strcpy(path, opath); } #endif ow = promif_preout(); promif_preprom(); ci[0] = p1275_ptr2cell("open"); /* Service name */ ci[1] = (cell_t)1; /* #argument cells */ ci[2] = (cell_t)1; /* #result cells */ ci[3] = p1275_ptr2cell(path); /* Arg1: Pathname */ ci[4] = (cell_t)0; /* Res1: Prime result */ (void) p1275_cif_handler(&ci); promif_postprom(); promif_postout(ow); #ifdef PROM_32BIT_ADDRS if (opath != NULL) promplat_free(path, len); #endif return (p1275_cell2int(ci[4])); /* Res1: ihandle */ }
pnode_t prom_finddevice(char *path) { cell_t ci[5]; #ifdef PROM_32BIT_ADDRS char *opath = NULL; size_t len; if ((uintptr_t)path > (uint32_t)-1) { opath = path; len = prom_strlen(opath) + 1; /* include terminating NUL */ path = promplat_alloc(len); if (path == NULL) { return (OBP_BADNODE); } (void) prom_strcpy(path, opath); } #endif promif_preprom(); ci[0] = p1275_ptr2cell("finddevice"); /* Service name */ ci[1] = (cell_t)1; /* #argument cells */ ci[2] = (cell_t)1; /* #result cells */ ci[3] = p1275_ptr2cell(path); /* Arg1: pathname */ ci[4] = p1275_dnode2cell(OBP_BADNODE); /* Res1: Prime result */ (void) p1275_cif_handler(&ci); promif_postprom(); #ifdef PROM_32BIT_ADDRS if (opath != NULL) promplat_free(path, len); #endif return ((pnode_t)p1275_cell2dnode(ci[4])); /* Res1: phandle */ }