Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 46041
Collapse All | Expand All

(-)parted-1.6.6/configure (-2 / +2 lines)
Lines 13714-13721 Link Here
13714
if test "$enable_Werror" = yes; then
13714
if test "$enable_Werror" = yes; then
13715
	CFLAGS="$CFLAGS -Werror"
13715
	CFLAGS="$CFLAGS -Werror"
13716
fi
13716
fi
13717
13717
ac_config_files="$ac_config_files Makefile include/Makefile include/parted/Makefile libparted/Makefile libparted/fs_ext2/Makefile libparted/fs_fat/Makefile libparted/fs_hfs/Makefile libparted/fs_jfs/Makefile libparted/fs_linux_swap/Makefile libparted/fs_ntfs/Makefile libparted/fs_reiserfs/Makefile libparted/fs_ufs/Makefile libparted/fs_xfs/Makefile libparted/fs_amiga/Makefile parted/Makefile partprobe/Makefile intl/Makefile doc/Makefile debug/Makefile debug/clearfat/Makefile debug/test/Makefile po/Makefile.in parted.spec"
13718
                                                                                                                                                                                                                            ac_config_files="$ac_config_files Makefile include/Makefile include/parted/Makefile libparted/Makefile libparted/fs_ext2/Makefile libparted/fs_fat/Makefile libparted/fs_hfs/Makefile libparted/fs_jfs/Makefile libparted/fs_linux_swap/Makefile libparted/fs_ntfs/Makefile libparted/fs_reiserfs/Makefile libparted/fs_ufs/Makefile libparted/fs_xfs/Makefile parted/Makefile partprobe/Makefile intl/Makefile doc/Makefile debug/Makefile debug/clearfat/Makefile debug/test/Makefile po/Makefile.in parted.spec"
13719
cat >confcache <<\_ACEOF
13718
cat >confcache <<\_ACEOF
13720
# This file is a shell script that caches the results of configure
13719
# This file is a shell script that caches the results of configure
13721
# tests run on this system so they can be shared between configure
13720
# tests run on this system so they can be shared between configure
Lines 14264-14269 Link Here
14264
  "libparted/fs_reiserfs/Makefile" ) CONFIG_FILES="$CONFIG_FILES libparted/fs_reiserfs/Makefile" ;;
14263
  "libparted/fs_reiserfs/Makefile" ) CONFIG_FILES="$CONFIG_FILES libparted/fs_reiserfs/Makefile" ;;
14265
  "libparted/fs_ufs/Makefile" ) CONFIG_FILES="$CONFIG_FILES libparted/fs_ufs/Makefile" ;;
14264
  "libparted/fs_ufs/Makefile" ) CONFIG_FILES="$CONFIG_FILES libparted/fs_ufs/Makefile" ;;
14266
  "libparted/fs_xfs/Makefile" ) CONFIG_FILES="$CONFIG_FILES libparted/fs_xfs/Makefile" ;;
14265
  "libparted/fs_xfs/Makefile" ) CONFIG_FILES="$CONFIG_FILES libparted/fs_xfs/Makefile" ;;
14266
  "libparted/fs_amiga/Makefile" ) CONFIG_FILES="$CONFIG_FILES libparted/fs_amiga/Makefile" ;;
14267
  "parted/Makefile" ) CONFIG_FILES="$CONFIG_FILES parted/Makefile" ;;
14267
  "parted/Makefile" ) CONFIG_FILES="$CONFIG_FILES parted/Makefile" ;;
14268
  "partprobe/Makefile" ) CONFIG_FILES="$CONFIG_FILES partprobe/Makefile" ;;
14268
  "partprobe/Makefile" ) CONFIG_FILES="$CONFIG_FILES partprobe/Makefile" ;;
14269
  "intl/Makefile" ) CONFIG_FILES="$CONFIG_FILES intl/Makefile" ;;
14269
  "intl/Makefile" ) CONFIG_FILES="$CONFIG_FILES intl/Makefile" ;;
(-)parted-1.6.6/libparted/Makefile.am (-2 / +5 lines)
Lines 11-17 Link Here
11
		fs_ntfs			\
11
		fs_ntfs			\
12
		fs_reiserfs		\
12
		fs_reiserfs		\
13
		fs_ufs			\
13
		fs_ufs			\
14
		fs_xfs
14
		fs_xfs			\
15
		fs_amiga
15
16
16
LIBS = @INTLLIBS@ @LIBS@
17
LIBS = @INTLLIBS@ @LIBS@
17
18
Lines 41-46 Link Here
41
			disk_dvh.c		\
42
			disk_dvh.c		\
42
			disk_pc98.c		\
43
			disk_pc98.c		\
43
			disk_sun.c		\
44
			disk_sun.c		\
45
			disk_amiga.c		\
44
			@OS@.c
46
			@OS@.c
45
47
46
EXTRA_libparted_la_SOURCES    = linux.c		\
48
EXTRA_libparted_la_SOURCES    = linux.c		\
Lines 57-63 Link Here
57
			fs_ntfs/libntfs.la		\
59
			fs_ntfs/libntfs.la		\
58
			fs_reiserfs/libreiserfs.la	\
60
			fs_reiserfs/libreiserfs.la	\
59
			fs_ufs/libufs.la		\
61
			fs_ufs/libufs.la		\
60
			fs_xfs/libxfs.la
62
			fs_xfs/libxfs.la		\
63
			fs_amiga/libamigafs.la
61
64
62
EXTRA_DIST	      = mbr.s
65
EXTRA_DIST	      = mbr.s
63
66
(-)parted-1.6.6/libparted/Makefile.in (-130 / +5 lines)
Lines 110-116 Link Here
110
UUID_LIBS = @UUID_LIBS@
110
UUID_LIBS = @UUID_LIBS@
111
VERSION = @VERSION@
111
VERSION = @VERSION@
112
112
113
SUBDIRS = fs_ext2					fs_fat					fs_hfs					fs_jfs					fs_linux_swap				fs_ntfs					fs_reiserfs				fs_ufs					fs_xfs
113
SUBDIRS = fs_ext2					fs_fat					fs_hfs					fs_jfs					fs_linux_swap				fs_ntfs					fs_reiserfs				fs_ufs					fs_xfs					fs_amiga
114
114
115
115
116
LIBS = @INTLLIBS@ @LIBS@
116
LIBS = @INTLLIBS@ @LIBS@
Lines 120-132 Link Here
120
libparted_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)  			-release $(LT_RELEASE)
120
libparted_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)  			-release $(LT_RELEASE)
121
121
122
122
123
libparted_la_SOURCES = blkpg.h						dvh.h						crc32.c						constraint.c					debug.c						device.c					exception.c					filesys.c					geom.c						libparted.c					natmath.c					timer.c						disk.c						disk_bsd.c					disk_dos.c					disk_gpt.c					disk_loop.c					disk_mac.c					disk_dvh.c					disk_pc98.c					disk_sun.c					@OS@.c
123
libparted_la_SOURCES = blkpg.h						dvh.h						crc32.c						constraint.c					debug.c						device.c					exception.c					filesys.c					geom.c						libparted.c					natmath.c					timer.c						disk.c						disk_bsd.c					disk_dos.c					disk_gpt.c					disk_loop.c					disk_mac.c					disk_dvh.c					disk_pc98.c					disk_sun.c					disk_amiga.c					@OS@.c
124
124
125
125
126
EXTRA_libparted_la_SOURCES = linux.c						gnu.c
126
EXTRA_libparted_la_SOURCES = linux.c						gnu.c
127
127
128
128
129
libparted_la_LIBADD = @UUID_LIBS@						@OS_LIBS@						@REISER_LIBS@						fs_ext2/libext2.la					fs_fat/libfat.la					fs_hfs/libhfs.la					fs_jfs/libjfs.la					fs_linux_swap/liblinuxswap.la				fs_ntfs/libntfs.la					fs_reiserfs/libreiserfs.la				fs_ufs/libufs.la					fs_xfs/libxfs.la
129
libparted_la_LIBADD = @UUID_LIBS@						@OS_LIBS@						@REISER_LIBS@						fs_ext2/libext2.la					fs_fat/libfat.la					fs_hfs/libhfs.la					fs_jfs/libjfs.la					fs_linux_swap/liblinuxswap.la				fs_ntfs/libntfs.la					fs_reiserfs/libreiserfs.la				fs_ufs/libufs.la					fs_xfs/libxfs.la					fs_amiga/libamigafs.la
130
130
131
131
132
EXTRA_DIST = mbr.s
132
EXTRA_DIST = mbr.s
Lines 144-154 Link Here
144
libparted_la_DEPENDENCIES =  fs_ext2/libext2.la fs_fat/libfat.la \
144
libparted_la_DEPENDENCIES =  fs_ext2/libext2.la fs_fat/libfat.la \
145
fs_hfs/libhfs.la fs_jfs/libjfs.la fs_linux_swap/liblinuxswap.la \
145
fs_hfs/libhfs.la fs_jfs/libjfs.la fs_linux_swap/liblinuxswap.la \
146
fs_ntfs/libntfs.la fs_reiserfs/libreiserfs.la fs_ufs/libufs.la \
146
fs_ntfs/libntfs.la fs_reiserfs/libreiserfs.la fs_ufs/libufs.la \
147
fs_xfs/libxfs.la
147
fs_xfs/libxfs.la fs_amiga/libamigafs.la
148
libparted_la_OBJECTS =  crc32.lo constraint.lo debug.lo device.lo \
148
libparted_la_OBJECTS =  crc32.lo constraint.lo debug.lo device.lo \
149
exception.lo filesys.lo geom.lo libparted.lo natmath.lo timer.lo \
149
exception.lo filesys.lo geom.lo libparted.lo natmath.lo timer.lo \
150
disk.lo disk_bsd.lo disk_dos.lo disk_gpt.lo disk_loop.lo disk_mac.lo \
150
disk.lo disk_bsd.lo disk_dos.lo disk_gpt.lo disk_loop.lo disk_mac.lo \
151
disk_dvh.lo disk_pc98.lo disk_sun.lo @OS@.lo
151
disk_dvh.lo disk_pc98.lo disk_sun.lo disk_amiga.lo @OS@.lo
152
CFLAGS = @CFLAGS@
152
CFLAGS = @CFLAGS@
153
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
153
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
154
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
154
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
Lines 361-491 Link Here
361
	      || exit 1; \
361
	      || exit 1; \
362
	  fi; \
362
	  fi; \
363
	done
363
	done
364
constraint.lo constraint.o : constraint.c ../include/parted/parted.h \
365
	../include/parted/constraint.h ../include/parted/device.h \
366
	../include/parted/timer.h ../include/parted/natmath.h \
367
	../include/parted/disk.h ../include/parted/filesys.h \
368
	../include/parted/geom.h ../include/parted/exception.h \
369
	../include/parted/debug.h ../config.h
370
crc32.lo crc32.o : crc32.c
371
debug.lo debug.o : debug.c ../config.h ../include/parted/parted.h \
372
	../include/parted/constraint.h ../include/parted/device.h \
373
	../include/parted/timer.h ../include/parted/natmath.h \
374
	../include/parted/disk.h ../include/parted/filesys.h \
375
	../include/parted/geom.h ../include/parted/exception.h
376
device.lo device.o : device.c ../config.h ../include/parted/parted.h \
377
	../include/parted/constraint.h ../include/parted/device.h \
378
	../include/parted/timer.h ../include/parted/natmath.h \
379
	../include/parted/disk.h ../include/parted/filesys.h \
380
	../include/parted/geom.h ../include/parted/exception.h \
381
	../include/parted/debug.h
382
disk.lo disk.o : disk.c ../config.h ../include/parted/parted.h \
383
	../include/parted/constraint.h ../include/parted/device.h \
384
	../include/parted/timer.h ../include/parted/natmath.h \
385
	../include/parted/disk.h ../include/parted/filesys.h \
386
	../include/parted/geom.h ../include/parted/exception.h \
387
	../include/parted/debug.h
388
disk_bsd.lo disk_bsd.o : disk_bsd.c ../config.h \
389
	../include/parted/parted.h ../include/parted/constraint.h \
390
	../include/parted/device.h ../include/parted/timer.h \
391
	../include/parted/natmath.h ../include/parted/disk.h \
392
	../include/parted/filesys.h ../include/parted/geom.h \
393
	../include/parted/exception.h ../include/parted/debug.h \
394
	../include/parted/endian.h
395
disk_dos.lo disk_dos.o : disk_dos.c ../config.h \
396
	../include/parted/parted.h ../include/parted/constraint.h \
397
	../include/parted/device.h ../include/parted/timer.h \
398
	../include/parted/natmath.h ../include/parted/disk.h \
399
	../include/parted/filesys.h ../include/parted/geom.h \
400
	../include/parted/exception.h ../include/parted/debug.h \
401
	../include/parted/endian.h
402
disk_dvh.lo disk_dvh.o : disk_dvh.c ../include/parted/parted.h \
403
	../include/parted/constraint.h ../include/parted/device.h \
404
	../include/parted/timer.h ../include/parted/natmath.h \
405
	../include/parted/disk.h ../include/parted/filesys.h \
406
	../include/parted/geom.h ../include/parted/exception.h \
407
	../include/parted/debug.h ../config.h \
408
	../include/parted/endian.h dvh.h
409
disk_gpt.lo disk_gpt.o : disk_gpt.c ../config.h \
410
	../include/parted/parted.h ../include/parted/constraint.h \
411
	../include/parted/device.h ../include/parted/timer.h \
412
	../include/parted/natmath.h ../include/parted/disk.h \
413
	../include/parted/filesys.h ../include/parted/geom.h \
414
	../include/parted/exception.h ../include/parted/debug.h \
415
	../include/parted/endian.h ../include/parted/crc32.h
416
disk_loop.lo disk_loop.o : disk_loop.c ../config.h \
417
	../include/parted/parted.h ../include/parted/constraint.h \
418
	../include/parted/device.h ../include/parted/timer.h \
419
	../include/parted/natmath.h ../include/parted/disk.h \
420
	../include/parted/filesys.h ../include/parted/geom.h \
421
	../include/parted/exception.h ../include/parted/debug.h \
422
	../include/parted/endian.h
423
disk_mac.lo disk_mac.o : disk_mac.c ../config.h \
424
	../include/parted/parted.h ../include/parted/constraint.h \
425
	../include/parted/device.h ../include/parted/timer.h \
426
	../include/parted/natmath.h ../include/parted/disk.h \
427
	../include/parted/filesys.h ../include/parted/geom.h \
428
	../include/parted/exception.h ../include/parted/debug.h \
429
	../include/parted/endian.h
430
disk_mips.lo disk_mips.o : ../config.h
431
disk_pc98.lo disk_pc98.o : disk_pc98.c ../config.h \
432
	../include/parted/parted.h ../include/parted/constraint.h \
433
	../include/parted/device.h ../include/parted/timer.h \
434
	../include/parted/natmath.h ../include/parted/disk.h \
435
	../include/parted/filesys.h ../include/parted/geom.h \
436
	../include/parted/exception.h ../include/parted/debug.h \
437
	../include/parted/endian.h
438
disk_sun.lo disk_sun.o : disk_sun.c ../config.h \
439
	../include/parted/parted.h ../include/parted/constraint.h \
440
	../include/parted/device.h ../include/parted/timer.h \
441
	../include/parted/natmath.h ../include/parted/disk.h \
442
	../include/parted/filesys.h ../include/parted/geom.h \
443
	../include/parted/exception.h ../include/parted/debug.h \
444
	../include/parted/endian.h
445
exception.lo exception.o : exception.c ../config.h \
446
	../include/parted/parted.h ../include/parted/constraint.h \
447
	../include/parted/device.h ../include/parted/timer.h \
448
	../include/parted/natmath.h ../include/parted/disk.h \
449
	../include/parted/filesys.h ../include/parted/geom.h \
450
	../include/parted/exception.h ../include/parted/debug.h
451
filesys.lo filesys.o : filesys.c ../config.h ../include/parted/parted.h \
452
	../include/parted/constraint.h ../include/parted/device.h \
453
	../include/parted/timer.h ../include/parted/natmath.h \
454
	../include/parted/disk.h ../include/parted/filesys.h \
455
	../include/parted/geom.h ../include/parted/exception.h \
456
	../include/parted/debug.h
457
geom.lo geom.o : geom.c ../config.h ../include/parted/parted.h \
458
	../include/parted/constraint.h ../include/parted/device.h \
459
	../include/parted/timer.h ../include/parted/natmath.h \
460
	../include/parted/disk.h ../include/parted/filesys.h \
461
	../include/parted/geom.h ../include/parted/exception.h \
462
	../include/parted/debug.h
463
libparted.lo libparted.o : libparted.c ../config.h \
464
	../include/parted/parted.h ../include/parted/constraint.h \
465
	../include/parted/device.h ../include/parted/timer.h \
466
	../include/parted/natmath.h ../include/parted/disk.h \
467
	../include/parted/filesys.h ../include/parted/geom.h \
468
	../include/parted/exception.h ../include/parted/debug.h \
469
	../include/parted/linux.h
470
linux.lo linux.o : linux.c ../config.h ../include/parted/parted.h \
471
	../include/parted/constraint.h ../include/parted/device.h \
472
	../include/parted/timer.h ../include/parted/natmath.h \
473
	../include/parted/disk.h ../include/parted/filesys.h \
474
	../include/parted/geom.h ../include/parted/exception.h \
475
	../include/parted/debug.h ../include/parted/linux.h blkpg.h
476
natmath.lo natmath.o : natmath.c ../include/parted/parted.h \
477
	../include/parted/constraint.h ../include/parted/device.h \
478
	../include/parted/timer.h ../include/parted/natmath.h \
479
	../include/parted/disk.h ../include/parted/filesys.h \
480
	../include/parted/geom.h ../include/parted/exception.h \
481
	../include/parted/debug.h ../config.h
482
timer.lo timer.o : timer.c ../include/parted/parted.h \
483
	../include/parted/constraint.h ../include/parted/device.h \
484
	../include/parted/timer.h ../include/parted/natmath.h \
485
	../include/parted/disk.h ../include/parted/filesys.h \
486
	../include/parted/geom.h ../include/parted/exception.h \
487
	../include/parted/debug.h ../config.h
488
489
info-am:
364
info-am:
490
info: info-recursive
365
info: info-recursive
491
dvi-am:
366
dvi-am:
(-)parted-1.6.6/libparted/disk_amiga.c (+1260 lines)
Line 0 Link Here
1
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2
3
    libparted - a library for manipulating disk partitions
4
    disk_amiga.c - libparted module to manipulate amiga RDB partition tables.
5
    Copyright (C) 2000, 2001 Free Software Foundation, Inc.
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  USA
20
21
    Contributor:  Sven Luther <luther@debian.org>
22
*/
23
24
#include "config.h"
25
26
#include <string.h>
27
28
#include <parted/parted.h>
29
#include <parted/debug.h>
30
#include <parted/endian.h>
31
32
#if ENABLE_NLS
33
#  include <libintl.h>
34
#  define _(String) dgettext (PACKAGE, String)
35
#else
36
#  define _(String) (String)
37
#endif /* ENABLE_NLS */
38
39
/* String manipulation */
40
static void _amiga_set_bstr (const char *cstr, char *bstr, int maxsize) {
41
	int size = strlen (cstr);
42
	int i;
43
44
	if (size >= maxsize) return;
45
	bstr[0] = size;
46
	for (i = 0; i<size; i++) bstr[i+1] = cstr[i];
47
}
48
static const char * _amiga_get_bstr (char * bstr) {
49
	char * cstr = bstr + 1;
50
	int size = bstr[0];
51
	
52
	cstr[size] = '\0';
53
	return cstr;
54
}
55
56
#define	IDNAME_RIGIDDISK	0x5244534B	/* 'RDSK' */
57
#define IDNAME_BADBLOCK		0x42414442	/* 'BADB' */
58
#define	IDNAME_PARTITION	0x50415254	/* 'PART' */
59
#define IDNAME_FILESYSHEADER	0x46534844	/* 'FSHD' */
60
#define IDNAME_LOADSEG		0x4C534547	/* 'LSEG' */
61
#define IDNAME_BOOT		0x424f4f54	/* 'BOOT' */
62
#define IDNAME_FREE		0xffffffff	
63
64
static const char *
65
_amiga_block_id (uint32_t id) {
66
	switch (id) {
67
		case IDNAME_RIGIDDISK :
68
			return "RDSK";
69
		case IDNAME_BADBLOCK :
70
			return "BADB";
71
		case IDNAME_PARTITION :
72
			return "PART";
73
		case IDNAME_FILESYSHEADER :
74
			return "FSHD";
75
		case IDNAME_LOADSEG :
76
			return "LSEG";
77
		case IDNAME_BOOT :
78
			return "BOOT";
79
		case IDNAME_FREE :
80
			return "<free>";
81
		default :
82
			return "<unknown>";
83
	}
84
}
85
static int
86
_amiga_valid_block_id (uint32_t id) {
87
	switch (id) {
88
		case IDNAME_RIGIDDISK :
89
		case IDNAME_BADBLOCK :
90
		case IDNAME_PARTITION :
91
		case IDNAME_FILESYSHEADER :
92
		case IDNAME_LOADSEG :
93
		case IDNAME_BOOT :
94
			return 1;
95
		case IDNAME_FREE :
96
		default :
97
			return 0;
98
	}
99
}
100
101
struct AmigaIds {
102
	uint32_t ID;
103
	struct AmigaIds *next;
104
};
105
106
static struct AmigaIds *
107
_amiga_add_id (uint32_t id, struct AmigaIds *ids) {
108
	struct AmigaIds *newid;
109
110
	if ((newid=ped_malloc(sizeof (struct AmigaIds)))==NULL) {
111
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
112
			_("%s : Failed to allocate id list element\n"), __func__);
113
		return 0;
114
	}
115
	newid->ID = id;
116
	newid->next = ids;
117
	return newid;
118
}
119
120
static void
121
_amiga_free_ids (struct AmigaIds *ids) {
122
	struct AmigaIds *current, *next;
123
124
	for (current = ids; current != NULL; current = next) {
125
		next = current->next;
126
		ped_free (current);
127
	}
128
}
129
static int
130
_amiga_id_in_list (uint32_t id, struct AmigaIds *ids) {
131
	struct AmigaIds *current;
132
133
	for (current = ids; current != NULL; current = current->next) {
134
		if (id == current->ID)
135
			return 1;
136
	}
137
	return 0;
138
}
139
140
struct AmigaBlock {
141
	uint32_t	amiga_ID;		/* Identifier 32 bit word */
142
	uint32_t	amiga_SummedLongss;	/* Size of the structure for checksums */
143
	int32_t		amiga_ChkSum;		/* Checksum of the structure */
144
};
145
#define AMIGA(pos) ((struct AmigaBlock *)(pos)) 
146
147
static int
148
_amiga_checksum (struct AmigaBlock *blk) {
149
	uint32_t *rdb = (uint32_t *) blk;
150
	uint32_t sum;
151
	int i, end;
152
153
	sum = PED_BE32_TO_CPU (rdb[0]);
154
	end = PED_BE32_TO_CPU (rdb[1]);
155
156
	if (end > PED_SECTOR_SIZE) end = PED_SECTOR_SIZE;
157
158
	for (i = 1; i < end; i++) sum += PED_BE32_TO_CPU (rdb[i]);
159
160
	return sum;
161
}
162
163
static void
164
_amiga_calculate_checksum (struct AmigaBlock *blk) {
165
	blk->amiga_ChkSum = PED_CPU_TO_BE32(
166
		PED_BE32_TO_CPU(blk->amiga_ChkSum) -
167
		_amiga_checksum((struct AmigaBlock *) blk));
168
	return;	
169
}
170
171
static struct AmigaBlock *
172
_amiga_read_block (PedDevice *dev, struct AmigaBlock *blk, PedSector block, struct AmigaIds *ids) {
173
	if (!ped_device_read (dev, blk, block, 1)) {
174
		ped_exception_throw(PED_EXCEPTION_ERROR,
175
			PED_EXCEPTION_CANCEL,
176
			_("%s : Couldn't read block %llu\n"), __func__, block);
177
		return NULL;
178
	}
179
	if (ids && !_amiga_id_in_list(PED_BE32_TO_CPU(blk->amiga_ID), ids))
180
		return NULL;
181
	if (_amiga_checksum (blk) != 0) {
182
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
183
			PED_EXCEPTION_FIX | PED_EXCEPTION_IGNORE | PED_EXCEPTION_CANCEL,
184
			_("%s : Bad checksum on block %llu of type %s\n"),
185
			__func__, block, _amiga_block_id(PED_BE32_TO_CPU(blk->amiga_ID))))
186
		{
187
			case PED_EXCEPTION_CANCEL :
188
				return NULL;
189
			case PED_EXCEPTION_FIX :
190
				_amiga_calculate_checksum(AMIGA(blk));
191
				if (!ped_device_write (dev, blk, block, 1)) {
192
					ped_exception_throw(PED_EXCEPTION_FATAL, PED_EXCEPTION_CANCEL,
193
						_("%s : Couldn't write block %d\n"), __func__, block);
194
					return NULL;
195
				}
196
			case PED_EXCEPTION_IGNORE :
197
			case PED_EXCEPTION_UNHANDLED :
198
			default : 
199
				return blk;
200
		}
201
	}
202
	return blk;
