2
libparted - a library for manipulating disk partitions
3
Copyright (C) 2005, 2007 Free Software Foundation, Inc.
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include <parted/parted.h>
22
#include <parted/endian.h>
23
#include <parted/debug.h>
27
# define _(String) dgettext (PACKAGE, String)
29
# define _(String) (String)
30
#endif /* ENABLE_NLS */
37
#define BFS_SPECIFIC(fs) ((struct BfsSpecific*) (fs->type_specific))
38
#define BFS_SB(fs) (BFS_SPECIFIC(fs)->sb)
41
const char BFS_MAGIC[4] = { 0x1B, 0xAD, 0xFA, 0xCE };
42
const long long BFS_SECTOR_SIZE = 512;
43
const uint32_t BFS_PED_SANITY = 0xffffffff;
44
const long long BFS_PED_MIN_INODES = 16;
47
bfs_probe (PedGeometry* geom)
51
PED_ASSERT (geom != NULL, return NULL);
52
PED_ASSERT (geom->dev != NULL, return NULL);
54
buf = ped_malloc (geom->dev->sector_size);
56
if (!ped_geometry_read (geom, buf, 0, 1))
59
//if ( PED_CPU_TO_LE32((uint32_t)buf) == BFS_MAGIC )
60
return ped_geometry_new (geom->dev, geom->start,
62
PED_CPU_TO_LE32((uint32_t)(buf+8)),
63
geom->dev->sector_size));
70
bfs_clobber (PedGeometry* geom)
74
PED_ASSERT (geom != NULL, return 0);
75
PED_ASSERT (geom->dev != NULL, return 0);
77
buf = ped_malloc (geom->dev->sector_size);
79
if (!ped_geometry_read (geom, buf, 0, 1))
82
return ped_geometry_write (geom, buf, 0, 1);
84
#endif /* !DISCOVER_ONLY */
88
bfs_alloc (const PedGeometry* geom)
92
fs = (PedFileSystem*) ped_malloc (sizeof (PedFileSystem));
96
fs->type_specific = (struct BfsSpecific*) ped_malloc (
97
sizeof (struct BfsSpecific));
98
if (!fs->type_specific)
101
fs->geom = ped_geometry_duplicate (geom);
103
goto error_free_type_specific;
108
error_free_type_specific:
109
ped_free (fs->type_specific);
118
bfs_free (PedFileSystem* fs)
120
ped_geometry_destroy (fs->geom);
121
ped_free (fs->type_specific);
126
static PedFileSystem*
127
bfs_open (PedGeometry *geom)
129
PedFileSystem* fs = bfs_alloc (geom);
131
struct bfs_sb* sb = (struct bfs_sb*) ped_malloc(sizeof(struct bfs_sb));
132
struct BfsSpecific* bfs;
135
PED_ASSERT (geom != NULL, return NULL);
136
PED_ASSERT (geom->dev != NULL, return NULL);
138
buf = ped_malloc (geom->dev->sector_size);
143
bfs = fs->type_specific;
145
if (!ped_geometry_read (geom, buf, 0, 1))
148
memcpy (sb, buf, BFS_SECTOR_SIZE);
156
#ifndef DISCOVER_ONLY
157
static struct bfs_inode* create_root_inode()
159
struct bfs_inode* root = ped_malloc (sizeof(struct bfs_inode));
166
root->mode = 512UL; /* rwxrwxrwx */
167
root->uid = root->gid = 0UL;
169
root->atime = root->ctime = 0UL;
170
memset ((void*)root->reserved, 0, 32*4);
176
static uint8_t* _block_alloc (int n)
178
return ped_calloc (n * BFS_SECTOR_SIZE);
182
static void _write_inodes (PedFileSystem* fs)
187
/* write a BFS block - always 512 bytes */
188
static int _write_block (PedFileSystem* fs, uint8_t* buf, int n)
190
/* FIXME: support for bs != 2^9 */
191
return ped_geometry_write ( fs->geom, buf, n, 1 );
195
static int _write_sb (PedFileSystem* fs)
197
uint8_t* sb = _block_alloc (1);
199
BFS_SB(fs)->magic = BFS_MAGIC;
200
BFS_SB(fs)->sanity = BFS_PED_SANITY;
201
BFS_SB(fs)->start = BFS_SPECIFIC(fs)->data_start;
202
BFS_SB(fs)->size = BFS_SPECIFIC(fs)->size;
204
memcpy (sb, BFS_SB(fs), sizeof(struct bfs_sb));
206
return _write_block (fs, sb, 1);
210
static PedFileSystem*
211
bfs_create (PedGeometry *geom, PedTimer *timer)
213
PedFileSystem* fs = bfs_alloc (geom);
214
int n_inodes = PED_MAX (BFS_PED_MIN_INODES, 16/*some sane value here*/);
216
/* TODO: check whether geometry is big enough */
218
fs->data_start = 1 + ped_round_up_to (n_inodes * 64, 512);
219
fs->size = geom->dev->sector_size * length;
221
ped_timer_set_state_name (timer, "Writing inodes");
225
ped_timer_set_state_name (timer, "Writing super block");
230
#endif /* !DISCOVER_ONLY */
233
static PedFileSystemOps bfs_ops = {
235
#ifndef DISCOVER_ONLY
236
clobber: bfs_clobber,
241
#ifndef DISCOVER_ONLY
250
get_create_constraint: NULL,
251
get_resize_constraint: NULL,
252
get_copy_constraint: NULL
255
static PedFileSystemType bfs_type = {
259
block_sizes: ((int[2]){512, 0})
263
ped_file_system_bfs_init ()
265
ped_file_system_type_register (&bfs_type);
269
ped_file_system_bfs_done ()
271
ped_file_system_type_unregister (&bfs_type);