static char * find_obppath (const char *sysfs_path_orig) { char *sysfs_path, *path; size_t path_size = strlen (sysfs_path_orig) + sizeof ("/obppath"); sysfs_path = xstrdup (sysfs_path_orig); path = xmalloc (path_size); while (1) { int fd; char *of_path; struct stat st; size_t size; snprintf(path, path_size, "%s/obppath", sysfs_path); #if 0 printf("Trying %s\n", path); #endif fd = open(path, O_RDONLY); if (fd < 0 || fstat (fd, &st) < 0) { snprintf(path, path_size, "%s/devspec", sysfs_path); fd = open(path, O_RDONLY); } if (fd < 0 || fstat (fd, &st) < 0) { kill_trailing_dir(sysfs_path); if (!strcmp(sysfs_path, "/sys")) { grub_util_info (_("`obppath' not found in parent dirs of `%s'," " no IEEE1275 name discovery"), sysfs_path_orig); free (path); free (sysfs_path); return NULL; } continue; } size = st.st_size; of_path = xmalloc (size + MAX_DISK_CAT + 1); memset(of_path, 0, size + MAX_DISK_CAT + 1); read(fd, of_path, size); close(fd); trim_newline(of_path); free (path); free (sysfs_path); return of_path; } }
static void find_obppath(char *of_path, const char *sysfs_path_orig) { char *sysfs_path, *path; sysfs_path = xmalloc (PATH_MAX); path = xmalloc (PATH_MAX); strcpy(sysfs_path, sysfs_path_orig); while (1) { int fd; snprintf(path, PATH_MAX, "%s/obppath", sysfs_path); #if 0 printf("Trying %s\n", path); #endif fd = open(path, O_RDONLY); if (fd < 0) { kill_trailing_dir(sysfs_path); if (!strcmp(sysfs_path, "/sys")) grub_util_error("'obppath' not found in parent dirs of %s", sysfs_path_orig); continue; } memset(of_path, 0, OF_PATH_MAX); read(fd, of_path, OF_PATH_MAX); close(fd); trim_newline(of_path); break; } free (path); free (sysfs_path); }