Bug#239816: [PATCH 2/2] libparted: Add support for atari partition tables

2016-12-09 Thread John Paul Adrian Glaubitz
Hi Colin!

On 12/09/2016 01:57 PM, Colin Watson wrote:
> Thanks for this.  I've satisfied myself that it shouldn't cause problems
> on other systems, so I've gone ahead and applied these patches to Debian
> unstable, though I expect I may need to refresh them at some point.

Thanks a lot, this is awesome :). Now I can build d-i images for m68k!

> A few minor comments, although I haven't reviewed the Atari-specific
> details:
> 
> On Sun, Dec 04, 2016 at 05:12:46PM +0100, John Paul Adrian Glaubitz wrote:
>> +static int
>> +atr_part_correct (AtariRawPartition* part, uint32_t hd_size)
>> +{
>> +uint32_t start, size;
>> +
>> +start = PED_BE32_TO_CPU (part->start);
>> +size = PED_BE32_TO_CPU (part->size);
>> +
>> +return isalnum_l(part->id[0], atr_c_locale)
>> +&& isalnum_l(part->id[1], atr_c_locale)
>> +&& isalnum_l(part->id[2], atr_c_locale)
>> +&& atr_start_size_correct (start, size, hd_size);
>> +}
> 
> I'd be inclined to just hand-roll a C-flavoured isalnum equivalent
> rather than bothering to instantiate a custom locale.

Makes sense. I can try looking into this.

>> @@ -96,6 +97,7 @@ init_disk_types ()
>>  ped_disk_bsd_init ();
>>  ped_disk_amiga_init ();
>>  ped_disk_aix_init ();
>> +ped_disk_atari_init ();
>>  }
> 
> Aside from dasd, these seem to be mostly reverse-alphabetical except
> that atari is now slightly out of sequence.  Any reason for that?
> (Ditto in done_disk_types.)

No, just an oversight :).

> Also, "git am" whinges about various minor whitespace things, which you
> should correct:
> 
> .git/rebase-apply/patch:710: space before tab in indent.
> disk,
> .git/rebase-apply/patch:711: space before tab in indent.
> PED_BE32_TO_CPU (table.part[i].start),
> .git/rebase-apply/patch:712: space before tab in indent.
> &pnum ) )
> .git/rebase-apply/patch:1460: space before tab in indent.
> < min_start ) ) {
> .git/rebase-apply/patch:1721: space before tab in indent.
>| PED_PARTITION_EXTENDED))

Thanks for spotting these. Will fix them!

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaub...@debian.org
`. `'   Freie Universitaet Berlin - glaub...@physik.fu-berlin.de
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913



Bug#239816: [PATCH 2/2] libparted: Add support for atari partition tables

2016-12-09 Thread Colin Watson
Thanks for this.  I've satisfied myself that it shouldn't cause problems
on other systems, so I've gone ahead and applied these patches to Debian
unstable, though I expect I may need to refresh them at some point.

A few minor comments, although I haven't reviewed the Atari-specific
details:

On Sun, Dec 04, 2016 at 05:12:46PM +0100, John Paul Adrian Glaubitz wrote:
> +static int
> +atr_part_correct (AtariRawPartition* part, uint32_t hd_size)
> +{
> + uint32_t start, size;
> +
> + start = PED_BE32_TO_CPU (part->start);
> + size = PED_BE32_TO_CPU (part->size);
> +
> + return isalnum_l(part->id[0], atr_c_locale)
> + && isalnum_l(part->id[1], atr_c_locale)
> + && isalnum_l(part->id[2], atr_c_locale)
> + && atr_start_size_correct (start, size, hd_size);
> +}

I'd be inclined to just hand-roll a C-flavoured isalnum equivalent
rather than bothering to instantiate a custom locale.

> @@ -96,6 +97,7 @@ init_disk_types ()
>   ped_disk_bsd_init ();
>   ped_disk_amiga_init ();
>   ped_disk_aix_init ();
> + ped_disk_atari_init ();
>  }

Aside from dasd, these seem to be mostly reverse-alphabetical except
that atari is now slightly out of sequence.  Any reason for that?
(Ditto in done_disk_types.)

Also, "git am" whinges about various minor whitespace things, which you
should correct:

.git/rebase-apply/patch:710: space before tab in indent.
disk,
.git/rebase-apply/patch:711: space before tab in indent.
PED_BE32_TO_CPU (table.part[i].start),
.git/rebase-apply/patch:712: space before tab in indent.
&pnum ) )
.git/rebase-apply/patch:1460: space before tab in indent.
< min_start ) ) {
.git/rebase-apply/patch:1721: space before tab in indent.
   | PED_PARTITION_EXTENDED))

Cheers,

-- 
Colin Watson   [cjwat...@debian.org]



Bug#239816: [PATCH 2/2] libparted: Add support for atari partition tables

