2 * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
9 #include <boot/platform.h>
10 #include <util/kernel_cpp.h>
20 // we're using some libroot specials
21 extern int __libc_argc
;
22 extern char **__libc_argv
;
23 extern const char *__progname
;
25 extern bool gShowMenu
;
29 get_device(const char *path
, Node
**_device
)
31 Handle
*device
= new Handle(path
);
35 if (device
->InitCheck() != B_OK
) {
36 fprintf(stderr
, "%s: Could not open image \"%s\": %s\n",
37 __progname
, path
, strerror(device
->InitCheck()));
49 add_device(const char *path
, NodeList
*list
)
52 status_t status
= get_device(path
, &device
);
56 printf("add \"%s\" to list of boot devices\n", path
);
64 recursive_add_device(const char *path
, NodeList
*list
)
66 DIR *dir
= opendir(path
);
70 struct dirent
*dirent
;
71 while ((dirent
= readdir(dir
)) != NULL
) {
72 // we don't care about names with a leading dot (incl. "." and "..")
73 if (dirent
->d_name
[0] == '.')
76 char nextPath
[PATH_MAX
];
77 strcpy(nextPath
, path
);
78 strcat(nextPath
, "/");
79 strcat(nextPath
, dirent
->d_name
);
81 // Note, this doesn't care about if it's a directory or not!
82 if (!strcmp(dirent
->d_name
, "raw")
83 && add_device(nextPath
, list
) == B_OK
)
86 recursive_add_device(nextPath
, list
);
95 get_next_argument(int32
*cookie
, bool options
)
97 int32 i
= *cookie
+ 1;
99 if (i
== 1 && !options
) {
100 // filter out options at the start
101 while (i
< __libc_argc
&& __libc_argv
[i
][0] == '-')
105 for (; i
< __libc_argc
; i
++) {
106 // Options come at the start
107 if (options
&& __libc_argv
[i
][0] != '-')
111 return __libc_argv
[i
];
119 get_next_option(int32
*cookie
)
121 return get_next_argument(cookie
, true);
126 get_next_device(int32
*cookie
)
128 return get_next_argument(cookie
, false);
136 platform_add_boot_device(struct stage2_args
*args
, NodeList
*devicesList
)
138 // we accept a boot device from the command line
139 status_t status
= B_ERROR
;
143 char *path
= get_next_device(&cookie
);
145 status
= get_device(path
, &device
);
147 status
= get_device("/boot/home/test-file-device", &device
);
150 devicesList
->Add(device
);
157 platform_get_boot_partition(struct stage2_args
*args
, Node
*device
,
158 NodeList
*list
, boot::Partition
**_partition
)
160 NodeIterator iterator
= list
->GetIterator();
161 boot::Partition
*partition
= NULL
;
162 while ((partition
= (boot::Partition
*)iterator
.Next()) != NULL
) {
163 // just take the first partition
164 *_partition
= partition
;
168 return B_ENTRY_NOT_FOUND
;
173 platform_add_block_devices(struct stage2_args
*args
, NodeList
*list
)
176 if (get_next_device(&cookie
) != NULL
) {
177 // add the devices provided on the command line
179 while ((path
= get_next_device(&cookie
)) != NULL
)
180 add_device(path
, list
);
183 bool addDevices
= true;
187 while ((option
= get_next_option(&cookie
)) != NULL
) {
188 if (!strcmp(option
, "--no-devices"))
190 else if (!strcmp(option
, "--no-scsi"))
192 else if (!strcmp(option
, "--menu"))
195 fprintf(stderr
, "usage: %s [OPTIONS] [image ...]\n"
196 " --no-devices\tDon't add real devices from /dev/disk\n"
197 " --no-scsi\tDon't add SCSI devices (might be problematic with some\n"
198 "\t\tUSB mass storage drivers)\n"
199 " --menu\tShow boot menu\n", __progname
);
205 recursive_add_device("/dev/disk/ide", list
);
206 recursive_add_device("/dev/disk/virtual", list
);
209 recursive_add_device("/dev/disk/scsi", list
);
217 platform_register_boot_device(Node
*device
)