* [PATCH] Support for OSX
@ 2009-07-16 17:45 Yves Blusseau
2009-07-16 18:25 ` Vladimir 'phcoder' Serbinenko
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Yves Blusseau @ 2009-07-16 17:45 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 215 bytes --]
Hi,
here's a patch so grub-setup can be compiled and work on MacOSX.
The only problem remaining is trampoline (nested functions), because
OSX don't want
to execute code in the heap.
Best Regards
Yves Blusseau
[-- Attachment #2: osx_support.diff --]
[-- Type: application/octet-stream, Size: 4966 bytes --]
commit 2217a1fc949054e18ee210e4bde749691387f7e8
Author: Yves Blusseau <yves.grub-devel@zetam.org>
Date: Thu Jul 16 17:38:46 2009 +0200
Adding support for OSX
diff --git a/ChangeLog b/ChangeLog
index d6c793f..fd839cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-07-16 Yves BLUSSEAU <yves.grub-devel@zetam.org>
+
+ Adding support to OSX
+
+ * util/getroot.c find_root_device now work on OSX
+ * util/hostdisk.c add macros and calls to support OSX
+
2009-07-16 Vladimir Serbinenko <phcoder@gmail.com>
Fix libusb
diff --git a/util/getroot.c b/util/getroot.c
index b50979d..120ab13 100644
--- a/util/getroot.c
+++ b/util/getroot.c
@@ -238,7 +238,7 @@ find_root_device (const char *dir, dev_t dev)
}
}
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
if (S_ISCHR (st.st_mode) && st.st_rdev == dev)
#else
if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
diff --git a/util/hostdisk.c b/util/hostdisk.c
index 4fc96bb..83ab393 100644
--- a/util/hostdisk.c
+++ b/util/hostdisk.c
@@ -92,6 +92,9 @@ struct hd_geometry
# include <sys/sysctl.h>
#endif
+#if defined(__APPLE__)
+# include <sys/disk.h>
+#endif
struct
{
char *drive;
@@ -185,7 +188,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
return GRUB_ERR_NONE;
}
-#elif defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#elif defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
{
unsigned long long nr;
int fd;
@@ -194,7 +197,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
if (fd == -1)
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device);
-# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
# else
if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode))
@@ -206,6 +209,8 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
if (ioctl (fd, DIOCGMEDIASIZE, &nr))
+# elif defined(__APPLE__)
+ if (ioctl (fd, DKIOCGETBLOCKCOUNT, &nr))
# else
if (ioctl (fd, BLKGETSIZE64, &nr))
# endif
@@ -213,12 +218,16 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
close (fd);
goto fail;
}
-
close (fd);
+
+#if defined (__APPLE__)
+ disk->total_sectors = nr;
+#else
disk->total_sectors = nr / 512;
if (nr % 512)
grub_util_error ("unaligned device size");
+#endif
grub_util_info ("the size of %s is %llu", name, disk->total_sectors);
@@ -371,11 +380,18 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
}
#endif
- if (fd < 0)
- {
- grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' in open_device()", map[disk->id].device);
- return -1;
- }
+#if defined(__APPLE__)
+ if (fd < 0) {
+ // if we can't have exclusive access, attempt
+ // to gracefully degrade to shared access
+ fd = open(map[disk->id].device, flags|O_SHLOCK);
+ }
+#endif
+
+ if (fd < 0) {
+ grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' in open_device()", map[disk->id].device);
+ return -1;
+ }
#endif /* ! __linux__ */
#if defined(__linux__) && (!defined(__GLIBC__) || \
@@ -811,7 +827,7 @@ convert_system_partition_to_system_disk (const char *os_dev)
path[8] = 0;
return path;
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
char *path = xstrdup (os_dev);
if (strncmp ("/dev/", path, 5) == 0)
{
@@ -890,7 +906,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
== 0)
return make_device_name (drive, -1, -1);
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
if (! S_ISCHR (st.st_mode))
#else
if (! S_ISBLK (st.st_mode))
@@ -1039,7 +1055,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
return make_device_name (drive, dos_part, bsd_part);
}
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
/* FreeBSD uses "/dev/[a-z]+[0-9]+(s[0-9]+[a-z]?)?". */
{
int dos_part = -1;
@@ -1047,11 +1063,10 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
if (strncmp ("/dev/", os_dev, 5) == 0)
{
- const char *p;
- char *q;
+ char *p, *q;
long int n;
- for (p = os_dev + 5; *p; ++p)
+ for (p = (char *) os_dev + 5; *p; ++p)
if (grub_isdigit(*p))
{
p = strchr (p, 's');
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Support for OSX
2009-07-16 17:45 [PATCH] Support for OSX Yves Blusseau
@ 2009-07-16 18:25 ` Vladimir 'phcoder' Serbinenko
2009-07-16 19:19 ` Pavel Roskin
2009-07-18 18:28 ` Robert Millan
2 siblings, 0 replies; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-07-16 18:25 UTC (permalink / raw)
To: The development of GRUB 2
Hello
On Thu, Jul 16, 2009 at 7:45 PM, Yves Blusseau<blusseau@zetam.org> wrote:
> Hi,
>
> here's a patch so grub-setup can be compiled and work on MacOSX.
>
There are stylistic problems with your patch. For the overview of our
style see http://www.gnu.org/prep/standards/
Your tabulations are wrong. Use emacs (recommended) or at least make
sure your editor creates correct identations.
We don't use // style comments. Use /* */
What is the reason of discarding const on p
> The only problem remaining is trampoline (nested functions), because OSX
> don't want
> to execute code in the heap.
Could you document on the wiki how to disable stack protection on Darwin/OSX?
>
> Best Regards
> Yves Blusseau
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>
--
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Support for OSX
2009-07-16 17:45 [PATCH] Support for OSX Yves Blusseau
2009-07-16 18:25 ` Vladimir 'phcoder' Serbinenko
@ 2009-07-16 19:19 ` Pavel Roskin
2009-07-16 19:38 ` Yves Blusseau
2009-07-18 18:28 ` Robert Millan
2 siblings, 1 reply; 5+ messages in thread
From: Pavel Roskin @ 2009-07-16 19:19 UTC (permalink / raw)
To: The development of GRUB 2
On Thu, 2009-07-16 at 19:45 +0200, Yves Blusseau wrote:
> Hi,
>
> here's a patch so grub-setup can be compiled and work on MacOSX.
> # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
> if (ioctl (fd, DIOCGMEDIASIZE, &nr))
> +# elif defined(__APPLE__)
> + if (ioctl (fd, DKIOCGETBLOCKCOUNT, &nr))
> # else
...
> +#if defined (__APPLE__)
> + disk->total_sectors = nr;
> +#else
> disk->total_sectors = nr / 512;
This is misleading. The same variable "nr" is used for different values
that are obtained by different calls.
> @@ -1047,11 +1063,10 @@ grub_util_biosdisk_get_grub_dev (const char
> *os_dev)
>
> if (strncmp ("/dev/", os_dev, 5) == 0)
> {
> - const char *p;
> - char *q;
> + char *p, *q;
> long int n;
>
> - for (p = os_dev + 5; *p; ++p)
> + for (p = (char *) os_dev + 5; *p; ++p)
The change to grub_util_biosdisk_get_grub_dev() is not described.
> The only problem remaining is trampoline (nested functions), because
> OSX don't want
> to execute code in the heap.
I think we should start an effort to eliminate the nested functions one
at a time.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Support for OSX
2009-07-16 19:19 ` Pavel Roskin
@ 2009-07-16 19:38 ` Yves Blusseau
0 siblings, 0 replies; 5+ messages in thread
From: Yves Blusseau @ 2009-07-16 19:38 UTC (permalink / raw)
To: The development of GRUB 2
Le 16 juil. 09 à 21:19, Pavel Roskin a écrit :
> On Thu, 2009-07-16 at 19:45 +0200, Yves Blusseau wrote:
>> Hi,
>>
>> here's a patch so grub-setup can be compiled and work on MacOSX.
>
>> # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
>> if (ioctl (fd, DIOCGMEDIASIZE, &nr))
>> +# elif defined(__APPLE__)
>> + if (ioctl (fd, DKIOCGETBLOCKCOUNT, &nr))
>> # else
> ...
>
>> +#if defined (__APPLE__)
>> + disk->total_sectors = nr;
>> +#else
>> disk->total_sectors = nr / 512;
>
> This is misleading. The same variable "nr" is used for different
> values
> that are obtained by different calls.
>
>> @@ -1047,11 +1063,10 @@ grub_util_biosdisk_get_grub_dev (const char
>> *os_dev)
>>
>> if (strncmp ("/dev/", os_dev, 5) == 0)
>> {
>> - const char *p;
>> - char *q;
>> + char *p, *q;
>> long int n;
>>
>> - for (p = os_dev + 5; *p; ++p)
>> + for (p = (char *) os_dev + 5; *p; ++p)
>
> The change to grub_util_biosdisk_get_grub_dev() is not described.
>
>> The only problem remaining is trampoline (nested functions), because
>> OSX don't want
>> to execute code in the heap.
>
> I think we should start an effort to eliminate the nested functions
> one
> at a time.
it will be great !
I will rewrite a new patch with good indentation and no misleading
variable
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Support for OSX
2009-07-16 17:45 [PATCH] Support for OSX Yves Blusseau
2009-07-16 18:25 ` Vladimir 'phcoder' Serbinenko
2009-07-16 19:19 ` Pavel Roskin
@ 2009-07-18 18:28 ` Robert Millan
2 siblings, 0 replies; 5+ messages in thread
From: Robert Millan @ 2009-07-18 18:28 UTC (permalink / raw)
To: The development of GRUB 2
On Thu, Jul 16, 2009 at 07:45:44PM +0200, Yves Blusseau wrote:
> Hi,
>
> here's a patch so grub-setup can be compiled and work on MacOSX.
>
> The only problem remaining is trampoline (nested functions), because OSX
> don't want
> to execute code in the heap.
Hi,
I have some comments (some of them have been brought up already), but my
mail client doesn't represent your attachment as text because it's Content-Type
field is set to "application/octet-stream" (rather than "text/*"), could you
resend it as a text attachment?
Thanks!
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-07-18 18:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-16 17:45 [PATCH] Support for OSX Yves Blusseau
2009-07-16 18:25 ` Vladimir 'phcoder' Serbinenko
2009-07-16 19:19 ` Pavel Roskin
2009-07-16 19:38 ` Yves Blusseau
2009-07-18 18:28 ` Robert Millan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.