~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to grub-core/fs/sfs.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* sfs.c - Amiga Smart FileSystem.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2005,2006,2007,2008,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/err.h>
 
21
#include <grub/file.h>
 
22
#include <grub/mm.h>
 
23
#include <grub/misc.h>
 
24
#include <grub/disk.h>
 
25
#include <grub/dl.h>
 
26
#include <grub/types.h>
 
27
#include <grub/fshelp.h>
 
28
 
 
29
/* The common header for a block.  */
 
30
struct grub_sfs_bheader
 
31
{
 
32
  grub_uint8_t magic[4];
 
33
  grub_uint32_t chksum;
 
34
  grub_uint32_t ipointtomyself;
 
35
} __attribute__ ((packed));
 
36
 
 
37
/* The sfs rootblock.  */
 
38
struct grub_sfs_rblock
 
39
{
 
40
  struct grub_sfs_bheader header;
 
41
  grub_uint32_t version;
 
42
  grub_uint8_t unused1[36];
 
43
  grub_uint32_t blocksize;
 
44
  grub_uint8_t unused2[40];
 
45
  grub_uint8_t unused3[8];
 
46
  grub_uint32_t rootobject;
 
47
  grub_uint32_t btree;
 
48
} __attribute__ ((packed));
 
49
 
 
50
/* A SFS object container.  */
 
51
struct grub_sfs_obj
 
52
{
 
53
  grub_uint8_t unused1[4];
 
54
  grub_uint32_t nodeid;
 
55
  grub_uint8_t unused2[4];
 
56
  union
 
57
  {
 
58
    struct
 
59
    {
 
60
      grub_uint32_t first_block;
 
61
      grub_uint32_t size;
 
62
    } file __attribute__ ((packed));
 
63
    struct
 
64
    {
 
65
      grub_uint32_t hashtable;
 
66
      grub_uint32_t dir_objc;
 
67
    } dir __attribute__ ((packed));
 
68
  } file_dir;
 
69
  grub_uint8_t unused3[4];
 
70
  grub_uint8_t type;
 
71
  grub_uint8_t filename[1];
 
72
  grub_uint8_t comment[1];
 
73
} __attribute__ ((packed));
 
74
 
 
75
#define GRUB_SFS_TYPE_DELETED   32
 
76
#define GRUB_SFS_TYPE_SYMLINK   64
 
77
#define GRUB_SFS_TYPE_DIR       128
 
78
 
 
79
/* A SFS object container.  */
 
80
struct grub_sfs_objc
 
81
{
 
82
  struct grub_sfs_bheader header;
 
83
  grub_uint32_t parent;
 
84
  grub_uint32_t next;
 
85
  grub_uint32_t prev;
 
86
  /* The amount of objects depends on the blocksize.  */
 
87
  struct grub_sfs_obj objects[1];
 
88
} __attribute__ ((packed));
 
89
 
 
90
struct grub_sfs_btree_node
 
91
{
 
92
  grub_uint32_t key;
 
93
  grub_uint32_t data;
 
94
} __attribute__ ((packed));
 
95
 
 
96
struct grub_sfs_btree_extent
 
97
{
 
98
  grub_uint32_t key;
 
99
  grub_uint32_t next;
 
100
  grub_uint32_t prev;
 
101
  grub_uint16_t size;
 
102
} __attribute__ ((packed));
 
103
 
 
104
struct grub_sfs_btree
 
105
{
 
106
  struct grub_sfs_bheader header;
 
107
  grub_uint16_t nodes;
 
108
  grub_uint8_t leaf;
 
109
  grub_uint8_t nodesize;
 
110
  /* Normally this can be kind of node, but just extents are
 
111
     supported.  */
 
112
  struct grub_sfs_btree_node node[1];
 
113
} __attribute__ ((packed));
 
114
 
 
115
 
 
116
 
 
117
struct grub_fshelp_node
 
118
{
 
119
  struct grub_sfs_data *data;
 
120
  int block;
 
121
  int size;
 
122
};
 
123
 
 
124
/* Information about a "mounted" sfs filesystem.  */
 
125
struct grub_sfs_data
 
126
{
 
127
  struct grub_sfs_rblock rblock;
 
128
  struct grub_fshelp_node diropen;
 
129
  grub_disk_t disk;
 
130
 
 
131
  /* Blocksize in sectors.  */
 
132
  unsigned int blocksize;
 
133
 
 
134
  /* Label of the filesystem.  */
 
135
  char *label;
 
136
};
 