2016-12-04 Thread John Paul Adrian Glaubitz
Signed-off-by: John Paul Adrian Glaubitz 
---
 libparted/labels/Makefile.am|1 +
 libparted/labels/atari.c| 1969 +++
 libparted/labels/pt-limit.gperf |1 +
 libparted/libparted.c   |4 +
 libparted/tests/common.c|3 +
 po/POTFILES.in  |1 +
 tests/t3310-flags.sh|6 +-
 tests/t9021-maxima.sh   |5 +-
 8 files changed, 1988 insertions(+), 2 deletions(-)
 create mode 100644 libparted/labels/atari.c

diff --git a/libparted/labels/Makefile.am b/libparted/labels/Makefile.am
index c996f81..3327c8c 100644
--- a/libparted/labels/Makefile.am
+++ b/libparted/labels/Makefile.am
@@ -19,6 +19,7 @@ noinst_LTLIBRARIES=   liblabels.la
 liblabels_la_SOURCES = \
   $(S390_SRCS) \
   aix.c\
+  atari.c  \
   bsd.c\
   dos.c\
   dvh.c\
diff --git a/libparted/labels/atari.c b/libparted/labels/atari.c
new file mode 100644
index 000..8ed0dfb
--- /dev/null
+++ b/libparted/labels/atari.c
@@ -0,0 +1,1969 @@
+/* -*- Mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+
+libparted - a library for manipulating disk partitions
+atari.c - libparted module to manipulate Atari partition tables.
+Copyright (C) 2000-2001, 2004, 2007-2014 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see .
+
+Contributor:  Guillaume Knispel 
+  John Paul Adrian Glaubitz 
+*/
+
+/*
+   Documentation :
+   README file of atari-fdisk
+   atari-fdisk source code
+   Linux atari partitions parser source code
+   ( fs/partitions/atari.[ch] )
+*/
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "pt-tools.h"
+
+#if ENABLE_NLS
+#  include 
+#  define _(String) dgettext (PACKAGE, String)
+#else
+#  define _(String) (String)
+#endif /* ENABLE_NLS */
+
+
+/** Atari data and structure stuff **/
+
+#define BOOTABLE_CKSUM 0x1234
+#define NONBOOT_CKSUM  0x4321
+
+#define GEM_MAX((32*1024*1024)/PED_SECTOR_SIZE_DEFAULT)
+
+#define PART_FLAG_USED 0x01
+#define PART_FLAG_BOOT_GEM 0x80/* GEMDOS  */
+#define PART_FLAG_BOOT_ASV 0x40/* Atari System V  */
+#define PART_FLAG_BOOT_BSD 0x20/* Net(?)BSD   */
+#define PART_FLAG_BOOT_LNX 0x10/* Linux   */
+#define PART_FLAG_BOOT_UNK 0x08/* unknown / other */
+
+#define N_AHDI 4
+#define N_ICD  8
+
+#define MAXIMUM_PARTS  64
+
+/* what we put instead of id, start and size in empty */
+/* partition tables, to be able to detect it */
+#define SIGNATURE_EMPTY_TABLE  "PARTEDATARI"
+#define SIGNATURE_EMPTY_SIZE   11
+
+/* to be compared to the last two bytes of 1st sector (Big Endian) */
+static const uint16_t atr_forbidden_sign[] = {
+   0x55AA,
+   0
+};
+
+static const char *atr_known_icd_pid[] = {
+   "BGM", "GEM", "LNX", "SWP", "RAW", NULL
+};
+
+/* static const char *atr_known_pid[] = { */
+/* "BGM", "GEM", "LNX", "MAC", "MIX", "MNX", "RAW", "SWP", "UNX", */
+/* "F32", "SV4", NULL */
+/* }; */
+
+struct _AtariPartID2BootFlag {
+   const char  pid[4];
+   uint8_t flag;
+};
+typedef struct _AtariPartID2BootFlag AtariPartID2BootFlag;
+
+static AtariPartID2BootFlag atr_pid2bf[] = {
+   { "GEM", PART_FLAG_BOOT_GEM },
+   { "BGM", PART_FLAG_BOOT_GEM },
+   { "UNX", PART_FLAG_BOOT_ASV },
+   { "LNX", PART_FLAG_BOOT_LNX },
+   { "",PART_FLAG_BOOT_UNK },
+};
+
+struct _AtariFS2PartId {
+   const char* fs;
+   const char  pid[4];
+   PedSector   max_sectors;
+};
+typedef struct _AtariFS2PartId AtariFS2PartId;
+
+static AtariFS2PartId atr_fs2pid[] = {
+/* Other ID are available : MIX MNX <= minix
+   UNX <= Atari SysV Unix
+   SV4 <= Univ System 4   */
+   { "ext2",   "LNX", INT32_MAX },
+   { "ext3",   "LNX", INT32_MAX },
+   { "fat16",  "GEM",   GEM_MAX }, /* small partitions */
+   { "fat16",  "BGM", INT32_MAX }, /* big partitions */
+   { "fat32",  "F32