2009-07-01 Pavel Roskin <proski@gnu.org>
[grub2/bean.git] / util / ieee1275 / devicemap.c
blobbddfc17e7694a014a70f5d134b0599139fac0f07
1 #include <stdio.h>
2 #include <string.h>
3 #include <grub/types.h>
4 #include <grub/util/deviceiter.h>
5 #include <grub/util/ofpath.h>
6 #include <grub/util/misc.h>
8 /* Since OF path names can have "," characters in them, and GRUB
9 internally uses "," to indicate partitions (unlike OF which uses
10 ":" for this purpose) we escape such commas. */
12 static char *
13 escape_of_path (const char *orig_path)
15 char *new_path, *d, c;
16 const char *p;
18 if (!strchr (orig_path, ','))
19 return (char *) orig_path;
21 new_path = xmalloc (strlen (orig_path) * 2);
23 p = orig_path;
24 d = new_path;
25 while ((c = *p++) != '\0')
27 if (c == ',')
28 *d++ = '\\';
29 *d++ = c;
32 free ((char *) orig_path);
34 return new_path;
37 void
38 grub_util_emit_devicemap_entry (FILE *fp, char *name, int is_floppy UNUSED,
39 int *num_fd UNUSED, int *num_hd UNUSED)
41 const char *orig_path = grub_util_devname_to_ofpath (name);
42 char *ofpath = escape_of_path (orig_path);
44 fprintf(fp, "(%s)\t%s\n", ofpath, name);
46 free (ofpath);