fs.h 3.95 KB
Newer Older
okuji's avatar
okuji committed
1 2
/* fs.h - filesystem manager */
/*
3
 *  GRUB  --  GRand Unified Bootloader
4
 *  Copyright (C) 2002,2003,2004,2007,2008,2009  Free Software Foundation, Inc.
okuji's avatar
okuji committed
5
 *
6
 *  GRUB is free software: you can redistribute it and/or modify
okuji's avatar
okuji committed
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
okuji's avatar
okuji committed
9 10
 *  (at your option) any later version.
 *
11
 *  GRUB is distributed in the hope that it will be useful,
okuji's avatar
okuji committed
12 13 14 15 16
 *  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
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
okuji's avatar
okuji committed
18 19
 */

20 21
#ifndef GRUB_FS_HEADER
#define GRUB_FS_HEADER	1
okuji's avatar
okuji committed
22

23 24 25
#include <grub/device.h>
#include <grub/symbol.h>
#include <grub/types.h>
okuji's avatar
okuji committed
26

27
#include <grub/list.h>
28 29 30 31
/* For embedding types.  */
#ifdef GRUB_UTIL
#include <grub/partition.h>
#endif
32

okuji's avatar
okuji committed
33
/* Forward declaration is required, because of mutual reference.  */
34
struct grub_file;
okuji's avatar
okuji committed
35

36 37
struct grub_dirhook_info
{
38 39 40
  unsigned dir:1;
  unsigned mtimeset:1;
  unsigned case_insensitive:1;
41
  unsigned inodeset:1;
42
  grub_int32_t mtime;
43
  grub_uint64_t inode;
44 45
};

46 47 48 49
typedef int (*grub_fs_dir_hook_t) (const char *filename,
				   const struct grub_dirhook_info *info,
				   void *data);

okuji's avatar
okuji committed
50
/* Filesystem descriptor.  */
51
struct grub_fs
okuji's avatar
okuji committed
52
{
53 54
  /* The next filesystem.  */
  struct grub_fs *next;
55
  struct grub_fs **prev;
56

okuji's avatar
okuji committed
57 58 59 60
  /* My name.  */
  const char *name;

  /* Call HOOK with each file under DIR.  */
61
  grub_err_t (*dir) (grub_device_t device, const char *path,
62
		     grub_fs_dir_hook_t hook, void *hook_data);
63

okuji's avatar
okuji committed
64
  /* Open a file named NAME and initialize FILE.  */
65
  grub_err_t (*open) (struct grub_file *file, const char *name);
66

okuji's avatar
okuji committed
67
  /* Read LEN bytes data from FILE into BUF.  */
68
  grub_ssize_t (*read) (struct grub_file *file, char *buf, grub_size_t len);
69

okuji's avatar
okuji committed
70
  /* Close the file FILE.  */
71
  grub_err_t (*close) (struct grub_file *file);
72

73
  /* Return the label of the device DEVICE in LABEL.  The label is
74
     returned in a grub_malloc'ed buffer and should be freed by the
75
     caller.  */
76
  grub_err_t (*label) (grub_device_t device, char **label);
okuji's avatar
okuji committed
77

78 79 80 81 82
  /* Return the uuid of the device DEVICE in UUID.  The uuid is
     returned in a grub_malloc'ed buffer and should be freed by the
     caller.  */
  grub_err_t (*uuid) (grub_device_t device, char **uuid);

83 84 85
  /* Get writing time of filesystem. */
  grub_err_t (*mtime) (grub_device_t device, grub_int32_t *timebuf);

86
#ifdef GRUB_UTIL
87 88
  /* Determine sectors available for embedding.  */
  grub_err_t (*embed) (grub_device_t device, unsigned int *nsectors,
89
		       unsigned int max_nsectors,
90 91 92
		       grub_embed_type_t embed_type,
		       grub_disk_addr_t **sectors);

93 94
  /* Whether this filesystem reserves first sector for DOS-style boot.  */
  int reserved_first_sector;
95 96 97

  /* Whether blocklist installs have a chance to work.  */
  int blocklist_install;
98
#endif
okuji's avatar
okuji committed
99
};
100
typedef struct grub_fs *grub_fs_t;
okuji's avatar
okuji committed
101 102

/* This is special, because block lists are not files in usual sense.  */
103
extern struct grub_fs grub_fs_blocklist;
okuji's avatar
okuji committed
104

105 106 107 108 109 110
/* This hook is used to automatically load filesystem modules.
   If this hook loads a module, return non-zero. Otherwise return zero.
   The newly loaded filesystem is assumed to be inserted into the head of
   the linked list GRUB_FS_LIST through the function grub_fs_register.  */
typedef int (*grub_fs_autoload_hook_t) (void);
extern grub_fs_autoload_hook_t EXPORT_VAR(grub_fs_autoload_hook);
111 112
extern grub_fs_t EXPORT_VAR (grub_fs_list);

113
#ifndef GRUB_LST_GENERATOR
114 115 116 117 118
static inline void
grub_fs_register (grub_fs_t fs)
{
  grub_list_push (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
}
119
#endif
120 121 122 123

static inline void
grub_fs_unregister (grub_fs_t fs)
{
124
  grub_list_remove (GRUB_AS_LIST (fs));
125 126 127
}

#define FOR_FILESYSTEMS(var) FOR_LIST_ELEMENTS((var), (grub_fs_list))
128

129
grub_fs_t EXPORT_FUNC(grub_fs_probe) (grub_device_t device);
okuji's avatar
okuji committed
130

131
#endif /* ! GRUB_FS_HEADER */