137
 
 
138
static grub_dl_t my_mod;
 
139
 
 
140
 
 
141
/* Lookup the extent starting with BLOCK in the filesystem described
 
142
   by DATA.  Return the extent size in SIZE and the following extent
 
143
   in NEXTEXT.  */
 
144
static grub_err_t
 
145
grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block,
 
146
                      int *size, int *nextext)
 
147
{
 
148
  char *treeblock;
 
149
  struct grub_sfs_btree *tree;
 
150
  int i;
 
151
  int next;
 
152
 
 
153
  treeblock = grub_malloc (data->blocksize);
 
154
  if (!block)
 
155
    return 0;
 
156
 
 
157
  next = grub_be_to_cpu32 (data->rblock.btree);
 
158
  tree = (struct grub_sfs_btree *) treeblock;
 
159
 
 
160
  /* Handle this level in the btree.  */
 
161
  do
 
162
    {
 
163
      grub_disk_read (data->disk, next, 0, data->blocksize, treeblock);
 
164
      if (grub_errno)
 
165
        {
 
166
          grub_free (treeblock);
 
167
          return grub_errno;
 
168
        }
 
169
 
 
170
      for (i = grub_be_to_cpu16 (tree->nodes) - 1; i >= 0; i--)
 
171
        {
 
172
 
 
173
#define EXTNODE(tree, index)                                            \
 
174
        ((struct grub_sfs_btree_node *) (((char *) &(tree)->node[0])    \
 
175
                                         + (index) * (tree)->nodesize))
 
176
 
 
177
          /* Follow the tree down to the leaf level.  */
 
178
          if ((grub_be_to_cpu32 (EXTNODE(tree, i)->key) <= block)
 
179
              && !tree->leaf)
 
180
            {
 
181
              next = grub_be_to_cpu32 (EXTNODE (tree, i)->data);
 
182
              break;
 
183
            }
 
184
 
 
185
          /* If the leaf level is reached, just find the correct extent.  */
 
186
          if (grub_be_to_cpu32 (EXTNODE (tree, i)->key) == block && tree->leaf)
 
187
            {
 
188
              struct grub_sfs_btree_extent *extent;
 
189
              extent = (struct grub_sfs_btree_extent *) EXTNODE (tree, i);
 
190
 
 
191
              /* We found a correct leaf.  */
 
192
              *size = grub_be_to_cpu16 (extent->size);
 
193
              *nextext = grub_be_to_cpu32 (extent->next);
 
194
 
 
195
              grub_free (treeblock);
 
196
              return 0;
 
197
            }
 
198
 
 
199
#undef EXTNODE
 
200
 
 
201
        }
 
202
    } while (!tree->leaf);
 
203
 
 
204
  grub_free (treeblock);
 
205
 
 
206
  return grub_error (GRUB_ERR_FILE_READ_ERROR, "SFS extent not found");
 
207
}
 
208
 
 
209
static grub_disk_addr_t
 
210
grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
 
211
{
 
212
  int blk = node->block;
 
213
  int size = 0;
 
214
  int next = 0;
 
215
 
 
216
  while (blk)
 
217
    {
 
218
      grub_err_t err;
 
219
 
 
220
      /* In case of the first block we don't have to lookup the
 
221
         extent, the minimum size is always 1.  */
 
222
      if (fileblock == 0)
 
223
        return blk;
 
224
 
 
225
      err = grub_sfs_read_extent (node->data, blk, &size, &next);
 
226
      if (err)
 
227
        return 0;
 
228
 
 
229
      if (fileblock < (unsigned int) size)
 
230
        return fileblock + blk;
 
231
 
 
232
      fileblock -= size;
 
233
 
 
234
      blk = next;
 
235
    }
 
236
 
 
237
  grub_error (GRUB_ERR_FILE_READ_ERROR,
 
238
              "reading a SFS block outside the extent");
 
239
 
 
240
  return 0;
 
241
}
 
242
 
 
243
 
 
244
/* Read LEN bytes from the file described by DATA starting with byte
 
245
   POS.  Return the amount of read bytes in READ.  */
 
246
static grub_ssize_t
 
247
grub_sfs_read_file (grub_fshelp_node_t node,
 
248
                    void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
 
249
                                       unsigned offset, unsigned length),
 
250
                    int pos, grub_size_t len, char *buf)
 
