~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to kern/file.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* file.c - file I/O functions */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2002,2006,2007,2009  Free Software Foundation, Inc.
5
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include <grub/misc.h>
21
 
#include <grub/err.h>
22
 
#include <grub/file.h>
23
 
#include <grub/mm.h>
24
 
#include <grub/fs.h>
25
 
#include <grub/device.h>
26
 
 
27
 
/* Get the device part of the filename NAME. It is enclosed by parentheses.  */
28
 
char *
29
 
grub_file_get_device_name (const char *name)
30
 
{
31
 
  if (name[0] == '(')
32
 
    {
33
 
      char *p = grub_strchr (name, ')');
34
 
      char *ret;
35
 
 
36
 
      if (! p)
37
 
        {
38
 
          grub_error (GRUB_ERR_BAD_FILENAME, "missing `)'");
39
 
          return 0;
40
 
        }
41
 
 
42
 
      ret = (char *) grub_malloc (p - name);
43
 
      if (! ret)
44
 
        return 0;
45
 
 
46
 
      grub_memcpy (ret, name + 1, p - name - 1);
47
 
      ret[p - name - 1] = '\0';
48
 
      return ret;
49
 
    }
50
 
 
51
 
  return 0;
52
 
}
53
 
 
54
 
grub_file_t
55
 
grub_file_open (const char *name)
56
 
{
57
 
  grub_device_t device;
58
 
  grub_file_t file = 0;
59
 
  char *device_name;
60
 
  char *file_name;
61
 
 
62
 
  device_name = grub_file_get_device_name (name);
63
 
  if (grub_errno)
64
 
    return 0;
65
 
 
66
 
  /* Get the file part of NAME.  */
67
 
  file_name = grub_strchr (name, ')');
68
 
  if (file_name)
69
 
    file_name++;
70
 
  else
71
 
    file_name = (char *) name;
72
 
 
73
 
  device = grub_device_open (device_name);
74
 
  grub_free (device_name);
75
 
  if (! device)
76
 
    goto fail;
77
 
 
78
 
  file = (grub_file_t) grub_zalloc (sizeof (*file));
79
 
  if (! file)
80
 
    goto fail;
81
 
 
82
 
  file->device = device;
83
 
 
84
 
  if (device->disk && file_name[0] != '/')
85
 
    /* This is a block list.  */
86
 
    file->fs = &grub_fs_blocklist;
87
 
  else
88
 
    {
89
 
      file->fs = grub_fs_probe (device);
90
 
      if (! file->fs)
91
 
        goto fail;
92
 
    }
93
 
 
94
 
  if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE)
95
 
    goto fail;
96
 
 
97
 
  return file;
98
 
 
99
 
 fail:
100
 
  if (device)
101
 
    grub_device_close (device);
102
 
 
103
 
  /* if (net) grub_net_close (net);  */
104
 
 
105
 
  grub_free (file);
106
 
 
107
 
  return 0;
108
 
}
109
 
 
110
 
grub_ssize_t
111
 
grub_file_read (grub_file_t file, void *buf, grub_size_t len)
112
 
{
113
 
  grub_ssize_t res;
114
 
 
115
 
  if (file->offset > file->size)
116
 
    {
117
 
      grub_error (GRUB_ERR_OUT_OF_RANGE,
118
 
                  "attempt to read past the end of file");
119
 
      return -1;
120
 
    }
121
 
 
122
 
  if (len == 0 || len > file->size - file->offset)
123
 
    len = file->size - file->offset;
124
 
 
125
 
  /* Prevent an overflow.  */
126
 
  if ((grub_ssize_t) len < 0)
127
 
    len >>= 1;
128
 
 
129
 
  if (len == 0)
130
 
    return 0;
131
 
 
132
 
  res = (file->fs->read) (file, buf, len);
133
 
  if (res > 0)
134
 
    file->offset += res;
135
 
 
136
 
  return res;
137
 
}
138
 
 
139
 
grub_err_t
140
 
grub_file_close (grub_file_t file)
141
 
{
142
 
  if (file->fs->close)
143
 
    (file->fs->close) (file);
144
 
 
145
 
  if (file->device)
146
 
    grub_device_close (file->device);
147
 
  grub_free (file);
148
 
  return grub_errno;
149
 
}
150
 
 
151
 
grub_off_t
152
 
grub_file_seek (grub_file_t file, grub_off_t offset)
153
 
{
154
 
  grub_off_t old;
155
 
 
156
 
  if (offset > file->size)
157
 
    {
158
 
      grub_error (GRUB_ERR_OUT_OF_RANGE,
159
 
                  "attempt to seek outside of the file");
160
 
      return -1;
161
 
    }
162
 
 
163
 
  old = file->offset;
164
 
  file->offset = offset;
165
 
  return old;
166
 
}