1
/* SILO I/O Manager for filesystem operations.
3
Copyright (C) 1996 Maurizio Plaza
4
1996,1997,1999 Jakub Jelinek
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22
#include <sys/types.h>
25
#include <stringops.h>
27
static unsigned long long doff; /* Block where partition starts */
29
static int read_sun_partition (int partno)
33
unsigned short csum, *ush;
35
rc = silo_disk_read((char *) &sdl, 512, 0);
37
silo_fatal("Cannot read partition");
40
if (sdl.magic != SUN_LABEL_MAGIC)
41
silo_fatal("Wrong disklabel magic");
42
for (csum = 0, ush = ((unsigned short *) ((&sdl) + 1)) - 1; ush >= (unsigned short *) &sdl;)
45
printf ("\nWarning: Your disklabel has wrong checksum. Use fdisk to correct it.");
46
doff = (((unsigned long long)sdl.ntrks) * sdl.nsect * sdl.partitions[partno - 1].start_cylinder) << 9; return 1;
49
static errcode_t silo_open (const char *name, int flags, io_channel * channel)
55
return EXT2_ET_BAD_DEVICE_NAME;
56
io = (io_channel) malloc (sizeof (struct struct_io_channel));
58
return EXT2_ET_BAD_DEVICE_NAME;
59
memset (io, 0, sizeof (struct struct_io_channel));
60
io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
61
io->manager = silo_io_manager;
62
io->name = (char *) malloc (strlen (name) + 1);
63
strcpy (io->name, name);
69
if (strncmp (name, "/dev/fd0", 8) && silo_disk_partitionable()) {
70
partno = *(name + strlen (name) - 1) - '0';
71
if (partno && !read_sun_partition (partno))
72
return EXT2_ET_BAD_DEVICE_NAME;
78
static errcode_t silo_close (io_channel channel)
83
static errcode_t silo_set_blksize (io_channel channel, int blksize)
85
channel->block_size = bs = blksize;
89
static errcode_t silo_read_blk (io_channel channel, unsigned long block, int count, void *data)
93
size = (count < 0) ? -count : count * bs;
94
got = silo_disk_read(data, size, ((unsigned long long)block) * bs + doff);
96
printf ("\nRead error on block %d (tried %d, got %d)\n", block, size, got);
97
return EXT2_ET_SHORT_READ;
102
static errcode_t silo_write_blk (io_channel channel, unsigned long block, int count, const void *data)
107
static errcode_t silo_flush (io_channel channel)
112
/* The actual I/O Manager. */
113
static struct struct_io_manager struct_silo_manager =
115
.magic = EXT2_ET_MAGIC_IO_MANAGER,
116
.name = "SILO I/O Manager",
119
.set_blksize = silo_set_blksize,
120
.read_blk = silo_read_blk,
121
.write_blk = silo_write_blk,
125
io_manager silo_io_manager = &struct_silo_manager;