203
}
204
205
struct RigidDiskBlock {
206
    uint32_t	rdb_ID;			/* Identifier 32 bit word : 'RDSK' */
207
    uint32_t	rdb_SummedLongs;	/* Size of the structure for checksums */
208
    int32_t	rdb_ChkSum;		/* Checksum of the structure */
209
    uint32_t	rdb_HostID;		/* SCSI Target ID of host, not really used */
210
    uint32_t	rdb_BlockBytes;		/* Size of disk blocks */
211
    uint32_t	rdb_Flags;		/* RDB Flags */
212
    /* block list heads */
213
    uint32_t	rdb_BadBlockList;	/* Bad block list */
214
    uint32_t	rdb_PartitionList;	/* Partition list */
215
    uint32_t	rdb_FileSysHeaderList;	/* File system header list */
216
    uint32_t	rdb_DriveInit;		/* Drive specific init code */
217
    uint32_t	rdb_BootBlockList;	/* Amiga OS 4 Boot Blocks */
218
    uint32_t	rdb_Reserved1[5];	/* Unused word, need to be set to $ffffffff */
219
    /* physical drive characteristics */
220
    uint32_t	rdb_Cylinders;		/* Number of the cylinders of the drive */
221
    uint32_t	rdb_Sectors;		/* Number of sectors of the drive */
222
    uint32_t	rdb_Heads;		/* Number of heads of the drive */
223
    uint32_t	rdb_Interleave;		/* Interleave */
224
    uint32_t	rdb_Park;		/* Head parking cylinder */
225
    uint32_t	rdb_Reserved2[3];	/* Unused word, need to be set to $ffffffff */
226
    uint32_t	rdb_WritePreComp;	/* Starting cylinder of write precompensation */
227
    uint32_t	rdb_ReducedWrite;	/* Starting cylinder of reduced write current */
228
    uint32_t	rdb_StepRate;		/* Step rate of the drive */
229
    uint32_t	rdb_Reserved3[5];	/* Unused word, need to be set to $ffffffff */
230
    /* logical drive characteristics */
231
    uint32_t	rdb_RDBBlocksLo;	/* low block of range reserved for hardblocks */
232
    uint32_t	rdb_RDBBlocksHi;	/* high block of range for these hardblocks */
233
    uint32_t	rdb_LoCylinder;		/* low cylinder of partitionable disk area */
234
    uint32_t	rdb_HiCylinder;		/* high cylinder of partitionable data area */
235
    uint32_t	rdb_CylBlocks;		/* number of blocks available per cylinder */
236
    uint32_t	rdb_AutoParkSeconds;	/* zero for no auto park */
237
    uint32_t	rdb_HighRDSKBlock;	/* highest block used by RDSK */
238
					/* (not including replacement bad blocks) */
239
    uint32_t	rdb_Reserved4;
240
    /* drive identification */
241
    char	rdb_DiskVendor[8];
242
    char	rdb_DiskProduct[16];
243
    char	rdb_DiskRevision[4];
244
    char	rdb_ControllerVendor[8];
245
    char	rdb_ControllerProduct[16];
246
    char	rdb_ControllerRevision[4];
247
    uint32_t	rdb_Reserved5[10];
248
};
249
250
#define RDSK(pos) ((struct RigidDiskBlock *)(pos)) 
251
252
#define AMIGA_RDB_NOT_FOUND ((uint32_t)0xffffffff)
253
#define	RDB_LOCATION_LIMIT	16
254
#define AMIGA_MAX_PARTITIONS 128
255
#define MAX_RDB_BLOCK (RDB_LOCATION_LIMIT + 2 * AMIGA_MAX_PARTITIONS + 2)
256
257
static uint32_t
258
_amiga_find_rdb (PedDevice *dev, struct RigidDiskBlock *rdb) {
259
	int i;
260
	struct AmigaIds *ids;
261
262
	ids = _amiga_add_id (IDNAME_RIGIDDISK, NULL);
263
264
	for (i = 0; i<RDB_LOCATION_LIMIT; i++) {
265
		if (!_amiga_read_block (dev, AMIGA(rdb), i, ids)) {
266
			continue;
267
		}
268
		if (PED_BE32_TO_CPU (rdb->rdb_ID) == IDNAME_RIGIDDISK) {
269
			_amiga_free_ids (ids);
270
			return i;
271
		}
272
	}
273
	_amiga_free_ids (ids);
274
	return AMIGA_RDB_NOT_FOUND;
275
}
276
277
struct PartitionBlock {
278
    uint32_t	pb_ID;			/* Identifier 32 bit word : 'PART' */
279
    uint32_t	pb_SummedLongs;		/* Size of the structure for checksums */
280
    int32_t	pb_ChkSum;		/* Checksum of the structure */
281
    uint32_t	pb_HostID;		/* SCSI Target ID of host, not really used */
282
    uint32_t	pb_Next;		/* Block number of the next PartitionBlock */
283
    uint32_t	pb_Flags;		/* Part Flags (NOMOUNT and BOOTABLE) */
284
    uint32_t	pb_Reserved1[2];
285
    uint32_t	pb_DevFlags;		/* Preferred flags for OpenDevice */
286
    uint8_t	pb_DriveName[32];	/* Preferred DOS device name: BSTR form */
287
    uint32_t	pb_Reserved2[15];
288
    uint32_t	de_TableSize;		/* Size of Environment vector */
289
    uint32_t	de_SizeBlock;		/* Size of the blocks in 32 bit words, usually 128 */
290
    uint32_t	de_SecOrg;	     	/* Not used; must be 0 */
291
    uint32_t	de_Surfaces;		/* Number of heads (surfaces) */
292
    uint32_t	de_SectorPerBlock;	/* Disk sectors per block, used with SizeBlock, usually 1 */
293
    uint32_t	de_BlocksPerTrack;	/* Blocks per track. drive specific */
294
    uint32_t	de_Reserved;		/* DOS reserved blocks at start of partition. */
295
    uint32_t	de_PreAlloc;		/* DOS reserved blocks at end of partition */
296
    uint32_t	de_Interleave;		/* Not used, usually 0 */
297
    uint32_t	de_LowCyl;		/* First cylinder of the partition */
298
    uint32_t	de_HighCyl;		/* Last cylinder of the partition */
299
    uint32_t	de_NumBuffers;		/* Initial # DOS of buffers.  */
300
    uint32_t	de_BufMemType;		/* Type of mem to allocate for buffers */
301
    uint32_t	de_MaxTransfer;		/* Max number of bytes to transfer at a time */
302
    uint32_t	de_Mask;		/* Address Mask to block out certain memory */
303
    int32_t	de_BootPri;		/* Boot priority for autoboot */
304
    uint32_t	de_DosType;		/* Dostype of the filesystem */
305
    uint32_t	de_Baud;		/* Baud rate for serial handler */
306
    uint32_t	de_Control;		/* Control word for handler/filesystem */
307
    uint32_t	de_BootBlocks;		/* Number of blocks containing boot code */
308
    uint32_t	pb_EReserved[12];
309
};
310
311
#define PART(pos) ((struct PartitionBlock *)(pos))
312
313
#define	PBFB_BOOTABLE	0	/* this partition is intended to be bootable */
314
#define	PBFF_BOOTABLE	1L	/*   (expected directories and files exist) */
315
#define	PBFB_NOMOUNT	1	/* do not mount this partition (e.g. manually */
316
#define	PBFF_NOMOUNT	2L	/*   mounted, but space reserved here) */
317
318
319
struct LinkedBlock {
320
    uint32_t	lk_ID;			/* Identifier 32 bit word */
321
    uint32_t	lk_SummedLongs;		/* Size of the structure for checksums */
322
    int32_t	lk_ChkSum;		/* Checksum of the structure */
323
    uint32_t	pb_HostID;		/* SCSI Target ID of host, not really used */
324
    uint32_t	lk_Next;		/* Block number of the next PartitionBlock */
325
};
326
struct Linked2Block {
327
    uint32_t	lk2_ID;			/* Identifier 32 bit word */
328
    uint32_t	lk2_SummedLongs;		/* Size of the structure for checksums */
329
    int32_t	lk2_ChkSum;		/* Checksum of the structure */
330
    uint32_t	lk2_Next;		/* Block number of the next PartitionBlock */
331
    uint32_t	lk2_Reverved[13];
332
    uint32_t	lk2_Linked;		/* Secondary linked list */
333
};
334
#define LINK_END	0xffffffff
335
#define LNK(pos)	((struct LinkedBlock *)(pos))
336
#define LNK2(pos)	((struct Linked2Block *)(pos))
337
338
339
static PedDiskType amiga_disk_type;
340
341
static int
342
amiga_probe (PedDevice *dev)
343
{
344
	struct RigidDiskBlock *rdb;
345
	uint32_t found;
346
	PED_ASSERT(dev!= NULL, return 0);
347
348
	if ((rdb=RDSK(ped_malloc(PED_SECTOR_SIZE)))==NULL) {
349
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
350
			_("%s : Failed to allocate rdb block\n"), __func__);
351
		return 0;
352
	}
353
	found = _amiga_find_rdb (dev, rdb);
354
	ped_free (rdb);
355
356
	return (found == AMIGA_RDB_NOT_FOUND ? 0 : 1);
357
}
358
		
359
static PedDisk*
360
amiga_alloc (PedDevice* dev)
361
{
362
	PedDisk *disk;
363
	struct AmigaDisk *adsk;
364
	struct RigidDiskBlock *rdb;
365
	int highest_cylinder, highest_block;
366
	PED_ASSERT(dev!= NULL, return NULL);
367
368
	if (!(disk = _ped_disk_alloc (dev, &amiga_disk_type))) {
369
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
370
			_("%s : Failed to allocate disk structure\n"), __func__);
371
		return NULL;
372
	}
373
374
	if (!(disk->disk_specific = ped_malloc (PED_SECTOR_SIZE))) {
375
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
376
			_("%s : Failed to allocate disk_specific rdb block\n"), __func__);
377
		ped_free (disk);
378
		return NULL;
379
	}
380
	rdb = disk->disk_specific;
381
382
	memset(rdb, -1, sizeof(struct RigidDiskBlock));
383
384
	rdb->rdb_ID = PED_CPU_TO_BE32 (IDNAME_RIGIDDISK);
385
	rdb->rdb_SummedLongs = PED_CPU_TO_BE32 (64);
386
	rdb->rdb_HostID = PED_CPU_TO_BE32 (0);
387
	rdb->rdb_BlockBytes = PED_CPU_TO_BE32 (PED_SECTOR_SIZE);
388
	rdb->rdb_Flags = PED_CPU_TO_BE32 (0);
389
390
	/* Block lists */
391
	rdb->rdb_BadBlockList = PED_CPU_TO_BE32 (LINK_END);
392
	rdb->rdb_PartitionList = PED_CPU_TO_BE32 (LINK_END);
393
	rdb->rdb_FileSysHeaderList = PED_CPU_TO_BE32 (LINK_END);
394
	rdb->rdb_DriveInit = PED_CPU_TO_BE32 (LINK_END);
395
	rdb->rdb_BootBlockList = PED_CPU_TO_BE32 (LINK_END);
396
	
397
	/* Physical drive characteristics */
398
	rdb->rdb_Cylinders = PED_CPU_TO_BE32 (dev->cylinders);
399
	rdb->rdb_Sectors = PED_CPU_TO_BE32 (dev->sectors);
400
	rdb->rdb_Heads = PED_CPU_TO_BE32 (dev->heads);
401
	rdb->rdb_Interleave = PED_CPU_TO_BE32 (0);
402
	rdb->rdb_Park = PED_CPU_TO_BE32 (dev->cylinders);
403
	rdb->rdb_WritePreComp = PED_CPU_TO_BE32 (dev->cylinders);
404
	rdb->rdb_ReducedWrite = PED_CPU_TO_BE32 (dev->cylinders);
405
	rdb->rdb_StepRate = PED_CPU_TO_BE32 (0);
406
407
	highest_cylinder = MAX_RDB_BLOCK / (dev->sectors * dev->heads) + 1;
408
	highest_block = highest_cylinder * dev->sectors * dev->heads - 1;
409
410
	/* Logical driver characteristics */
411
	rdb->rdb_RDBBlocksLo = PED_CPU_TO_BE32 (0);
412
	rdb->rdb_RDBBlocksHi = PED_CPU_TO_BE32 (highest_block);
413
	rdb->rdb_LoCylinder = PED_CPU_TO_BE32 (highest_cylinder);
414
	rdb->rdb_HiCylinder = PED_CPU_TO_BE32 (dev->cylinders -1);
415
	rdb->rdb_CylBlocks = PED_CPU_TO_BE32 (dev->sectors * dev->heads);
416
	rdb->rdb_AutoParkSeconds = PED_CPU_TO_BE32 (0);
417
	/* rdb_HighRDSKBlock will only be set when writing */
418
	rdb->rdb_HighRDSKBlock = PED_CPU_TO_BE32 (0);
419
420
	/* Driver identification */
421
	_amiga_set_bstr("", rdb->rdb_DiskVendor, 8);
422
	_amiga_set_bstr(dev->model, rdb->rdb_DiskProduct, 16);
423
	_amiga_set_bstr("", rdb->rdb_DiskRevision, 4);
424
	_amiga_set_bstr("", rdb->rdb_ControllerVendor, 8);
425
	_amiga_set_bstr("", rdb->rdb_ControllerProduct, 16);
426
	_amiga_set_bstr("", rdb->rdb_ControllerRevision, 4);
427
428
	/* And calculate the checksum */
429
	_amiga_calculate_checksum ((struct AmigaBlock *) rdb);
430
	
431
	return disk;
432
}
433
434
static PedDisk*
435
amiga_duplicate (const PedDisk* disk)
436
{
437
	PedDisk*	new_disk;
438
	struct RigidDiskBlock *	new_rdb;
439
	struct RigidDiskBlock * old_rdb;
440
	PED_ASSERT(disk!= NULL, return NULL);
441
	PED_ASSERT(disk->dev!= NULL, return NULL);
442
	PED_ASSERT(disk->disk_specific!= NULL, return NULL);
443
444
	old_rdb = (struct RigidDiskBlock *) disk->disk_specific;
445
       
446
	if (!(new_disk = ped_disk_new_fresh (disk->dev, &amiga_disk_type))) {
447
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
448
			_("%s : Failed to allocate a new disk structure\n"), __func__);
449
		return NULL;
450
	}
451
452
	new_rdb = (struct RigidDiskBlock *) new_disk->disk_specific;
453
	memcpy (new_rdb, old_rdb, 256);
454
	return new_disk;
455
}
456
457
static void
458
amiga_free (PedDisk* disk)
459
{
460
	PED_ASSERT(disk!= NULL, return);
461
	PED_ASSERT(disk->disk_specific!= NULL, return);
462
463
	ped_free (disk->disk_specific);
464
	_ped_disk_free (disk);
465
}
466
467
#ifndef DISCOVER_ONLY
468
static int
469
amiga_clobber (PedDevice* dev)
470
{
471
	struct RigidDiskBlock *rdb;
472
	uint32_t i;
473
	int result = 0;
474
	PED_ASSERT(dev!= NULL, return 0);
475
476
	if ((rdb=RDSK(ped_malloc(PED_SECTOR_SIZE)))==NULL) {
477
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
478
			_("%s : Failed to allocate rdb block\n"), __func__);
479
		return 0;
480
	}
481
482
	while ((i = _amiga_find_rdb (dev, rdb)) != AMIGA_RDB_NOT_FOUND) {
483
		rdb->rdb_ID = PED_CPU_TO_BE32 (0);
484
		result = ped_device_write (dev, (void*) rdb, i, 1);
485
	}
486
487
	ped_free (rdb);
488
489
	return result;
490
}
491
#endif /* !DISCOVER_ONLY */
492
493
static int
494
_amiga_loop_check (uint32_t block, uint32_t * blocklist, uint32_t max)
495
{
496
	uint32_t i;
497
498
	for (i = 0; i < max; i++)
499
		if (block == blocklist[i]) {
500
			/* We are looping, let's stop.  */
501
			return 1;
502
		}
503
	blocklist[max] = block;
504
	return 0;
505
}
506
507
/* We have already allocated a rdb, we are now reading it from the disk */
508
static int
509
amiga_read (PedDisk* disk)
510
{
511
	struct RigidDiskBlock *rdb;
512
	struct PartitionBlock *partition;
513
	uint32_t partblock;
514
	uint32_t partlist[AMIGA_MAX_PARTITIONS];
515
	PedSector cylblocks;
516
	int i;
517
518
	PED_ASSERT(disk!= NULL, return 0);
519
	PED_ASSERT(disk->dev!= NULL, return 0);
520
	PED_ASSERT(disk->disk_specific!= NULL, return 0);
521
	rdb = RDSK(disk->disk_specific);
522
523
	if (_amiga_find_rdb (disk->dev, rdb) == AMIGA_RDB_NOT_FOUND) {
524
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
525
			_("%s : Didn't find rdb block, should never happen\n"), __func__);
526
		return 0;
527
	}
528
529
	/* Let's copy the rdb read geometry to the dev */
530
	disk->dev->cylinders = PED_BE32_TO_CPU (rdb->rdb_Cylinders);
531
	disk->dev->heads = PED_BE32_TO_CPU (rdb->rdb_Heads);
532
	disk->dev->sectors = PED_BE32_TO_CPU (rdb->rdb_Sectors);
533
	cylblocks = (PedSector) PED_BE32_TO_CPU (rdb->rdb_Heads) *
534
		(PedSector) PED_BE32_TO_CPU (rdb->rdb_Sectors);
535
536
	/* Remove all partitions in the former in memory table */
537
	ped_disk_delete_all (disk);
538
539
	/* Let's allocate a partition block */
540
	if (!(partition = ped_malloc (PED_SECTOR_SIZE))) {
541
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
542
			_("%s : Failed to allocate partition block\n"), __func__);
543
		return 0;
544
	}
545
546
	/* We initialize the hardblock free list to detect loops */
547
	for (i = 0; i < AMIGA_MAX_PARTITIONS; i++) partlist[i] = LINK_END;
548
549
	for (i = 1, partblock = PED_BE32_TO_CPU(rdb->rdb_PartitionList);
550
		i < AMIGA_MAX_PARTITIONS && partblock != LINK_END;
551
		i++, partblock = PED_BE32_TO_CPU(partition->pb_Next))
552
	{
553
		PedPartition *part;
554
		PedSector start, end;
555
		struct DosEnvec *de;
556
		PedConstraint *constraint_exact;
557
		int j; 
558
559
		/* Let's look for loops in the partition table */
560
		if (_amiga_loop_check(partblock, partlist, i)) {
561
			break;
562
		}
563
564
		/* Let's allocate and read a partition block to get its geometry*/
565
		if (!_amiga_read_block (disk->dev, AMIGA(partition), (PedSector)partblock, NULL)) {
566
			ped_free(partition);
567
			return 0;
568
		}
569
570
		start = ((PedSector) PED_BE32_TO_CPU (partition->de_LowCyl)) * cylblocks;
571
		end = ((((PedSector) PED_BE32_TO_CPU (partition->de_HighCyl))+1) * (cylblocks))-1;
572
573
		/* We can now construct a new partition */
574
		if (!(part = ped_partition_new (disk, 0, NULL, start, end))) {
575
			ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
576
				_("%s : Failed to allocate new partition (%llu -> %llu)\n"),
577
				__func__, start, end);
578
			ped_free(partition);
579
			return 0;
580
		}
581
		/* And copy over the partition block */
582
		memcpy(part->disk_specific, partition, 256);
583
584
		part->num = i;
585
		part->type = 0;
586
		/* Let's probe what filesystem is present on the disk */
587
		part->fs_type = ped_file_system_probe (&part->geom);
588
		
589
		constraint_exact = ped_constraint_exact (&part->geom);
590
		if (!ped_disk_add_partition (disk, part, constraint_exact)) {
591
			ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
592
				_("%s : Failed to add new partition\n"), __func__);
593
			ped_free(partition);
594
			return 0;
595
		}
596
		ped_constraint_destroy (constraint_exact);
597
	}
598
	return 1;
599
}
600
601
static int
602
_amiga_find_free_blocks(PedDisk *disk, uint32_t *table,
603
	struct LinkedBlock *block, uint32_t first, uint32_t type)
604
{
605
	PedSector next;
606
607
	PED_ASSERT(disk!= NULL, return 0);
608
	PED_ASSERT(disk->dev!= NULL, return 0);
609
610
	for (next = first; next != LINK_END; next = PED_BE32_TO_CPU(block->lk_Next)) {
611
		if (table[next] != IDNAME_FREE) {
612
			switch (ped_exception_throw(PED_EXCEPTION_ERROR,
613
				PED_EXCEPTION_FIX | PED_EXCEPTION_IGNORE | PED_EXCEPTION_CANCEL,
614
				_("%s : Loop detected at block %d\n"), __func__, next))
615
			{
616
				case PED_EXCEPTION_CANCEL :
617
					return 0;
618
				case PED_EXCEPTION_FIX :
619
					/* TODO : Need to add fixing code */
620
				case PED_EXCEPTION_IGNORE :
621
				case PED_EXCEPTION_UNHANDLED :
622
				default : 
623
					return 1;
624
			}
625
		}
626
627
		if (!_amiga_read_block (disk->dev, AMIGA(block), next, NULL)) {
628
			return 0;
629
		}
630
		if (PED_BE32_TO_CPU(block->lk_ID) != type) {
631
			switch (ped_exception_throw(PED_EXCEPTION_ERROR,
632
				PED_EXCEPTION_CANCEL,
633
				_("%s : The %s list seems bad at block %s\n"),
634
				__func__, _amiga_block_id(PED_BE32_TO_CPU(block->lk_ID)), next))
635
			{
636
				/* TODO : to more subtile things here */
637
				case PED_EXCEPTION_CANCEL :
638
				case PED_EXCEPTION_UNHANDLED :
639
				default : 
640
					return 0;
641
			}
642
		}
643
		table[next] = type;
644
		if (PED_BE32_TO_CPU(block->lk_ID) == IDNAME_FILESYSHEADER) {
645
			if (_amiga_find_free_blocks(disk, table, block,
646
				PED_BE32_TO_CPU(LNK2(block)->lk2_Linked),
647
				IDNAME_LOADSEG) == 0) return 0;
648
		}
649
	}
650
	return 1;
651
}
652
static uint32_t
653
_amiga_next_free_block(uint32_t *table, uint32_t start, uint32_t type) {
654
	int i;
655
656
	for (i = start; table[i] != type && table[i] != IDNAME_FREE; i++);
657
	return i;
658
}
659
static PedPartition *
660
_amiga_next_real_partition(PedDisk *disk, PedPartition *part) {
661
	PedPartition *next;
662
663
	for (next = ped_disk_next_partition (disk, part);
664
		next != NULL && !ped_partition_is_active (next);
665
		next = ped_disk_next_partition (disk, next));
666
	return next;
667
}
668
#ifndef DISCOVER_ONLY
669
static int
670
amiga_write (PedDisk* disk)
671
{
672
	struct RigidDiskBlock *rdb;
673
	struct LinkedBlock *block;
674
	struct PartitionBlock *partition;
675
	PedPartition *part, *next_part;
676
	PedSector cylblocks, first_hb, last_hb, last_used_hb;
677
	uint32_t * table;
678
	uint32_t i, rdb_block, max_part;
679
	uint32_t rdb_num, part_num, block_num, next_num;
680
681
	PED_ASSERT (disk != NULL, return 0;);
682
	PED_ASSERT (disk->dev != NULL, return 0;);
683
	PED_ASSERT (disk->disk_specific != NULL, return 0;);
684
685
	if (!(rdb = ped_malloc (PED_SECTOR_SIZE))) {
686
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
687
			_("%s : Failed to allocate rdb block\n"), __func__);
688
		return 0;
689
	}
690
	/* Let's read the rdb */
691
	if ((rdb_num = _amiga_find_rdb (disk->dev, rdb)) == AMIGA_RDB_NOT_FOUND) {
692
		rdb_num = 2;
693
	} else {
694
		memcpy (RDSK(disk->disk_specific), rdb, PED_SECTOR_SIZE);
695
	}
696
	ped_free (rdb);
697
	rdb = RDSK(disk->disk_specific);
698
699
	/* Let's copy the rdb read geometry to the dev */
700
	disk->dev->cylinders = PED_BE32_TO_CPU (rdb->rdb_Cylinders);
701
	disk->dev->heads = PED_BE32_TO_CPU (rdb->rdb_Heads);
702
	disk->dev->sectors = PED_BE32_TO_CPU (rdb->rdb_Sectors);
703
	cylblocks = (PedSector) PED_BE32_TO_CPU (rdb->rdb_Heads) *
704
		(PedSector) PED_BE32_TO_CPU (rdb->rdb_Sectors);
705
	first_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_RDBBlocksLo);
706
	last_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_RDBBlocksHi);
707
	last_used_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_HighRDSKBlock);
708
709
	/* let's allocate a free block table and initialize it */
710
	if (!(table = ped_malloc ((last_hb - first_hb + 1) * sizeof(uint32_t)))) {
711
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
712
			_("%s : Failed to allocate free block table\n"), __func__);
713
		return 0;
714
	}
715
	memset(table, 0xff, (last_hb - first_hb + 1) * sizeof(uint32_t));
716
	for (i = 0; i<=rdb_num; i++) table[i] = IDNAME_RIGIDDISK;
717
	
718
	/* Let's allocate a partition block */
719
	if (!(block = ped_malloc (PED_SECTOR_SIZE))) {
720
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
721
			_("%s : Failed to allocate partition block\n"), __func__);
722
		ped_free (table);
723
		return 0;
724
	}
725
726
	/* And fill the free block table */
727
	if (_amiga_find_free_blocks(disk, table, block,
728
		PED_BE32_TO_CPU (rdb->rdb_BadBlockList), IDNAME_BADBLOCK) == 0)
729
	{
730
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
731
			PED_EXCEPTION_CANCEL,
732
			_("%s : Failed to list badblocks\n"), __func__))
733
		{
734
			case PED_EXCEPTION_CANCEL :
735
			case PED_EXCEPTION_UNHANDLED :
736
			default : 
737
				ped_free (table);
738
				ped_free (block);
739
				return 0;
740
		}
741
	}
742
	if (_amiga_find_free_blocks(disk, table, block,
743
		PED_BE32_TO_CPU (rdb->rdb_PartitionList), IDNAME_PARTITION) == 0)
744
	{
745
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
746
			PED_EXCEPTION_CANCEL,
747
			_("%s : Failed to list partitionblocks\n"), __func__))
748
		{
749
			case PED_EXCEPTION_CANCEL :
750
			case PED_EXCEPTION_UNHANDLED :
751
			default : 
752
				ped_free (table);
753
				ped_free (block);
754
				return 0;
755
		}
756
	}
757
	if (_amiga_find_free_blocks(disk, table, block,
758
		PED_BE32_TO_CPU (rdb->rdb_FileSysHeaderList), IDNAME_FILESYSHEADER) == 0)
759
	{
760
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
761
			PED_EXCEPTION_CANCEL,
762
			_("%s : Failed to list filesystemblocks\n"), __func__))
763
		{
764
			case PED_EXCEPTION_CANCEL :
765
			case PED_EXCEPTION_UNHANDLED :
766
			default : 
767
				ped_free (table);
768
				ped_free (block);
769
				return 0;
770
		}
771
	}
772
	if (_amiga_find_free_blocks(disk, table, block,
773
		PED_BE32_TO_CPU (rdb->rdb_BootBlockList), IDNAME_BOOT) == 0)
774
	{
775
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
776
			PED_EXCEPTION_CANCEL,
777
			_("%s : Failed to list bootblocks\n"), __func__))