251
{
 
252
  return grub_fshelp_read_file (node->data->disk, node, read_hook,
 
253
                                pos, len, buf, grub_sfs_read_block,
 
254
                                node->size, 0);
 
255
}
 
256
 
 
257
 
 
258
static struct grub_sfs_data *
 
259
grub_sfs_mount (grub_disk_t disk)
 
260
{
 
261
  struct grub_sfs_data *data;
 
262
  struct grub_sfs_objc *rootobjc;
 
263
  char *rootobjc_data = 0;
 
264
  unsigned int blk;
 
265
 
 
266
  data = grub_malloc (sizeof (*data));
 
267
  if (!data)
 
268
    return 0;
 
269
 
 
270
  /* Read the rootblock.  */
 
271
  grub_disk_read (disk, 0, 0, sizeof (struct grub_sfs_rblock),
 
272
                  &data->rblock);
 
273
  if (grub_errno)
 
274
    goto fail;
 
275
 
 
276
  /* Make sure this is a sfs filesystem.  */
 
277
  if (grub_strncmp ((char *) (data->rblock.header.magic), "SFS", 4))
 
278
    {
 
279
      grub_error (GRUB_ERR_BAD_FS, "not a SFS filesystem");
 
280
      goto fail;
 
281
    }
 
282
 
 
283
  data->blocksize = grub_be_to_cpu32 (data->rblock.blocksize);
 
284
  rootobjc_data = grub_malloc (data->blocksize);
 
285
  if (! rootobjc_data)
 
286
    goto fail;
 
287
 
 
288
  /* Read the root object container.  */
 
289
  grub_disk_read (disk, grub_be_to_cpu32 (data->rblock.rootobject), 0,
 
290
                  data->blocksize, rootobjc_data);
 
291
  if (grub_errno)
 
292
    goto fail;
 
293
 
 
294
  rootobjc = (struct grub_sfs_objc *) rootobjc_data;
 
295
 
 
296
  blk = grub_be_to_cpu32 (rootobjc->objects[0].file_dir.dir.dir_objc);
 
297
  data->diropen.size = 0;
 
298
  data->diropen.block = blk;
 
299
  data->diropen.data = data;
 
300
  data->disk = disk;
 
301
  data->label = grub_strdup ((char *) (rootobjc->objects[0].filename));
 
302
 
 
303
  return data;
 
304
 
 
305
 fail:
 
306
  if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
 
307
    grub_error (GRUB_ERR_BAD_FS, "not an SFS filesystem");
 
308
 
 
309
  grub_free (data);
 
310
  grub_free (rootobjc_data);
 
311
  return 0;
 
312
}
 
313
 
 
314
 
 
315
static char *
 
316
grub_sfs_read_symlink (grub_fshelp_node_t node)
 
317
{
 
318
  struct grub_sfs_data *data = node->data;
 
319
  char *symlink;
 
320
  char *block;
 
321
 
 
322
  block = grub_malloc (data->blocksize);
 
323
  if (!block)
 
324
    return 0;
 
325
 
 
326
  grub_disk_read (data->disk, node->block, 0, data->blocksize, block);
 
327
  if (grub_errno)
 
328
    {
 
329
      grub_free (block);
 
330
      return 0;
 
331
    }
 
332
 
 
333
  /* This is just a wild guess, but it always worked for me.  How the
 
334
     SLNK block looks like is not documented in the SFS docs.  */
 
335
  symlink = grub_strdup (&block[24]);
 
336
  grub_free (block);
 
337
  if (!symlink)
 
338
    return 0;
 
339
 
 
340
  return symlink;
 
341
}
 
342
 
 
343
static int
 
344
grub_sfs_iterate_dir (grub_fshelp_node_t dir,
 
345
                       int NESTED_FUNC_ATTR
 
346
                       (*hook) (const char *filename,
 
347
                                enum grub_fshelp_filetype filetype,
 
348
                                grub_fshelp_node_t node))
 
