/[grub]/grub2/kern/device.c
ViewVC logotype

Diff of /grub2/kern/device.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by okuji, Wed Jul 20 20:30:45 2005 UTC revision 1.5 by okuji, Sat Aug 20 07:49:01 2005 UTC
# Line 25  Line 25 
25  #include <grub/mm.h>  #include <grub/mm.h>
26  #include <grub/misc.h>  #include <grub/misc.h>
27  #include <grub/env.h>  #include <grub/env.h>
28    #include <grub/partition.h>
29    
30  grub_device_t  grub_device_t
31  grub_device_open (const char *name)  grub_device_open (const char *name)
# Line 78  grub_device_close (grub_device_t device) Line 79  grub_device_close (grub_device_t device)
79    
80    return grub_errno;    return grub_errno;
81  }  }
82    
83    int
84    grub_device_iterate (int (*hook) (const char *name))
85    {
86      auto int iterate_disk (const char *disk_name);
87      auto int iterate_partition (grub_disk_t disk,
88                                  const grub_partition_t partition);
89      
90      int iterate_disk (const char *disk_name)
91        {
92          grub_device_t dev;
93    
94          if (hook (disk_name))
95            return 1;
96          
97          dev = grub_device_open (disk_name);
98          if (! dev)
99            return 1;
100          
101          if (dev->disk && dev->disk->has_partitions)
102            if (grub_partition_iterate (dev->disk, iterate_partition))
103              {
104                grub_device_close (dev);
105                return 1;
106              }
107    
108          grub_device_close (dev);
109          return 0;
110        }
111      
112      int iterate_partition (grub_disk_t disk, const grub_partition_t partition)
113        {
114          char *partition_name;
115          char *device_name;
116          int ret;
117          
118          partition_name = grub_partition_get_name (partition);
119          if (! partition_name)
120            return 1;
121          
122          device_name = grub_malloc (grub_strlen (disk->name) + 1
123                                     + grub_strlen (partition_name) + 1);
124          if (! device_name)
125            {
126              grub_free (partition_name);
127              return 1;
128            }
129    
130          grub_sprintf (device_name, "%s,%s", disk->name, partition_name);
131          grub_free (partition_name);
132    
133          ret = hook (device_name);
134          grub_free (device_name);
135          return ret;
136        }
137    
138      /* Only disk devices are supported at the moment.  */
139      return grub_disk_dev_iterate (iterate_disk);
140    }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26