778
		{
779
			case PED_EXCEPTION_CANCEL :
780
			case PED_EXCEPTION_UNHANDLED :
781
			default : 
782
				ped_free (table);
783
				ped_free (block);
784
				return 0;
785
		}
786
	}
787
788
	block_num = next_num = part_num = _amiga_next_free_block(table, rdb_num+1, IDNAME_PARTITION);
789
	part = _amiga_next_real_partition(disk, NULL);
790
	if (part == NULL) {
791
		rdb->rdb_PartitionList = PED_CPU_TO_BE32(LINK_END);
792
	} else {
793
		rdb->rdb_PartitionList = PED_CPU_TO_BE32(part_num);
794
		while (part != NULL) {
795
			PED_ASSERT(part->disk_specific!=NULL, return 0);
796
			next_part = _amiga_next_real_partition(disk, part);
797
			block_num = next_num;
798
			next_num = _amiga_next_free_block(table, block_num+1, IDNAME_PARTITION);
799
			partition = PART(part->disk_specific);
800
			partition->pb_Next = next_part==NULL ? PED_CPU_TO_BE32(LINK_END):PED_CPU_TO_BE32(next_num);
801
			partition->de_LowCyl = PED_CPU_TO_BE32(part->geom.start/cylblocks);
802
			partition->de_HighCyl = PED_CPU_TO_BE32((part->geom.end+1)/cylblocks-1);
803
			_amiga_calculate_checksum(AMIGA(partition));
804
			if (!ped_device_write (disk->dev, (void*) partition, block_num, 1)) {
805
				switch (ped_exception_throw(PED_EXCEPTION_ERROR,
806
					PED_EXCEPTION_CANCEL,
807
					_("%s : Failed to write partition block at\n"), __func__, block_num))
808
				{
809
					case PED_EXCEPTION_CANCEL :
810
					case PED_EXCEPTION_UNHANDLED :
811
					default : 
812
						ped_free (table);
813
						ped_free (block);
814
						/* WARNING : If we fail here, we stop everything,
815
						 * and the partition table is lost. A Better
816
						 * solution should be found, using the second
817
						 * half of the hardblocks to not overwrite the
818
						 * old partition table. It becomes problematic
819
						 * if we use more than half of the hardblocks. */
820
						return 0;
821
				}
822
			}
823
			part = next_part;
824
		}
825
	}
826
	if (block_num >PED_BE32_TO_CPU (rdb->rdb_HighRDSKBlock)) {
827
		rdb->rdb_HighRDSKBlock = PED_CPU_TO_BE32(block_num);
828
	}
829
	_amiga_calculate_checksum(AMIGA(rdb));
830
	if (!ped_device_write (disk->dev, (void*) disk->disk_specific, rdb_num, 1)) {
831
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
832
			PED_EXCEPTION_CANCEL,
833
			_("%s : Failed to write rdb block at\n"), __func__, rdb_num))
834
		{
835
			case PED_EXCEPTION_CANCEL :
836
			case PED_EXCEPTION_UNHANDLED :
837
			default : 
838
				ped_free (table);
839
				ped_free (block);
840
				return 0;
841
		}
842
	}
843
			
844
	ped_free (table);
845
	ped_free (block);
846
	return ped_device_sync (disk->dev);
847
}
848
#endif /* !DISCOVER_ONLY */
849
850
static PedPartition*
851
amiga_partition_new (const PedDisk* disk, PedPartitionType part_type,
852
		   const PedFileSystemType* fs_type,
853
		   PedSector start, PedSector end)
854
{
855
	PedPartition *part;
856
	PedDevice *dev;
857
	PedSector cyl;
858
	struct PartitionBlock *partition;
859
	struct RigidDiskBlock *rdb;
860
861
	PED_ASSERT(disk!= NULL, return NULL);
862
	PED_ASSERT(disk->dev!= NULL, return NULL);
863
	PED_ASSERT(disk->disk_specific!= NULL, return NULL);
864
	dev = disk->dev;
865
	cyl = (PedSector) (dev->sectors * dev->heads);
866
	rdb = RDSK(disk->disk_specific);
867
868
	if (!(part = _ped_partition_alloc (disk, part_type, fs_type, start, end))) {
869
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
870
			_("%s : Failed to allocate a partition structure (%llu, %llu)"),
871
			__func__, start, end);
872
		return NULL;
873
	}
874
	
875
876
	if (ped_partition_is_active (part)) {
877
		if (!(part->disk_specific = ped_malloc (PED_SECTOR_SIZE))) {
878
			ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
879
				_("%s : Failed to allocate a partition disk_specific block\n"), __func__);
880
			ped_free (part);
881
			return NULL;
882
		}
883
		partition = PART(part->disk_specific);
884
		memset(partition, -1, sizeof(struct PartitionBlock));
885
886
		partition->pb_ID = PED_CPU_TO_BE32(IDNAME_PARTITION);
887
		partition->pb_SummedLongs = PED_CPU_TO_BE32(64);
888
		partition->pb_HostID = rdb->rdb_HostID;
889
		partition->pb_Flags = PED_CPU_TO_BE32(0);
890
		/* TODO : use a scheme including the device name and the
891
		 * partition number, if it is possible */
892
		_amiga_set_bstr("dhx", partition->pb_DriveName, 32);
893
894
		partition->de_TableSize = PED_CPU_TO_BE32(19);
895
		partition->de_SizeBlock = PED_CPU_TO_BE32(128);
896
		partition->de_SecOrg = PED_CPU_TO_BE32(0);
897
		partition->de_Surfaces = PED_CPU_TO_BE32(dev->heads);
898
		partition->de_SectorPerBlock = PED_CPU_TO_BE32(1);
899
		partition->de_BlocksPerTrack = PED_CPU_TO_BE32(dev->sectors);
900
		partition->de_Reserved = PED_CPU_TO_BE32(2);
901
		partition->de_PreAlloc = PED_CPU_TO_BE32(0);
902
		partition->de_Interleave = PED_CPU_TO_BE32(0);
903
		partition->de_LowCyl = PED_CPU_TO_BE32(start/cyl);
904
		partition->de_HighCyl = PED_CPU_TO_BE32((end+1)/cyl-1);
905
		partition->de_NumBuffers = PED_CPU_TO_BE32(30);
906
		partition->de_BufMemType = PED_CPU_TO_BE32(0);
907
		partition->de_MaxTransfer = PED_CPU_TO_BE32(0x7fffffff);
908
		partition->de_Mask = PED_CPU_TO_BE32(0xffffffff);
909
		partition->de_BootPri = PED_CPU_TO_BE32(0);
910
		partition->de_DosType = PED_CPU_TO_BE32(0x4c4e5800);
911
		partition->de_Baud = PED_CPU_TO_BE32(0);
912
		partition->de_Control = PED_CPU_TO_BE32(0);
913
		partition->de_BootBlocks = PED_CPU_TO_BE32(0);
914
915
	} else {
916
		part->disk_specific = NULL;
917
	}
918
	return part;
919
}
920
921
static PedPartition*
922
amiga_partition_duplicate (const PedPartition* part)
923
{
924
	PedPartition *new_part;
925
	struct PartitionBlock *new_amiga_part;
926
	struct PartitionBlock *old_amiga_part;
927
928
	PED_ASSERT(part!= NULL, return NULL);
929
	PED_ASSERT(part->disk!= NULL, return NULL);
930
	PED_ASSERT(part->disk_specific!= NULL, return NULL);
931
	old_amiga_part = (struct PartitionBlock *) part->disk_specific;
932
933
	new_part = ped_partition_new (part->disk, part->type,
934
				      part->fs_type, part->geom.start,
935
				      part->geom.end);
936
	if (!new_part) {
937
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
938
			_("%s : Failed to allocate a new partition structure\n"), __func__);
939
		return NULL;
940
	}
941
942
	new_amiga_part = (struct PartitionBlock *) new_part->disk_specific;
943
	memcpy (new_amiga_part, old_amiga_part, 256);
944
945
	return new_part;
946
}
947
948
static void
949
amiga_partition_destroy (PedPartition* part)
950
{
951
	PED_ASSERT (part != NULL, return);
952
953
	if (ped_partition_is_active (part)) {
954
		PED_ASSERT (part->disk_specific!= NULL, return);
955
		ped_free (part->disk_specific);
956
	}
957
	_ped_partition_free (part);
958
}
959
960
static int
961
amiga_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type)
962
{
963
	struct PartitionBlock *partition;
964
965
	PED_ASSERT (part != NULL, return 0);
966
	PED_ASSERT (part->disk_specific != NULL, return 0);
967
	partition = PART(part->disk_specific);
968
969
	part->fs_type = fs_type;
970
971
	if (!fs_type)
972
		partition->de_DosType = PED_CPU_TO_BE32(0x4c4e5800); /* 'LNX\0' */
973
	else if (!strcmp (fs_type->name, "ext2"))
974
		partition->de_DosType = PED_CPU_TO_BE32(0x4c4e5800); /* 'LNX\0' */
975
	else if (!strcmp (fs_type->name, "ext3"))
976
		partition->de_DosType = PED_CPU_TO_BE32(0x45585403); /* 'EXT\3' */
977
	else if (!strcmp (fs_type->name, "linux-swap"))
978
		partition->de_DosType = PED_CPU_TO_BE32(0x53575000); /* 'SWP\0' */
979
	else if (!strcmp (fs_type->name, "fat16"))
980
		partition->de_DosType = PED_CPU_TO_BE32(0x46415400); /* 'FAT\0' */
981
	else if (!strcmp (fs_type->name, "fat32"))
982
		partition->de_DosType = PED_CPU_TO_BE32(0x46415401); /* 'FAT\1'*/
983
	else if (!strcmp (fs_type->name, "hfs"))
984
		partition->de_DosType = PED_CPU_TO_BE32(0x48465300); /* 'HFS\0' */
985
	else if (!strcmp (fs_type->name, "jfs"))
986
		partition->de_DosType = PED_CPU_TO_BE32(0x4a465300); /* 'JFS\0' */
987
	else if (!strcmp (fs_type->name, "ntfs"))
988
		partition->de_DosType = PED_CPU_TO_BE32(0x4e544653); /* 'NTFS' */
989
	else if (!strcmp (fs_type->name, "reiserfs"))
990
		partition->de_DosType = PED_CPU_TO_BE32(0x52465300); /* 'RFS\0' */
991
	else if (!strcmp (fs_type->name, "sun-ufs"))
992
		partition->de_DosType = PED_CPU_TO_BE32(0x53554653); /* 'SUFS' */
993
	else if (!strcmp (fs_type->name, "hp-ufs"))
994
		partition->de_DosType = PED_CPU_TO_BE32(0x48554653); /* 'HUFS' */
995
	else if (!strcmp (fs_type->name, "xfs"))
996
		partition->de_DosType = PED_CPU_TO_BE32(0x58465300); /* 'XFS\0' */
997
	else
998
		partition->de_DosType = PED_CPU_TO_BE32(0x00000000); /* unknown */
999
	return 1;
1000
}
1001
1002
static int
1003
amiga_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
1004
{
1005
	struct PartitionBlock *partition;
1006
1007
	PED_ASSERT (part != NULL, return 0);
1008
	PED_ASSERT (part->disk_specific != NULL, return 0);
1009
1010
	partition = PART(part->disk_specific);
1011
1012
	switch (flag) {
1013
		case PED_PARTITION_BOOT:
1014
			if (state) partition->pb_Flags |= PED_CPU_TO_BE32(PBFF_BOOTABLE);
1015
			else partition->pb_Flags &= ~(PED_CPU_TO_BE32(PBFF_BOOTABLE));
1016
			return 1;
1017
		case PED_PARTITION_HIDDEN:
1018
			if (state) partition->pb_Flags |= PED_CPU_TO_BE32(PBFF_NOMOUNT);
1019
			else partition->pb_Flags &= ~(PED_CPU_TO_BE32(PBFF_NOMOUNT));
1020
			return 1;
1021
		default:
1022
			return 0;
1023
	}
1024
}
1025
1026
static int
1027
amiga_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
1028
{
1029
	struct PartitionBlock *partition;
1030
1031
	PED_ASSERT (part != NULL, return 0);
1032
	PED_ASSERT (part->disk_specific != NULL, return 0);
1033
1034
	partition = PART(part->disk_specific);
1035
1036
	switch (flag) {
1037
		case PED_PARTITION_BOOT:
1038
			return (partition->pb_Flags & PED_CPU_TO_BE32(PBFF_BOOTABLE));
1039
		case PED_PARTITION_HIDDEN:
1040
			return (partition->pb_Flags & PED_CPU_TO_BE32(PBFF_NOMOUNT));
1041
		default:
1042
			return 0;
1043
	}
1044
}
1045
1046
static int
1047
amiga_partition_is_flag_available (const PedPartition* part,
1048
				 PedPartitionFlag flag)
1049
{
1050
	switch (flag) {
1051
	case PED_PARTITION_BOOT:
1052
	case PED_PARTITION_HIDDEN:
1053
		return 1;
1054
	default:
1055
		return 0;
1056
	}
1057
}
1058
1059
static void             
1060
amiga_partition_set_name (PedPartition* part, const char* name)
1061
{               
1062
	struct PartitionBlock *partition;
1063
1064
	PED_ASSERT (part != NULL, return);
1065
	PED_ASSERT (part->disk_specific != NULL, return);
1066
1067
	partition = PART(part->disk_specific);
1068
	_amiga_set_bstr(name, partition->pb_DriveName, 32);
1069
}
1070
static const char*
1071
amiga_partition_get_name (const PedPartition* part)
1072
{
1073
	struct PartitionBlock *partition;
1074
1075
	PED_ASSERT (part != NULL, return 0);
1076
	PED_ASSERT (part->disk_specific != NULL, return 0);
1077
1078
	partition = PART(part->disk_specific);
1079
1080
	return _amiga_get_bstr(partition->pb_DriveName);
1081
}
1082
1083
static PedConstraint*
1084
_amiga_get_constraint (const PedDisk *disk)
1085
{
1086
	PedDevice *dev = disk->dev;
1087
	PedAlignment start_align, end_align;
1088
	PedGeometry max_geom;
1089
	struct RigidDiskBlock *rdb = RDSK(disk->disk_specific);
1090
	PedSector cyl = (PedSector) PED_BE32_TO_CPU(rdb->rdb_Sectors) *
1091
		PED_BE32_TO_CPU(rdb->rdb_Heads);
1092
	PedSector start = ((273 / cyl) + 1) * cyl;
1093
	PedSector length = dev->length - start;
1094
	PedSector max_part = (length / cyl) * cyl;
1095
1096
	if (!ped_alignment_init(&start_align, 0, cyl)) {
1097
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1098
			_("%s : Failed to initialize the start constraint\n"), __func__);
1099
		return NULL;
1100
	}
1101
	if (!ped_alignment_init(&end_align, -1, cyl)) {
1102
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1103
			_("%s : Failed to initialize the end constraint\n"), __func__);
1104
		return NULL;
1105
	}
1106
	if (!ped_geometry_init(&max_geom, dev, start, length)) {
1107
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1108
			_("%s : Failed to initialize the max constraint\n"), __func__);
1109
		return NULL;
1110
	}
1111
1112
	return ped_constraint_new (&start_align, &end_align,
1113
		&max_geom, &max_geom, cyl, max_part);
1114
}
1115
1116
static int
1117
amiga_partition_align (PedPartition* part, const PedConstraint* constraint)
1118
{
1119
1120
	PED_ASSERT (part != NULL, return 0);
1121
	PED_ASSERT (part->disk != NULL, return 0);
1122
	
1123
	if (_ped_partition_attempt_align (part, constraint,
1124
					  _amiga_get_constraint (part->disk)))
1125
	{
1126
	       	return 1;
1127
	}
1128
1129
#ifndef DISCOVER_ONLY
1130
	ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1131
		_("%s : Unable to satisfy all constraints on the partition."), __func__);
1132
#endif
1133
	return 0;
1134
}
1135
1136
static int
1137
amiga_partition_enumerate (PedPartition* part)
1138
{
1139
	
1140
	int i;
1141
	PedPartition* p;
1142
	
1143
	PED_ASSERT (part != NULL, return 0);
1144
	PED_ASSERT (part->disk != NULL, return 0);
1145
1146
	/* never change the partition numbers */
1147
	if (part->num != -1)
1148
		return 1;
1149
	for (i = 1; i <= AMIGA_MAX_PARTITIONS; i++) {
1150
		p = ped_disk_get_partition (part->disk, i);
1151
		if (!p) {
1152
			part->num = i;
1153
			return 1;
1154
		}
1155
	}
1156
1157
	/* failed to allocate a number */
1158
#ifndef DISCOVER_ONLY
1159
	ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1160
		_("%s : Unable to allocate a partition"), __func__);
1161
#endif
1162
	return 0;
1163
}
1164
1165
static int
1166
amiga_alloc_metadata (PedDisk* disk)
1167
{
1168
	PedPartition*		new_part;
1169
	PedConstraint*		constraint_any = NULL;
1170
	PedSector		highest_block;
1171
1172
	PED_ASSERT (disk != NULL, goto error);
1173
	PED_ASSERT (disk->dev != NULL, goto error);
1174
1175
	constraint_any = ped_constraint_any (disk->dev);
1176
1177
	/* Allocate space for the RDB */
1178
	new_part = ped_partition_new (disk, PED_PARTITION_METADATA, NULL, 0, MAX_RDB_BLOCK);
1179
	if (!new_part)
1180
		goto error;
1181
1182
	if (!ped_disk_add_partition (disk, new_part, constraint_any)) {
1183
		ped_partition_destroy (new_part);
1184
		goto error;
1185
	}
1186
1187
	ped_constraint_destroy (constraint_any);
1188
	return 1;
1189
error:
1190
	ped_constraint_destroy (constraint_any);
1191
	return 0;
1192
}
1193
1194
static int
1195
amiga_get_max_primary_partition_count (const PedDisk* disk)
1196
{
1197
	return AMIGA_MAX_PARTITIONS;
1198
}
1199
1200
static PedDiskOps amiga_disk_ops = {
1201
	probe:			amiga_probe,
1202
#ifndef DISCOVER_ONLY
1203
	clobber:		amiga_clobber,
1204
#else
1205
	clobber:		NULL,
1206
#endif
1207
	alloc:			amiga_alloc,
1208
	duplicate:		amiga_duplicate,
1209
	free:			amiga_free,
1210
	read:			amiga_read,
1211
#ifndef DISCOVER_ONLY
1212
	write:			amiga_write,
1213
#else
1214
	write:			NULL,
1215
#endif
1216
1217
	partition_new:		amiga_partition_new,
1218
	partition_duplicate:	amiga_partition_duplicate,
1219
	partition_destroy:	amiga_partition_destroy,
1220
	partition_set_system:	amiga_partition_set_system,
1221
	partition_set_flag:	amiga_partition_set_flag,
1222
	partition_get_flag:	amiga_partition_get_flag,
1223
	partition_is_flag_available:
1224
				amiga_partition_is_flag_available,
1225
	partition_set_name:	amiga_partition_set_name,
1226
	partition_get_name:	amiga_partition_get_name,
1227
	partition_align:	amiga_partition_align,
1228
	partition_enumerate:	amiga_partition_enumerate,
1229
1230
1231
	alloc_metadata:		amiga_alloc_metadata,
1232
	get_max_primary_partition_count:
1233
				amiga_get_max_primary_partition_count
1234
};
1235
1236
static PedDiskType amiga_disk_type = {
1237
	next:		NULL,
1238
	name:		"amiga",
1239
	ops:		&amiga_disk_ops,
1240
	features:	PED_DISK_TYPE_PARTITION_NAME
1241
};
1242
1243
void
1244
ped_disk_amiga_init ()
1245
{
1246
	PED_ASSERT(sizeof(struct AmigaBlock) != 3, return);
1247
	PED_ASSERT(sizeof(struct RigidDiskBlock) != 64, return);
1248
	PED_ASSERT(sizeof(struct PartitionBlock) != 64, return);
1249
	PED_ASSERT(sizeof(struct LinkedBlock) != 5, return);
1250
	PED_ASSERT(sizeof(struct Linked2Block) != 18, return);
1251
1252
	ped_register_disk_type (&amiga_disk_type);
1253
}
1254
1255
void
1256
ped_disk_amiga_done ()
1257
{
1258
1259
	ped_unregister_disk_type (&amiga_disk_type);
1260
}
(-)parted-1.6.6/libparted/disk_amiga.c.2 (+1524 lines)
Line 0 Link Here
1
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2
3
    libparted - a library for manipulating disk partitions
4
    Copyright (C) 2000, 2001 Free Software Foundation, Inc.
5
6
    This program is free software; you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
10
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
16
    You should have received a copy of the GNU General Public License
17
    along with this program; if not, write to the Free Software
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20
    Contributor:  Sven Luther <luther@debian.org>
21
*/
22
23
#include "config.h"
24
25
#include <string.h>
26
27
#include <parted/parted.h>
28
#include <parted/debug.h>
29
#include <parted/endian.h>
30
31
#if ENABLE_NLS
32
#  include <libintl.h>
33
#  define _(String) dgettext (PACKAGE, String)
34
#else
35
#  define _(String) (String)
36
#endif /* ENABLE_NLS */
37
38
#define DEBUG_BLOCK	0x01
39
#define DEBUG_CONST	0x02
40
#define DEBUG_FUNCS	0x04
41
#define DEBUG_ERROR	0x08
42
#define DEBUG_READ	0X10
43
#define DEBUG_WRITE	0X20
44
#if 0
45
#define MASTER_DEBUG DEBUG_BLOCK | DEBUG_CONST | DEBUG_FUNCS | DEBUG_ERROR | DEBUG_READ | DEBUG_WRITE
46
#endif
47
48
#ifdef MASTER_DEBUG
49
#define DPRINT(l,a,b...) do { if ((l) & (MASTER_DEBUG)) fprintf(stderr, "AMIGA : %s: " a, __func__ , ## b); } while (0) 
50
#define DPRINTF(l,a,b...) do { if ((l) & (MASTER_DEBUG)) fprintf(stderr, a, ## b); } while (0) 
51
#define TRACE() DPRINT(DEBUG_FUNCS, "\n")
52
#else 
53
#define DPRINT(l,a,b...)
54
#define DPRINTF(l,a,b...)
55
#define TRACE()
56
#endif /* MASTER_DEBUG */
57
58
/* String manipulation */
59
static void _amiga_set_bstr (const char *cstr, char *bstr, int maxsize) {
60
	int size = strlen (cstr);
61
	int i;
62
	TRACE();
63
64
	if (size >= maxsize) return;
65
	bstr[0] = size;
66
	for (i = 0; i<size; i++) bstr[i+1] = cstr[i];
67
}
68
static const char * _amiga_get_bstr (char * bstr) {
69
	char * cstr = bstr + 1;
70
	int size = bstr[0];
71
	TRACE();
72
	
73
	cstr[size] = '\0';
74
	return cstr;
75
}
76
77
#define	IDNAME_RIGIDDISK	0x5244534B	/* 'RDSK' */
78
#define IDNAME_BADBLOCK		0x42414442	/* 'BADB' */
79
#define	IDNAME_PARTITION	0x50415254	/* 'PART' */
80
#define IDNAME_FILESYSHEADER	0x46534844	/* 'FSHD' */
81
#define IDNAME_LOADSEG		0x4C534547	/* 'LSEG' */
82
#define IDNAME_BOOT		0x424f4f54	/* 'BOOT' */
83
#define IDNAME_FREE		0xffffffff	
84
85
static const char *
86
_amiga_block_id (uint32_t id) {
87
	TRACE();
88
	switch (id) {
89
		case IDNAME_RIGIDDISK :
90
			return "RDSK";
91
		case IDNAME_BADBLOCK :
92
			return "BADB";
93
		case IDNAME_PARTITION :
94
			return "PART";
95
		case IDNAME_FILESYSHEADER :
96
			return "FSHD";
97
		case IDNAME_LOADSEG :
98
			return "LSEG";
99
		case IDNAME_BOOT :
100
			return "BOOT";
101
		case IDNAME_FREE :
102
			return "<free>";
103
		default :
104
			return "<unknown>";
105
	}
106
}
107
static int
108
_amiga_valid_block_id (uint32_t id) {
109
	TRACE();
110
	switch (id) {
111
		case IDNAME_RIGIDDISK :
112
		case IDNAME_BADBLOCK :
113
		case IDNAME_PARTITION :
114
		case IDNAME_FILESYSHEADER :
115
		case IDNAME_LOADSEG :
116
		case IDNAME_BOOT :
117
			return 1;
118
		case IDNAME_FREE :
119
		default :
120
			return 0;
121
	}
122
}
123
struct AmigaBlock {
124
    uint32_t	amiga_ID;		/* Identifier 32 bit word */
125
    uint32_t	amiga_SummedLongss;	/* Size of the structure for checksums */
126
    int32_t	amiga_ChkSum;		/* Checksum of the structure */
127
};
128
#define AMIGA(pos) ((struct AmigaBlock *)(pos)) 
129
130
static int
131
_amiga_checksum (struct AmigaBlock *blk) {
132
	uint32_t *rdb = (uint32_t *) blk;
133
	uint32_t sum;
134
	int i, end;
135
	TRACE();
136
137
	sum = PED_BE32_TO_CPU (rdb[0]);
138
	end = PED_BE32_TO_CPU (rdb[1]);
139
140
	if (end > PED_SECTOR_SIZE) end = PED_SECTOR_SIZE;
141
142
	for (i = 1; i < end; i++) sum += PED_BE32_TO_CPU (rdb[i]);
143
144
	return sum;
145
}
146
147
static void
148
_amiga_calculate_checksum (struct AmigaBlock *blk) {
149
	TRACE();
150
	blk->amiga_ChkSum = PED_CPU_TO_BE32(
151
		PED_BE32_TO_CPU(blk->amiga_ChkSum) -
152
		_amiga_checksum((struct AmigaBlock *) blk));
153
	return;	
154
}
155
156
static struct AmigaBlock *
157
_amiga_read_block (PedDevice *dev, struct AmigaBlock *blk, PedSector block) {
158
	if (!ped_device_read (dev, blk, block, 1)) {
159
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
160
			PED_EXCEPTION_CANCEL,
161
			_("%s : Couldn't read block %llu\n"), __func__, block))
162
		{
163
			case PED_EXCEPTION_CANCEL :
164
			case PED_EXCEPTION_UNHANDLED :
165
			default : 
166
				return NULL;
167
		}
168
	}