349
{
 
350
  struct grub_fshelp_node *node = 0;
 
351
  struct grub_sfs_data *data = dir->data;
 
352
  char *objc_data;
 
353
  struct grub_sfs_objc *objc;
 
354
  unsigned int next = dir->block;
 
355
  int pos;
 
356
 
 
357
  auto int NESTED_FUNC_ATTR grub_sfs_create_node (const char *name, int block,
 
358
                                                  int size, int type);
 
359
 
 
360
  int NESTED_FUNC_ATTR grub_sfs_create_node (const char *name, int block,
 
361
                                             int size, int type)
 
362
    {
 
363
      node = grub_malloc (sizeof (*node));
 
364
      if (!node)
 
365
        return 1;
 
366
 
 
367
      node->data = data;
 
368
      node->size = size;
 
369
      node->block = block;
 
370
 
 
371
      return hook (name, type, node);
 
372
    }
 
373
 
 
374
  objc_data = grub_malloc (data->blocksize);
 
375
  if (!objc_data)
 
376
    goto fail;
 
377
 
 
378
  /* The Object container can consist of multiple blocks, iterate over
 
379
     every block.  */
 
380
  while (next)
 
381
    {
 
382
      grub_disk_read (data->disk, next, 0, data->blocksize, objc_data);
 
383
      if (grub_errno)
 
384
        goto fail;
 
385
 
 
386
      objc = (struct grub_sfs_objc *) objc_data;
 
387
 
 
388
      pos = (char *) &objc->objects[0] - (char *) objc;
 
389
 
 
390
      /* Iterate over all entries in this block.  */
 
391
      while (pos + sizeof (struct grub_sfs_obj) < data->blocksize)
 
392
        {
 
393
          struct grub_sfs_obj *obj;
 
394
          obj = (struct grub_sfs_obj *) ((char *) objc + pos);
 
395
          char *filename = (char *) (obj->filename);
 
396
          int len;
 
397
          enum grub_fshelp_filetype type;
 
398
          unsigned int block;
 
399
 
 
400
          /* The filename and comment dynamically increase the size of
 
401
             the object.  */
 
402
          len = grub_strlen (filename);
 
403
          len += grub_strlen (filename + len + 1);
 
404
 
 
405
          pos += sizeof (*obj) + len;
 
406
          /* Round up to a multiple of two bytes.  */
 
407
          pos = ((pos + 1) >> 1) << 1;
 
408
 
 
409
          if (grub_strlen (filename) == 0)
 
410
            continue;
 
411
 
 
412
          /* First check if the file was not deleted.  */
 
413
          if (obj->type & GRUB_SFS_TYPE_DELETED)
 
414
            continue;
 
415
          else if (obj->type & GRUB_SFS_TYPE_SYMLINK)
 
416
            type = GRUB_FSHELP_SYMLINK;
 
417
          else if (obj->type & GRUB_SFS_TYPE_DIR)
 
418
            type = GRUB_FSHELP_DIR;
 
419
          else
 
420
            type = GRUB_FSHELP_REG;
 
421
 
 
422
          if (type == GRUB_FSHELP_DIR)
 
423
            block = grub_be_to_cpu32 (obj->file_dir.dir.dir_objc);
 
424
          else
 
425
            block = grub_be_to_cpu32 (obj->file_dir.file.first_block);
 
426
 
 
427
          if (grub_sfs_create_node (filename, block,
 
428
                                    grub_be_to_cpu32 (obj->file_dir.file.size),
 
429
                                    type))
 
430
            {
 
431
              grub_free (objc_data);
 
432
              return 1;
 
433
            }
 
434
        }
 
435
 
 
436
      next = grub_be_to_cpu32 (objc->next);
 
437
    }
 
438
 
 
439
 fail:
 
440
  grub_free (objc_data);
 
441
  return 0;
 
442
}
 
443
 
 
444
 
 
445
/* Open a file named NAME and initialize FILE.  */
 
446
static grub_err_t
 
447
grub_sfs_open (struct grub_file *file, const char *name)
 
448
{
 
449
  struct grub_sfs_data *data;
 
450
  struct grub_fshelp_node *fdiro = 0;
 
451
 
 
452
  grub_dl_ref (my_mod);
 
453
 
 
454
  data = grub_sfs_mount (file->device->disk);
 
455
  if (!data)
 
456
    goto fail;
 
457
 
 
458
  grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_sfs_iterate_dir,
 
459
                         grub_sfs_read_symlink, GRUB_FSHELP_REG);
 
460
  if (grub_errno)
 
461
    goto fail;
 
462
 
 
463
  file->size = fdiro->size;
 
464
  data->diropen = *fdiro;
 
465
  grub_free (fdiro);
 
466
 
 
467
  file->data = data;
 
468
  file->offset = 0;
 
469
 
 
470
  return 0;
 
