385bd9c12e
* kern/env.c (struct grub_env_context): Removed "sorted". Renamed "next" to "prev" for readability. (struct grub_env_sorted_var): New struct. (grub_env_context): Renamed to ... (initial_context): ... this. (grub_env_var_context): Renamed to ... (current_context): ... this. (grub_env_find): Look only at CURRENT_CONTEXT. (grub_env_context_open): Rewritten to copy exported variables from previous context. (grub_env_context_close): Rewritten according to the new scheme. Also, add an assertion to prevent the initial context from removed. (grub_env_insert): Removed the code for the sorted list. (grub_env_remove): Likewise. (grub_env_export): Simply mark the variable with GRUB_ENV_VAR_GLOBAL. (grub_env_set): A cosmetic change for naming consistency. (grub_env_get): Likewise. (grub_env_unset): Likewise. (grub_env_iterate): Rewritten to sort variables within this function. (grub_register_variable_hook): Fixed for naming consistency. Call grub_env_find again, only if NAME is not found at the first time. (mangle_data_slot_name): New function. (grub_env_set_data_slot): Likewise. (grub_env_get_data_slot): Likewise. (grub_env_unset_data_slot): Likewise. * include/grub/env.h (grub_env_var_type): New enum. (GRUB_ENV_VAR_LOCAL): New constant. (GRUB_ENV_VAR_GLOBAL): Likewise. (GRUB_ENV_VAR_DATA): Likewise. (struct grub_env_var): Removed "sort_next" and "sort_prevp". Added "type". (grub_env_set): Replace VAR with NAME for consistency. (grub_register_variable_hook): Likewise. (grub_env_export): Specify the name of the argument. (grub_env_set_data_slot): New prototype. (grub_env_get_data_slot): Likewise. (grub_env_unset_data_slot): Likewise.
73 lines
2.4 KiB
C
73 lines
2.4 KiB
C
/*
|
|
* GRUB -- GRand Unified Bootloader
|
|
* Copyright (C) 2003,2005,2006 Free Software Foundation, Inc.
|
|
*
|
|
* GRUB is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with GRUB; if not, write to the Free Software
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#ifndef GRUB_ENV_HEADER
|
|
#define GRUB_ENV_HEADER 1
|
|
|
|
#include <grub/symbol.h>
|
|
#include <grub/err.h>
|
|
#include <grub/types.h>
|
|
|
|
struct grub_env_var;
|
|
|
|
typedef char *(*grub_env_read_hook_t) (struct grub_env_var *var,
|
|
const char *val);
|
|
typedef char *(*grub_env_write_hook_t) (struct grub_env_var *var,
|
|
const char *val);
|
|
|
|
enum grub_env_var_type
|
|
{
|
|
/* The default variable type which is local in current context. */
|
|
GRUB_ENV_VAR_LOCAL,
|
|
|
|
/* The exported type, which is passed to new contexts. */
|
|
GRUB_ENV_VAR_GLOBAL,
|
|
|
|
/* The data slot type, which is used to store arbitrary data. */
|
|
GRUB_ENV_VAR_DATA
|
|
};
|
|
|
|
struct grub_env_var
|
|
{
|
|
char *name;
|
|
char *value;
|
|
grub_env_read_hook_t read_hook;
|
|
grub_env_write_hook_t write_hook;
|
|
struct grub_env_var *next;
|
|
struct grub_env_var **prevp;
|
|
enum grub_env_var_type type;
|
|
};
|
|
|
|
grub_err_t EXPORT_FUNC(grub_env_set) (const char *name, const char *val);
|
|
char *EXPORT_FUNC(grub_env_get) (const char *name);
|
|
void EXPORT_FUNC(grub_env_unset) (const char *name);
|
|
void EXPORT_FUNC(grub_env_iterate) (int (*func) (struct grub_env_var *var));
|
|
grub_err_t EXPORT_FUNC(grub_register_variable_hook) (const char *name,
|
|
grub_env_read_hook_t read_hook,
|
|
grub_env_write_hook_t write_hook);
|
|
grub_err_t EXPORT_FUNC(grub_env_context_open) (void);
|
|
grub_err_t EXPORT_FUNC(grub_env_context_close) (void);
|
|
grub_err_t EXPORT_FUNC(grub_env_export) (const char *name);
|
|
|
|
grub_err_t EXPORT_FUNC(grub_env_set_data_slot) (const char *name,
|
|
const void *ptr);
|
|
void *EXPORT_FUNC(grub_env_get_data_slot) (const char *name);
|
|
void EXPORT_FUNC(grub_env_unset_data_slot) (const char *name);
|
|
|
|
#endif /* ! GRUB_ENV_HEADER */
|