169
	if (_amiga_checksum (blk) != 0) {
170
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
171
			PED_EXCEPTION_FIX | PED_EXCEPTION_IGNORE | PED_EXCEPTION_CANCEL,
172
			_("%s : Bad checksum on block %llu of type %s\n"),
173
			__func__, block, _amiga_block_id(PED_BE32_TO_CPU(blk->amiga_ID))))
174
		{
175
			case PED_EXCEPTION_CANCEL :
176
				return NULL;
177
			case PED_EXCEPTION_FIX :
178
				_amiga_calculate_checksum(AMIGA(blk));
179
				if (!ped_device_write (dev, blk, block, 1)) {
180
					switch (ped_exception_throw(PED_EXCEPTION_FATAL,
181
						PED_EXCEPTION_CANCEL,
182
						_("%s : Couldn't write block %d\n"), __func__, block))
183
					{
184
						case PED_EXCEPTION_CANCEL :
185
						case PED_EXCEPTION_UNHANDLED :
186
						default : 
187
							return NULL;
188
					}
189
				}
190
			case PED_EXCEPTION_IGNORE :
191
			case PED_EXCEPTION_UNHANDLED :
192
			default : 
193
				return blk;
194
		}
195
	}
196
	return blk;
197
}
198
199
struct RigidDiskBlock {
200
    uint32_t	rdb_ID;			/* Identifier 32 bit word : 'RDSK' */
201
    uint32_t	rdb_SummedLongs;	/* Size of the structure for checksums */
202
    int32_t	rdb_ChkSum;		/* Checksum of the structure */
203
    uint32_t	rdb_HostID;		/* SCSI Target ID of host, not really used */
204
    uint32_t	rdb_BlockBytes;		/* Size of disk blocks */
205
    uint32_t	rdb_Flags;		/* RDB Flags */
206
    /* block list heads */
207
    uint32_t	rdb_BadBlockList;	/* Bad block list */
208
    uint32_t	rdb_PartitionList;	/* Partition list */
209
    uint32_t	rdb_FileSysHeaderList;	/* File system header list */
210
    uint32_t	rdb_DriveInit;		/* Drive specific init code */
211
    uint32_t	rdb_BootBlockList;	/* Amiga OS 4 Boot Blocks */
212
    uint32_t	rdb_Reserved1[5];	/* Unused word, need to be set to $ffffffff */
213
    /* physical drive characteristics */
214
    uint32_t	rdb_Cylinders;		/* Number of the cylinders of the drive */
215
    uint32_t	rdb_Sectors;		/* Number of sectors of the drive */
216
    uint32_t	rdb_Heads;		/* Number of heads of the drive */
217
    uint32_t	rdb_Interleave;		/* Interleave */
218
    uint32_t	rdb_Park;		/* Head parking cylinder */
219
    uint32_t	rdb_Reserved2[3];	/* Unused word, need to be set to $ffffffff */
220
    uint32_t	rdb_WritePreComp;	/* Starting cylinder of write precompensation */
221
    uint32_t	rdb_ReducedWrite;	/* Starting cylinder of reduced write current */
222
    uint32_t	rdb_StepRate;		/* Step rate of the drive */
223
    uint32_t	rdb_Reserved3[5];	/* Unused word, need to be set to $ffffffff */
224
    /* logical drive characteristics */
225
    uint32_t	rdb_RDBBlocksLo;	/* low block of range reserved for hardblocks */
226
    uint32_t	rdb_RDBBlocksHi;	/* high block of range for these hardblocks */
227
    uint32_t	rdb_LoCylinder;		/* low cylinder of partitionable disk area */
228
    uint32_t	rdb_HiCylinder;		/* high cylinder of partitionable data area */
229
    uint32_t	rdb_CylBlocks;		/* number of blocks available per cylinder */
230
    uint32_t	rdb_AutoParkSeconds;	/* zero for no auto park */
231
    uint32_t	rdb_HighRDSKBlock;	/* highest block used by RDSK */
232
					/* (not including replacement bad blocks) */
233
    uint32_t	rdb_Reserved4;
234
    /* drive identification */
235
    char	rdb_DiskVendor[8];
236
    char	rdb_DiskProduct[16];
237
    char	rdb_DiskRevision[4];
238
    char	rdb_ControllerVendor[8];
239
    char	rdb_ControllerProduct[16];
240
    char	rdb_ControllerRevision[4];
241
    uint32_t	rdb_Reserved5[10];
242
};
243
244
#define	RDB_LOCATION_LIMIT	16
245
#define RDSK(pos) ((struct RigidDiskBlock *)(pos)) 
246
247
/* TODO : print drive ident strings */
248
void _amiga_dump_rdb (struct RigidDiskBlock * rdb) {
249
	TRACE();
250
	DPRINT(DEBUG_BLOCK, "RigidDiskBlock\n\trgb_ID = %08x %s\n",
251
		PED_BE32_TO_CPU(rdb->rdb_ID),
252
		(PED_BE32_TO_CPU(rdb->rdb_ID)==IDNAME_RIGIDDISK ? "RDSK" : ""));
253
	DPRINT(DEBUG_BLOCK, "\trdb_SummedLongs = %08x\n",
254
		PED_BE32_TO_CPU(rdb->rdb_SummedLongs));
255
	DPRINT(DEBUG_BLOCK, "\trdb_ChkSum = %08x (block checksum is %d)\n",
256
		PED_BE32_TO_CPU(rdb->rdb_ChkSum), _amiga_checksum (AMIGA(rdb)));
257
	DPRINT(DEBUG_BLOCK, "\trdb_HostID = %08x\n", PED_BE32_TO_CPU(rdb->rdb_HostID));
258
	DPRINT(DEBUG_BLOCK, "\trdb_BlockBytes = %08x\n", PED_BE32_TO_CPU(rdb->rdb_BlockBytes));
259
	DPRINT(DEBUG_BLOCK, "\trdb_Flags = %08x\n", PED_BE32_TO_CPU(rdb->rdb_Flags));
260
	DPRINT(DEBUG_BLOCK, "\trdb_BadBlockList = %08x\n", PED_BE32_TO_CPU(rdb->rdb_BadBlockList));
261
	DPRINT(DEBUG_BLOCK, "\trdb_PartitionList = %08x\n", PED_BE32_TO_CPU(rdb->rdb_PartitionList));
262
	DPRINT(DEBUG_BLOCK, "\trdb_FileSysHeaderList = %08x\n", PED_BE32_TO_CPU(rdb->rdb_FileSysHeaderList));
263
	DPRINT(DEBUG_BLOCK, "\trdb_DriveInit = %08x\n", PED_BE32_TO_CPU(rdb->rdb_DriveInit));
264
	DPRINT(DEBUG_BLOCK, "\trdb_BootBlockList = %08x\n", PED_BE32_TO_CPU(rdb->rdb_BootBlockList));
265
	DPRINT(DEBUG_BLOCK, "\trdb_Cylinders = %08x\n", PED_BE32_TO_CPU(rdb->rdb_Cylinders));
266
	DPRINT(DEBUG_BLOCK, "\trdb_Sectors = %08x\n", PED_BE32_TO_CPU(rdb->rdb_Sectors));
267
	DPRINT(DEBUG_BLOCK, "\trdb_Heads = %08x\n", PED_BE32_TO_CPU(rdb->rdb_Heads));
268
	DPRINT(DEBUG_BLOCK, "\trdb_Interleave = %08x\n", PED_BE32_TO_CPU(rdb->rdb_Interleave));
269
	DPRINT(DEBUG_BLOCK, "\trdb_Park = %08x\n", PED_BE32_TO_CPU(rdb->rdb_Park));
270
	DPRINT(DEBUG_BLOCK, "\trdb_WritePreComp = %08x\n", PED_BE32_TO_CPU(rdb->rdb_WritePreComp));
271
	DPRINT(DEBUG_BLOCK, "\trdb_ReducedWrite = %08x\n", PED_BE32_TO_CPU(rdb->rdb_ReducedWrite));
272
	DPRINT(DEBUG_BLOCK, "\trdb_StepRate = %08x\n", PED_BE32_TO_CPU(rdb->rdb_StepRate));
273
	DPRINT(DEBUG_BLOCK, "\trdb_RDBBlocksLo = %u\n", PED_BE32_TO_CPU(rdb->rdb_RDBBlocksLo));
274
	DPRINT(DEBUG_BLOCK, "\trdb_RDBBlocksHi = %u\n", PED_BE32_TO_CPU(rdb->rdb_RDBBlocksHi));
275
	DPRINT(DEBUG_BLOCK, "\trdb_LoCylinder = %u\n", PED_BE32_TO_CPU(rdb->rdb_LoCylinder));
276
	DPRINT(DEBUG_BLOCK, "\trdb_HiCylinder = %u\n", PED_BE32_TO_CPU(rdb->rdb_HiCylinder));
277
	DPRINT(DEBUG_BLOCK, "\trdb_CylBlocks = %u (Heads*Sectors = %u\n",
278
		PED_BE32_TO_CPU(rdb->rdb_CylBlocks),
279
		PED_BE32_TO_CPU(rdb->rdb_Sectors)*PED_BE32_TO_CPU(rdb->rdb_Heads));
280
	DPRINT(DEBUG_BLOCK, "\trdb_AutoParkSeconds = %08x\n", PED_BE32_TO_CPU(rdb->rdb_AutoParkSeconds));
281
	DPRINT(DEBUG_BLOCK, "\trdb_HighRDSKBlock = %08x\n", PED_BE32_TO_CPU(rdb->rdb_HighRDSKBlock));
282
}
283
284
#define AMIGA_RDB_NOT_FOUND ((uint32_t)0xffffffff)
285
286
static uint32_t
287
_amiga_find_rdb (PedDevice *dev, struct RigidDiskBlock *rdb) {
288
	int i;
289
	TRACE();
290
291
	for (i = 0; i<RDB_LOCATION_LIMIT; i++) {
292
		if (!_amiga_read_block (dev, AMIGA(rdb), i)) {
293
			continue;
294
		}
295
		if (PED_BE32_TO_CPU (rdb->rdb_ID) == IDNAME_RIGIDDISK) {
296
			return i;
297
		}
298
	}
299
	return AMIGA_RDB_NOT_FOUND;
300
}
301
302
struct PartitionBlock {
303
    uint32_t	pb_ID;			/* Identifier 32 bit word : 'PART' */
304
    uint32_t	pb_SummedLongs;		/* Size of the structure for checksums */
305
    int32_t	pb_ChkSum;		/* Checksum of the structure */
306
    uint32_t	pb_HostID;		/* SCSI Target ID of host, not really used */
307
    uint32_t	pb_Next;		/* Block number of the next PartitionBlock */
308
    uint32_t	pb_Flags;		/* Part Flags (NOMOUNT and BOOTABLE) */
309
    uint32_t	pb_Reserved1[2];
310
    uint32_t	pb_DevFlags;		/* Preferred flags for OpenDevice */
311
    uint8_t	pb_DriveName[32];	/* Preferred DOS device name: BSTR form */
312
    uint32_t	pb_Reserved2[15];
313
    uint32_t	de_TableSize;		/* Size of Environment vector */
314
    uint32_t	de_SizeBlock;		/* Size of the blocks in 32 bit words, usually 128 */
315
    uint32_t	de_SecOrg;	     	/* Not used; must be 0 */
316
    uint32_t	de_Surfaces;		/* Number of heads (surfaces) */
317
    uint32_t	de_SectorPerBlock;	/* Disk sectors per block, used with SizeBlock, usually 1 */
318
    uint32_t	de_BlocksPerTrack;	/* Blocks per track. drive specific */
319
    uint32_t	de_Reserved;		/* DOS reserved blocks at start of partition. */
320
    uint32_t	de_PreAlloc;		/* DOS reserved blocks at end of partition */
321
    uint32_t	de_Interleave;		/* Not used, usually 0 */
322
    uint32_t	de_LowCyl;		/* First cylinder of the partition */
323
    uint32_t	de_HighCyl;		/* Last cylinder of the partition */
324
    uint32_t	de_NumBuffers;		/* Initial # DOS of buffers.  */
325
    uint32_t	de_BufMemType;		/* Type of mem to allocate for buffers */
326
    uint32_t	de_MaxTransfer;		/* Max number of bytes to transfer at a time */
327
    uint32_t	de_Mask;		/* Address Mask to block out certain memory */
328
    int32_t	de_BootPri;		/* Boot priority for autoboot */
329
    uint32_t	de_DosType;		/* Dostype of the filesystem */
330
    uint32_t	de_Baud;		/* Baud rate for serial handler */
331
    uint32_t	de_Control;		/* Control word for handler/filesystem */
332
    uint32_t	de_BootBlocks;		/* Number of blocks containing boot code */
333
    uint32_t	pb_EReserved[12];
334
};
335
336
#define PART(pos) ((struct PartitionBlock *)(pos))
337
338
#define	PBFB_BOOTABLE	0	/* this partition is intended to be bootable */
339
#define	PBFF_BOOTABLE	1L	/*   (expected directories and files exist) */
340
#define	PBFB_NOMOUNT	1	/* do not mount this partition (e.g. manually */
341
#define	PBFF_NOMOUNT	2L	/*   mounted, but space reserved here) */
342
343
void _amiga_dump_part (struct PartitionBlock * part) {
344
	TRACE();
345
	DPRINT(DEBUG_BLOCK, "Partition : cylinder %d to %d, blocksize : %d (in bytes)\n",
346
		PED_BE32_TO_CPU(part->de_LowCyl),
347
		PED_BE32_TO_CPU(part->de_HighCyl),
348
		PED_BE32_TO_CPU(part->de_SizeBlock)*4*PED_BE32_TO_CPU(part->de_SectorPerBlock));
349
	DPRINT(DEBUG_BLOCK, "\tdostype : %08x, reserved : %d, prealloc : %d\n",
350
		PED_BE32_TO_CPU(part->de_DosType),
351
		PED_BE32_TO_CPU(part->de_Reserved),
352
		PED_BE32_TO_CPU(part->de_PreAlloc));
353
	DPRINT(DEBUG_BLOCK, "PartitionBlock\n");
354
	DPRINT(DEBUG_BLOCK, "\tpart_ID = %08x %s\n", PED_BE32_TO_CPU(part->pb_ID),
355
		(PED_BE32_TO_CPU(part->pb_ID)==IDNAME_PARTITION ? "PART" : ""));
356
	DPRINT(DEBUG_BLOCK, "\tpart_SummedLongs = %08x\n",
357
		PED_BE32_TO_CPU(part->pb_SummedLongs));
358
	DPRINT(DEBUG_BLOCK, "\tpart_ChkSum = %08x (block checksum is %d)\n",
359
		PED_BE32_TO_CPU(part->pb_ChkSum), _amiga_checksum (AMIGA(part)));
360
	DPRINT(DEBUG_BLOCK, "\tpart_HostID = %08x\n", PED_BE32_TO_CPU(part->pb_HostID));
361
	DPRINT(DEBUG_BLOCK, "\tpart_Next = %08x (%d)\n",
362
		PED_BE32_TO_CPU(part->pb_Next), PED_BE32_TO_CPU(part->pb_Next));
363
	DPRINT(DEBUG_BLOCK, "\tpart_Flags = %08x\n", PED_BE32_TO_CPU(part->pb_Flags));
364
	DPRINT(DEBUG_BLOCK, "\tpart_DevFlags = %08x\n", PED_BE32_TO_CPU(part->pb_DevFlags));
365
	DPRINT(DEBUG_BLOCK, "\tpart_DriveName = %s\n", _amiga_get_bstr(part->pb_DriveName));
366
	DPRINT(DEBUG_BLOCK, "\tde_TableSize = %08x\n", PED_BE32_TO_CPU(part->de_TableSize));
367
	DPRINT(DEBUG_BLOCK, "\tde_SizeBlock = %08x\n", PED_BE32_TO_CPU(part->de_SizeBlock));
368
	DPRINT(DEBUG_BLOCK, "\tde_SecOrg = %08x\n", PED_BE32_TO_CPU(part->de_SecOrg));
369
	DPRINT(DEBUG_BLOCK, "\tde_Surfaces = %08x\n", PED_BE32_TO_CPU(part->de_Surfaces));
370
	DPRINT(DEBUG_BLOCK, "\tde_SectorPerBlock = %08x\n", PED_BE32_TO_CPU(part->de_SectorPerBlock));
371
	DPRINT(DEBUG_BLOCK, "\tde_BlocksPerTrack = %08x\n", PED_BE32_TO_CPU(part->de_BlocksPerTrack));
372
	DPRINT(DEBUG_BLOCK, "\tde_Reserved = %08x\n", PED_BE32_TO_CPU(part->de_Reserved));
373
	DPRINT(DEBUG_BLOCK, "\tde_PreAlloc = %08x\n", PED_BE32_TO_CPU(part->de_PreAlloc));
374
	DPRINT(DEBUG_BLOCK, "\tde_Interleave = %08x\n", PED_BE32_TO_CPU(part->de_Interleave));
375
	DPRINT(DEBUG_BLOCK, "\tde_LowCyl = %08x\n", PED_BE32_TO_CPU(part->de_LowCyl));
376
	DPRINT(DEBUG_BLOCK, "\tde_HighCyl = %08x\n", PED_BE32_TO_CPU(part->de_HighCyl));
377
	DPRINT(DEBUG_BLOCK, "\tde_NumBuffers = %08x\n", PED_BE32_TO_CPU(part->de_NumBuffers));
378
	DPRINT(DEBUG_BLOCK, "\tde_BufMemType = %08x\n", PED_BE32_TO_CPU(part->de_BufMemType));
379
	DPRINT(DEBUG_BLOCK, "\tde_MaxTransfer = %08x\n", PED_BE32_TO_CPU(part->de_MaxTransfer));
380
	DPRINT(DEBUG_BLOCK, "\tde_Mask = %08x\n", PED_BE32_TO_CPU(part->de_Mask));
381
	DPRINT(DEBUG_BLOCK, "\tde_BootPri = %08x\n", PED_BE32_TO_CPU(part->de_BootPri));
382
	DPRINT(DEBUG_BLOCK, "\tde_DosType = %08x\n", PED_BE32_TO_CPU(part->de_DosType));
383
	DPRINT(DEBUG_BLOCK, "\tde_Baud = %08x\n", PED_BE32_TO_CPU(part->de_Baud));
384
	DPRINT(DEBUG_BLOCK, "\tde_Control = %08x\n", PED_BE32_TO_CPU(part->de_Control));
385
	DPRINT(DEBUG_BLOCK, "\tde_BootBlocks = %08x\n", PED_BE32_TO_CPU(part->de_BootBlocks));
386
}
387
388
#define AMIGA_MAX_PARTITIONS 128
389
390
struct LinkedBlock {
391
    uint32_t	lk_ID;			/* Identifier 32 bit word */
392
    uint32_t	lk_SummedLongs;		/* Size of the structure for checksums */
393
    int32_t	lk_ChkSum;		/* Checksum of the structure */
394
    uint32_t	pb_HostID;		/* SCSI Target ID of host, not really used */
395
    uint32_t	lk_Next;		/* Block number of the next PartitionBlock */
396
};
397
struct Linked2Block {
398
    uint32_t	lk2_ID;			/* Identifier 32 bit word */
399
    uint32_t	lk2_SummedLongs;		/* Size of the structure for checksums */
400
    int32_t	lk2_ChkSum;		/* Checksum of the structure */
401
    uint32_t	lk2_Next;		/* Block number of the next PartitionBlock */
402
    uint32_t	lk2_Reverved[13];
403
    uint32_t	lk2_Linked;		/* Secondary linked list */
404
};
405
#define LINK_END	0xffffffff
406
#define LNK(pos)	((struct LinkedBlock *)(pos))
407
#define LNK2(pos)	((struct Linked2Block *)(pos))
408
409
void _amiga_dump_linked (struct LinkedBlock * block) {
410
	TRACE();
411
	DPRINT(DEBUG_BLOCK, "LinkedBlock\n\tpart_ID = %08x %s\n",
412
		PED_BE32_TO_CPU(block->lk_ID),
413
		_amiga_block_id(PED_BE32_TO_CPU(block->lk_ID)));
414
	DPRINT(DEBUG_BLOCK, "\tlk_SummedLongs = %08x\n",
415
			PED_BE32_TO_CPU(block->lk_SummedLongs));
416
	DPRINT(DEBUG_BLOCK, "\tlk_ChkSum = %08x (block checksum is %d)\n",
417
		block->lk_ChkSum, _amiga_checksum (AMIGA(block)));
418
	DPRINT(DEBUG_BLOCK, "\tlk_Next = %08x (%d)\n",
419
		PED_BE32_TO_CPU(block->lk_Next), PED_BE32_TO_CPU(block->lk_Next));
420
	if (PED_BE32_TO_CPU(block->lk_ID)==IDNAME_FILESYSHEADER) {
421
		DPRINT(DEBUG_BLOCK, "\tlk2_Linked = %08x (%d)\n", 
422
			PED_BE32_TO_CPU(LNK2(block)->lk2_Linked),
423
			PED_BE32_TO_CPU(LNK2(block)->lk2_Linked));
424
	}
425
}
426
427
#define MAX_RDB_BLOCK (RDB_LOCATION_LIMIT + 2 * AMIGA_MAX_PARTITIONS + 2)
428
429
static PedDiskType amiga_disk_type;
430
431
static int
432
amiga_probe (PedDevice *dev)
433
{
434
	struct RigidDiskBlock *rdb;
435
	uint32_t found;
436
	TRACE();
437
	PED_ASSERT(dev!= NULL, return 0);
438
439
	if ((rdb=RDSK(ped_malloc(PED_SECTOR_SIZE)))==NULL) {
440
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
441
			PED_EXCEPTION_CANCEL,
442
			_("%s : Failed to allocate rdb block\n"), __func__))
443
		{
444
			case PED_EXCEPTION_CANCEL :
445
			case PED_EXCEPTION_UNHANDLED :
446
			default : 
447
				return 0;
448
		}
449
	}
450
	found = _amiga_find_rdb (dev, rdb);
451
	ped_free (rdb);
452
453
	return (found == AMIGA_RDB_NOT_FOUND ? 0 : 1);
454
}
455
		
456
static PedDisk*
457
amiga_alloc (PedDevice* dev)
458
{
459
	PedDisk *disk;
460
	struct AmigaDisk *adsk;
461
	struct RigidDiskBlock *rdb;
462
	int highest_cylinder, highest_block;
463
	TRACE();
464
	PED_ASSERT(dev!= NULL, return NULL);
465
466
	if (!(disk = _ped_disk_alloc (dev, &amiga_disk_type))) {
467
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
468
			PED_EXCEPTION_CANCEL,
469
			_("%s : Failed to allocate disk structure\n"), __func__))
470
		{
471
			case PED_EXCEPTION_CANCEL :
472
			case PED_EXCEPTION_UNHANDLED :
473
			default : 
474
				return NULL;
475
		}
476
	}
477
478
	if (!(disk->disk_specific = ped_malloc (PED_SECTOR_SIZE))) {
479
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
480
			PED_EXCEPTION_CANCEL,
481
			_("%s : Failed to allocate disk_specific rdb block\n"), __func__))
482
		{
483
			case PED_EXCEPTION_CANCEL :
484
			case PED_EXCEPTION_UNHANDLED :
485
			default : 
486
				ped_free (disk);
487
				return NULL;
488
		}
489
	}
490
	rdb = disk->disk_specific;
491
492
	memset(rdb, -1, sizeof(struct RigidDiskBlock));
493
494
	rdb->rdb_ID = PED_CPU_TO_BE32 (IDNAME_RIGIDDISK);
495
	rdb->rdb_SummedLongs = PED_CPU_TO_BE32 (64);
496
	rdb->rdb_HostID = PED_CPU_TO_BE32 (0);
497
	rdb->rdb_BlockBytes = PED_CPU_TO_BE32 (PED_SECTOR_SIZE);
498
	rdb->rdb_Flags = PED_CPU_TO_BE32 (0);
499
500
	/* Block lists */
501
	rdb->rdb_BadBlockList = PED_CPU_TO_BE32 (0xffffffff);
502
	rdb->rdb_PartitionList = PED_CPU_TO_BE32 (0xffffffff);
503
	rdb->rdb_FileSysHeaderList = PED_CPU_TO_BE32 (0xffffffff);
504
	rdb->rdb_DriveInit = PED_CPU_TO_BE32 (0xffffffff);
505
	
506
	/* Physical drive characteristics */
507
	rdb->rdb_Cylinders = PED_CPU_TO_BE32 (dev->cylinders);
508
	rdb->rdb_Sectors = PED_CPU_TO_BE32 (dev->sectors);
509
	rdb->rdb_Heads = PED_CPU_TO_BE32 (dev->heads);
510
	rdb->rdb_Interleave = PED_CPU_TO_BE32 (0);
511
	rdb->rdb_Park = PED_CPU_TO_BE32 (dev->cylinders);
512
	rdb->rdb_WritePreComp = PED_CPU_TO_BE32 (dev->cylinders);
513
	rdb->rdb_ReducedWrite = PED_CPU_TO_BE32 (dev->cylinders);
514
	rdb->rdb_StepRate = PED_CPU_TO_BE32 (0);
515
516
	highest_cylinder = MAX_RDB_BLOCK / (dev->sectors * dev->heads) + 1;
517
	highest_block = highest_cylinder * dev->sectors * dev->heads - 1;
518
519
	/* Logical driver characteristics */
520
	rdb->rdb_RDBBlocksLo = PED_CPU_TO_BE32 (0);
521
	rdb->rdb_RDBBlocksHi = PED_CPU_TO_BE32 (highest_block);
522
	rdb->rdb_LoCylinder = PED_CPU_TO_BE32 (highest_cylinder);
523
	rdb->rdb_HiCylinder = PED_CPU_TO_BE32 (dev->cylinders -1);
524
	rdb->rdb_CylBlocks = PED_CPU_TO_BE32 (dev->sectors * dev->heads);
525
	rdb->rdb_AutoParkSeconds = PED_CPU_TO_BE32 (0);
526
	/* rdb_HighRDSKBlock will only be set when writing */
527
	rdb->rdb_HighRDSKBlock = PED_CPU_TO_BE32 (0);
528
529
	/* Driver identification */
530
	_amiga_set_bstr("", rdb->rdb_DiskVendor, 8);
531
	_amiga_set_bstr(dev->model, rdb->rdb_DiskProduct, 16);
532
	_amiga_set_bstr("", rdb->rdb_DiskRevision, 4);
533
	_amiga_set_bstr("", rdb->rdb_ControllerVendor, 8);
