[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Provide grub_dl_ref() and grub_dl_unref() for GRUB_UTIL
From: |
Pavel Roskin |
Subject: |
[PATCH] Provide grub_dl_ref() and grub_dl_unref() for GRUB_UTIL |
Date: |
Mon, 04 May 2009 20:13:24 -0400 |
Hello!
The GRUB code is full of constructs like
#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
#endif
It's better to avoid having source files littered with preprocessor
conditionals. This patch implements grub_dl_ref() and grub_dl_unref()
as inline functions when GRUB_UTIL is defined.
I'm not using the unused attribute to match the existing signature of
those functions.
ChangeLog:
* include/grub/dl.h [GRUB_UTIL]: Provide inline implementations
of grub_dl_ref() and grub_dl_unref(). Remove preprocessor
conditionals around all callers.
diff --git a/commands/parttool.c b/commands/parttool.c
index b4cbf00..58751ca 100644
--- a/commands/parttool.c
+++ b/commands/parttool.c
@@ -46,10 +46,8 @@ grub_parttool_register(const char *part_name,
struct grub_parttool *cur;
int nargs = 0;
-#ifndef GRUB_UTIL
if (! parts)
grub_dl_ref (mymod);
-#endif
cur = (struct grub_parttool *) grub_malloc (sizeof (struct grub_parttool));
cur->next = parts;
@@ -89,10 +87,8 @@ grub_parttool_unregister (int handle)
prev = cur;
cur = cur->next;
}
-#ifndef GRUB_UTIL
if (! parts)
grub_dl_unref (mymod);
-#endif
}
static grub_err_t
diff --git a/fs/affs.c b/fs/affs.c
index 4ddc347..8b7bc02 100644
--- a/fs/affs.c
+++ b/fs/affs.c
@@ -104,9 +104,7 @@ struct grub_affs_data
int htsize;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
static grub_disk_addr_t
@@ -392,9 +390,7 @@ grub_affs_open (struct grub_file *file, const char *name)
struct grub_affs_data *data;
struct grub_fshelp_node *fdiro = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_affs_mount (file->device->disk);
if (!data)
@@ -419,9 +415,7 @@ grub_affs_open (struct grub_file *file, const char *name)
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -432,9 +426,7 @@ grub_affs_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -477,9 +469,7 @@ grub_affs_dir (grub_device_t device, const char *path,
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_affs_mount (device->disk);
if (!data)
@@ -497,9 +487,7 @@ grub_affs_dir (grub_device_t device, const char *path,
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -512,9 +500,7 @@ grub_affs_label (grub_device_t device, char **label)
struct grub_affs_file file;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_affs_mount (disk);
if (data)
@@ -533,9 +519,7 @@ grub_affs_label (grub_device_t device, char **label)
else
*label = 0;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -557,9 +541,7 @@ static struct grub_fs grub_affs_fs =
GRUB_MOD_INIT(affs)
{
grub_fs_register (&grub_affs_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(affs)
diff --git a/fs/afs.c b/fs/afs.c
index 90d8864..d710095 100644
--- a/fs/afs.c
+++ b/fs/afs.c
@@ -175,9 +175,7 @@ struct grub_afs_data
struct grub_fshelp_node diropen;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
static grub_afs_off_t
grub_afs_run_to_num (struct grub_afs_sblock *sb,
@@ -505,9 +503,7 @@ grub_afs_open (struct grub_file *file, const char *name)
struct grub_afs_data *data;
struct grub_fshelp_node *fdiro = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_afs_mount (file->device->disk);
if (! data)
@@ -532,9 +528,7 @@ fail:
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -553,9 +547,7 @@ grub_afs_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -583,9 +575,7 @@ grub_afs_dir (grub_device_t device, const char *path,
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_afs_mount (device->disk);
if (! data)
@@ -603,9 +593,7 @@ grub_afs_dir (grub_device_t device, const char *path,
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -623,9 +611,7 @@ static struct grub_fs grub_afs_fs = {
GRUB_MOD_INIT (afs)
{
grub_fs_register (&grub_afs_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI (afs)
diff --git a/fs/cpio.c b/fs/cpio.c
index bedd65e..7a49fc1 100644
--- a/fs/cpio.c
+++ b/fs/cpio.c
@@ -74,9 +74,7 @@ struct grub_cpio_data
grub_uint32_t size;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
static grub_err_t
grub_cpio_find_file (struct grub_cpio_data *data, char **name,
@@ -192,9 +190,7 @@ grub_cpio_dir (grub_device_t device, const char *path,
const char *np;
int len;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
prev = 0;
@@ -251,9 +247,7 @@ fail:
if (data)
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -266,9 +260,7 @@ grub_cpio_open (grub_file_t file, const char *name)
char *fn;
int i, j;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_cpio_mount (file->device->disk);
if (!data)
@@ -322,9 +314,7 @@ fail:
if (data)
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -344,9 +334,7 @@ grub_cpio_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -370,9 +358,7 @@ GRUB_MOD_INIT (tar)
#endif
{
grub_fs_register (&grub_cpio_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
#ifdef MODE_USTAR
diff --git a/fs/ext2.c b/fs/ext2.c
index ab50db0..596c859 100644
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -317,9 +317,7 @@ struct grub_ext2_data
struct grub_fshelp_node diropen;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
@@ -725,9 +723,7 @@ grub_ext2_open (struct grub_file *file, const char *name)
struct grub_ext2_data *data;
struct grub_fshelp_node *fdiro = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_ext2_mount (file->device->disk);
if (! data)
@@ -759,9 +755,7 @@ grub_ext2_open (struct grub_file *file, const char *name)
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -771,9 +765,7 @@ grub_ext2_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -825,9 +817,7 @@ grub_ext2_dir (grub_device_t device, const char *path,
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_ext2_mount (device->disk);
if (! data)
@@ -845,9 +835,7 @@ grub_ext2_dir (grub_device_t device, const char *path,
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -858,9 +846,7 @@ grub_ext2_label (grub_device_t device, char **label)
struct grub_ext2_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_ext2_mount (disk);
if (data)
@@ -868,9 +854,7 @@ grub_ext2_label (grub_device_t device, char **label)
else
*label = NULL;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -883,9 +867,7 @@ grub_ext2_uuid (grub_device_t device, char **uuid)
struct grub_ext2_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_ext2_mount (disk);
if (data)
@@ -900,9 +882,7 @@ grub_ext2_uuid (grub_device_t device, char **uuid)
else
*uuid = NULL;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -916,9 +896,7 @@ grub_ext2_mtime (grub_device_t device, grub_int32_t *tm)
struct grub_ext2_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_ext2_mount (disk);
if (!data)
@@ -926,9 +904,7 @@ grub_ext2_mtime (grub_device_t device, grub_int32_t *tm)
else
*tm = grub_le_to_cpu32 (data->sblock.utime);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -954,9 +930,7 @@ static struct grub_fs grub_ext2_fs =
GRUB_MOD_INIT(ext2)
{
grub_fs_register (&grub_ext2_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(ext2)
diff --git a/fs/fat.c b/fs/fat.c
index 025319b..bd213d9 100644
--- a/fs/fat.c
+++ b/fs/fat.c
@@ -149,9 +149,7 @@ struct grub_fat_data
grub_uint32_t uuid;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
static int
fat_log2 (unsigned x)
@@ -692,9 +690,7 @@ grub_fat_dir (grub_device_t device, const char *path,
char *dirname = 0;
char *p;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_fat_mount (disk);
if (! data)
@@ -723,9 +719,7 @@ grub_fat_dir (grub_device_t device, const char *path,
grub_free (dirname);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -736,9 +730,7 @@ grub_fat_open (grub_file_t file, const char *name)
struct grub_fat_data *data = 0;
char *p = (char *) name;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_fat_mount (file->device->disk);
if (! data)
@@ -767,9 +759,7 @@ grub_fat_open (grub_file_t file, const char *name)
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -786,9 +776,7 @@ grub_fat_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -810,9 +798,7 @@ grub_fat_label (grub_device_t device, char **label)
return 0;
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_fat_mount (disk);
if (! data)
@@ -830,9 +816,7 @@ grub_fat_label (grub_device_t device, char **label)
fail:
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -845,9 +829,7 @@ grub_fat_uuid (grub_device_t device, char **uuid)
struct grub_fat_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_fat_mount (disk);
if (data)
@@ -859,9 +841,7 @@ grub_fat_uuid (grub_device_t device, char **uuid)
else
*uuid = NULL;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -883,9 +863,7 @@ static struct grub_fs grub_fat_fs =
GRUB_MOD_INIT(fat)
{
grub_fs_register (&grub_fat_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(fat)
diff --git a/fs/hfs.c b/fs/hfs.c
index ef318d4..ca2e561 100644
--- a/fs/hfs.c
+++ b/fs/hfs.c
@@ -159,9 +159,7 @@ struct grub_hfs_record
int datalen;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
static int grub_hfs_find_node (struct grub_hfs_data *, char *,
grub_uint32_t, int, char *, int);
@@ -972,9 +970,7 @@ grub_hfs_dir (grub_device_t device, const char *path,
struct grub_hfs_data *data;
struct grub_hfs_filerec frec;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_hfs_mount (device->disk);
if (!data)
@@ -995,9 +991,7 @@ grub_hfs_dir (grub_device_t device, const char *path,
fail:
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -1010,18 +1004,14 @@ grub_hfs_open (struct grub_file *file, const char *name)
struct grub_hfs_data *data;
struct grub_hfs_filerec frec;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_hfs_mount (file->device->disk);
if (grub_hfs_find_dir (data, name, &frec, 0))
{
grub_free (data);
-#ifndef GRUB_UTIL
- grub_dl_unref (my_mod);
-#endif
+ grub_dl_unref (my_mod);
return grub_errno;
}
@@ -1029,9 +1019,7 @@ grub_hfs_open (struct grub_file *file, const char *name)
{
grub_free (data);
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a file");
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -1061,9 +1049,7 @@ grub_hfs_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return 0;
}
@@ -1102,9 +1088,7 @@ static struct grub_fs grub_hfs_fs =
GRUB_MOD_INIT(hfs)
{
grub_fs_register (&grub_hfs_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(hfs)
diff --git a/fs/hfsplus.c b/fs/hfsplus.c
index 0a7bedd..e74d20c 100644
--- a/fs/hfsplus.c
+++ b/fs/hfsplus.c
@@ -226,9 +226,7 @@ struct grub_hfsplus_data
int embedded_offset;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
/* Return the offset of the record with the index INDEX, in the node
@@ -827,9 +825,7 @@ grub_hfsplus_open (struct grub_file *file, const char *name)
struct grub_hfsplus_data *data;
struct grub_fshelp_node *fdiro = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_hfsplus_mount (file->device->disk);
if (!data)
@@ -855,9 +851,7 @@ grub_hfsplus_open (struct grub_file *file, const char *name)
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -868,9 +862,7 @@ grub_hfsplus_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -916,9 +908,7 @@ grub_hfsplus_dir (grub_device_t device, const char *path,
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_hfsplus_mount (device->disk);
if (!data)
@@ -939,9 +929,7 @@ grub_hfsplus_dir (grub_device_t device, const char *path,
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -964,9 +952,7 @@ grub_hfsplus_mtime (grub_device_t device, grub_int32_t *tm)
struct grub_hfsplus_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_hfsplus_mount (disk);
if (!data)
@@ -974,9 +960,7 @@ grub_hfsplus_mtime (grub_device_t device, grub_int32_t *tm)
else
*tm = grub_be_to_cpu32 (data->volheader.utime) - 2082844800;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -990,9 +974,7 @@ grub_hfsplus_uuid (grub_device_t device, char **uuid)
struct grub_hfsplus_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_hfsplus_mount (disk);
if (data)
@@ -1005,9 +987,7 @@ grub_hfsplus_uuid (grub_device_t device, char **uuid)
else
*uuid = NULL;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -1032,9 +1012,7 @@ static struct grub_fs grub_hfsplus_fs =
GRUB_MOD_INIT(hfsplus)
{
grub_fs_register (&grub_hfsplus_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(hfsplus)
diff --git a/fs/iso9660.c b/fs/iso9660.c
index 2278fdc..140d8c2 100644
--- a/fs/iso9660.c
+++ b/fs/iso9660.c
@@ -150,9 +150,7 @@ struct grub_fshelp_node
unsigned int dir_off;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
/* Iterate over the susp entries, starting with block SUA_BLOCK on the
@@ -688,9 +686,7 @@ grub_iso9660_dir (grub_device_t device, const char *path,
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_iso9660_mount (device->disk);
if (! data)
@@ -717,9 +713,7 @@ grub_iso9660_dir (grub_device_t device, const char *path,
fail:
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -733,9 +727,7 @@ grub_iso9660_open (struct grub_file *file, const char *name)
struct grub_fshelp_node rootnode;
struct grub_fshelp_node *foundnode;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_iso9660_mount (file->device->disk);
if (!data)
@@ -763,9 +755,7 @@ grub_iso9660_open (struct grub_file *file, const char *name)
return 0;
fail:
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -796,9 +786,7 @@ grub_iso9660_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -832,9 +820,7 @@ grub_iso9660_uuid (grub_device_t device, char **uuid)
struct grub_iso9660_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_iso9660_mount (disk);
if (data)
@@ -868,9 +854,7 @@ grub_iso9660_uuid (grub_device_t device, char **uuid)
else
*uuid = NULL;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -894,9 +878,7 @@ static struct grub_fs grub_iso9660_fs =
GRUB_MOD_INIT(iso9660)
{
grub_fs_register (&grub_iso9660_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(iso9660)
diff --git a/fs/jfs.c b/fs/jfs.c
index 3b5520f..8187005 100644
--- a/fs/jfs.c
+++ b/fs/jfs.c
@@ -229,9 +229,7 @@ struct grub_jfs_diropen
} __attribute__ ((packed));
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, int
ino);
@@ -734,9 +732,7 @@ grub_jfs_dir (grub_device_t device, const char *path,
struct grub_jfs_data *data = 0;
struct grub_jfs_diropen *diro = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_jfs_mount (device->disk);
if (!data)
@@ -773,9 +769,7 @@ grub_jfs_dir (grub_device_t device, const char *path,
grub_jfs_closedir (diro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -787,9 +781,7 @@ grub_jfs_open (struct grub_file *file, const char *name)
{
struct grub_jfs_data *data;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_jfs_mount (file->device->disk);
if (!data)
@@ -814,9 +806,7 @@ grub_jfs_open (struct grub_file *file, const char *name)
fail:
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -839,9 +829,7 @@ grub_jfs_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -876,9 +864,7 @@ static struct grub_fs grub_jfs_fs =
GRUB_MOD_INIT(jfs)
{
grub_fs_register (&grub_jfs_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(jfs)
diff --git a/fs/minix.c b/fs/minix.c
index 0789718..2b30c54 100644
--- a/fs/minix.c
+++ b/fs/minix.c
@@ -112,9 +112,7 @@ struct grub_minix_data
int filename_size;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
static grub_err_t grub_minix_find_file (struct grub_minix_data *data,
const char *path);
@@ -607,9 +605,7 @@ static struct grub_fs grub_minix_fs =
GRUB_MOD_INIT(minix)
{
grub_fs_register (&grub_minix_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(minix)
diff --git a/fs/ntfs.c b/fs/ntfs.c
index 5d18159..e039be0 100644
--- a/fs/ntfs.c
+++ b/fs/ntfs.c
@@ -25,9 +25,7 @@
#include <grub/fshelp.h>
#include <grub/ntfs.h>
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
ntfscomp_func_t grub_ntfscomp_func;
@@ -885,10 +883,7 @@ grub_ntfs_dir (grub_device_t device, const char *path,
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
-
data = grub_ntfs_mount (device->disk);
if (!data)
@@ -915,9 +910,7 @@ fail:
grub_free (data);
}
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -928,9 +921,7 @@ grub_ntfs_open (grub_file_t file, const char *name)
struct grub_ntfs_data *data = 0;
struct grub_fshelp_node *mft = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_ntfs_mount (file->device->disk);
if (!data)
@@ -968,9 +959,7 @@ fail:
grub_free (data);
}
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -1011,9 +1000,7 @@ grub_ntfs_close (grub_file_t file)
grub_free (data);
}
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -1025,9 +1012,7 @@ grub_ntfs_label (grub_device_t device, char **label)
struct grub_fshelp_node *mft = 0;
char *pa;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
*label = 0;
@@ -1079,9 +1064,7 @@ fail:
grub_free (data);
}
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -1092,9 +1075,7 @@ grub_ntfs_uuid (grub_device_t device, char **uuid)
struct grub_ntfs_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_ntfs_mount (disk);
if (data)
@@ -1105,9 +1086,7 @@ grub_ntfs_uuid (grub_device_t device, char **uuid)
else
*uuid = NULL;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -1128,9 +1107,7 @@ static struct grub_fs grub_ntfs_fs = {
GRUB_MOD_INIT (ntfs)
{
grub_fs_register (&grub_ntfs_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI (ntfs)
diff --git a/fs/reiserfs.c b/fs/reiserfs.c
index 16a9e04..30bd872 100644
--- a/fs/reiserfs.c
+++ b/fs/reiserfs.c
@@ -60,9 +60,7 @@
#define S_IFLNK 0xA000
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
#define assert(boolean) real_assert (boolean, __FILE__, __LINE__)
static inline void
@@ -986,9 +984,7 @@ grub_reiserfs_open (struct grub_file *file, const char
*name)
grub_uint32_t block_number;
grub_uint16_t entry_version, block_size, entry_location;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_reiserfs_mount (file->device->disk);
if (! data)
goto fail;
@@ -1061,9 +1057,7 @@ grub_reiserfs_open (struct grub_file *file, const char
*name)
assert (grub_errno != GRUB_ERR_NONE);
grub_free (found);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -1257,9 +1251,7 @@ grub_reiserfs_close (grub_file_t file)
grub_free (data);
grub_free (node);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -1287,9 +1279,7 @@ grub_reiserfs_dir (grub_device_t device, const char *path,
grub_free (node);
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_reiserfs_mount (device->disk);
if (! data)
goto fail;
@@ -1311,16 +1301,12 @@ grub_reiserfs_dir (grub_device_t device, const char
*path,
goto fail;
grub_reiserfs_iterate_dir (found, iterate);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
fail:
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -1347,9 +1333,7 @@ grub_reiserfs_uuid (grub_device_t device, char **uuid)
struct grub_reiserfs_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_reiserfs_mount (disk);
if (data)
@@ -1364,9 +1348,7 @@ grub_reiserfs_uuid (grub_device_t device, char **uuid)
else
*uuid = NULL;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -1388,9 +1370,7 @@ static struct grub_fs grub_reiserfs_fs =
GRUB_MOD_INIT(reiserfs)
{
grub_fs_register (&grub_reiserfs_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(reiserfs)
diff --git a/fs/sfs.c b/fs/sfs.c
index 314a6fd..8dc5951 100644
--- a/fs/sfs.c
+++ b/fs/sfs.c
@@ -135,9 +135,7 @@ struct grub_sfs_data
char *label;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
/* Lookup the extent starting with BLOCK in the filesystem described
@@ -454,9 +452,7 @@ grub_sfs_open (struct grub_file *file, const char *name)
struct grub_sfs_data *data;
struct grub_fshelp_node *fdiro = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_sfs_mount (file->device->disk);
if (!data)
@@ -483,9 +479,7 @@ grub_sfs_open (struct grub_file *file, const char *name)
grub_free (data->label);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -496,9 +490,7 @@ grub_sfs_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -540,9 +532,7 @@ grub_sfs_dir (grub_device_t device, const char *path,
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_sfs_mount (device->disk);
if (!data)
@@ -562,9 +552,7 @@ grub_sfs_dir (grub_device_t device, const char *path,
grub_free (data->label);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -600,9 +588,7 @@ static struct grub_fs grub_sfs_fs =
GRUB_MOD_INIT(sfs)
{
grub_fs_register (&grub_sfs_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(sfs)
diff --git a/fs/udf.c b/fs/udf.c
index bbad458..53fb63b 100644
--- a/fs/udf.c
+++ b/fs/udf.c
@@ -356,9 +356,7 @@ struct grub_fshelp_node
int part_ref;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
static grub_uint32_t
grub_udf_get_block (struct grub_udf_data *data,
@@ -790,9 +788,7 @@ grub_udf_dir (grub_device_t device, const char *path,
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_udf_mount (device->disk);
if (!data)
@@ -814,9 +810,7 @@ grub_udf_dir (grub_device_t device, const char *path,
fail:
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -828,9 +822,7 @@ grub_udf_open (struct grub_file *file, const char *name)
struct grub_fshelp_node rootnode;
struct grub_fshelp_node *foundnode;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_udf_mount (file->device->disk);
if (!data)
@@ -851,9 +843,7 @@ grub_udf_open (struct grub_file *file, const char *name)
return 0;
fail:
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -879,9 +869,7 @@ grub_udf_close (grub_file_t file)
grub_free (node);
}
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -916,9 +904,7 @@ static struct grub_fs grub_udf_fs = {
GRUB_MOD_INIT (udf)
{
grub_fs_register (&grub_udf_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI (udf)
diff --git a/fs/ufs.c b/fs/ufs.c
index b799449..562bf7b 100644
--- a/fs/ufs.c
+++ b/fs/ufs.c
@@ -207,9 +207,7 @@ struct grub_ufs_data
int linknest;
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
/* Forward declaration. */
static grub_err_t grub_ufs_find_file (struct grub_ufs_data *data,
@@ -720,9 +718,7 @@ grub_ufs_label (grub_device_t device, char **label)
{
struct grub_ufs_data *data = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
*label = 0;
@@ -733,9 +729,7 @@ grub_ufs_label (grub_device_t device, char **label)
*label = grub_strdup ((char *) data->sblock.volume_name);
}
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -748,9 +742,7 @@ grub_ufs_mtime (grub_device_t device, grub_int32_t *tm)
{
struct grub_ufs_data *data = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_ufs_mount (device->disk);
if (!data)
@@ -760,9 +752,7 @@ grub_ufs_mtime (grub_device_t device, grub_int32_t *tm)
else
*tm = grub_le_to_cpu64 (data->sblock.mtime2);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -786,9 +776,7 @@ static struct grub_fs grub_ufs_fs =
GRUB_MOD_INIT(ufs)
{
grub_fs_register (&grub_ufs_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(ufs)
diff --git a/fs/xfs.c b/fs/xfs.c
index a5c2d42..3907abc 100644
--- a/fs/xfs.c
+++ b/fs/xfs.c
@@ -148,9 +148,7 @@ struct grub_xfs_data
};
-#ifndef GRUB_UTIL
static grub_dl_t my_mod;
-#endif
@@ -641,9 +639,7 @@ grub_xfs_dir (grub_device_t device, const char *path,
return hook (filename, &info);
}
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_xfs_mount (device->disk);
if (!data)
@@ -661,9 +657,7 @@ grub_xfs_dir (grub_device_t device, const char *path,
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
@@ -678,9 +672,7 @@ grub_xfs_open (struct grub_file *file, const char *name)
struct grub_xfs_data *data;
struct grub_fshelp_node *fdiro = 0;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_xfs_mount (file->device->disk);
if (!data)
@@ -714,9 +706,7 @@ grub_xfs_open (struct grub_file *file, const char *name)
grub_free (fdiro);
grub_free (data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return grub_errno;
}
@@ -738,9 +728,7 @@ grub_xfs_close (grub_file_t file)
{
grub_free (file->data);
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
return GRUB_ERR_NONE;
}
@@ -752,9 +740,7 @@ grub_xfs_label (grub_device_t device, char **label)
struct grub_xfs_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_xfs_mount (disk);
if (data)
@@ -762,9 +748,7 @@ grub_xfs_label (grub_device_t device, char **label)
else
*label = 0;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -777,9 +761,7 @@ grub_xfs_uuid (grub_device_t device, char **uuid)
struct grub_xfs_data *data;
grub_disk_t disk = device->disk;
-#ifndef GRUB_UTIL
grub_dl_ref (my_mod);
-#endif
data = grub_xfs_mount (disk);
if (data)
@@ -794,9 +776,7 @@ grub_xfs_uuid (grub_device_t device, char **uuid)
else
*uuid = NULL;
-#ifndef GRUB_UTIL
grub_dl_unref (my_mod);
-#endif
grub_free (data);
@@ -820,9 +800,7 @@ static struct grub_fs grub_xfs_fs =
GRUB_MOD_INIT(xfs)
{
grub_fs_register (&grub_xfs_fs);
-#ifndef GRUB_UTIL
my_mod = mod;
-#endif
}
GRUB_MOD_FINI(xfs)
diff --git a/include/grub/dl.h b/include/grub/dl.h
index 5e46374..4ff6240 100644
--- a/include/grub/dl.h
+++ b/include/grub/dl.h
@@ -82,8 +82,23 @@ grub_dl_t grub_dl_load_core (void *addr, grub_size_t size);
int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod);
void grub_dl_unload_unneeded (void);
void grub_dl_unload_all (void);
+#ifdef GRUB_UTIL
+static inline int
+grub_dl_ref (grub_dl_t mod)
+{
+ (void) mod;
+ return 0;
+}
+static inline int
+grub_dl_unref (grub_dl_t mod)
+{
+ (void) mod;
+ return 0;
+}
+#else
int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod);
int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod);
+#endif
void EXPORT_FUNC(grub_dl_iterate) (int (*hook) (grub_dl_t mod));
grub_dl_t EXPORT_FUNC(grub_dl_get) (const char *name);
grub_err_t EXPORT_FUNC(grub_dl_register_symbol) (const char *name, void *addr,
diff --git a/loader/xnu.c b/loader/xnu.c
index 2b6ffa4..18264bc 100644
--- a/loader/xnu.c
+++ b/loader/xnu.c
@@ -1306,20 +1306,16 @@ grub_cmd_xnu_resume (grub_command_t cmd __attribute__
((unused)),
void
grub_xnu_lock ()
{
-#ifndef GRUB_UTIL
if (!locked)
grub_dl_ref (my_mod);
-#endif
locked = 1;
}
void
grub_xnu_unlock ()
{
-#ifndef GRUB_UTIL
if (locked)
grub_dl_unref (my_mod);
-#endif
locked = 0;
}
--
Regards,
Pavel Roskin
- [PATCH] Provide grub_dl_ref() and grub_dl_unref() for GRUB_UTIL,
Pavel Roskin <=