1
/* editenv.c - tool to edit environment block. */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2008,2009,2010,2013 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21
#include <grub/types.h>
22
#include <grub/emu/misc.h>
23
#include <grub/util/misc.h>
24
#include <grub/util/install.h>
25
#include <grub/lib/envblk.h>
26
#include <grub/i18n.h>
27
#include <grub/emu/hostfile.h>
32
#define DEFAULT_ENVBLK_SIZE 1024
35
grub_util_create_envblk_file (const char *name)
41
buf = xmalloc (DEFAULT_ENVBLK_SIZE);
43
namenew = xasprintf ("%s.new", name);
44
fp = grub_util_fopen (namenew, "wb");
46
grub_util_error (_("cannot open `%s': %s"), namenew,
49
memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
50
memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#',
51
DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
53
if (fwrite (buf, 1, DEFAULT_ENVBLK_SIZE, fp) != DEFAULT_ENVBLK_SIZE)
54
grub_util_error (_("cannot write to `%s': %s"), namenew,
58
grub_util_file_sync (fp);
62
if (grub_util_rename (namenew, name) < 0)
63
grub_util_error (_("cannot rename the file %s to %s"), namenew, name);