534
	_amiga_set_bstr("", rdb->rdb_ControllerProduct, 16);
535
	_amiga_set_bstr("", rdb->rdb_ControllerRevision, 4);
536
537
	/* And calculate the checksum */
538
	_amiga_calculate_checksum ((struct AmigaBlock *) rdb);
539
	
540
	return disk;
541
}
542
543
static PedDisk*
544
amiga_duplicate (const PedDisk* disk)
545
{
546
	PedDisk*	new_disk;
547
	struct RigidDiskBlock *	new_rdb;
548
	struct RigidDiskBlock * old_rdb;
549
	TRACE();
550
	PED_ASSERT(disk!= NULL, return NULL);
551
	PED_ASSERT(disk->dev!= NULL, return NULL);
552
	PED_ASSERT(disk->disk_specific!= NULL, return NULL);
553
554
	old_rdb = (struct RigidDiskBlock *) disk->disk_specific;
555
       
556
	if (!(new_disk = ped_disk_new_fresh (disk->dev, &amiga_disk_type))) {
557
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
558
			PED_EXCEPTION_CANCEL,
559
			_("%s : Failed to allocate a new disk structure\n"), __func__))
560
		{
561
			case PED_EXCEPTION_CANCEL :
562
			case PED_EXCEPTION_UNHANDLED :
563
			default : 
564
				return NULL;
565
		}
566
	}
567
568
	new_rdb = (struct RigidDiskBlock *) new_disk->disk_specific;
569
	memcpy (new_rdb, old_rdb, 256);
570
	return new_disk;
571
}
572
573
static void
574
amiga_free (PedDisk* disk)
575
{
576
	TRACE();
577
	PED_ASSERT(disk!= NULL, return);
578
	PED_ASSERT(disk->disk_specific!= NULL, return);
579
580
	ped_free (disk->disk_specific);
581
	_ped_disk_free (disk);
582
}
583
584
#ifndef DISCOVER_ONLY
585
static int
586
amiga_clobber (PedDevice* dev)
587
{
588
	struct RigidDiskBlock *rdb;
589
	uint32_t i;
590
	int result = 0;
591
	TRACE();
592
	PED_ASSERT(dev!= NULL, return 0);
593
594
	if ((rdb=RDSK(ped_malloc(PED_SECTOR_SIZE)))==NULL) {
595
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
596
			PED_EXCEPTION_CANCEL,
597
			_("%s : Failed to allocate rdb block\n"), __func__))
598
		{
599
			case PED_EXCEPTION_CANCEL :
600
			case PED_EXCEPTION_UNHANDLED :
601
			default : 
602
				return 0;
603
		}
604
	}
605
606
	while ((i = _amiga_find_rdb (dev, rdb)) != AMIGA_RDB_NOT_FOUND) {
607
		rdb->rdb_ID = PED_CPU_TO_BE32 (0);
608
		result = ped_device_write (dev, (void*) rdb, i, 1);
609
	}
610
611
	ped_free (rdb);
612
613
	return result;
614
}
615
#endif /* !DISCOVER_ONLY */
616
617
static int
618
_amiga_loop_check (uint32_t block, uint32_t * blocklist, uint32_t max)
619
{
620
	uint32_t i;
621
	TRACE();
622
623
	for (i = 0; i < max; i++)
624
		if (block == blocklist[i]) {
625
			/* We are looping, let's stop.  */
626
			return 1;
627
		}
628
	blocklist[max] = block;
629
	return 0;
630
}
631
632
/* We have already allocated a rdb, we are now reading it from the disk */
633
static int
634
amiga_read (PedDisk* disk)
635
{
636
	struct RigidDiskBlock *rdb;
637
	struct PartitionBlock *partition;
638
	uint32_t partblock;
639
	uint32_t partlist[AMIGA_MAX_PARTITIONS];
640
	PedSector cylblocks;
641
	int i;
642
	TRACE();
643
	PED_ASSERT(disk!= NULL, return 0);
644
	PED_ASSERT(disk->dev!= NULL, return 0);
645
	PED_ASSERT(disk->disk_specific!= NULL, return 0);
646
	rdb = RDSK(disk->disk_specific);
647
648
	if (_amiga_find_rdb (disk->dev, rdb) == AMIGA_RDB_NOT_FOUND) {
649
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
650
			PED_EXCEPTION_CANCEL,
651
			_("%s : Didn't find rdb block, should never happen\n"), __func__))
652
		{
653
			case PED_EXCEPTION_CANCEL :
654
			case PED_EXCEPTION_UNHANDLED :
655
			default : 
656
				return 0;
657
		}
658
	}
659
#if (DEBUG_BLOCKS & MASTER_DEBUG)
660
		_amiga_dump_rdb(rdb);
661
#endif
662
663
	/* Let's copy the rdb read geometry to the dev */
664
	disk->dev->cylinders = PED_BE32_TO_CPU (rdb->rdb_Cylinders);
665
	disk->dev->heads = PED_BE32_TO_CPU (rdb->rdb_Heads);
666
	disk->dev->sectors = PED_BE32_TO_CPU (rdb->rdb_Sectors);
667
	cylblocks = (PedSector) PED_BE32_TO_CPU (rdb->rdb_Heads) *
668
		(PedSector) PED_BE32_TO_CPU (rdb->rdb_Sectors);
669
670
	/* Remove all partitions in the former in memory table */
671
	ped_disk_delete_all (disk);
672
673
	/* Let's allocate a partition block */
674
	if (!(partition = ped_malloc (PED_SECTOR_SIZE))) {
675
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
676
			PED_EXCEPTION_CANCEL,
677
			_("%s : Failed to allocate partition block\n"), __func__))
678
		{
679
			case PED_EXCEPTION_CANCEL :
680
			case PED_EXCEPTION_UNHANDLED :
681
			default : 
682
				return 0;
683
		}
684
	}
685
686
	/* We initialize the hardblock free list to detect loops */
687
	for (i = 0; i < AMIGA_MAX_PARTITIONS; i++) partlist[i] = 0xffffffff;
688
689
	for (i = 1, partblock = PED_BE32_TO_CPU(rdb->rdb_PartitionList);
690
		i < AMIGA_MAX_PARTITIONS && partblock != 0xffffffff;
691
		i++, partblock = PED_BE32_TO_CPU(partition->pb_Next))
692
	{
693
		PedPartition *part;
694
		PedSector start, end;
695
		struct DosEnvec *de;
696
		PedConstraint *constraint_exact;
697
		int j; 
698
699
		/* Let's look for loops in the partition table */
700
		if (_amiga_loop_check(partblock, partlist, i)) {
701
			break;
702
		}
703
704
		/* Let's allocate and read a partition block to get its geometry*/
705
		if (!_amiga_read_block (disk->dev, AMIGA(partition), (PedSector)partblock)) {
706
			ped_free(partition);
707
			return 0;
708
		}
709
#if (DEBUG_BLOCK & MASTER_DEBUG)
710
		_amiga_dump_part(partition);
711
#endif
712
713
		start = ((PedSector) PED_BE32_TO_CPU (partition->de_LowCyl)) * cylblocks;
714
		end = ((((PedSector) PED_BE32_TO_CPU (partition->de_HighCyl))+1) * (cylblocks))-1;
715
716
		/* We can now construct a new partition */
717
		if (!(part = ped_partition_new (disk, 0, NULL, start, end))) {
718
			switch (ped_exception_throw(PED_EXCEPTION_ERROR,
719
				PED_EXCEPTION_CANCEL,
720
				_("%s : Failed to allocate new partition (%llu -> %llu)\n"),
721
				__func__, start, end))
722
			{
723
				case PED_EXCEPTION_CANCEL :
724
				case PED_EXCEPTION_UNHANDLED :
725
				default : 
726
					ped_free(partition);
727
					return 0;
728
			}
729
		}
730
		/* And copy over the partition block */
731
		memcpy(part->disk_specific, partition, 256);
732
733
		part->num = i;
734
		part->type = 0;
735
		/* Let's probe what filesystem is present on the disk */
736
		part->fs_type = ped_file_system_probe (&part->geom);
737
		
738
		constraint_exact = ped_constraint_exact (&part->geom);
739
		if (!ped_disk_add_partition (disk, part, constraint_exact)) {
740
			switch (ped_exception_throw(PED_EXCEPTION_ERROR,
741
				PED_EXCEPTION_CANCEL,
742
				_("%s : Failed to add new partition\n"), __func__))
743
			{
744
				case PED_EXCEPTION_CANCEL :
745
				case PED_EXCEPTION_UNHANDLED :
746
				default : 
747
					ped_free(partition);
748
					return 0;
749
			}
750
		}
751
		ped_constraint_destroy (constraint_exact);
752
	}
753
	return 1;
754
}
755
756
static int
757
_amiga_find_free_blocks(PedDisk *disk, uint32_t *table,
758
	struct LinkedBlock *block, uint32_t first, uint32_t type)
759
{
760
	PedSector next;
761
	TRACE();
762
	PED_ASSERT(disk!= NULL, return 0);
763
	PED_ASSERT(disk->dev!= NULL, return 0);
764
765
	for (next = first; next != LINK_END; next = PED_BE32_TO_CPU(block->lk_Next)) {
766
		if (table[next] != IDNAME_FREE) {
767
			switch (ped_exception_throw(PED_EXCEPTION_ERROR,
768
				PED_EXCEPTION_FIX | PED_EXCEPTION_IGNORE | PED_EXCEPTION_CANCEL,
769
				_("%s : Loop detected at block %d\n"), __func__, next))
770
			{
771
				case PED_EXCEPTION_CANCEL :
772
					return 0;
773
				case PED_EXCEPTION_FIX :
774
					/* Need to add fixing code */
775
				case PED_EXCEPTION_IGNORE :
776
				case PED_EXCEPTION_UNHANDLED :
777
				default : 
778
					return 1;
779
			}
780
		}
781
782
		if (!_amiga_read_block (disk->dev, AMIGA(block), next)) {
783
			return 0;
784
		}
785
#if (DEBUG_BLOCK & MASTER_DEBUG)
786
		_amiga_dump_linked(block);
787
#endif
788
		if (PED_BE32_TO_CPU(block->lk_ID) != type) {
789
			switch (ped_exception_throw(PED_EXCEPTION_ERROR,
790
				PED_EXCEPTION_CANCEL,
791
				_("%s : The %s list seems bad at block %s\n"),
792
				__func__, _amiga_block_id(PED_BE32_TO_CPU(block->lk_ID)), next))
793
			{
794
				case PED_EXCEPTION_CANCEL :
795
				case PED_EXCEPTION_UNHANDLED :
796
				default : 
797
					return 0;
798
			}
799
		}
800
		table[next] = type;
801
		if (PED_BE32_TO_CPU(block->lk_ID) == IDNAME_FILESYSHEADER) {
802
			if (_amiga_find_free_blocks(disk, table, block,
803
				PED_BE32_TO_CPU(LNK2(block)->lk2_Linked),
804
				IDNAME_LOADSEG) == 0) return 0;
805
		}
806
	}
807
	return 1;
808
}
809
static uint32_t
810
_amiga_next_free_block(uint32_t *table, uint32_t start, uint32_t type) {
811
	int i;
812
	TRACE();
813
814
	for (i = start; table[i] != type && table[i] != IDNAME_FREE; i++);
815
	return i;
816
}
817
static PedPartition *
818
_amiga_next_real_partition(PedDisk *disk, PedPartition *part) {
819
	PedPartition *next;
820
	TRACE();
821
822
	for (next = ped_disk_next_partition (disk, part);
823
		next != NULL && !ped_partition_is_active (next);
824
		next = ped_disk_next_partition (disk, next));
825
	return next;
826
}
827
#ifndef DISCOVER_ONLY
828
static int
829
amiga_write (PedDisk* disk)
830
{
831
	struct RigidDiskBlock *rdb;
832
	struct LinkedBlock *block;
833
	struct PartitionBlock *partition;
834
	PedPartition *part, *next_part;
835
	PedSector cylblocks, first_hb, last_hb, last_used_hb;
836
	uint32_t * table;
837
	uint32_t i, rdb_block, max_part;
838
	uint32_t rdb_num, part_num, block_num, next_num;
839
	TRACE();
840
841
	PED_ASSERT (disk != NULL, return 0;);
842
	PED_ASSERT (disk->dev != NULL, return 0;);
843
	PED_ASSERT (disk->disk_specific != NULL, return 0;);
844
845
	if (!(rdb = ped_malloc (PED_SECTOR_SIZE))) {
846
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
847
			PED_EXCEPTION_CANCEL,
848
			_("%s : Failed to allocate rdb block\n"), __func__))
849
		{
850
			case PED_EXCEPTION_CANCEL :
851
			case PED_EXCEPTION_UNHANDLED :
852
			default : 
853
				return 0;
854
		}
855
	}
856
	/* Let's read the rdb */
857
	if ((rdb_num = _amiga_find_rdb (disk->dev, rdb)) == AMIGA_RDB_NOT_FOUND) {
858
		rdb_num = 2;
859
	} else {
860
		memcpy (RDSK(disk->disk_specific), rdb, PED_SECTOR_SIZE);
861
	}
862
	ped_free (rdb);
863
	rdb = RDSK(disk->disk_specific);
864
#if (DEBUG_BLOCK & MASTER_DEBUG)
865
		_amiga_dump_rdb(rdb);
866
#endif
867
868
	/* Let's copy the rdb read geometry to the dev */
869
	disk->dev->cylinders = PED_BE32_TO_CPU (rdb->rdb_Cylinders);
870
	disk->dev->heads = PED_BE32_TO_CPU (rdb->rdb_Heads);
871
	disk->dev->sectors = PED_BE32_TO_CPU (rdb->rdb_Sectors);
872
	cylblocks = (PedSector) PED_BE32_TO_CPU (rdb->rdb_Heads) *
873
		(PedSector) PED_BE32_TO_CPU (rdb->rdb_Sectors);
874
	first_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_RDBBlocksLo);
875
	last_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_RDBBlocksHi);
876
	last_used_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_HighRDSKBlock);
877
878
	/* let's allocate a free block table and initialize it */
879
	if (!(table = ped_malloc ((last_hb - first_hb + 1) * sizeof(uint32_t)))) {
880
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
881
			PED_EXCEPTION_CANCEL,
882
			_("%s : Failed to allocate free block table\n"), __func__))
883
		{
884
			case PED_EXCEPTION_CANCEL :
885
			case PED_EXCEPTION_UNHANDLED :
886
			default : 
887
				return 0;
888
		}
889
	}
890
	memset(table, 0xff, (last_hb - first_hb + 1) * sizeof(uint32_t));
891
	for (i = 0; i<=rdb_num; i++) table[i] = IDNAME_RIGIDDISK;
892
	
893
	/* Let's allocate a partition block */
894
	if (!(block = ped_malloc (PED_SECTOR_SIZE))) {
895
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
896
			PED_EXCEPTION_CANCEL,
897
			_("%s : Failed to allocate partition block\n"), __func__))
898
		{
899
			case PED_EXCEPTION_CANCEL :
900
			case PED_EXCEPTION_UNHANDLED :
901
			default : 
902
				ped_free (table);
903
				return 0;
904
		}
905
	}
906
907
	/* And fill the free block table */
908
	if (_amiga_find_free_blocks(disk, table, block,
909
		PED_BE32_TO_CPU (rdb->rdb_BadBlockList), IDNAME_BADBLOCK) == 0)
910
	{
911
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
912
			PED_EXCEPTION_CANCEL,
913
			_("%s : Failed to list badblocks\n"), __func__))
914
		{
915
			case PED_EXCEPTION_CANCEL :
916
			case PED_EXCEPTION_UNHANDLED :
917
			default : 
918
				ped_free (table);
919
				ped_free (block);
920
				return 0;
921
		}
922
	}
923
	if (_amiga_find_free_blocks(disk, table, block,
924
		PED_BE32_TO_CPU (rdb->rdb_PartitionList), IDNAME_PARTITION) == 0)
925
	{
926
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
927
			PED_EXCEPTION_CANCEL,
928
			_("%s : Failed to list partitionblocks\n"), __func__))
929
		{
930
			case PED_EXCEPTION_CANCEL :
931
			case PED_EXCEPTION_UNHANDLED :
932
			default : 
933
				ped_free (table);
934
				ped_free (block);
935
				return 0;
936
		}
937
	}
938
	if (_amiga_find_free_blocks(disk, table, block,
939
		PED_BE32_TO_CPU (rdb->rdb_FileSysHeaderList), IDNAME_FILESYSHEADER) == 0)
940
	{
941
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
942
			PED_EXCEPTION_CANCEL,
943
			_("%s : Failed to list filesystemblocks\n"), __func__))
944
		{
945
			case PED_EXCEPTION_CANCEL :
946
			case PED_EXCEPTION_UNHANDLED :
947
			default : 
948
				ped_free (table);
949
				ped_free (block);
950
				return 0;
951
		}
952
	}
953
	if (_amiga_find_free_blocks(disk, table, block,
954
		PED_BE32_TO_CPU (rdb->rdb_BootBlockList), IDNAME_BOOT) == 0)
955
	{
956
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
957
			PED_EXCEPTION_CANCEL,
958
			_("%s : Failed to list bootblocks\n"), __func__))
959
		{
960
			case PED_EXCEPTION_CANCEL :
961
			case PED_EXCEPTION_UNHANDLED :
962
			default : 
963
				ped_free (table);
964
				ped_free (block);
965
				return 0;
966
		}
967
	}
968
969
	block_num = next_num = part_num = _amiga_next_free_block(table, rdb_num+1, IDNAME_PARTITION);
970
	part = _amiga_next_real_partition(disk, NULL);
971
	if (part == NULL) {
972
		rdb->rdb_PartitionList = PED_CPU_TO_BE32(LINK_END);
973
	} else {
974
		rdb->rdb_PartitionList = PED_CPU_TO_BE32(part_num);
975
		while (part != NULL) {
976
			PED_ASSERT(part->disk_specific!=NULL, return 0);
977
			next_part = _amiga_next_real_partition(disk, part);
978
			block_num = next_num;
979
			next_num = _amiga_next_free_block(table, block_num+1, IDNAME_PARTITION);
980
			partition = PART(part->disk_specific);
981
			partition->pb_Next = next_part==NULL ? PED_CPU_TO_BE32(LINK_END):PED_CPU_TO_BE32(next_num);
982
			partition->de_LowCyl = PED_CPU_TO_BE32(part->geom.start/cylblocks);
983
			partition->de_HighCyl = PED_CPU_TO_BE32((part->geom.end+1)/cylblocks-1);
984
			_amiga_calculate_checksum(AMIGA(partition));
985
			if (!ped_device_write (disk->dev, (void*) partition, block_num, 1)) {
986
				switch (ped_exception_throw(PED_EXCEPTION_ERROR,
987
					PED_EXCEPTION_CANCEL,
988
					_("%s : Failed to write partition block at\n"), __func__, block_num))
989
				{
990
					case PED_EXCEPTION_CANCEL :
991
					case PED_EXCEPTION_UNHANDLED :
992
					default : 
993
						ped_free (table);
994
						ped_free (block);
995
						/* WARNING : If we fail here, we stop everything,
996
						 * and the partition table is lost. A Better
997
						 * solution should be found, using the second
998
						 * half of the hardblocks to not overwrite the
999
						 * old partition table. It becomes problematic
1000
						 * if we use more than half of the hardblocks. */
1001
						return 0;
1002
				}
1003
			}
1004
			part = next_part;
1005
		}
1006
	}
1007
	if (block_num >PED_BE32_TO_CPU (rdb->rdb_HighRDSKBlock)) {
1008
		rdb->rdb_HighRDSKBlock = PED_CPU_TO_BE32(block_num);
1009
	}
1010
	_amiga_calculate_checksum(AMIGA(rdb));
1011
	if (!ped_device_write (disk->dev, (void*) disk->disk_specific, rdb_num, 1)) {
1012
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
1013
			PED_EXCEPTION_CANCEL,
1014
			_("%s : Failed to write rdb block at\n"), __func__, rdb_num))
1015
		{
1016
			case PED_EXCEPTION_CANCEL :
1017
			case PED_EXCEPTION_UNHANDLED :
1018
			default : 
1019
				ped_free (table);
1020
				ped_free (block);
1021
				return 0;
1022
		}
1023
	}
1024
			
1025
#if (DEBUG_BLOCK & MASTER_DEBUG)
1026
		_amiga_dump_rdb(rdb);
1027
#endif
1028
	ped_free (table);
1029
	ped_free (block);
1030
	return ped_device_sync (disk->dev);
1031
}
1032
#endif /* !DISCOVER_ONLY */
1033
1034
static PedPartition*
1035
amiga_partition_new (const PedDisk* disk, PedPartitionType part_type,
1036
		   const PedFileSystemType* fs_type,
1037
		   PedSector start, PedSector end)
1038
{
1039
	PedPartition *part;
1040
	PedDevice *dev;
1041
	PedSector cyl;
1042
	struct PartitionBlock *partition;
1043
	struct RigidDiskBlock *rdb;
1044
	TRACE();
1045
	PED_ASSERT(disk!= NULL, return NULL);
1046
	PED_ASSERT(disk->dev!= NULL, return NULL);
1047
	PED_ASSERT(disk->disk_specific!= NULL, return NULL);
1048
	dev = disk->dev;
1049
	cyl = (PedSector) (dev->sectors * dev->heads);
1050
	rdb = RDSK(disk->disk_specific);
1051
1052
	if (!(part = _ped_partition_alloc (disk, part_type, fs_type, start, end))) {
1053
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
1054
			PED_EXCEPTION_CANCEL,
1055
			_("%s : Failed to allocate a partition structure (%llu, %llu)"),
1056
			__func__, start, end))
1057
		{
1058
			case PED_EXCEPTION_CANCEL :
1059
			case PED_EXCEPTION_UNHANDLED :
1060
			default : 
1061
				return NULL;
1062
		}
1063
	}
1064
	
1065
1066
	if (ped_partition_is_active (part)) {
1067
		if (!(part->disk_specific = ped_malloc (PED_SECTOR_SIZE))) {
1068
			switch (ped_exception_throw(PED_EXCEPTION_ERROR,
1069
				PED_EXCEPTION_CANCEL,
1070
				_("%s : Failed to allocate a partition disk_specific block\n"), __func__))
1071
			{
1072
				case PED_EXCEPTION_CANCEL :
1073
				case PED_EXCEPTION_UNHANDLED :
1074
				default : 
1075
					ped_free (part);
1076
					return NULL;
1077
			}
1078
		}
1079
		partition = PART(part->disk_specific);
1080
		memset(partition, -1, sizeof(struct PartitionBlock));
1081
1082
		partition->pb_ID = PED_CPU_TO_BE32(IDNAME_PARTITION);
1083
		partition->pb_SummedLongs = PED_CPU_TO_BE32(64);
1084
		partition->pb_HostID = rdb->rdb_HostID;
1085
		partition->pb_Flags = PED_CPU_TO_BE32(0);
1086
		/* TODO : use a scheme including the device name and the
1087
		 * partition number, if it is possible */
1088
		_amiga_set_bstr("dhx", partition->pb_DriveName, 32);
1089
1090
		partition->de_TableSize = PED_CPU_TO_BE32(19);
1091
		partition->de_SizeBlock = PED_CPU_TO_BE32(128);
1092
		partition->de_SecOrg = PED_CPU_TO_BE32(0);
1093
		partition->de_Surfaces = PED_CPU_TO_BE32(dev->heads);
1094
		partition->de_SectorPerBlock = PED_CPU_TO_BE32(1);
1095
		partition->de_BlocksPerTrack = PED_CPU_TO_BE32(dev->sectors);
1096
		partition->de_Reserved = PED_CPU_TO_BE32(2);
1097
		partition->de_PreAlloc = PED_CPU_TO_BE32(0);
1098
		partition->de_Interleave = PED_CPU_TO_BE32(0);
1099
		partition->de_LowCyl = PED_CPU_TO_BE32(start/cyl);
1100
		partition->de_HighCyl = PED_CPU_TO_BE32((end+1)/cyl-1);
1101
		partition->de_NumBuffers = PED_CPU_TO_BE32(30);
1102
		partition->de_BufMemType = PED_CPU_TO_BE32(0);
1103
		partition->de_MaxTransfer = PED_CPU_TO_BE32(0x7fffffff);
1104
		partition->de_Mask = PED_CPU_TO_BE32(0xffffffff);
1105
		partition->de_BootPri = PED_CPU_TO_BE32(0);
1106
		partition->de_DosType = PED_CPU_TO_BE32(0x4c4e5800);
1107
		partition->de_Baud = PED_CPU_TO_BE32(0);
1108
		partition->de_Control = PED_CPU_TO_BE32(0);
1109
		partition->de_BootBlocks = PED_CPU_TO_BE32(0);
1110
1111
#if (DEBUG_BLOCK & MASTER_DEBUG)
1112
		_amiga_dump_part(partition);
1113
#endif
1114
	} else {
1115
		part->disk_specific = NULL;
1116
	}
1117
	return part;
1118
}
1119
1120
static PedPartition*
1121
amiga_partition_duplicate (const PedPartition* part)
1122
{
1123
	PedPartition *new_part;
1124
	struct PartitionBlock *new_amiga_part;
1125
	struct PartitionBlock *old_amiga_part;
1126
	TRACE();
1127
	PED_ASSERT(part!= NULL, return NULL);
1128
	PED_ASSERT(part->disk!= NULL, return NULL);
1129
	PED_ASSERT(part->disk_specific!= NULL, return NULL);
1130
	old_amiga_part = (struct PartitionBlock *) part->disk_specific;
1131
1132
	new_part = ped_partition_new (part->disk, part->type,
1133
				      part->fs_type, part->geom.start,
1134
				      part->geom.end);
1135
	if (!new_part) {
1136
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
1137
			PED_EXCEPTION_CANCEL,
1138
			_("%s : Failed to allocate a new partition structure\n"), __func__))
1139
		{
1140
			case PED_EXCEPTION_CANCEL :
1141
			case PED_EXCEPTION_UNHANDLED :
1142
			default : 
1143
				return NULL;
1144
		}
1145
	}
1146
1147
	new_amiga_part = (struct PartitionBlock *) new_part->disk_specific;
1148
	memcpy (new_amiga_part, old_amiga_part, 256);
1149
1150
	return new_part;
