~youscribe/parted/3.1

« back to all changes in this revision

Viewing changes to libparted/fs/amiga/asfs.c

  • Committer: Guilhem Lettron
  • Date: 2012-10-22 14:37:59 UTC
  • Revision ID: guilhem+ubuntu@lettron.fr-20121022143759-m403kecgz13sknvp
3.1 from tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    asfs.c -- parted asfs filesystem support
 
3
    Copyright (C) 1998-2000, 2007, 2009-2012 Free Software Foundation, Inc.
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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/>.
 
17
*/
 
18
 
 
19
#include <config.h>
 
20
 
 
21
#include <parted/parted.h>
 
22
#include <parted/debug.h>
 
23
#include <parted/endian.h>
 
24
 
 
25
#include "amiga.h"
 
26
#include "asfs.h"
 
27
 
 
28
#if ENABLE_NLS
 
29
#  include <libintl.h>
 
30
#  define _(String) dgettext (PACKAGE, String)
 
31
#else
 
32
#  define _(String) (String)
 
33
#endif /* ENABLE_NLS */
 
34
 
 
35
static int
 
36
_asfs_probe_root (PedGeometry *geom, uint32_t *block, int blocksize, PedSector root) {
 
37
        int i, sum;
 
38
        PedSector start, end;
 
39
 
 
40
        if (PED_BE32_TO_CPU (block[0]) != 0x53465300) return 0;
 
41
        for (i = 0, sum = 1; i < 128*blocksize; i++) sum += PED_BE32_TO_CPU (block[i]);
 
42
        if (sum != 0) return 0;
 
43
        if (PED_BE32_TO_CPU (block[2]) * blocksize + geom->start != root) {
 
44
                return 0;
 
45
        }
 
46
        start = ((((PedSector) PED_BE32_TO_CPU (block[8])) << 32)
 
47
                + (PedSector) PED_BE32_TO_CPU (block[9])) / 512;
 
48
        end = (((((PedSector) PED_BE32_TO_CPU (block[10])) << 32)
 
49
                + (PedSector) PED_BE32_TO_CPU (block[11])) / 512) - 1;
 
50
        if (start != geom->start || end != geom->end) return 0;
 
51
        return 1;
 
52
}
 
53
 
 
54
static PedGeometry*
 
55
_asfs_probe (PedGeometry* geom)
 
56
{
 
57
        uint32_t *block;
 
58
        struct PartitionBlock * part;
 
59
        int blocksize = 1;
 
60
        PedSector root;
 
61
        int found = 0;
 
62
 
 
63
        PED_ASSERT (geom != NULL);
 
64
        PED_ASSERT (geom->dev != NULL);
 
65
 
 
66
        /* Finds the blocksize of the partition block */
 
67
        if (!(part = ped_malloc (PED_SECTOR_SIZE_DEFAULT*blocksize))) {
 
68
                ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
 
69
                        _("%s : Failed to allocate partition block\n"), __func__);
 
70
                goto error_part;
 
71
        }
 
72
        if (amiga_find_part(geom, part) != NULL) {
 
73
                blocksize = PED_BE32_TO_CPU (part->de_SizeBlock)
 
74
                        * PED_BE32_TO_CPU (part->de_SectorPerBlock) / 128;
 
75
        }
 
76
        free (part);
 
77
 
 
78
        /* Test boot block */
 
79
        if (!(block = ped_malloc (PED_SECTOR_SIZE_DEFAULT*blocksize))) {
 
80
                ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
 
81
                        _("%s : Failed to allocate block\n"), __func__);
 
82
                goto error_block;
 
83
        }
 
84
        root = geom->start;
 
85
        if (!ped_device_read (geom->dev, block, root, blocksize)) {
 
86
                ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
 
87
                        _("%s : Couldn't read root block %llu\n"), __func__, root);
 
88
                goto error;
 
89
        }
 
90
        if (PED_BE32_TO_CPU (block[0]) != 0x53465300) {
 
91
                goto error;
 
92
        }
 
93
 
 
94
        /* Find and test the root blocks */
 
95
        if (_asfs_probe_root(geom, block, blocksize, root)) {
 
96
                found++;
 
97
        }
 
98
        root = geom->end - blocksize - (geom->length % blocksize) + 1;
 
99
        if (!ped_device_read (geom->dev, block, root, 1)) {
 
100
                ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
 
101
                        _("%s : Couldn't read root block %llu\n"), __func__, root);
 
102
                goto error;
 
103
        }
 
104
        if (_asfs_probe_root(geom, block, blocksize, root)) {
 
105
                found++;
 
106
        }
 
107
        if (found != 0) {
 
108
                free (block);
 
109
                return ped_geometry_duplicate (geom);
 
110
        }
 
111
 
 
112
error:
 
113
        free (block);
 
114
error_block:
 
115
error_part:
 
116
        return NULL;
 
117
}
 
118
 
 
119
static PedFileSystemOps _asfs_ops = {
 
120
        probe:          _asfs_probe,
 
121
};
 
122
 
 
123
PedFileSystemType _asfs_type = {
 
124
       next:             NULL,
 
125
       ops:              &_asfs_ops,
 
126
       name:             "asfs",
 
127
       block_sizes:      ((int[2]){512, 0})
 
128
};