471
 
 
472
 fail:
 
473
  if (data && fdiro != &data->diropen)
 
474
    grub_free (fdiro);
 
475
  if (data)
 
476
    grub_free (data->label);
 
477
  grub_free (data);
 
478
 
 
479
  grub_dl_unref (my_mod);
 
480
 
 
481
  return grub_errno;
 
482
}
 
483
 
 
484
 
 
485
static grub_err_t
 
486
grub_sfs_close (grub_file_t file)
 
487
{
 
488
  grub_free (file->data);
 
489
 
 
490
  grub_dl_unref (my_mod);
 
491
 
 
492
  return GRUB_ERR_NONE;
 
493
}
 
494
 
 
495
 
 
496
/* Read LEN bytes data from FILE into BUF.  */
 
497
static grub_ssize_t
 
498
grub_sfs_read (grub_file_t file, char *buf, grub_size_t len)
 
499
{
 
500
  struct grub_sfs_data *data = (struct grub_sfs_data *) file->data;
 
501
 
 
502
  int size = grub_sfs_read_file (&data->diropen, file->read_hook,
 
503
                                 file->offset, len, buf);
 
504
 
 
505
  return size;
 
506
}
 
507
 
 
508
 
 
509
static grub_err_t
 
510
grub_sfs_dir (grub_device_t device, const char *path,
 
511
               int (*hook) (const char *filename,
 
512
                            const struct grub_dirhook_info *info))
 
513
{
 
514
  struct grub_sfs_data *data = 0;
 
515
  struct grub_fshelp_node *fdiro = 0;
 
516
 
 
517
  auto int NESTED_FUNC_ATTR iterate (const char *filename,
 
518
                                     enum grub_fshelp_filetype filetype,
 
519
                                     grub_fshelp_node_t node);
 
520
 
 
521
  int NESTED_FUNC_ATTR iterate (const char *filename,
 
522
                                enum grub_fshelp_filetype filetype,
 
523
                                grub_fshelp_node_t node)
 
524
    {
 
525
      struct grub_dirhook_info info;
 
526
      grub_memset (&info, 0, sizeof (info));
 
527
      info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
 
528
      grub_free (node);
 
529
      return hook (filename, &info);
 
530
    }
 
531
 
 
532
  grub_dl_ref (my_mod);
 
533
 
 
534
  data = grub_sfs_mount (device->disk);
 
535
  if (!data)
 
536
    goto fail;
 
537
 
 
538
  grub_fshelp_find_file (path, &data->diropen, &fdiro, grub_sfs_iterate_dir,
 
539
                        grub_sfs_read_symlink, GRUB_FSHELP_DIR);
 
540
  if (grub_errno)
 
541
    goto fail;
 
542
 
 
543
  grub_sfs_iterate_dir (fdiro, iterate);
 
544
 
 
545
 fail:
 
546
  if (data && fdiro != &data->diropen)
 
547
    grub_free (fdiro);
 
548
  if (data)
 
549
    grub_free (data->label);
 
550
  grub_free (data);
 
551
 
 
552
  grub_dl_unref (my_mod);
 
553
 
 
554
  return grub_errno;
 
555
}
 
556
 
 
557
 
 
558
static grub_err_t
 
559
grub_sfs_label (grub_device_t device, char **label)
 
560
{
 
561
  struct grub_sfs_data *data;
 
562
  grub_disk_t disk = device->disk;
 
563
 
 
564
  data = grub_sfs_mount (disk);
 
565
  if (data)
 
566
    *label = data->label;
 
567
 
 
568
  grub_free (data);
 
569
 
 
570
  return grub_errno;
 
571
}
 
572
 
 
573
 
 
574
static struct grub_fs grub_sfs_fs =
 
575
  {
 
576
    .name = "sfs",
 
577
    .dir = grub_sfs_dir,
 
578
    .open = grub_sfs_open,
 
579
    .read = grub_sfs_read,
 
580
    .close = grub_sfs_close,
 
581
    .label = grub_sfs_label,
 
582
    .next = 0
 
583
  };
 
584
 
 
585
GRUB_MOD_INIT(sfs)
 
586
{
 
587
  grub_fs_register (&grub_sfs_fs);
 
588
  my_mod = mod;
 
589
}
 
590
 
 
591
GRUB_MOD_FINI(sfs)
 
592
{
 
593
  grub_fs_unregister (&grub_sfs_fs);
 
594
}