~ubuntu-branches/ubuntu/hardy/silo/hardy-updates

« back to all changes in this revision

Viewing changes to second/fs/iom.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-10-25 09:28:08 UTC
  • mfrom: (15.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071025092808-1yhj12t7s4zqsfu5
Tags: 1.4.13a+git20070930-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build with -fno-stack-protector.
  - Change silo.postinst to automatically update the boot block without
    invoking siloconfig and keep asking questions on upgrades.
  - Convert silo.conf to use /dev/disk/by-uuid.
  - Ubuntu maintainer foobar.
  - Fix debian/rules call to dh_installdocs.
  - Drop the requirement of gcc-4.1 and start using default gcc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* SILO I/O Manager for filesystem operations.
 
2
   
 
3
   Copyright (C) 1996 Maurizio Plaza
 
4
                 1996,1997,1999 Jakub Jelinek
 
5
                 2001 Ben Collins
 
6
   
 
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.
 
11
   
 
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.
 
16
 
 
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,
 
20
   USA.  */
 
21
 
 
22
#include <sys/types.h>
 
23
#include <silo.h>
 
24
#include <file.h>
 
25
#include <stringops.h>
 
26
 
 
27
static unsigned long long doff;         /* Block where partition starts */
 
28
 
 
29
static int read_sun_partition (int partno)
 
30
{
 
31
    int rc;
 
32
    sun_partition sdl;
 
33
    unsigned short csum, *ush;
 
34
 
 
35
    rc = silo_disk_read((char *) &sdl, 512, 0);
 
36
    if (rc != 512) {
 
37
        silo_fatal("Cannot read partition");
 
38
        return 0;
 
39
    }
 
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;)
 
43
        csum ^= *ush--;
 
44
    if (csum)
 
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;
 
47
}
 
48
 
 
49
static errcode_t silo_open (const char *name, int flags, io_channel * channel)
 
50
{
 
51
    int partno;
 
52
    io_channel io;
 
53
 
 
54
    if (!name)
 
55
        return EXT2_ET_BAD_DEVICE_NAME;
 
56
    io = (io_channel) malloc (sizeof (struct struct_io_channel));
 
57
    if (!io)
 
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);
 
64
    io->block_size = bs;
 
65
    io->read_error = 0;
 
66
    io->write_error = 0;
 
67
 
 
68
    doff = 0LL;
 
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;
 
73
    }
 
74
    *channel = io;
 
75
    return 0;
 
76
}
 
77
 
 
78
static errcode_t silo_close (io_channel channel)
 
79
{
 
80
    return 0;
 
81
}
 
82
 
 
83
static errcode_t silo_set_blksize (io_channel channel, int blksize)
 
84
{
 
85
    channel->block_size = bs = blksize;
 
86
    return 0;
 
87
}
 
88
 
 
89
static errcode_t silo_read_blk (io_channel channel, unsigned long block, int count, void *data)
 
90
{
 
91
    int size, got;
 
92
 
 
93
    size = (count < 0) ? -count : count * bs;
 
94
    got = silo_disk_read(data, size, ((unsigned long long)block) * bs + doff);
 
95
    if (got != size) {
 
96
        printf ("\nRead error on block %d (tried %d, got %d)\n", block, size, got);
 
97
        return EXT2_ET_SHORT_READ;
 
98
    }
 
99
    return 0;
 
100
}
 
101
 
 
102
static errcode_t silo_write_blk (io_channel channel, unsigned long block, int count, const void *data)
 
103
{
 
104
    return 0;
 
105
}
 
106
 
 
107
static errcode_t silo_flush (io_channel channel)
 
108
{
 
109
    return 0;
 
110
}
 
111
 
 
112
/* The actual I/O Manager.  */
 
113
static struct struct_io_manager struct_silo_manager =
 
114
{
 
115
    .magic              = EXT2_ET_MAGIC_IO_MANAGER,
 
116
    .name               = "SILO I/O Manager",
 
117
    .open               = silo_open,
 
118
    .close              = silo_close,
 
119
    .set_blksize        = silo_set_blksize,
 
120
    .read_blk           = silo_read_blk,
 
121
    .write_blk          = silo_write_blk,
 
122
    .flush              = silo_flush
 
123
};
 
124
 
 
125
io_manager silo_io_manager = &struct_silo_manager;