1151
}
1152
1153
static void
1154
amiga_partition_destroy (PedPartition* part)
1155
{
1156
	TRACE();
1157
	PED_ASSERT (part != NULL, return);
1158
1159
	if (ped_partition_is_active (part)) {
1160
		PED_ASSERT (part->disk_specific!= NULL, return);
1161
		ped_free (part->disk_specific);
1162
	}
1163
	_ped_partition_free (part);
1164
}
1165
1166
static int
1167
amiga_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type)
1168
{
1169
	struct PartitionBlock *partition;
1170
	TRACE();
1171
1172
	PED_ASSERT (part != NULL, return 0);
1173
	PED_ASSERT (part->disk_specific != NULL, return 0);
1174
	partition = PART(part->disk_specific);
1175
1176
	part->fs_type = fs_type;
1177
1178
	if (!fs_type)
1179
		partition->de_DosType = PED_CPU_TO_BE32(0x4c4e5800); /* 'LNX\0' */
1180
	else if (!strcmp (fs_type->name, "ext2"))
1181
		partition->de_DosType = PED_CPU_TO_BE32(0x4c4e5800); /* 'LNX\0' */
1182
	else if (!strcmp (fs_type->name, "ext3"))
1183
		partition->de_DosType = PED_CPU_TO_BE32(0x45585403); /* 'EXT\3' */
1184
	else if (!strcmp (fs_type->name, "linux-swap"))
1185
		partition->de_DosType = PED_CPU_TO_BE32(0x53575000); /* 'SWP\0' */
1186
	else if (!strcmp (fs_type->name, "fat16"))
1187
		partition->de_DosType = PED_CPU_TO_BE32(0x46415400); /* 'FAT\0' */
1188
	else if (!strcmp (fs_type->name, "fat32"))
1189
		partition->de_DosType = PED_CPU_TO_BE32(0x46415401); /* 'FAT\1'*/
1190
	else if (!strcmp (fs_type->name, "hfs"))
1191
		partition->de_DosType = PED_CPU_TO_BE32(0x48465300); /* 'HFS\0' */
1192
	else if (!strcmp (fs_type->name, "jfs"))
1193
		partition->de_DosType = PED_CPU_TO_BE32(0x4a465300); /* 'JFS\0' */
1194
	else if (!strcmp (fs_type->name, "ntfs"))
1195
		partition->de_DosType = PED_CPU_TO_BE32(0x4e544653); /* 'NTFS' */
1196
	else if (!strcmp (fs_type->name, "reiserfs"))
1197
		partition->de_DosType = PED_CPU_TO_BE32(0x52465300); /* 'RFS\0' */
1198
	else if (!strcmp (fs_type->name, "sun-ufs"))
1199
		partition->de_DosType = PED_CPU_TO_BE32(0x53554653); /* 'SUFS' */
1200
	else if (!strcmp (fs_type->name, "hp-ufs"))
1201
		partition->de_DosType = PED_CPU_TO_BE32(0x48554653); /* 'HUFS' */
1202
	else if (!strcmp (fs_type->name, "xfs"))
1203
		partition->de_DosType = PED_CPU_TO_BE32(0x58465300); /* 'XFS\0' */
1204
	else
1205
		partition->de_DosType = PED_CPU_TO_BE32(0x00000000); /* unknown */
1206
	return 1;
1207
}
1208
1209
static int
1210
amiga_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
1211
{
1212
	struct PartitionBlock *partition;
1213
	TRACE();
1214
1215
	PED_ASSERT (part != NULL, return 0);
1216
	PED_ASSERT (part->disk_specific != NULL, return 0);
1217
1218
	partition = PART(part->disk_specific);
1219
1220
	switch (flag) {
1221
		case PED_PARTITION_BOOT:
1222
			if (state) partition->pb_Flags |= PED_CPU_TO_BE32(PBFF_BOOTABLE);
1223
			else partition->pb_Flags &= ~(PED_CPU_TO_BE32(PBFF_BOOTABLE));
1224
			return 1;
1225
		case PED_PARTITION_HIDDEN:
1226
			if (state) partition->pb_Flags |= PED_CPU_TO_BE32(PBFF_NOMOUNT);
1227
			else partition->pb_Flags &= ~(PED_CPU_TO_BE32(PBFF_NOMOUNT));
1228
			return 1;
1229
		default:
1230
			return 0;
1231
	}
1232
}
1233
1234
static int
1235
amiga_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
1236
{
1237
	struct PartitionBlock *partition;
1238
	TRACE();
1239
1240
	PED_ASSERT (part != NULL, return 0);
1241
	PED_ASSERT (part->disk_specific != NULL, return 0);
1242
1243
	partition = PART(part->disk_specific);
1244
1245
	switch (flag) {
1246
		case PED_PARTITION_BOOT:
1247
			return (partition->pb_Flags & PED_CPU_TO_BE32(PBFF_BOOTABLE));
1248
		case PED_PARTITION_HIDDEN:
1249
			return (partition->pb_Flags & PED_CPU_TO_BE32(PBFF_NOMOUNT));
1250
		default:
1251
			return 0;
1252
	}
1253
}
1254
1255
static int
1256
amiga_partition_is_flag_available (const PedPartition* part,
1257
				 PedPartitionFlag flag)
1258
{
1259
	TRACE();
1260
	switch (flag) {
1261
	case PED_PARTITION_BOOT:
1262
	case PED_PARTITION_HIDDEN:
1263
		return 1;
1264
	default:
1265
		return 0;
1266
	}
1267
}
1268
1269
static void             
1270
amiga_partition_set_name (PedPartition* part, const char* name)
1271
{               
1272
	struct PartitionBlock *partition;
1273
	TRACE();
1274
1275
	PED_ASSERT (part != NULL, return);
1276
	PED_ASSERT (part->disk_specific != NULL, return);
1277
1278
	partition = PART(part->disk_specific);
1279
	_amiga_set_bstr(name, partition->pb_DriveName, 32);
1280
}
1281
static const char*
1282
amiga_partition_get_name (const PedPartition* part)
1283
{
1284
	struct PartitionBlock *partition;
1285
	TRACE();
1286
1287
	PED_ASSERT (part != NULL, return 0);
1288
	PED_ASSERT (part->disk_specific != NULL, return 0);
1289
1290
	partition = PART(part->disk_specific);
1291
1292
	return _amiga_get_bstr(partition->pb_DriveName);
1293
}
1294
1295
static PedConstraint*
1296
_amiga_get_constraint (const PedDisk *disk)
1297
{
1298
	PedDevice *dev = disk->dev;
1299
	PedAlignment start_align, end_align;
1300
	PedGeometry max_geom;
1301
	struct RigidDiskBlock *rdb = RDSK(disk->disk_specific);
1302
	PedSector cyl = (PedSector) PED_BE32_TO_CPU(rdb->rdb_Sectors) *
1303
		PED_BE32_TO_CPU(rdb->rdb_Heads);
1304
	PedSector start = ((273 / cyl) + 1) * cyl;
1305
	PedSector length = dev->length - start;
1306
	PedSector max_part = (length / cyl) * cyl;
1307
	TRACE();
1308
1309
	if (!ped_alignment_init(&start_align, 0, cyl)) {
1310
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
1311
			PED_EXCEPTION_CANCEL,
1312
			_("%s : Failed to initialize the start constraint\n"), __func__))
1313
		{
1314
			case PED_EXCEPTION_CANCEL :
1315
			case PED_EXCEPTION_UNHANDLED :
1316
			default : 
1317
				return NULL;
1318
		}
1319
	}
1320
	if (!ped_alignment_init(&end_align, -1, cyl)) {
1321
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
1322
			PED_EXCEPTION_CANCEL,
1323
			_("%s : Failed to initialize the end constraint\n"), __func__))
1324
		{
1325
			case PED_EXCEPTION_CANCEL :
1326
			case PED_EXCEPTION_UNHANDLED :
1327
			default : 
1328
				return NULL;
1329
		}
1330
	}
1331
	if (!ped_geometry_init(&max_geom, dev, start, length)) {
1332
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
1333
			PED_EXCEPTION_CANCEL,
1334
			_("%s : Failed to initialize the max constraint\n"), __func__))
1335
		{
1336
			case PED_EXCEPTION_CANCEL :
1337
			case PED_EXCEPTION_UNHANDLED :
1338
			default : 
1339
				return NULL;
1340
		}
1341
	}
1342
1343
	return ped_constraint_new (&start_align, &end_align,
1344
		&max_geom, &max_geom, cyl, max_part);
1345
}
1346
1347
static void
1348
_amiga_dump_constraint (const PedConstraint* constraint)
1349
{
1350
	DPRINT (DEBUG_CONST, "Align Start : offset = %lld, grain = %lld\n",
1351
		constraint->start_align->offset,
1352
		constraint->start_align->grain_size);
1353
	DPRINT (DEBUG_CONST, "Align End : offset = %lld, grain = %lld\n",
1354
		constraint->end_align->offset,
1355
		constraint->end_align->grain_size);
1356
	DPRINT (DEBUG_CONST, "Range Start : start = %lld, length = %lld, end = %lld\n",
1357
		constraint->start_range->start,
1358
		constraint->start_range->length,
1359
		constraint->start_range->end);
1360
	DPRINT (DEBUG_CONST, "Range End : start = %lld, length = %lld, end = %lld\n",
1361
		constraint->end_range->start,
1362
		constraint->end_range->length,
1363
		constraint->end_range->end);
1364
	DPRINT (DEBUG_CONST, "Size : min = %lld, Max = %lld\n",
1365
		constraint->min_size, constraint->max_size);
1366
}
1367
1368
static int
1369
amiga_partition_align (PedPartition* part, const PedConstraint* constraint)
1370
{
1371
	TRACE();
1372
1373
	PED_ASSERT (part != NULL, return 0);
1374
	PED_ASSERT (part->disk != NULL, return 0);
1375
	
1376
#if (DEBUG_CONST & MASTER_DEBUG)
1377
	_amiga_dump_constraint (constraint);
1378
	_amiga_dump_constraint (_amiga_get_constraint (part->disk));
1379
#endif
1380
	if (_ped_partition_attempt_align (part, constraint,
1381
					  _amiga_get_constraint (part->disk)))
1382
	{
1383
	       	return 1;
1384
	}
1385
1386
#ifndef DISCOVER_ONLY
1387
	ped_exception_throw (
1388
		PED_EXCEPTION_ERROR,
1389
		PED_EXCEPTION_CANCEL,
1390
		_("%s : Unable to satisfy all constraints on the partition."), __func__);
1391
#endif
1392
	return 0;
1393
}
1394
1395
static int
1396
amiga_partition_enumerate (PedPartition* part)
1397
{
1398
	
1399
	int i;
1400
	PedPartition* p;
1401
	TRACE();
1402
	
1403
	PED_ASSERT (part != NULL, return 0);
1404
	PED_ASSERT (part->disk != NULL, return 0);
1405
1406
	/* never change the partition numbers */
1407
	if (part->num != -1)
1408
		return 1;
1409
	for (i = 1; i <= AMIGA_MAX_PARTITIONS; i++) {
1410
		p = ped_disk_get_partition (part->disk, i);
1411
		if (!p) {
1412
			part->num = i;
1413
			return 1;
1414
		}
1415
	}
1416
1417
	/* failed to allocate a number */
1418
#ifndef DISCOVER_ONLY
1419
	ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1420
			     _("%s : Unable to allocate a partition"), __func__);
1421
#endif
1422
	return 0;
1423
}
1424
1425
static int
1426
amiga_alloc_metadata (PedDisk* disk)
1427
{
1428
	PedPartition*		new_part;
1429
	PedConstraint*		constraint_any = NULL;
1430
	PedSector		highest_block;
1431
	TRACE();
1432
1433
	PED_ASSERT (disk != NULL, goto error);
1434
	PED_ASSERT (disk->dev != NULL, goto error);
1435
1436
	constraint_any = ped_constraint_any (disk->dev);
1437
1438
	/* Allocate space for the RDB */
1439
	new_part = ped_partition_new (disk, PED_PARTITION_METADATA, NULL, 0, MAX_RDB_BLOCK);
1440
	if (!new_part)
1441
		goto error;
1442
1443
	if (!ped_disk_add_partition (disk, new_part, constraint_any)) {
1444
		ped_partition_destroy (new_part);
1445
		goto error;
1446
	}
1447
1448
	ped_constraint_destroy (constraint_any);
1449
	return 1;
1450
error:
1451
	ped_constraint_destroy (constraint_any);
1452
	return 0;
1453
}
1454
1455
static int
1456
amiga_get_max_primary_partition_count (const PedDisk* disk)
1457
{
1458
	TRACE();
1459
	return AMIGA_MAX_PARTITIONS;
1460
}
1461
1462
static PedDiskOps amiga_disk_ops = {
1463
	probe:			amiga_probe,
1464
#ifndef DISCOVER_ONLY
1465
	clobber:		amiga_clobber,
1466
#else
1467
	clobber:		NULL,
1468
#endif
1469
	alloc:			amiga_alloc,
1470
	duplicate:		amiga_duplicate,
1471
	free:			amiga_free,
1472
	read:			amiga_read,
1473
#ifndef DISCOVER_ONLY
1474
	write:			amiga_write,
1475
#else
1476
	write:			NULL,
1477
#endif
1478
1479
	partition_new:		amiga_partition_new,
1480
	partition_duplicate:	amiga_partition_duplicate,
1481
	partition_destroy:	amiga_partition_destroy,
1482
	partition_set_system:	amiga_partition_set_system,
1483
	partition_set_flag:	amiga_partition_set_flag,
1484
	partition_get_flag:	amiga_partition_get_flag,
1485
	partition_is_flag_available:
1486
				amiga_partition_is_flag_available,
1487
	partition_set_name:	amiga_partition_set_name,
1488
	partition_get_name:	amiga_partition_get_name,
1489
	partition_align:	amiga_partition_align,
1490
	partition_enumerate:	amiga_partition_enumerate,
1491
1492
1493
	alloc_metadata:		amiga_alloc_metadata,
1494
	get_max_primary_partition_count:
1495
				amiga_get_max_primary_partition_count
1496
};
1497
1498
static PedDiskType amiga_disk_type = {
1499
	next:		NULL,
1500
	name:		"amiga",
1501
	ops:		&amiga_disk_ops,
1502
	features:	PED_DISK_TYPE_PARTITION_NAME
1503
};
1504
1505
void
1506
ped_disk_amiga_init ()
1507
{
1508
	TRACE();
1509
	PED_ASSERT(sizeof(struct AmigaBlock) != 3, return);
1510
	PED_ASSERT(sizeof(struct RigidDiskBlock) != 64, return);
1511
	PED_ASSERT(sizeof(struct PartitionBlock) != 64, return);
1512
	PED_ASSERT(sizeof(struct LinkedBlock) != 5, return);
1513
	PED_ASSERT(sizeof(struct Linked2Block) != 18, return);
1514
1515
	ped_register_disk_type (&amiga_disk_type);
1516
}
1517
1518
void
1519
ped_disk_amiga_done ()
1520
{
1521
	TRACE();
1522
1523
	ped_unregister_disk_type (&amiga_disk_type);
1524
}
(-)parted-1.6.6/libparted/fs_amiga/Makefile.am (+14 lines)
Line 0 Link Here
1
partedincludedir      =	-I$(top_srcdir)/include
2
3
noinst_LTLIBRARIES    =	libamigafs.la
4
libext2_la_SOURCES    =	amiga.h		\
5
			amiga.c		\
6
			affs.h		\
7
			affs.c		\
8
			asfs.h		\
9
			asfs.c		\
10
			apfs.h		\
11
			apfs.c		\
12
			interface.c
13
14
INCLUDES = $(partedincludedir) @INTLINCS@
(-)parted-1.6.6/libparted/fs_amiga/Makefile.in (+340 lines)
Line 0 Link Here
1
# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
2
3
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
4
# This Makefile.in is free software; the Free Software Foundation
5
# gives unlimited permission to copy and/or distribute it,
6
# with or without modifications, as long as this notice is preserved.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
10
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
# PARTICULAR PURPOSE.
12
13
14
SHELL = @SHELL@
15
16
srcdir = @srcdir@
17
top_srcdir = @top_srcdir@
18
VPATH = @srcdir@
19
prefix = @prefix@
20
exec_prefix = @exec_prefix@
21
22
bindir = @bindir@
23
sbindir = @sbindir@
24
libexecdir = @libexecdir@
25
datadir = @datadir@
26
sysconfdir = @sysconfdir@
27
sharedstatedir = @sharedstatedir@
28
localstatedir = @localstatedir@
29
libdir = @libdir@
30
infodir = @infodir@
31
mandir = @mandir@
32
includedir = @includedir@
33
oldincludedir = /usr/include
34
35
DESTDIR =
36
37
pkgdatadir = $(datadir)/@PACKAGE@
38
pkglibdir = $(libdir)/@PACKAGE@
39
pkgincludedir = $(includedir)/@PACKAGE@
40
41
top_builddir = ../..
42
43
ACLOCAL = @ACLOCAL@
44
AUTOCONF = @AUTOCONF@
45
AUTOMAKE = @AUTOMAKE@
46
AUTOHEADER = @AUTOHEADER@
47
48
INSTALL = @INSTALL@
49
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
50
INSTALL_DATA = @INSTALL_DATA@
51
INSTALL_SCRIPT = @INSTALL_SCRIPT@
52
transform = @program_transform_name@
53
54
NORMAL_INSTALL = :
55
PRE_INSTALL = :
56
POST_INSTALL = :
57
NORMAL_UNINSTALL = :
58
PRE_UNINSTALL = :
59
POST_UNINSTALL = :
60
host_alias = @host_alias@
61
host_triplet = @host@
62
AS = @AS@
63
BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@
64
CATALOGS = @CATALOGS@
65
CATOBJEXT = @CATOBJEXT@
66
CC = @CC@
67
DATADIRNAME = @DATADIRNAME@
68
DLLTOOL = @DLLTOOL@
69
ECHO = @ECHO@
70
EXEEXT = @EXEEXT@
71
GENCAT = @GENCAT@
72
GLIBC21 = @GLIBC21@
73
GMOFILES = @GMOFILES@
74
GMSGFMT = @GMSGFMT@
75
INSTOBJEXT = @INSTOBJEXT@
76
INTLBISON = @INTLBISON@
77
INTLINCS = @INTLINCS@
78
INTLLIBS = @INTLLIBS@
79
INTLOBJS = @INTLOBJS@
80
INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@
81
LIBICONV = @LIBICONV@
82
LIBTOOL = @LIBTOOL@
83
LN_S = @LN_S@
84
LT_AGE = @LT_AGE@
85
LT_CURRENT = @LT_CURRENT@
86
LT_RELEASE = @LT_RELEASE@
87
LT_REVISION = @LT_REVISION@
88
MAKEINFO = @MAKEINFO@
89
MKINSTALLDIRS = @MKINSTALLDIRS@
90
MSGFMT = @MSGFMT@
91
OBJDUMP = @OBJDUMP@
92
OBJEXT = @OBJEXT@
93
OS = @OS@
94
OS_LIBS = @OS_LIBS@
95
PACKAGE = @PACKAGE@
96
PARTEDLDFLAGS = @PARTEDLDFLAGS@
97
PARTED_LIBS = @PARTED_LIBS@
98
POFILES = @POFILES@
99
POSUB = @POSUB@
100
RANLIB = @RANLIB@
101
REISER_LIBS = @REISER_LIBS@
102
STRIP = @STRIP@
103
USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@
104
USE_NLS = @USE_NLS@
105
UUID_LIBS = @UUID_LIBS@
106
VERSION = @VERSION@
107
108
partedincludedir = -I$(top_srcdir)/include
109
110
noinst_LTLIBRARIES = libamigafs.la
111
libamiga_la_SOURCES = amiga.h amiga.c affs.h affs.c asfs.h asfs.c apfs.h apfs.c interface.c
112
113
INCLUDES = $(partedincludedir) @INTLINCS@
114
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
115
CONFIG_HEADER = ../../config.h
116
CONFIG_CLEAN_FILES = 
117
LTLIBRARIES =  $(noinst_LTLIBRARIES)
118
119
120
DEFS = @DEFS@ -I. -I$(srcdir) -I../..
121
CPPFLAGS = @CPPFLAGS@
122
LDFLAGS = @LDFLAGS@
123
LIBS = @LIBS@
124
libamigafs_la_LDFLAGS = 
125
libamigafs_la_LIBADD = 
126
libamigafs_la_OBJECTS =  amiga.lo affs.lo asfs.lo apfs.lo interface.lo
127
CFLAGS = @CFLAGS@
128
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
129
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
130
CCLD = $(CC)
131
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
132
DIST_COMMON =  Makefile.am Makefile.in
133
134
135
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
136
137
TAR = tar
138
GZIP_ENV = --best
139
SOURCES = $(libamigafs_la_SOURCES)
140
OBJECTS = $(libamigafs_la_OBJECTS)
141
142
all: all-redirect
143
.SUFFIXES:
144
.SUFFIXES: .S .c .lo .o .obj .s
145
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
146
	cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps libparted/fs_amiga/Makefile
147
148
Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
149
	cd $(top_builddir) \
150
	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
151
152
153
mostlyclean-noinstLTLIBRARIES:
154
155
clean-noinstLTLIBRARIES:
156
	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
157
158
distclean-noinstLTLIBRARIES:
159
160
maintainer-clean-noinstLTLIBRARIES:
161
162
.c.o:
163
	$(COMPILE) -c $<
164
165
# FIXME: We should only use cygpath when building on Windows,
166
# and only if it is available.
167
.c.obj:
168
	$(COMPILE) -c `cygpath -w $<`
169
170
.s.o:
171
	$(COMPILE) -c $<
172
173
.S.o:
174
	$(COMPILE) -c $<
175
176
mostlyclean-compile:
177
	-rm -f *.o core *.core
178
	-rm -f *.$(OBJEXT)
179
180
clean-compile:
181
182
distclean-compile:
183
	-rm -f *.tab.c
184
185
maintainer-clean-compile:
186
187
.c.lo:
188
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
189
190
.s.lo:
191
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
192
193
.S.lo:
194
	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
195
196
mostlyclean-libtool:
197
	-rm -f *.lo
198
199
clean-libtool:
200
	-rm -rf .libs _libs
201
202
distclean-libtool:
203
204
maintainer-clean-libtool:
205
206
libamigafs.la: $(libamigafs_la_OBJECTS) $(libamigafs_la_DEPENDENCIES)
207
	$(LINK)  $(libamigafs_la_LDFLAGS) $(libamigafs_la_OBJECTS) $(libamigafs_la_LIBADD) $(LIBS)
208
209
tags: TAGS
210
211
ID: $(HEADERS) $(SOURCES) $(LISP)
212
	list='$(SOURCES) $(HEADERS)'; \
213
	unique=`for i in $$list; do echo $$i; done | \
214
	  awk '    { files[$$0] = 1; } \
215
	       END { for (i in files) print i; }'`; \
216
	here=`pwd` && cd $(srcdir) \
217
	  && mkid -f$$here/ID $$unique $(LISP)
218
219
TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) $(LISP)
220
	tags=; \
221
	here=`pwd`; \
222
	list='$(SOURCES) $(HEADERS)'; \
223
	unique=`for i in $$list; do echo $$i; done | \
224
	  awk '    { files[$$0] = 1; } \
225
	       END { for (i in files) print i; }'`; \
226
	test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
227
	  || (cd $(srcdir) && etags -o $$here/TAGS $(ETAGS_ARGS) $$tags  $$unique $(LISP))
228
229
mostlyclean-tags:
230
231
clean-tags:
232
233
distclean-tags:
234
	-rm -f TAGS ID
235
236
maintainer-clean-tags:
237
238
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
239
240
subdir = libparted/fs_amiga
241
242
distdir: $(DISTFILES)
243
	@for file in $(DISTFILES); do \
244
	  d=$(srcdir); \
245
	  if test -d $$d/$$file; then \
246
	    cp -pr $$d/$$file $(distdir)/$$file; \
247
	  else \
248
	    test -f $(distdir)/$$file \
249
	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
250
	    || cp -p $$d/$$file $(distdir)/$$file || :; \
251
	  fi; \
252
	done
253
amigafs.lo amiga.o affs.o asfs.o apfs.o interface.o : \
254
	amiga.c affs.c asfs.c apfs.c interface.c \
255
	amiga.h affs.h asfs.h apfs.h \
256
	../../config.h ../../include/parted/parted.h \
257
	../../include/parted/constraint.h ../../include/parted/device.h \
258
	../../include/parted/timer.h ../../include/parted/natmath.h \
259
	../../include/parted/disk.h ../../include/parted/filesys.h \
260
	../../include/parted/geom.h ../../include/parted/exception.h \
261
	../../include/parted/endian.h platform_defs.h 
262
263
info-am:
264
info: info-am
265
dvi-am:
266
dvi: dvi-am
267
check-am: all-am
268
check: check-am
269
installcheck-am:
270
installcheck: installcheck-am
271
install-exec-am:
272
install-exec: install-exec-am
273
274
install-data-am:
275
install-data: install-data-am
276
277
install-am: all-am
278
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
279
install: install-am
280
uninstall-am:
281
uninstall: uninstall-am
282
all-am: Makefile $(LTLIBRARIES)
283
all-redirect: all-am
284
install-strip:
285
	$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
286
installdirs:
287
288
289
mostlyclean-generic:
290
291
clean-generic:
292
293
distclean-generic:
294
	-rm -f Makefile $(CONFIG_CLEAN_FILES)
295
	-rm -f config.cache config.log stamp-h stamp-h[0-9]*
296
297
maintainer-clean-generic:
298
mostlyclean-am:  mostlyclean-noinstLTLIBRARIES mostlyclean-compile \
299
		mostlyclean-libtool mostlyclean-tags \
300
		mostlyclean-generic
301
302
mostlyclean: mostlyclean-am
303
304
clean-am:  clean-noinstLTLIBRARIES clean-compile clean-libtool \
305
		clean-tags clean-generic mostlyclean-am
306
307
clean: clean-am
308
309
distclean-am:  distclean-noinstLTLIBRARIES distclean-compile \
310
		distclean-libtool distclean-tags distclean-generic \
311
		clean-am
312
	-rm -f libtool
313
314
distclean: distclean-am
315
316
maintainer-clean-am:  maintainer-clean-noinstLTLIBRARIES \
317
		maintainer-clean-compile maintainer-clean-libtool \
318
		maintainer-clean-tags maintainer-clean-generic \
319
		distclean-am
320
	@echo "This command is intended for maintainers to use;"
321
	@echo "it deletes files that may require special tools to rebuild."
322
323
maintainer-clean: maintainer-clean-am
324
325
.PHONY: mostlyclean-noinstLTLIBRARIES distclean-noinstLTLIBRARIES \
326
clean-noinstLTLIBRARIES maintainer-clean-noinstLTLIBRARIES \
327
mostlyclean-compile distclean-compile clean-compile \
328
maintainer-clean-compile mostlyclean-libtool distclean-libtool \
329
clean-libtool maintainer-clean-libtool tags mostlyclean-tags \
330
distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
331
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
332
install-exec install-data-am install-data install-am install \
333
uninstall-am uninstall all-redirect all-am all installdirs \
334
mostlyclean-generic distclean-generic clean-generic \
335
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
336
337
338
# Tell versions [3.59,3.63) of GNU make to not export all variables.
339
# Otherwise a system limit (for SysV at least) may be exceeded.
340
.NOEXPORT:
(-)parted-1.6.6/libparted/fs_amiga/affs.c (+447 lines)
Line 0 Link Here
1
/*
2
    affs.c -- parted suppoer for affs filesystems
3
    Copyright (C) 1998-2000 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 2 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, write to the Free Software
17
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
*/
19
20
#include "config.h"
21
22
#include <stdlib.h>
23
#include <string.h>
24
#include <parted/parted.h>
25
#include <parted/debug.h>
26
#include <parted/endian.h>
27
28
#include "amiga.h"
29
#include "affs.h"
30
31
#if ENABLE_NLS
32
#  include <libintl.h>
33
#  define _(String) dgettext (PACKAGE, String)
34
#else
35
#  define _(String) (String)
36
#endif /* ENABLE_NLS */
37
38
static int
39
_affs_probe_root (uint32_t *block, int blocksize) {
40
	int i;
41
	uint32_t sum;
42
43
	if (PED_BE32_TO_CPU (block[0]) != 2) return 0;
44
	if (PED_BE32_TO_CPU (block[128*blocksize-1]) != 1) return 0;
45
	for (i = 0, sum = 0; i < 128*blocksize; i++)
46
		sum += PED_BE32_TO_CPU (block[i]);
47
	if (sum) return 0;
48
	return 1;
49
}
50
51
static PedGeometry*
52
_generic_affs_probe (PedGeometry* geom, uint32_t kind)
53
{
54
	uint32_t *block;
55
	int32_t i;
56
	PedSector root, len, pos;
57
	struct PartitionBlock * part;
58
	int blocksize = 1, reserved = 2, prealloc = 0;
59
60
	PED_ASSERT (geom != NULL, return NULL);
61
	PED_ASSERT (geom->dev != NULL, return NULL);
62
63
	/* Finds the blocksize, prealloc and reserved values of the partition block */
64
	if (!(part = ped_malloc (PED_SECTOR_SIZE*blocksize))) {
65
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
66
			_("%s : Failed to allocate partition block\n"), __func__);
67
		goto error_part;
68
	}
69
	if (amiga_find_part(geom, part) != NULL) {
70
		prealloc = PED_BE32_TO_CPU (part->de_PreAlloc);
71
		reserved = PED_BE32_TO_CPU (part->de_Reserved);
72
		reserved = reserved == 0 ? 1 : reserved;
73
		blocksize = PED_BE32_TO_CPU (part->de_SizeBlock)
74
			* PED_BE32_TO_CPU (part->de_SectorPerBlock) / 128;
75
	}
76
	ped_free (part);
77
78
	/* Test boot block */
79
	if (!(block = ped_malloc (PED_SECTOR_SIZE*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
	if (!ped_device_read (geom->dev, block, geom->start, blocksize)) {
85
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
86
			_("%s : Couldn't read boot block %llu\n"), __func__, geom->start);
87
		goto error;
88
	}
89
	if (PED_BE32_TO_CPU (block[0]) != kind) {
90
		goto error;
91
	}
92
93
	/* Find and test the root block */
94
	len = geom->length / blocksize - reserved;
95
	pos = (len - 1) / 2;
96
	root = geom->start + (pos + reserved) * blocksize;
97
	printf ("Pralloc = %d, Reserved = %d, blocksize = %d, root block at %llu\n",
98
		prealloc, reserved, blocksize, root);
99
100
	if (!ped_device_read (geom->dev, block, root, blocksize)) {
101
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
102
			_("%s : Couldn't read root block %llu\n"), __func__, root);
103
		goto error;
104
	}
105
	if (_affs_probe_root(block, blocksize) == 1) {
106
		ped_free (block);
107
		return ped_geometry_duplicate (geom);
108
	}
109
110
error:
111
	ped_free (block);
112
error_block:
113
error_part:
114
	return NULL;
115
}
116
static PedGeometry*
117
_affs0_probe (PedGeometry* geom) {
118
	return _generic_affs_probe (geom, 0x444f5300);
119
}
120
static PedGeometry*
121
_affs1_probe (PedGeometry* geom) {
122
	return _generic_affs_probe (geom, 0x444f5301);
123
}
124
static PedGeometry*
125
_affs2_probe (PedGeometry* geom) {
126
	return _generic_affs_probe (geom, 0x444f5302);
127
}
128
static PedGeometry*
129
_affs3_probe (PedGeometry* geom) {
130
	return _generic_affs_probe (geom, 0x444f5303);
131
}
132
static PedGeometry*
133
_affs4_probe (PedGeometry* geom) {
134
	return _generic_affs_probe (geom, 0x444f5304);
135
}
136
static PedGeometry*
137
_affs5_probe (PedGeometry* geom) {
138
	return _generic_affs_probe (geom, 0x444f5305);
139
}
140
static PedGeometry*
141
_affs6_probe (PedGeometry* geom) {
142
	return _generic_affs_probe (geom, 0x444f5306);
143
}
144
static PedGeometry*
145
_affs7_probe (PedGeometry* geom) {
146
	return _generic_affs_probe (geom, 0x444f5307);
147
}
148
static PedGeometry*
149
_amufs_probe (PedGeometry* geom) {
150
	return _generic_affs_probe (geom, 0x6d754653);
151
}
152
static PedGeometry*
153
_amufs0_probe (PedGeometry* geom) {
154
	return _generic_affs_probe (geom, 0x6d754600);
155
}
156
static PedGeometry*
157
_amufs1_probe (PedGeometry* geom) {
158
	return _generic_affs_probe (geom, 0x6d754601);
159
}
160
static PedGeometry*
161
_amufs2_probe (PedGeometry* geom) {
162
	return _generic_affs_probe (geom, 0x6d754602);
163
}
164
static PedGeometry*
165
_amufs3_probe (PedGeometry* geom) {
166
	return _generic_affs_probe (geom, 0x6d754603);
167
}
168
static PedGeometry*
169
_amufs4_probe (PedGeometry* geom) {
170
	return _generic_affs_probe (geom, 0x6d754604);
171
}
172
static PedGeometry*
173
_amufs5_probe (PedGeometry* geom) {
174
	return _generic_affs_probe (geom, 0x6d754605);
175
}
176
177
static PedFileSystemOps _affs0_ops = {
178
	probe:		_affs0_probe,
179
	clobber:	NULL,
180
	open:		NULL,
181
	create:         NULL,
182
	close:		NULL,
183
	check:          NULL,
184
	resize:		NULL,
185
	copy:           NULL,
186
	get_create_constraint:	NULL,
187
	get_copy_constraint:	NULL,
188
	get_resize_constraint:	NULL
189
};
190
static PedFileSystemOps _affs1_ops = {
191
	probe:		_affs1_probe,
192
	clobber:	NULL,
193
	open:		NULL,
194
	create:         NULL,
195
	close:		NULL,
196
	check:          NULL,
197
	resize:		NULL,
198
	copy:           NULL,
199
	get_create_constraint:	NULL,
200
	get_copy_constraint:	NULL,
201
	get_resize_constraint:	NULL
202
};
203
static PedFileSystemOps _affs2_ops = {
204
	probe:		_affs2_probe,
205
	clobber:	NULL,
206
	open:		NULL,
207
	create:         NULL,
208
	close:		NULL,
209
	check:          NULL,
210
	resize:		NULL,
211
	copy:           NULL,
212
	get_create_constraint:	NULL,
213
	get_copy_constraint:	NULL,
214
	get_resize_constraint:	NULL
215
};
216
static PedFileSystemOps _affs3_ops = {
217
	probe:		_affs3_probe,
218
	clobber:	NULL,
219
	open:		NULL,
220
	create:         NULL,
221
	close:		NULL,
222
	check:          NULL,
223
	resize:		NULL,
224
	copy:           NULL,
225
	get_create_constraint:	NULL,
226
	get_copy_constraint:	NULL,
227
	get_resize_constraint:	NULL
228
};
229
static PedFileSystemOps _affs4_ops = {
230
	probe:		_affs4_probe,
231
	clobber:	NULL,
232
	open:		NULL,
233
	create:         NULL,
234
	close:		NULL,
235
	check:          NULL,
236
	resize:		NULL,
237
	copy:           NULL,
238
	get_create_constraint:	NULL,
239
	get_copy_constraint:	NULL,
240
	get_resize_constraint:	NULL
241
};
242
static PedFileSystemOps _affs5_ops = {
243
	probe:		_affs5_probe,
244
	clobber:	NULL,
245
	open:		NULL,
246
	create:         NULL,
247
	close:		NULL,
248
	check:          NULL,
249
	resize:		NULL,
250
	copy:           NULL,
251
	get_create_constraint:	NULL,
252
	get_copy_constraint:	NULL,
253
	get_resize_constraint:	NULL
254
};
255
static PedFileSystemOps _affs6_ops = {
256
	probe:		_affs6_probe,
257
	clobber:	NULL,
258
	open:		NULL,
259
	create:         NULL,
260
	close:		NULL,
261
	check:          NULL,
262
	resize:		NULL,
263
	copy:           NULL,
264
	get_create_constraint:	NULL,
265
	get_copy_constraint:	NULL,
266
	get_resize_constraint:	NULL
267
};
268
static PedFileSystemOps _affs7_ops = {
269
	probe:		_affs7_probe,
270
	clobber:	NULL,
271
	open:		NULL,
272
	create:         NULL,
273
	close:		NULL,
274
	check:          NULL,
275
	resize:		NULL,
276
	copy:           NULL,
277
	get_create_constraint:	NULL,
278
	get_copy_constraint:	NULL,
279
	get_resize_constraint:	NULL
280
};
281
static PedFileSystemOps _amufs_ops = {
282
	probe:		_amufs_probe,
283
	clobber:	NULL,
284
	open:		NULL,
285
	create:         NULL,
286
	close:		NULL,
287
	check:          NULL,
288
	resize:		NULL,
289
	copy:           NULL,
290
	get_create_constraint:	NULL,
291
	get_copy_constraint:	NULL,
292
	get_resize_constraint:	NULL
293
};
294
static PedFileSystemOps _amufs0_ops = {
295
	probe:		_amufs0_probe,
296
	clobber:	NULL,
297
	open:		NULL,
298
	create:         NULL,
299
	close:		NULL,
300
	check:          NULL,
301
	resize:		NULL,
302
	copy:           NULL,
303
	get_create_constraint:	NULL,
304
	get_copy_constraint:	NULL,
305
	get_resize_constraint:	NULL
306
};
307
static PedFileSystemOps _amufs1_ops = {
308
	probe:		_amufs1_probe,
309
	clobber:	NULL,
310
	open:		NULL,
311
	create:         NULL,
312
	close:		NULL,
313
	check:          NULL,
314
	resize:		NULL,
315
	copy:           NULL,
316
	get_create_constraint:	NULL,
317
	get_copy_constraint:	NULL,
318
	get_resize_constraint:	NULL
319
};
320
static PedFileSystemOps _amufs2_ops = {
321
	probe:		_amufs2_probe,
322
	clobber:	NULL,
323
	open:		NULL,
324
	create:         NULL,
325
	close:		NULL,
326
	check:          NULL,
327
	resize:		NULL,
328
	copy:           NULL,
329
	get_create_constraint:	NULL,
330
	get_copy_constraint:	NULL,
331
	get_resize_constraint:	NULL
332
};
333
static PedFileSystemOps _amufs3_ops = {
334
	probe:		_amufs3_probe,
335
	clobber:	NULL,
336
	open:		NULL,
337
	create:         NULL,
338
	close:		NULL,
339
	check:          NULL,
340
	resize:		NULL,
341
	copy:           NULL,
342
	get_create_constraint:	NULL,
343
	get_copy_constraint:	NULL,
344
	get_resize_constraint:	NULL
345
};
346
static PedFileSystemOps _amufs4_ops = {
347
	probe:		_amufs4_probe,
348
	clobber:	NULL,
349
	open:		NULL,
350
	create:         NULL,
351
	close:		NULL,
352
	check:          NULL,
353
	resize:		NULL,
354
	copy:           NULL,
355
	get_create_constraint:	NULL,
356
	get_copy_constraint:	NULL,
357
	get_resize_constraint:	NULL
358
};
359
static PedFileSystemOps _amufs5_ops = {
360
	probe:		_amufs5_probe,
361
	clobber:	NULL,
362
	open:		NULL,
363
	create:         NULL,
364
	close:		NULL,
365
	check:          NULL,
366
	resize:		NULL,
367
	copy:           NULL,
368
	get_create_constraint:	NULL,
369
	get_copy_constraint:	NULL,
370
	get_resize_constraint:	NULL
371
};
372
373
PedFileSystemType _affs0_type = {
374
       next:		 NULL,
375
       ops:		 &_affs0_ops,
376
       name:		 "affs0"
377
};
378
PedFileSystemType _affs1_type = {
379
       next:		 NULL,
380
       ops:		 &_affs1_ops,
381
       name:		 "affs1"
382
};
383
PedFileSystemType _affs2_type = {
384
       next:		 NULL,
385
       ops:		 &_affs2_ops,
386
       name:		 "affs2"
387
};
388
PedFileSystemType _affs3_type = {
389
       next:		 NULL,
390
       ops:		 &_affs3_ops,
391
       name:		 "affs3"
392
};
393
PedFileSystemType _affs4_type = {
394
       next:		 NULL,
395
       ops:		 &_affs4_ops,
396
       name:		 "affs4"
397
};
398
PedFileSystemType _affs5_type = {
399
       next:		 NULL,
400
       ops:		 &_affs5_ops,
401
       name:		 "affs5"
402
};
403
PedFileSystemType _affs6_type = {
404
       next:		 NULL,
405
       ops:		 &_affs6_ops,
406
       name:		 "affs6"
407
};
408
PedFileSystemType _affs7_type = {
409
       next:		 NULL,
410
       ops:		 &_affs7_ops,
411
       name:		 "affs7"
412
};
413
PedFileSystemType _amufs_type = {
414
       next:		 NULL,
415
       ops:		 &_amufs_ops,
416
       name:		 "amufs"
417
};
418
PedFileSystemType _amufs0_type = {
419
       next:		 NULL,
420
       ops:		 &_amufs0_ops,
421
       name:		 "amufs0"
422
};
423
PedFileSystemType _amufs1_type = {
424
       next:		 NULL,
425
       ops:		 &_amufs1_ops,
426
       name:		 "amufs1"
427
};
428
PedFileSystemType _amufs2_type = {
429
       next:		 NULL,
430
       ops:		 &_amufs2_ops,
431
       name:		 "amufs2"
432
};
433
PedFileSystemType _amufs3_type = {
434
       next:		 NULL,
435
       ops:		 &_amufs3_ops,
436
       name:		 "amufs3"
437
};
438
PedFileSystemType _amufs4_type = {
439
       next:		 NULL,
440
       ops:		 &_amufs4_ops,
441
       name:		 "amufs4"
442
};
443
PedFileSystemType _amufs5_type = {
444
       next:		 NULL,
445
       ops:		 &_amufs5_ops,
446
       name:		 "amufs5"
447
};
(-)parted-1.6.6/libparted/fs_amiga/affs.h (+20 lines)
Line 0 Link Here
1
2
/*
3
    affs.h -- parted suppoer for affs filesystems header files
4
    Copyright (C) 1998-2000 Free Software Foundation, Inc.
5
  
6
    This program is free software; you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
10
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
16
    You should have received a copy of the GNU General Public License
17
    along with this program; if not, write to the Free Software
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
*/
20
(-)parted-1.6.6/libparted/fs_amiga/amiga.c (+382 lines)
Line 0 Link Here
1
/* 
2
    libparted/fs_amiga - amiga filesystem support.
3
    Copyright (C) 2000, 2001 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 2 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, write to the Free Software
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
    Contributor:  Sven Luther <luther@debian.org>
20
*/
21
22
#include <string.h>
23
#include <parted/parted.h>
24
#include <parted/debug.h>
25
#include <parted/endian.h>
26
27
#include "amiga.h"
28
29
#if ENABLE_NLS
30
#  include <libintl.h>
31
#  define _(String) dgettext (PACKAGE, String)
32
#else
33
#  define _(String) (String)
34
#endif /* ENABLE_NLS */
35
36
/* String manipulation */
37
static void _amiga_set_bstr (const char *cstr, char *bstr, int maxsize) {
38
	int size = strlen (cstr);
39
	int i;
40
41
	if (size >= maxsize) return;
42
	bstr[0] = size;
43
	for (i = 0; i<size; i++) bstr[i+1] = cstr[i];
44
}
45
static const char * _amiga_get_bstr (char * bstr) {
46
	char * cstr = bstr + 1;
47
	int size = bstr[0];
48
	
49
	cstr[size] = '\0';
50
	return cstr;
51
}
52
53
#define	IDNAME_RIGIDDISK	0x5244534B	/* 'RDSK' */
54
#define IDNAME_BADBLOCK		0x42414442	/* 'BADB' */
55
#define	IDNAME_PARTITION	0x50415254	/* 'PART' */
56
#define IDNAME_FILESYSHEADER	0x46534844	/* 'FSHD' */
57
#define IDNAME_LOADSEG		0x4C534547	/* 'LSEG' */
58
#define IDNAME_BOOT		0x424f4f54	/* 'BOOT' */
59
#define IDNAME_FREE		0xffffffff	
60
61
static const char *
62
_amiga_block_id (uint32_t id) {
63
	switch (id) {
64
		case IDNAME_RIGIDDISK :
65
			return "RDSK";
66
		case IDNAME_BADBLOCK :
67
			return "BADB";
68
		case IDNAME_PARTITION :
69
			return "PART";
70
		case IDNAME_FILESYSHEADER :
71
			return "FSHD";
72
		case IDNAME_LOADSEG :
73
			return "LSEG";
74
		case IDNAME_BOOT :
75
			return "BOOT";
76
		case IDNAME_FREE :
77
			return "<free>";
78
		default :
79
			return "<unknown>";
80
	}
81
}
82
static int
83
_amiga_valid_block_id (uint32_t id) {
84
	switch (id) {
85
		case IDNAME_RIGIDDISK :
86
		case IDNAME_BADBLOCK :
87
		case IDNAME_PARTITION :
88
		case IDNAME_FILESYSHEADER :
89
		case IDNAME_LOADSEG :
90
		case IDNAME_BOOT :
91
			return 1;
92
		case IDNAME_FREE :
93
		default :
94
			return 0;
95
	}
96
}
97
98
struct AmigaIds *
99
_amiga_add_id (uint32_t id, struct AmigaIds *ids) {
100
	struct AmigaIds *newid;
101
102
	if ((newid=ped_malloc(sizeof (struct AmigaIds)))==NULL) {
103
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
104
			_("%s : Failed to allocate id list element\n"), __func__);
105
		return 0;
106
	}
107
	newid->ID = id;
108
	newid->next = ids;
109
	return newid;
110
}
111
112
void
113
_amiga_free_ids (struct AmigaIds *ids) {
114
	struct AmigaIds *current, *next;
115
116
	for (current = ids; current != NULL; current = next) {
117
		next = current->next;
118
		ped_free (current);
119
	}
120
}
121
int
122
_amiga_id_in_list (uint32_t id, struct AmigaIds *ids) {
123
	struct AmigaIds *current;
124
125
	for (current = ids; current != NULL; current = current->next) {
126
		if (id == current->ID)
127
			return 1;
128
	}
129
	return 0;
130
}
131
132
#define AMIGA_RDB_NOT_FOUND	((uint32_t)0xffffffff)
133
134
struct AmigaBlock {
135
    uint32_t	amiga_ID;		/* Identifier 32 bit word */
136
    uint32_t	amiga_SummedLongss;	/* Size of the structure for checksums */
137
    int32_t	amiga_ChkSum;		/* Checksum of the structure */
138
};
139
#define AMIGA(pos) ((struct AmigaBlock *)(pos)) 
140
141
struct RigidDiskBlock {
142
    uint32_t	rdb_ID;			/* Identifier 32 bit word : 'RDSK' */
143
    uint32_t	rdb_SummedLongs;	/* Size of the structure for checksums */
144
    int32_t	rdb_ChkSum;		/* Checksum of the structure */
145
    uint32_t	rdb_HostID;		/* SCSI Target ID of host, not really used */
146
    uint32_t	rdb_BlockBytes;		/* Size of disk blocks */
147
    uint32_t	rdb_Flags;		/* RDB Flags */
148
    /* block list heads */
149
    uint32_t	rdb_BadBlockList;	/* Bad block list */
150
    uint32_t	rdb_PartitionList;	/* Partition list */
151
    uint32_t	rdb_FileSysHeaderList;	/* File system header list */
152
    uint32_t	rdb_DriveInit;		/* Drive specific init code */
153
    uint32_t	rdb_BootBlockList;	/* Amiga OS 4 Boot Blocks */
154
    uint32_t	rdb_Reserved1[5];	/* Unused word, need to be set to $ffffffff */
155
    /* physical drive characteristics */
156
    uint32_t	rdb_Cylinders;		/* Number of the cylinders of the drive */
157
    uint32_t	rdb_Sectors;		/* Number of sectors of the drive */
158
    uint32_t	rdb_Heads;		/* Number of heads of the drive */
159
    uint32_t	rdb_Interleave;		/* Interleave */
160
    uint32_t	rdb_Park;		/* Head parking cylinder */
161
    uint32_t	rdb_Reserved2[3];	/* Unused word, need to be set to $ffffffff */
162
    uint32_t	rdb_WritePreComp;	/* Starting cylinder of write precompensation */
163
    uint32_t	rdb_ReducedWrite;	/* Starting cylinder of reduced write current */
164
    uint32_t	rdb_StepRate;		/* Step rate of the drive */
165
    uint32_t	rdb_Reserved3[5];	/* Unused word, need to be set to $ffffffff */
166
    /* logical drive characteristics */
167
    uint32_t	rdb_RDBBlocksLo;	/* low block of range reserved for hardblocks */
168
    uint32_t	rdb_RDBBlocksHi;	/* high block of range for these hardblocks */
169
    uint32_t	rdb_LoCylinder;		/* low cylinder of partitionable disk area */
170
    uint32_t	rdb_HiCylinder;		/* high cylinder of partitionable data area */
171
    uint32_t	rdb_CylBlocks;		/* number of blocks available per cylinder */
172
    uint32_t	rdb_AutoParkSeconds;	/* zero for no auto park */
173
    uint32_t	rdb_HighRDSKBlock;	/* highest block used by RDSK */
174
					/* (not including replacement bad blocks) */
175
    uint32_t	rdb_Reserved4;
176
    /* drive identification */
177
    char	rdb_DiskVendor[8];
178
    char	rdb_DiskProduct[16];
179
    char	rdb_DiskRevision[4];
180
    char	rdb_ControllerVendor[8];
181
    char	rdb_ControllerProduct[16];
182
    char	rdb_ControllerRevision[4];
183
    uint32_t	rdb_Reserved5[10];
184
};
185
186
#define AMIGA_MAX_PARTITIONS	128
187
#define	RDB_LOCATION_LIMIT	16
188
#define RDSK(pos) ((struct RigidDiskBlock *)(pos)) 
189
190
static int
191
_amiga_checksum (struct AmigaBlock *blk) {
192
	uint32_t *rdb = (uint32_t *) blk;
193
	uint32_t sum;
194
	int i, end;
195
196
	sum = PED_BE32_TO_CPU (rdb[0]);
197
	end = PED_BE32_TO_CPU (rdb[1]);
198
199
	if (end > PED_SECTOR_SIZE) end = PED_SECTOR_SIZE;
200
201
	for (i = 1; i < end; i++) sum += PED_BE32_TO_CPU (rdb[i]);
202
203
	return sum;
204
}
205
206
static void
207
_amiga_calculate_checksum (struct AmigaBlock *blk) {
208
209
	blk->amiga_ChkSum = PED_CPU_TO_BE32(
210
		PED_BE32_TO_CPU(blk->amiga_ChkSum) -
211
		_amiga_checksum((struct AmigaBlock *) blk));
212
	return;	
213
}
214
215
216
static struct AmigaBlock *
217
_amiga_read_block (PedDevice *dev, struct AmigaBlock *blk, PedSector block, struct AmigaIds *ids) {
218
	if (!ped_device_read (dev, blk, block, 1)) {
219
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
220
			PED_EXCEPTION_CANCEL,
221
			_("%s : Couldn't read block %llu\n"), __func__, block))
222
		{
223
			case PED_EXCEPTION_CANCEL :
224
			case PED_EXCEPTION_UNHANDLED :
225
			default : 
226
				return NULL;
227
		}
228
	}
229
	if (ids && !_amiga_id_in_list(PED_BE32_TO_CPU(blk->amiga_ID), ids))
230
		return NULL;
231
	if (_amiga_checksum (blk) != 0) {
232
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
233
			PED_EXCEPTION_FIX | PED_EXCEPTION_IGNORE | PED_EXCEPTION_CANCEL,
234
			_("%s : Bad checksum on block %llu of type %s\n"),
235
			__func__, block, _amiga_block_id(PED_BE32_TO_CPU(blk->amiga_ID))))
236
		{
237
			case PED_EXCEPTION_CANCEL :
238
				return NULL;
239
			case PED_EXCEPTION_FIX :
240
				_amiga_calculate_checksum(AMIGA(blk));
241
				if (!ped_device_write (dev, blk, block, 1)) {
242
					switch (ped_exception_throw(PED_EXCEPTION_FATAL,
243
						PED_EXCEPTION_CANCEL,
244
						_("%s : Couldn't write block %d\n"), __func__, block))
245
					{
246
						case PED_EXCEPTION_CANCEL :
247
						case PED_EXCEPTION_UNHANDLED :
248
						default : 
249
							return NULL;
250
					}
251
				}
252
			case PED_EXCEPTION_IGNORE :
253
			case PED_EXCEPTION_UNHANDLED :
254
			default : 
255
				return blk;
256
		}
257
	}
258
	return blk;
259
}
260
261
static uint32_t
262
_amiga_find_rdb (PedDevice *dev, struct RigidDiskBlock *rdb) {
263
	int i;
264
	struct AmigaIds *ids;
265
	
266
	ids = _amiga_add_id (IDNAME_RIGIDDISK, NULL);
267
268
	for (i = 0; i<RDB_LOCATION_LIMIT; i++) {
269
		if (!_amiga_read_block (dev, AMIGA(rdb), i, ids)) {
270
			continue;
271
		}
272
		if (PED_BE32_TO_CPU (rdb->rdb_ID) == IDNAME_RIGIDDISK) {
273
			_amiga_free_ids (ids);
274
			return i;
275
		}
276
	}
277
	_amiga_free_ids (ids);
278
	return AMIGA_RDB_NOT_FOUND;
279
}
280
281
static int
282
_amiga_loop_check (uint32_t block, uint32_t * blocklist, uint32_t max)
283
{
284
	uint32_t i;
285
286
	for (i = 0; i < max; i++)
287
		if (block == blocklist[i]) {
288
			/* We are looping, let's stop.  */
289
			return 1;
290
		}
291
	blocklist[max] = block;
292
	return 0;
293
}
294
295
/* We have already allocated a rdb, we are now reading it from the disk */
296
struct PartitionBlock *
297
amiga_find_part (PedGeometry *geom, struct PartitionBlock *part)
298
{
299
	struct RigidDiskBlock *rdb;
300
	uint32_t partblock;
301
	uint32_t partlist[AMIGA_MAX_PARTITIONS];
302
	int i;
303
304
	PED_ASSERT(geom!= NULL, return NULL);
305
	PED_ASSERT(geom->dev!= NULL, return NULL);
306
307
	if (!(rdb = ped_malloc (PED_SECTOR_SIZE))) {
308
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
309
			PED_EXCEPTION_CANCEL,
310
			_("%s : Failed to allocate disk_specific rdb block\n"), __func__))
311
		{
312
			case PED_EXCEPTION_CANCEL :
313
			case PED_EXCEPTION_UNHANDLED :
314
			default : 
315
				return NULL;
316
		}
317
	}
318
	if (_amiga_find_rdb (geom->dev, rdb) == AMIGA_RDB_NOT_FOUND) {
319
		switch (ped_exception_throw(PED_EXCEPTION_ERROR,
320
			PED_EXCEPTION_CANCEL,
321
			_("%s : Didn't find rdb block, should never happen\n"), __func__))
322
		{
323
			case PED_EXCEPTION_CANCEL :
324
			case PED_EXCEPTION_UNHANDLED :
325
			default : 
326
				ped_free(rdb);
327
				return NULL;
328
		}
329
	}
330
331
	/* We initialize the hardblock free list to detect loops */
332
	for (i = 0; i < AMIGA_MAX_PARTITIONS; i++) partlist[i] = 0xffffffff;
333
334
	for (i = 1, partblock = PED_BE32_TO_CPU(rdb->rdb_PartitionList);
335
		i < AMIGA_MAX_PARTITIONS && partblock != 0xffffffff;
336
		i++, partblock = PED_BE32_TO_CPU(part->pb_Next))
337
	{
338
		PedSector start, end;
339
		PedSector cylblocks;
340
341
		/* Let's look for loops in the partition table */
342
		if (_amiga_loop_check(partblock, partlist, i)) {
343
			ped_free (rdb);
344
			return NULL;
345
		}
346
		/* Let's read a partition block to get its geometry*/
347
		if (!ped_device_read (geom->dev, part, (PedSector)partblock, 1)) {
348
			switch (ped_exception_throw(PED_EXCEPTION_ERROR,
349
				PED_EXCEPTION_CANCEL,
350
				_("%s : Failed to to read partition block %llu\n"),
351
				__func__, (PedSector)partblock))
352
			{
353
				case PED_EXCEPTION_CANCEL :
354
				case PED_EXCEPTION_UNHANDLED :
355
				default : 
356
					ped_free(rdb);
357
					return NULL;
358
			}
359
		}
360
361
		/* Current block is not a Partition Block */
362
		if (part->pb_ID != IDNAME_PARTITION) {
363
			ped_free (rdb);
364
			return NULL;
365
		}
366
367
		/* Calculate the geometry of the partition */
368
		cylblocks = ((PedSector) PED_BE32_TO_CPU (part->de_Surfaces)) *
369
			((PedSector) PED_BE32_TO_CPU (part->de_BlocksPerTrack));
370
		start = ((PedSector) PED_BE32_TO_CPU (part->de_LowCyl)) * cylblocks;
371
		end = ((((PedSector) PED_BE32_TO_CPU (part->de_HighCyl))+1) * (cylblocks))-1;
372
373
		/* And check if it is the one we are searching for */
374
		if (start == geom->start && end == geom->end) {
375
			ped_free (rdb);
376
			return part;
377
		}
378
	}
379
380
	ped_free (rdb);
381
	return NULL;
382
}
(-)parted-1.6.6/libparted/fs_amiga/amiga.h (+71 lines)
Line 0 Link Here
1
/*
2
    util.h -- amiga partition table headers.
3
    Copyright (C) 1998-2000 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 2 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, write to the Free Software
17
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
*/
19
20
struct PartitionBlock {
21
    uint32_t	pb_ID;			/* Identifier 32 bit word : 'PART' */
22
    uint32_t	pb_SummedLongs;		/* Size of the structure for checksums */
23
    int32_t	pb_ChkSum;		/* Checksum of the structure */
24
    uint32_t	pb_HostID;		/* SCSI Target ID of host, not really used */
25
    uint32_t	pb_Next;		/* Block number of the next PartitionBlock */
26
    uint32_t	pb_Flags;		/* Part Flags (NOMOUNT and BOOTABLE) */
27
    uint32_t	pb_Reserved1[2];
28
    uint32_t	pb_DevFlags;		/* Preferred flags for OpenDevice */
29
    uint8_t	pb_DriveName[32];	/* Preferred DOS device name: BSTR form */
30
    uint32_t	pb_Reserved2[15];
31
    uint32_t	de_TableSize;		/* Size of Environment vector */
32
    uint32_t	de_SizeBlock;		/* Size of the blocks in 32 bit words, usually 128 */
33
    uint32_t	de_SecOrg;	     	/* Not used; must be 0 */
34
    uint32_t	de_Surfaces;		/* Number of heads (surfaces) */
35
    uint32_t	de_SectorPerBlock;	/* Disk sectors per block, used with SizeBlock, usually 1 */
36
    uint32_t	de_BlocksPerTrack;	/* Blocks per track. drive specific */
37
    uint32_t	de_Reserved;		/* DOS reserved blocks at start of partition. */
38
    uint32_t	de_PreAlloc;		/* DOS reserved blocks at end of partition */
39
    uint32_t	de_Interleave;		/* Not used, usually 0 */
40
    uint32_t	de_LowCyl;		/* First cylinder of the partition */
41
    uint32_t	de_HighCyl;		/* Last cylinder of the partition */
42
    uint32_t	de_NumBuffers;		/* Initial # DOS of buffers.  */
43
    uint32_t	de_BufMemType;		/* Type of mem to allocate for buffers */
44
    uint32_t	de_MaxTransfer;		/* Max number of bytes to transfer at a time */
45
    uint32_t	de_Mask;		/* Address Mask to block out certain memory */
46
    int32_t	de_BootPri;		/* Boot priority for autoboot */
47
    uint32_t	de_DosType;		/* Dostype of the filesystem */
48
    uint32_t	de_Baud;		/* Baud rate for serial handler */
49
    uint32_t	de_Control;		/* Control word for handler/filesystem */
50
    uint32_t	de_BootBlocks;		/* Number of blocks containing boot code */
51
    uint32_t	pb_EReserved[12];
52
};
53
54
#define PART(pos) ((struct PartitionBlock *)(pos))
55
56
#define	PBFB_BOOTABLE	0	/* this partition is intended to be bootable */
57
#define	PBFF_BOOTABLE	1L	/*   (expected directories and files exist) */
58
#define	PBFB_NOMOUNT	1	/* do not mount this partition (e.g. manually */
59
#define	PBFF_NOMOUNT	2L	/*   mounted, but space reserved here) */
60
61
struct PartitionBlock * amiga_find_part (PedGeometry *geom, struct PartitionBlock *part);
62
63
struct AmigaIds {
64
	uint32_t ID;
65
	struct AmigaIds *next;
66
};
67
68
struct AmigaIds * _amiga_add_id (uint32_t id, struct AmigaIds *ids);
69
void _amiga_free_ids (struct AmigaIds *ids);
70
int _amiga_id_in_list (uint32_t id, struct AmigaIds *ids);
71
(-)parted-1.6.6/libparted/fs_amiga/apfs.c (+150 lines)
Line 0 Link Here
1
/*
2
    apfs.c -- parted support for apfs filesystems
3
    Copyright (C) 1998-2000 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 2 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, write to the Free Software
17
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
*/
19
20
#include "config.h"
21
22
#include <stdlib.h>
23
#include <string.h>
24
#include <parted/parted.h>
25
#include <parted/debug.h>
26
#include <parted/endian.h>
27
28
#include "amiga.h"
29
#include "apfs.h"
30
31
#if ENABLE_NLS
32
#  include <libintl.h>
33
#  define _(String) dgettext (PACKAGE, String)
34
#else
35
#  define _(String) (String)
36
#endif /* ENABLE_NLS */
37
38
static int
39
_apfs_probe_root (uint32_t *block, uint32_t blocksize, uint32_t kind) {
40
	if (PED_BE32_TO_CPU (block[0]) != kind) return 0;
41
	return 1;
42
}
43
44
static PedGeometry*
45
_generic_apfs_probe (PedGeometry* geom, uint32_t kind)
46
{
47
	uint32_t *block;
48
	int32_t i, sum;
49
	PedSector root;
50
	struct PartitionBlock * part;
51
	uint32_t blocksize = 1, reserved = 2, prealloc = 0;
52
53
	PED_ASSERT (geom != NULL, return NULL);
54
	PED_ASSERT (geom->dev != NULL, return NULL);
55
56
	/* Finds the blocksize, prealloc and reserved values of the partition block */
57
	if (!(part = ped_malloc (PED_SECTOR_SIZE*blocksize))) {
58
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
59
			_("%s : Failed to allocate partition block\n"), __func__);
60
		goto error_part;
61
	}
62
	if (amiga_find_part(geom, part) != NULL) {
63
		prealloc = PED_BE32_TO_CPU (part->de_PreAlloc);
64
		reserved = PED_BE32_TO_CPU (part->de_Reserved);
65
		blocksize = PED_BE32_TO_CPU (part->de_SizeBlock)
66
			* PED_BE32_TO_CPU (part->de_SectorPerBlock) / 128;
67
	}
68
	ped_free (part);
69
70
	/* Test boot block */
71
	if (!(block = ped_malloc (PED_SECTOR_SIZE*blocksize))) {
72
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
73
			_("%s : Failed to allocate block\n"), __func__);
74
		goto error_block;
75
	}
76
	if (!ped_device_read (geom->dev, block, geom->start, blocksize)) {
77
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
78
			_("%s : Couldn't read boot block %llu\n"), __func__, geom->start);
79
		goto error;
80
	}
81
	if (PED_BE32_TO_CPU (block[0]) != kind) {
82
		goto error;
83
	}
84
85
	/* Find and test the root block */
86
	root = geom->start+reserved*blocksize;
87
	if (!ped_device_read (geom->dev, block, root, blocksize)) {
88
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
89
			_("%s : Couldn't read root block %llu\n"), __func__, root);
90
		goto error;
91
	}
92
	if (_apfs_probe_root(block, blocksize, kind) == 1) {
93
		ped_free(block);
94
		return ped_geometry_duplicate (geom);
95
	}
96
97
error:
98
	ped_free (block);
99
error_block:
100
error_part:
101
	return NULL;
102
}
103
104
static PedGeometry*
105
_apfs1_probe (PedGeometry* geom) {
106
	return _generic_apfs_probe (geom, 0x50463101);
107
}
108
109
static PedGeometry*
110
_apfs2_probe (PedGeometry* geom) {
111
	return _generic_apfs_probe (geom, 0x50463102);
112
}
113
114
static PedFileSystemOps _apfs1_ops = {
115
	probe:		_apfs1_probe,
116
	clobber:	NULL,
117
	open:		NULL,
118
	create:         NULL,
119
	close:		NULL,
120
	check:          NULL,
121
	resize:		NULL,
122
	copy:           NULL,
123
	get_create_constraint:	NULL,
124
	get_copy_constraint:	NULL,
125
	get_resize_constraint:	NULL
126
};
127
static PedFileSystemOps _apfs2_ops = {
128
	probe:		_apfs2_probe,
129
	clobber:	NULL,
130
	open:		NULL,
131
	create:         NULL,
132
	close:		NULL,
133
	check:          NULL,
134
	resize:		NULL,
135
	copy:           NULL,
136
	get_create_constraint:	NULL,
137
	get_copy_constraint:	NULL,
138
	get_resize_constraint:	NULL
139
};
140
141
PedFileSystemType _apfs1_type = {
142
       next:		 NULL,
143
       ops:		 &_apfs1_ops,
144
       name:		 "apfs1"
145
};
146
PedFileSystemType _apfs2_type = {
147
       next:		 NULL,
148
       ops:		 &_apfs2_ops,
149
       name:		 "apfs2"
150
};
(-)parted-1.6.6/libparted/fs_amiga/apfs.h (+19 lines)
Line 0 Link Here
1
2
/*
3
    apfs.h -- parted support for apfs filesystems header files
4
    Copyright (C) 1998-2000 Free Software Foundation, Inc.
5
  
6
    This program is free software; you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
10
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
16
    You should have received a copy of the GNU General Public License
17
    along with this program; if not, write to the Free Software
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
*/
(-)parted-1.6.6/libparted/fs_amiga/asfs.c (+144 lines)
Line 0 Link Here
1
/*
2
    asfs.c -- parted asfs filesystem support
3
    Copyright (C) 1998-2000 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 2 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, write to the Free Software
17
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
*/
19
20
#include "config.h"
21
22
#include <stdlib.h>
23
#include <string.h>
24
#include <parted/parted.h>
25
#include <parted/debug.h>
26
#include <parted/endian.h>
27
28
#include "amiga.h"
29
#include "asfs.h"
30
31
#if ENABLE_NLS
32
#  include <libintl.h>
33
#  define _(String) dgettext (PACKAGE, String)
34
#else
35
#  define _(String) (String)
36
#endif /* ENABLE_NLS */
37
38
static int
39
_asfs_probe_root (PedGeometry *geom, uint32_t *block, int blocksize, PedSector root) {
40
	int i, sum;
41
	PedSector start, end;
42
43
	if (PED_BE32_TO_CPU (block[0]) != 0x53465300) return 0;
44
	for (i = 0, sum = 1; i < 128*blocksize; i++) sum += PED_BE32_TO_CPU (block[i]);
45
	if (sum != 0) return 0;
46
	if (PED_BE32_TO_CPU (block[2]) * blocksize + geom->start != root) {
47
		return 0;
48
	}
49
	start = ((((PedSector) PED_BE32_TO_CPU (block[8])) << 32)
50
		+ (PedSector) PED_BE32_TO_CPU (block[9])) / 512;
51
	end = (((((PedSector) PED_BE32_TO_CPU (block[10])) << 32)
52
		+ (PedSector) PED_BE32_TO_CPU (block[11])) / 512) - 1;
53
	if (start != geom->start || end != geom->end) return 0;
54
	return 1;
55
}
56
57
static PedGeometry*
58
_asfs_probe (PedGeometry* geom)
59
{
60
	uint32_t *block;
61
	struct PartitionBlock * part;
62
	int blocksize = 1, reserved = 1, prealloc = 1;
63
	PedSector root, root2;
64
	int found = 0;
65
66
	PED_ASSERT (geom != NULL, return NULL);
67
	PED_ASSERT (geom->dev != NULL, return NULL);
68
69
	/* Finds the blocksize, prealloc and reserved values of the partition block */
70
	if (!(part = ped_malloc (PED_SECTOR_SIZE*blocksize))) {
71
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
72
			_("%s : Failed to allocate partition block\n"), __func__);
73
		goto error_part;
74
	}
75
	if (amiga_find_part(geom, part) != NULL) {
76
		prealloc = PED_BE32_TO_CPU (part->de_PreAlloc) == 0 ?
77
			1 : PED_BE32_TO_CPU (part->de_PreAlloc);
78
		reserved = PED_BE32_TO_CPU (part->de_Reserved) == 0 ?
79
			1 : PED_BE32_TO_CPU (part->de_Reserved);
80
		blocksize = PED_BE32_TO_CPU (part->de_SizeBlock)
81
			* PED_BE32_TO_CPU (part->de_SectorPerBlock) / 128;
82
	}
83
	ped_free (part);
84
85
	/* Test boot block */
86
	if (!(block = ped_malloc (PED_SECTOR_SIZE*blocksize))) {
87
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
88
			_("%s : Failed to allocate block\n"), __func__);
89
		goto error_block;
90
	}
91
	root = geom->start;
92
	if (!ped_device_read (geom->dev, block, root, blocksize)) {
93
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
94
			_("%s : Couldn't read root block %llu\n"), __func__, root);
95
		goto error;
96
	}
97
	if (PED_BE32_TO_CPU (block[0]) != 0x53465300) {
98
		goto error;
99
	}
100
101
	/* Find and test the root blocks */
102
	if (_asfs_probe_root(geom, block, blocksize, root)) {
103
		found++;
104
	}
105
	root = geom->end - blocksize - (geom->length % blocksize) + 1;
106
	if (!ped_device_read (geom->dev, block, root, 1)) {
107
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
108
			_("%s : Couldn't read root block %llu\n"), __func__, root);
109
		goto error;
110
	}
111
	if (_asfs_probe_root(geom, block, blocksize, root)) {
112
		found++;
113
	}
114
	if (found != 0) {
115
		ped_free (block);
116
		return ped_geometry_duplicate (geom);
117
	}
118
119
error:
120
	ped_free (block);
121
error_block:
122
error_part:
123
	return NULL;
124
}
125
126
static PedFileSystemOps _asfs_ops = {
127
	probe:		_asfs_probe,
128
	clobber:	NULL,
129
	open:		NULL,
130
	create:         NULL,
131
	close:		NULL,
132
	check:          NULL,
133
	resize:		NULL,
134
	copy:           NULL,
135
	get_create_constraint:	NULL,
136
	get_copy_constraint:	NULL,
137
	get_resize_constraint:	NULL
138
};
139
140
PedFileSystemType _asfs_type = {
141
       next:		 NULL,
142
       ops:		 &_asfs_ops,
143
       name:		 "asfs"
144
};
(-)parted-1.6.6/libparted/fs_amiga/asfs.h (+19 lines)
Line 0 Link Here
1
2
/*
3
    asfs.h -- parted asfs filesystem support header files
4
    Copyright (C) 1998-2000 Free Software Foundation, Inc.
5
  
6
    This program is free software; you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
10
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
16
    You should have received a copy of the GNU General Public License
17
    along with this program; if not, write to the Free Software
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
*/
(-)parted-1.6.6/libparted/fs_amiga/interface.c (+90 lines)
Line 0 Link Here
1
/*
2
    interface.c -- parted support amiga filesystems
3
    Copyright (C) 1998-2000 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 2 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, write to the Free Software
17
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
*/
19
20
21
#include "config.h"
22
23
#include <stdlib.h>
24
#include <string.h>
25
#include <parted/parted.h>
26
#include <parted/debug.h>
27
#include <parted/endian.h>
28
29
extern PedFileSystemType _affs0_type;
30
extern PedFileSystemType _affs1_type;
31
extern PedFileSystemType _affs2_type;
32
extern PedFileSystemType _affs3_type;
33
extern PedFileSystemType _affs4_type;
34
extern PedFileSystemType _affs5_type;
35
extern PedFileSystemType _affs6_type;
36
extern PedFileSystemType _affs7_type;
37
extern PedFileSystemType _amufs_type;
38
extern PedFileSystemType _amufs0_type;
39
extern PedFileSystemType _amufs1_type;
40
extern PedFileSystemType _amufs2_type;
41
extern PedFileSystemType _amufs3_type;
42
extern PedFileSystemType _amufs4_type;
43
extern PedFileSystemType _amufs5_type;
44
extern PedFileSystemType _asfs_type;
45
extern PedFileSystemType _apfs1_type;
46
extern PedFileSystemType _apfs2_type;
47
48
void ped_file_system_amiga_init ()
49
{
50
	ped_file_system_type_register (&_affs0_type);
51
	ped_file_system_type_register (&_affs1_type);
52
	ped_file_system_type_register (&_affs2_type);
53
	ped_file_system_type_register (&_affs3_type);
54
	ped_file_system_type_register (&_affs4_type);
55
	ped_file_system_type_register (&_affs5_type);
56
	ped_file_system_type_register (&_affs6_type);
57
	ped_file_system_type_register (&_affs7_type);
58
	ped_file_system_type_register (&_amufs_type);
59
	ped_file_system_type_register (&_amufs0_type);
60
	ped_file_system_type_register (&_amufs1_type);
61
	ped_file_system_type_register (&_amufs2_type);
62
	ped_file_system_type_register (&_amufs3_type);
63
	ped_file_system_type_register (&_amufs4_type);
64
	ped_file_system_type_register (&_amufs5_type);
65
	ped_file_system_type_register (&_asfs_type);
66
	ped_file_system_type_register (&_apfs1_type);
67
	ped_file_system_type_register (&_apfs2_type);
68
}
69
70
void ped_file_system_amiga_done ()
71
{
72
	ped_file_system_type_unregister (&_affs0_type);
73
	ped_file_system_type_unregister (&_affs1_type);
74
	ped_file_system_type_unregister (&_affs2_type);
75
	ped_file_system_type_unregister (&_affs3_type);
76
	ped_file_system_type_unregister (&_affs4_type);
77
	ped_file_system_type_unregister (&_affs5_type);
78
	ped_file_system_type_unregister (&_affs6_type);
79
	ped_file_system_type_unregister (&_affs7_type);
80
	ped_file_system_type_unregister (&_amufs_type);
81
	ped_file_system_type_unregister (&_amufs0_type);
82
	ped_file_system_type_unregister (&_amufs1_type);
83
	ped_file_system_type_unregister (&_amufs2_type);
84
	ped_file_system_type_unregister (&_amufs3_type);
85
	ped_file_system_type_unregister (&_amufs4_type);
86
	ped_file_system_type_unregister (&_amufs5_type);
87
	ped_file_system_type_unregister (&_asfs_type);
88
	ped_file_system_type_unregister (&_apfs1_type);
89
	ped_file_system_type_unregister (&_apfs2_type);
90
}
(-)parted-1.6.6/libparted/libparted.c (+8 lines)
Lines 86-97 Link Here
86
extern void ped_disk_msdos_init ();
86
extern void ped_disk_msdos_init ();
87
extern void ped_disk_pc98_init ();
87
extern void ped_disk_pc98_init ();
88
extern void ped_disk_sun_init ();
88
extern void ped_disk_sun_init ();
89
extern void ped_disk_amiga_init ();
89
90
90
static void
91
static void
91
init_disk_types ()
92
init_disk_types ()
92
{
93
{
93
	ped_disk_loop_init ();	/* must be last in the probe list */
94
	ped_disk_loop_init ();	/* must be last in the probe list */
94
95
96
	ped_disk_amiga_init ();
95
	ped_disk_sun_init ();
97
	ped_disk_sun_init ();
96
#ifdef ENABLE_PC98
98
#ifdef ENABLE_PC98
97
	ped_disk_pc98_init ();
99
	ped_disk_pc98_init ();
Lines 104-109 Link Here
104
}
106
}
105
107
106
#ifdef ENABLE_FS
108
#ifdef ENABLE_FS
109
extern void ped_file_system_amiga_init (void);
107
extern void ped_file_system_xfs_init (void);
110
extern void ped_file_system_xfs_init (void);
108
extern void ped_file_system_ufs_init (void);
111
extern void ped_file_system_ufs_init (void);
109
extern void ped_file_system_reiserfs_init (void);
112
extern void ped_file_system_reiserfs_init (void);
Lines 117-122 Link Here
117
static void
120
static void
118
init_file_system_types ()
121
init_file_system_types ()
119
{
122
{
123
	ped_file_system_amiga_init ();
120
	ped_file_system_xfs_init ();
124
	ped_file_system_xfs_init ();
121
	ped_file_system_ufs_init ();
125
	ped_file_system_ufs_init ();
122
	ped_file_system_reiserfs_init ();
126
	ped_file_system_reiserfs_init ();
Lines 137-146 Link Here
137
extern void ped_disk_msdos_done ();
141
extern void ped_disk_msdos_done ();
138
extern void ped_disk_pc98_done ();
142
extern void ped_disk_pc98_done ();
139
extern void ped_disk_sun_done ();
143
extern void ped_disk_sun_done ();
144
extern void ped_disk_amiga_done ();
140
145
141
static void
146
static void
142
done_disk_types ()
147
done_disk_types ()
143
{
148
{
149
	ped_disk_amiga_done ();
144
	ped_disk_sun_done ();
150
	ped_disk_sun_done ();
145
#ifdef ENABLE_PC98
151
#ifdef ENABLE_PC98
146
	ped_disk_pc98_done ();
152
	ped_disk_pc98_done ();
Lines 190-195 Link Here
190
extern void ped_file_system_reiserfs_done (void);
196
extern void ped_file_system_reiserfs_done (void);
191
extern void ped_file_system_ufs_done (void);
197
extern void ped_file_system_ufs_done (void);
192
extern void ped_file_system_xfs_done (void);
198
extern void ped_file_system_xfs_done (void);
199
extern void ped_file_system_amiga_done (void);
193
200
194
static void
201
static void
195
done_file_system_types ()
202
done_file_system_types ()
Lines 203-208 Link Here
203
	ped_file_system_reiserfs_done ();
210
	ped_file_system_reiserfs_done ();
204
	ped_file_system_ufs_done ();
211
	ped_file_system_ufs_done ();
205
	ped_file_system_xfs_done ();
212
	ped_file_system_xfs_done ();
213
	ped_file_system_amiga_done ();
206
}
214
}
207
#endif /* ENABLE_FS */
215
#endif /* ENABLE_FS */
208
216

Return to bug 46041