Merge branch 'org.openembedded.dev' of git@git.openembedded.net:openembedded into...
[vuplus_openembedded] / packages / parted / files / parted-1.8.x.patch
1 diff --git a/configure.ac b/configure.ac
2 index f1284a0..9f0971b 100644
3 --- a/configure.ac
4 +++ b/configure.ac
5 @@ -5,7 +5,7 @@ dnl
6  dnl This file may be modified and/or distributed without restriction.
7  
8  AC_PREREQ(2.61)
9 -AC_INIT([GNU parted],[1.8.8],[bug-parted@gnu.org])
10 +AC_INIT([GNU parted],[1.8.9],[bug-parted@gnu.org])
11  
12  AC_CONFIG_SRCDIR(include/parted/parted.h)
13  
14 @@ -24,7 +24,7 @@ dnl function signatures changed),
15  dnl set PED_BINARY_AGE _and_ PED_INTERFACE_AGE to 0.
16  PED_MAJOR_VERSION=1
17  PED_MINOR_VERSION=8
18 -PED_MICRO_VERSION=8
19 +PED_MICRO_VERSION=9
20  PED_INTERFACE_AGE=0
21  PED_BINARY_AGE=0
22  PED_VERSION_SUFFIX=
23 @@ -471,14 +471,7 @@ AC_CHECK_HEADER([execinfo.h], [
24         ])
25  ])
26  
27 -dnl Checks for #defines.
28 -AC_COMPILE_IFELSE([
29 -       AC_LANG_PROGRAM([[
30 -       #if defined __s390__ || defined __s390x__
31 -       #  message s390 defined
32 -       #endif
33 -       ]])], [compile_for_s390="no"], [compile_for_s390="yes"])
34 -AM_CONDITIONAL([COMPILE_FOR_S390], [test "$compile_for_s390" = "yes"])
35 +AM_CONDITIONAL([COMPILE_FOR_S390], [test "$host_cpu" = s390 || test "$host_cpu" = s390x])
36  
37  dnl check for "check", unit testing library/header
38  PKG_CHECK_MODULES([CHECK], [check >= 0.9.3], have_check=yes, have_check=no)
39 diff --git a/doc/C/parted.8 b/doc/C/parted.8
40 index 7040402..fdf3d04 100644
41 --- a/doc/C/parted.8
42 +++ b/doc/C/parted.8
43 @@ -124,6 +124,18 @@ and a human-friendly form for output).
44  .B version
45  Display version information and a copyright message.
46  .RE
47 +.SH KNOWN ISSUES
48 +ext3 filesystem resizing does not currently work, please use
49 +.BR resize2fs (8)
50 +instead.
51 +
52 +Resizing partitions with an ext3 filesystem will not generally work because
53 +of the above issue.  Use
54 +.BR resize2fs (8)
55 +to resize the filesystem and resize the partition manually using
56 +.BR fdisk (8)
57 +or a similar tool.  For LVM situations, you will need to use the LVM commands
58 +to resize the LVM elements.
59  .SH REPORTING BUGS
60  Report bugs to <bug-parted@gnu.org>
61  .SH SEE ALSO
62 diff --git a/doc/parted.texi b/doc/parted.texi
63 index 139ea77..86ec076 100644
64 --- a/doc/parted.texi
65 +++ b/doc/parted.texi
66 @@ -14,7 +14,7 @@ resizing, checking and copy partitions and file systems on them.
67  @ifnottex @c texi2pdf don't understand copying and insertcopying ???
68  @c modifications must also be done in the titlepage
69  @copying
70 -Copyright @copyright{} 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
71 +Copyright @copyright{} 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
72  Free Software Foundation, Inc.
73  
74  Permission is granted to copy, distribute and/or modify this document
75 @@ -63,7 +63,7 @@ Free Documentation License''.
76  
77  @c WTF doesn't texi2html include the titlepage?
78  @ifhtml
79 -@insertcopying 
80 +@insertcopying
81  @end ifhtml
82  
83  This document describes the use of GNU Parted, a program for creating,
84 @@ -257,7 +257,7 @@ $ @kbd{make}
85  However, there are a few options for @command{configure}:
86  
87  @table @code
88 -@item --without-readline               
89 +@item --without-readline
90  turns off use of readline.  This is useful for making rescue disks,
91  etc., where few libraries are available.
92  
93 @@ -275,12 +275,12 @@ you don't need the flexibility.
94  @item --disable-fs
95  disable all file system support
96  
97 -@item --disable-nls                    
98 +@item --disable-nls
99  turns off native language support.  This is useful for use with old
100  versions of glibc, or a trimmed down version of glibc suitable for
101  rescue disks.
102  
103 -@item --disable-shared         
104 +@item --disable-shared
105  turns off shared libraries.  This may be necessary for use with old
106  versions of GNU libc, if you get a compile error about a ``spilled
107  register''.  Also useful for boot/rescue disks.
108 @@ -301,7 +301,7 @@ disable writing (for debugging)
109  
110  @node Static binaries
111  @section Using static binaries of GNU Parted
112 -@cindex static binary 
113 +@cindex static binary
114  @cindex unsupported platforms
115  @cindex resizing root device
116  
117 @@ -320,7 +320,7 @@ of the latest GNU Parted version is available, which you can use thus:
118  
119  @subsection Creating the Parted disk
120  @enumerate
121 -@item Boot your system 
122 +@item Boot your system
123  
124  @item Download @file{parted-static-VERSION.tgz} from @uref{ftp://ftp.gnu.org/gnu/parted/static}
125  @item Unpack the tarball, resulting in a file called ``parted.static".
126 @@ -329,7 +329,7 @@ of the latest GNU Parted version is available, which you can use thus:
127  
128  @item Do a low-level format on it (on GNU/Linux this can be achieved with
129        the tool ``fdformat" from the ``util-linux" package.
130 -      This is basically a sanity check because floppy disks often 
131 +      This is basically a sanity check because floppy disks often
132        contain bad blocks.
133  
134  @item Create a file system. Example:
135 @@ -359,7 +359,7 @@ $ @kbd{umount /mnt/floppy}
136  
137  @subsection Using the Parted disk
138  @enumerate
139 -@item Choose a rescue disk that suits you. 
140 +@item Choose a rescue disk that suits you.
141  
142  @item Boot off your rescue disk.  Mount the disk you copied Parted onto.
143  
144 @@ -383,7 +383,7 @@ $ @kbd{umount /mnt/floppy}
145  @end menu
146  
147  @node Partitioning
148 -@section Introduction to Partitioning 
149 +@section Introduction to Partitioning
150  @cindex partitioning overview
151  
152  Unfortunately, partitioning your disk is rather complicated.  This is
153 @@ -566,7 +566,7 @@ Supported file systems:
154  (provided the destination partition is larger than the source partition)
155  
156  @item fat16, fat32
157 -@item linux-swap       
158 +@item linux-swap
159  (equivalent to mkswap on destination partition)
160  @item reiserfs (if libreiserfs is installed)
161  
162 @@ -918,7 +918,7 @@ partitions can be resized only so long as the new extended partition
163  completely contains all logical partitions.
164  
165  Note that Parted can manipulate partitions whether or not they have been
166 -defragmented, so you do not need to defragmenting the disk before
167 +defragmented, so you do not need to defragment the disk before
168  using Parted.
169  
170  Supported file systems:
171 @@ -1031,7 +1031,7 @@ Microsoft operating systems.
172  
173  @item raid
174  (MS-DOS) - this flag can be enabled to tell linux the partition is a
175 -software RAID partition. 
176 +software RAID partition.
177  
178  @item LVM
179  (MS-DOS) - this flag can be enabled to tell linux the partition is a
180 @@ -1109,59 +1109,59 @@ specified after an input number.  Input numbers can be followed by
181  an unit (without any space or other character between them), in
182  which case this unit apply instead of the default unit for this
183  particular number, but CHS and cylinder units are not supported as
184 -a suffix.  If no suffix is given, then the default unit is assumed. 
185 +a suffix.  If no suffix is given, then the default unit is assumed.
186  Parted will compute sensible ranges for the locations you specify
187  (e.g. a range of +/- 500 MB when you specify the location in ``G'')
188  and will select the nearest location in this range from the one you
189  wrote that satisfies constraints from both the operation, the
190  filesystem being worked on, the disk label, other partitions and so
191  on.  Use the sector unit ``s'' to specify exact locations (if they
192 -do not satisfy all onstraints, Parted will ask you for the nearest 
193 +do not satisfy all onstraints, Parted will ask you for the nearest
194  solution).  Note that negative numbers count back from the end of
195 -the disk, with ``-1s'' pointing to the end of the disk.  
196 +the disk, with ``-1s'' pointing to the end of the disk.
197  
198  Example:
199  
200  @example
201  @group
202 -(parted) unit compact                                                     
203 -(parted) print                                                            
204 +(parted) unit compact
205 +(parted) print
206  Disk geometry for /dev/hda: 0kB - 123GB
207  Disk label type: msdos
208  Number  Start   End     Size    Type      File system  Flags
209  1       32kB    1078MB  1077MB  primary   reiserfs     boot
210 -2       1078MB  2155MB  1078MB  primary   linux-swap   
211 -3       2155MB  123GB   121GB   extended               
212 -5       2155MB  7452MB  5297MB  logical   reiserfs     
213 +2       1078MB  2155MB  1078MB  primary   linux-swap
214 +3       2155MB  123GB   121GB   extended
215 +5       2155MB  7452MB  5297MB  logical   reiserfs
216  @end group
217  @group
218 -(parted) unit chs print                                                   
219 +(parted) unit chs print
220  Disk geometry for /dev/hda: 0,0,0 - 14946,225,62
221  BIOS cylinder,head,sector geometry: 14946,255,63.  Each cylinder
222  is 8225kB.
223  Disk label type: msdos
224  Number  Start       End         Type      File system  Flags
225  1       0,1,0       130,254,62  primary   reiserfs     boot
226 -2       131,0,0     261,254,62  primary   linux-swap   
227 -3       262,0,0     14945,254,62 extended               
228 -5       262,2,0     905,254,62  logical   reiserfs     
229 +2       131,0,0     261,254,62  primary   linux-swap
230 +3       262,0,0     14945,254,62 extended
231 +5       262,2,0     905,254,62  logical   reiserfs
232  @end group
233  @group
234 -(parted) unit mb print                                                    
235 +(parted) unit mb print
236  Disk geometry for /dev/hda: 0MB - 122942MB
237  Disk label type: msdos
238  Number  Start   End     Size    Type      File system  Flags
239  1       0MB     1078MB  1077MB  primary   reiserfs     boot
240 -2       1078MB  2155MB  1078MB  primary   linux-swap   
241 -3       2155MB  122935MB 120780MB extended               
242 -5       2155MB  7452MB  5297MB  logical   reiserfs     
243 +2       1078MB  2155MB  1078MB  primary   linux-swap
244 +3       2155MB  122935MB 120780MB extended
245 +5       2155MB  7452MB  5297MB  logical   reiserfs
246  @end group
247  @end example
248  
249  @end deffn
250  
251  @node Related information
252 -@chapter Related information 
253 +@chapter Related information
254  @cindex further reading
255  @cindex related documentation
256  
257 diff --git a/include/parted/constraint.h b/include/parted/constraint.h
258 index 7a39602..6496926 100644
259 --- a/include/parted/constraint.h
260 +++ b/include/parted/constraint.h
261 @@ -22,6 +22,7 @@
262  typedef struct _PedConstraint  PedConstraint;
263  
264  #include <parted/device.h>
265 +#include <parted/geom.h>
266  #include <parted/natmath.h>
267  
268  struct _PedConstraint {
269 diff --git a/include/parted/device.h b/include/parted/device.h
270 index cf32dba..e669688 100644
271 --- a/include/parted/device.h
272 +++ b/include/parted/device.h
273 @@ -26,6 +26,7 @@
274  #ifndef PED_DEVICE_H_INCLUDED
275  #define PED_DEVICE_H_INCLUDED
276  
277 +#include <parted/constraint.h>
278  #include <parted/timer.h>
279  
280  /** We can address 2^63 sectors */
281 @@ -45,9 +46,7 @@ typedef enum {
282          PED_DEVICE_DASD         = 9,
283          PED_DEVICE_VIODASD      = 10,
284          PED_DEVICE_SX8          = 11,
285 -#ifdef ENABLE_DEVICE_MAPPER
286          PED_DEVICE_DM           = 12,
287 -#endif
288          PED_DEVICE_XVD          = 13
289  } PedDeviceType;
290  
291 diff --git a/include/parted/disk.h b/include/parted/disk.h
292 index b82ea0f..1b0133d 100644
293 --- a/include/parted/disk.h
294 +++ b/include/parted/disk.h
295 @@ -1,6 +1,6 @@
296  /*
297      libparted - a library for manipulating disk partitions
298 -    Copyright (C) 1999, 2000, 2001, 2002, 2007 Free Software Foundation, Inc.
299 +    Copyright (C) 1999, 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
300  
301      This program is free software; you can redistribute it and/or modify
302      it under the terms of the GNU General Public License as published by
303 @@ -52,10 +52,11 @@ enum _PedPartitionFlag {
304          PED_PARTITION_HPSERVICE=8,
305          PED_PARTITION_PALO=9,
306          PED_PARTITION_PREP=10,
307 -        PED_PARTITION_MSFT_RESERVED=11
308 +        PED_PARTITION_MSFT_RESERVED=11,
309 +        PED_PARTITION_BIOS_GRUB=12
310  };
311  #define PED_PARTITION_FIRST_FLAG        PED_PARTITION_BOOT
312 -#define PED_PARTITION_LAST_FLAG         PED_PARTITION_MSFT_RESERVED
313 +#define PED_PARTITION_LAST_FLAG         PED_PARTITION_BIOS_GRUB
314  
315  enum _PedDiskTypeFeature {
316          PED_DISK_TYPE_EXTENDED=1,       /**< supports extended partitions */
317 diff --git a/include/parted/linux.h b/include/parted/linux.h
318 index 52d28be..05a2f0e 100644
319 --- a/include/parted/linux.h
320 +++ b/include/parted/linux.h
321 @@ -22,7 +22,7 @@
322  #include <parted/parted.h>
323  #include <parted/device.h>
324  
325 -#if defined __s390__ || defined __s390x__
326 +#if defined(__s390__) || defined(__s390x__)
327  #  include <parted/fdasd.h>
328  #endif
329  
330 diff --git a/include/parted/natmath.h b/include/parted/natmath.h
331 index 32a6e28..e387833 100644
332 --- a/include/parted/natmath.h
333 +++ b/include/parted/natmath.h
334 @@ -30,6 +30,7 @@
335  typedef struct _PedAlignment   PedAlignment;
336  
337  #include <parted/disk.h>
338 +#include <parted/device.h>
339  
340  #define PED_MIN(a, b)  ( ((a)<(b)) ? (a) : (b) )
341  #define PED_MAX(a, b)  ( ((a)>(b)) ? (a) : (b) )
342 diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
343 index 462ab92..9876956 100644
344 --- a/libparted/arch/linux.c
345 +++ b/libparted/arch/linux.c
346 @@ -64,7 +64,7 @@
347  #define HDIO_GETGEO             0x0301  /* get device geometry */
348  #define HDIO_GET_IDENTITY       0x030d  /* get IDE identification info */
349  
350 -#if defined(O_DIRECT) && (!defined(__s390__) || !defined(__s390x__))
351 +#if defined(O_DIRECT) && !(defined(__s390__) || defined(__s390x__))
352  #define RD_MODE (O_RDONLY | O_DIRECT)
353  #define WR_MODE (O_WRONLY | O_DIRECT)
354  #define RW_MODE (O_RDWR | O_DIRECT)
355 @@ -986,7 +986,7 @@ error:
356  }
357  
358  static int
359 -init_dasd (PedDevice* dev, char* model_name)
360 +init_dasd (PedDevice* dev, const char* model_name)
361  {
362          struct stat             dev_stat;
363          struct hd_geometry      geo;
364 @@ -1042,7 +1042,7 @@ error:
365  }
366  
367  static int
368 -init_generic (PedDevice* dev, char* model_name)
369 +init_generic (PedDevice* dev, const char* model_name)
370  {
371          struct stat             dev_stat;
372          PedExceptionOption      ex_status;
373 diff --git a/libparted/cs/natmath.c b/libparted/cs/natmath.c
374 index b8b4a95..fd376cd 100644
375 --- a/libparted/cs/natmath.c
376 +++ b/libparted/cs/natmath.c
377 @@ -74,16 +74,16 @@ ped_round_down_to (PedSector sector, PedSector grain_size)
378         return sector - abs_mod (sector, grain_size);
379  }
380  
381 -inline PedSector
382 +PedSector
383  ped_div_round_up (PedSector numerator, PedSector divisor)
384  {
385 -                return (numerator + divisor - 1) / divisor;
386 +       return (numerator + divisor - 1) / divisor;
387  }
388  
389 -inline PedSector
390 +PedSector
391  ped_div_round_to_nearest (PedSector numerator, PedSector divisor)
392  {
393 -                return (numerator + divisor/2) / divisor;
394 +       return (numerator + divisor/2) / divisor;
395  }
396  
397  /* Rounds a number up to the closest number that is a multiple of
398 diff --git a/libparted/disk.c b/libparted/disk.c
399 index 1582f26..c465d40 100644
400 --- a/libparted/disk.c
401 +++ b/libparted/disk.c
402 @@ -224,23 +224,24 @@ static int
403  _add_duplicate_part (PedDisk* disk, PedPartition* old_part)
404  {
405         PedPartition*   new_part;
406 -       PedConstraint*  constraint_exact;
407 +       int ret;
408  
409         new_part = disk->type->ops->partition_duplicate (old_part);
410         if (!new_part)
411                 goto error;
412         new_part->disk = disk;
413  
414 -       constraint_exact = ped_constraint_exact (&new_part->geom);
415 -       if (!constraint_exact)
416 +       _disk_push_update_mode (disk);
417 +       ret = _disk_raw_add (disk, new_part);
418 +       _disk_pop_update_mode (disk);
419 +       if (!ret)
420                 goto error_destroy_new_part;
421 -       if (!ped_disk_add_partition (disk, new_part, constraint_exact))
422 -                       goto error_destroy_constraint_exact;
423 -       ped_constraint_destroy (constraint_exact);
424 +#ifdef DEBUG
425 +       if (!_disk_check_sanity (disk))
426 +               goto error_destroy_new_part;
427 +#endif
428         return 1;
429  
430 -error_destroy_constraint_exact:
431 -       ped_constraint_destroy (constraint_exact);
432  error_destroy_new_part:
433         ped_partition_destroy (new_part);
434  error:
435 @@ -2161,6 +2162,8 @@ ped_partition_flag_get_name (PedPartitionFlag flag)
436         switch (flag) {
437         case PED_PARTITION_BOOT:
438                 return N_("boot");
439 +       case PED_PARTITION_BIOS_GRUB:
440 +               return N_("bios_grub");
441         case PED_PARTITION_ROOT:
442                 return N_("root");
443         case PED_PARTITION_SWAP:
444 diff --git a/libparted/exception.c b/libparted/exception.c
445 index 0940d65..230a9b7 100644
446 --- a/libparted/exception.c
447 +++ b/libparted/exception.c
448 @@ -1,6 +1,6 @@
449  /*
450      libparted - a library for manipulating disk partitions
451 -    Copyright (C) 1999, 2000, 2007 Free Software Foundation, Inc.
452 +    Copyright (C) 1999, 2000, 2007-2008 Free Software Foundation, Inc.
453  
454      This program is free software; you can redistribute it and/or modify
455      it under the terms of the GNU General Public License as published by
456 @@ -73,7 +73,7 @@ static PedExceptionHandler*   ex_handler = default_handler;
457  static PedException*           ex = NULL;
458  static int                     ex_fetch_count = 0;
459  
460 -static char*   type_strings [] = {
461 +static const char *const type_strings [] = {
462         N_("Information"),
463         N_("Warning"),
464         N_("Error"),
465 @@ -82,7 +82,7 @@ static char*  type_strings [] = {
466         N_("No Implementation")
467  };
468  
469 -static char*   option_strings [] = {
470 +static const char *const option_strings [] = {
471         N_("Fix"),
472         N_("Yes"),
473         N_("No"),
474 @@ -98,7 +98,7 @@ static char*  option_strings [] = {
475  char*
476  ped_exception_get_type_string (PedExceptionType ex_type)
477  {
478 -       return type_strings [ex_type - 1];
479 +       return (char *) type_strings [ex_type - 1];
480  }
481  
482  /* FIXME: move this out to the prospective math.c */
483 @@ -121,7 +121,7 @@ ped_log2 (int n)
484  char*
485  ped_exception_get_option_string (PedExceptionOption ex_opt)
486  {
487 -       return option_strings [ped_log2 (ex_opt)];
488 +       return (char *) option_strings [ped_log2 (ex_opt)];
489  }
490  
491  static PedExceptionOption
492 @@ -243,8 +243,8 @@ ped_exception_throw (PedExceptionType ex_type,
493         ex->type = ex_type;
494         ex->options = ex_opts;
495  
496 -       while (1) {
497 -                       ex->message = (char*) malloc (size);
498 +       while (message) {
499 +                       ex->message = (char*) malloc (size * sizeof (char));
500                         if (!ex->message)
501                                         goto no_memory;
502  
503 @@ -256,6 +256,7 @@ ped_exception_throw (PedExceptionType ex_type,
504                                         break;
505  
506                         size += 10;
507 +                       ped_free (ex->message);
508         }
509  
510         return do_throw ();
511 diff --git a/libparted/fs/ext2/ext2.c b/libparted/fs/ext2/ext2.c
512 index 618fca9..79fc6f6 100644
513 --- a/libparted/fs/ext2/ext2.c
514 +++ b/libparted/fs/ext2/ext2.c
515 @@ -727,7 +727,10 @@ struct ext2_fs *ext2_open(struct ext2_dev_handle *handle, int state)
516                             EXT2_FEATURE_RO_COMPAT_LARGE_FILE)))
517         {
518                 ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
519 -                    _("File system has an incompatible feature enabled."));
520 +                    _("File system has an incompatible feature enabled.  "
521 +                      "Compatible features are has_journal, dir_index, "
522 +                      "filetype, sparse_super and large_file.  "
523 +                      "Use tune2fs or debugfs to remove features."));
524                 goto error_free_fs;
525         }
526  
527 diff --git a/libparted/fs/ext2/ext2_block_relocator.c b/libparted/fs/ext2/ext2_block_relocator.c
528 index b75a4c5..60f3d50 100644
529 --- a/libparted/fs/ext2/ext2_block_relocator.c
530 +++ b/libparted/fs/ext2/ext2_block_relocator.c
531 @@ -691,10 +691,11 @@ static int ext2_block_relocator_flush(struct ext2_fs *fs, struct ext2_block_relo
532                 {
533                         /* FIXXXME gross hack */
534                         fprintf(stderr, "relocating %s blocks",
535 -                               ((char *[4]){"direct",
536 -                                                    "singly indirect",
537 -                                                    "doubly indirect",
538 -                                                    "triply indirect"})[i]);
539 +                               ((const char *const [4])
540 +                                {"direct",
541 +                                 "singly indirect",
542 +                                 "doubly indirect",
543 +                                 "triply indirect"})[i]);
544                         fflush(stderr);
545                 }
546  
547 diff --git a/libparted/fs/ext2/ext2_mkfs.c b/libparted/fs/ext2/ext2_mkfs.c
548 index 19931dd..b1a8ce3 100644
549 --- a/libparted/fs/ext2/ext2_mkfs.c
550 +++ b/libparted/fs/ext2/ext2_mkfs.c
551 @@ -1,6 +1,6 @@
552  /*
553      ext2_mkfs.c -- ext2 fs creator
554 -    Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
555 +    Copyright (C) 1999, 2000, 2001, 2007-2008 Free Software Foundation, Inc.
556  
557      This program is free software; you can redistribute it and/or modify
558      it under the terms of the GNU General Public License as published by
559 @@ -263,7 +263,7 @@ error:
560  
561  /* returns the offset into the buffer of the start of the next dir entry */
562  static int _set_dirent(void* buf, int offset, int block_size, int is_last,
563 -                      uint32_t inode, char* name, int file_type)
564 +                      uint32_t inode, const char* name, int file_type)
565  {
566         struct ext2_dir_entry_2 *dirent = (void*) (((char*)buf) + offset);
567         int name_len = strlen(name);
568 diff --git a/libparted/fs/fat/resize.c b/libparted/fs/fat/resize.c
569 index 7386948..5f24ec2 100644
570 --- a/libparted/fs/fat/resize.c
571 +++ b/libparted/fs/fat/resize.c
572 @@ -1,6 +1,6 @@
573  /*
574      libparted
575 -    Copyright (C) 1998, 1999, 2000, 2007 Free Software Foundation, Inc.
576 +    Copyright (C) 1998, 1999, 2000, 2007-2008 Free Software Foundation, Inc.
577  
578      This program is free software; you can redistribute it and/or modify
579      it under the terms of the GNU General Public License as published by
580 @@ -481,8 +481,8 @@ ask_type (PedFileSystem* fs, int fat16_ok, int fat32_ok, FatType* out_fat_type)
581  {
582         FatSpecific*            fs_info = FAT_SPECIFIC (fs);
583         PedExceptionOption      status;
584 -       char*                   fat16_msg;
585 -       char*                   fat32_msg;
586 +       const char*             fat16_msg;
587 +       const char*             fat32_msg;
588  
589         if (fs_info->fat_type == FAT_TYPE_FAT16)
590                 fat16_msg = _("If you leave your file system as FAT16, "
591 diff --git a/libparted/fs/fat/traverse.c b/libparted/fs/fat/traverse.c
592 index 3d2e2b5..4ef2044 100644
593 --- a/libparted/fs/fat/traverse.c
594 +++ b/libparted/fs/fat/traverse.c
595 @@ -120,7 +120,7 @@ fat_traverse_mark_dirty (FatTraverseInfo* trav_info)
596  
597  FatTraverseInfo*
598  fat_traverse_begin (PedFileSystem* fs, FatCluster start_cluster,
599 -                   char* dir_name)
600 +                   const char* dir_name)
601  {
602         FatSpecific*            fs_info = FAT_SPECIFIC (fs);
603         FatTraverseInfo*        trav_info;
604 diff --git a/libparted/fs/fat/traverse.h b/libparted/fs/fat/traverse.h
605 index 21e4c27..afb24a5 100644
606 --- a/libparted/fs/fat/traverse.h
607 +++ b/libparted/fs/fat/traverse.h
608 @@ -42,7 +42,8 @@ extern int fat_traverse_entries_per_buffer (FatTraverseInfo* trav_info);
609  /* starts traversal at an arbitary cluster.  if start_cluster==0, then uses
610     root directory */
611  extern FatTraverseInfo* fat_traverse_begin (PedFileSystem* fs,
612 -                                    FatCluster start_cluster, char* dir_name);
613 +                                           FatCluster start_cluster,
614 +                                           const char* dir_name);
615  
616  extern int fat_traverse_complete (FatTraverseInfo* trav_info);
617  
618 diff --git a/libparted/labels/bsd.c b/libparted/labels/bsd.c
619 index f25353b..ee9aba0 100644
620 --- a/libparted/labels/bsd.c
621 +++ b/libparted/labels/bsd.c
622 @@ -108,6 +108,9 @@ typedef struct {
623  
624  typedef struct {
625         uint8_t         type;
626 +       int                     boot;
627 +       int                     raid;
628 +       int                     lvm;
629  } BSDPartitionData;
630  
631  static PedDiskType bsd_disk_type;
632 @@ -394,6 +397,9 @@ bsd_partition_new (const PedDisk* disk, PedPartitionType part_type,
633                 if (!bsd_data)
634                         goto error_free_part;
635                 bsd_data->type = 0;
636 +               bsd_data->boot = 0;
637 +               bsd_data->raid = 0;
638 +               bsd_data->lvm  = 0;
639         } else {
640                 part->disk_specific = NULL;
641         }
642 @@ -423,6 +429,9 @@ bsd_partition_duplicate (const PedPartition* part)
643         old_bsd_data = (BSDPartitionData*) part->disk_specific;
644         new_bsd_data = (BSDPartitionData*) new_part->disk_specific;
645         new_bsd_data->type = old_bsd_data->type;
646 +       new_bsd_data->boot = old_bsd_data->boot;
647 +       new_bsd_data->raid = old_bsd_data->raid;
648 +       new_bsd_data->lvm = old_bsd_data->lvm;
649         return new_part;
650  }
651  
652 @@ -456,14 +465,60 @@ bsd_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type)
653  static int
654  bsd_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
655  {
656 -       /* no flags for bsd */
657 +       PedDisk*                        disk;
658 +//     PedPartition*           walk; // since -Werror, this unused variable would break build
659 +       BSDPartitionData*       bsd_data;
660 +
661 +       PED_ASSERT (part != NULL, return 0);
662 +       PED_ASSERT (part->disk_specific != NULL, return 0);
663 +       PED_ASSERT (part->disk != NULL, return 0);
664 +
665 +       bsd_data = part->disk_specific;
666 +       disk = part->disk;
667 +
668 +       switch (flag) {
669 +               case PED_PARTITION_BOOT:
670 +                       bsd_data->boot = state;
671 +                       return 1;
672 +               case PED_PARTITION_RAID:
673 +                       if (state) {
674 +                               bsd_data->lvm = 0;
675 +                       }
676 +                       bsd_data->raid = state;
677 +                       return 1;
678 +               case PED_PARTITION_LVM:
679 +                       if (state) {
680 +                               bsd_data->raid = 0;
681 +                       }
682 +                       bsd_data->lvm = state;
683 +               default:
684 +                       ;
685 +       }
686         return 0;
687  }
688  
689  static int
690  bsd_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
691  {
692 -       /* no flags for bsd */
693 +       BSDPartitionData*               bsd_data;
694 +
695 +       PED_ASSERT (part != NULL, return 0);
696 +       PED_ASSERT (part->disk_specific != NULL, return 0);
697 +
698 +       bsd_data = part->disk_specific;
699 +       switch (flag) {
700 +               case PED_PARTITION_BOOT:
701 +                       return bsd_data->boot;
702 +
703 +               case PED_PARTITION_RAID:
704 +                       return bsd_data->raid;
705 +
706 +               case PED_PARTITION_LVM:
707 +                       return bsd_data->lvm;
708 +
709 +               default:
710 +                       ;
711 +       }
712         return 0;
713  }
714  
715 @@ -471,7 +526,14 @@ static int
716  bsd_partition_is_flag_available (const PedPartition* part,
717                                  PedPartitionFlag flag)
718  {
719 -       /* no flags for bsd */
720 +       switch (flag) {
721 +               case PED_PARTITION_BOOT:
722 +               case PED_PARTITION_RAID:
723 +               case PED_PARTITION_LVM:
724 +                       return 1;
725 +               default:
726 +                       ;
727 +       }
728         return 0;
729  }
730  
731 diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
732 index c686658..641257c 100644
733 --- a/libparted/labels/dos.c
734 +++ b/libparted/labels/dos.c
735 @@ -190,14 +190,16 @@ msdos_probe (const PedDevice *dev)
736         if (PED_LE16_TO_CPU (part_table->magic) != MSDOS_MAGIC)
737                 goto probe_fail;
738  
739 -       /* if this is a FAT fs, fail here.  Note that the Smart Boot Manager
740 -        * Loader (SBML) signature indicates a partition table, not a file
741 -        * system.
742 +       /* If this is a FAT fs, fail here.  Checking for the FAT signature
743 +        * has some false positives; instead, do what the Linux kernel does
744 +        * and ensure that each partition has a boot indicator that is
745 +        * either 0 or 0x80.
746          */
747 -       if ((!strncmp (part_table->boot_code + 0x36, "FAT", 3)
748 -           && strncmp (part_table->boot_code + 0x40, "SBML", 4) != 0)
749 -           || !strncmp (part_table->boot_code + 0x52, "FAT", 3))
750 -               goto probe_fail;
751 +       for (i = 0; i < 4; i++) {
752 +               if (part_table->partitions[i].boot_ind != 0
753 +                   && part_table->partitions[i].boot_ind != 0x80)
754 +                       goto probe_fail;
755 +       }
756  
757         /* If this is a GPT disk, fail here */
758         for (i = 0; i < 4; i++) {
759 diff --git a/libparted/labels/fdasd.c b/libparted/labels/fdasd.c
760 index e4ecf52..7adf12f 100644
761 --- a/libparted/labels/fdasd.c
762 +++ b/libparted/labels/fdasd.c
763 @@ -149,7 +149,7 @@ fdasd_error (fdasd_anchor_t *anc, enum fdasd_failure why, char * str)
764                 case device_verification_failed:
765                         sprintf(error, "fdasd: %s -- %s\n",
766                                 _("Device verification failed"),
767 -                               _("The specified device is not a valid DASD device"));,
768 +                               _("The specified device is not a valid DASD device"));
769                         break;
770                 default: 
771                         sprintf(error, "fdasd: %s: %s\n", _("Fatal error"), str);
772 diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
773 index 4dc4f10..cb90d11 100644
774 --- a/libparted/labels/gpt.c
775 +++ b/libparted/labels/gpt.c
776 @@ -4,7 +4,7 @@
777      original version by Matt Domsch <Matt_Domsch@dell.com>
778      Disclaimed into the Public Domain
779  
780 -    Portions Copyright (C) 2001, 2002, 2003, 2005, 2006, 2007
781 +    Portions Copyright (C) 2001, 2002, 2003, 2005, 2006, 2007, 2008
782          Free Software Foundation, Inc.
783  
784      EFI GUID Partition Table handling
785 @@ -86,6 +86,10 @@ typedef struct {
786      ((efi_guid_t) { PED_CPU_TO_LE32 (0xC12A7328), PED_CPU_TO_LE16 (0xF81F), \
787                     PED_CPU_TO_LE16 (0x11d2), 0xBA, 0x4B, \
788                     { 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B }})
789 +#define PARTITION_BIOS_GRUB_GUID \
790 +    ((efi_guid_t) { PED_CPU_TO_LE32 (0x21686148), PED_CPU_TO_LE16 (0x6449), \
791 +                   PED_CPU_TO_LE16 (0x6E6f), 0x74, 0x4E, \
792 +                   { 0x65, 0x65, 0x64, 0x45, 0x46, 0x49 }})
793  #define LEGACY_MBR_PARTITION_GUID \
794      ((efi_guid_t) { PED_CPU_TO_LE32 (0x024DEE41), PED_CPU_TO_LE16 (0x33E7), \
795                     PED_CPU_TO_LE16 (0x11d3, 0x9D, 0x69, \
796 @@ -245,6 +249,7 @@ typedef struct _GPTPartitionData {
797         int             lvm;
798         int             raid;
799         int             boot;
800 +       int             bios_grub;
801         int             hp_service;
802          int             hidden;
803          int             msftres;
804 @@ -753,13 +758,16 @@ _parse_part_entry (PedDisk* disk, GuidPartitionEntry_t* pte)
805          
806          gpt_part_data->lvm = gpt_part_data->raid 
807                  = gpt_part_data->boot = gpt_part_data->hp_service
808 -                = gpt_part_data->hidden = gpt_part_data->msftres = 0;
809 +                = gpt_part_data->hidden = gpt_part_data->msftres
810 +                = gpt_part_data->bios_grub = 0;
811  
812          if (pte->Attributes.RequiredToFunction & 0x1)
813                  gpt_part_data->hidden = 1;
814         
815         if (!guid_cmp (gpt_part_data->type, PARTITION_SYSTEM_GUID))
816                 gpt_part_data->boot = 1;
817 +       else if (!guid_cmp (gpt_part_data->type, PARTITION_BIOS_GRUB_GUID))
818 +               gpt_part_data->bios_grub = 1;
819         else if (!guid_cmp (gpt_part_data->type, PARTITION_RAID_GUID))
820                 gpt_part_data->raid = 1;
821         else if (!guid_cmp (gpt_part_data->type, PARTITION_LVM_GUID))
822 @@ -1130,6 +1138,7 @@ gpt_partition_new (const PedDisk* disk,
823         gpt_part_data->lvm = 0;
824         gpt_part_data->raid = 0;
825         gpt_part_data->boot = 0;
826 +       gpt_part_data->bios_grub = 0;
827         gpt_part_data->hp_service = 0;
828          gpt_part_data->hidden = 0;
829          gpt_part_data->msftres = 0;
830 @@ -1208,6 +1217,10 @@ gpt_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type)
831                 gpt_part_data->type = PARTITION_SYSTEM_GUID;
832                 return 1;
833         }
834 +       if (gpt_part_data->bios_grub) {
835 +               gpt_part_data->type = PARTITION_BIOS_GRUB_GUID;
836 +               return 1;
837 +       }
838         if (gpt_part_data->hp_service) {
839                 gpt_part_data->type = PARTITION_HPSERVICE_GUID;
840                 return 1;
841 @@ -1306,6 +1319,16 @@ gpt_partition_set_flag(PedPartition *part,
842                 if (state)
843                          gpt_part_data->raid 
844                                  = gpt_part_data->lvm
845 +                                = gpt_part_data->bios_grub
846 +                                = gpt_part_data->hp_service
847 +                                = gpt_part_data->msftres = 0;
848 +               return gpt_partition_set_system (part, part->fs_type);
849 +       case PED_PARTITION_BIOS_GRUB:
850 +               gpt_part_data->bios_grub = state;
851 +               if (state)
852 +                        gpt_part_data->raid 
853 +                                = gpt_part_data->lvm
854 +                                = gpt_part_data->boot
855                                  = gpt_part_data->hp_service
856                                  = gpt_part_data->msftres = 0;
857                 return gpt_partition_set_system (part, part->fs_type);
858 @@ -1314,6 +1337,7 @@ gpt_partition_set_flag(PedPartition *part,
859                 if (state)
860                          gpt_part_data->boot
861                                  = gpt_part_data->lvm
862 +                                = gpt_part_data->bios_grub
863                                  = gpt_part_data->hp_service
864                                  = gpt_part_data->msftres = 0;
865                 return gpt_partition_set_system (part, part->fs_type);
866 @@ -1322,6 +1346,7 @@ gpt_partition_set_flag(PedPartition *part,
867                 if (state)
868                          gpt_part_data->boot
869                                  = gpt_part_data->raid
870 +                                = gpt_part_data->bios_grub
871                                  = gpt_part_data->hp_service
872                                  = gpt_part_data->msftres = 0;
873                 return gpt_partition_set_system (part, part->fs_type);
874 @@ -1331,6 +1356,7 @@ gpt_partition_set_flag(PedPartition *part,
875                          gpt_part_data->boot
876                                  = gpt_part_data->raid
877                                  = gpt_part_data->lvm
878 +                                = gpt_part_data->bios_grub
879                                  = gpt_part_data->msftres = 0;
880                 return gpt_partition_set_system (part, part->fs_type);
881          case PED_PARTITION_MSFT_RESERVED:
882 @@ -1339,6 +1365,7 @@ gpt_partition_set_flag(PedPartition *part,
883                          gpt_part_data->boot
884                                  = gpt_part_data->raid
885                                  = gpt_part_data->lvm
886 +                                = gpt_part_data->bios_grub
887                                  = gpt_part_data->hp_service = 0;
888                  return gpt_partition_set_system (part, part->fs_type);
889          case PED_PARTITION_HIDDEN:
890 @@ -1367,6 +1394,8 @@ gpt_partition_get_flag(const PedPartition *part, PedPartitionFlag flag)
891                 return gpt_part_data->lvm;
892         case PED_PARTITION_BOOT:
893                 return gpt_part_data->boot;
894 +       case PED_PARTITION_BIOS_GRUB:
895 +               return gpt_part_data->bios_grub;
896         case PED_PARTITION_HPSERVICE:
897                 return gpt_part_data->hp_service;
898          case PED_PARTITION_MSFT_RESERVED:
899 @@ -1390,6 +1419,7 @@ gpt_partition_is_flag_available(const PedPartition * part,
900         case PED_PARTITION_RAID:
901         case PED_PARTITION_LVM:
902         case PED_PARTITION_BOOT:
903 +       case PED_PARTITION_BIOS_GRUB:
904         case PED_PARTITION_HPSERVICE:
905          case PED_PARTITION_MSFT_RESERVED:
906          case PED_PARTITION_HIDDEN:        
907 diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
908 index f014194..538e0c0 100644
909 --- a/libparted/labels/mac.c
910 +++ b/libparted/labels/mac.c
911 @@ -1,6 +1,6 @@
912  /*
913      libparted - a library for manipulating disk partitions
914 -    Copyright (C) 2000, 2002, 2004, 2007 Free Software Foundation, Inc.
915 +    Copyright (C) 2000, 2002, 2004, 2007-2008 Free Software Foundation, Inc.
916  
917      This program is free software; you can redistribute it and/or modify
918      it under the terms of the GNU General Public License as published by
919 @@ -376,19 +376,19 @@ mac_clobber (PedDevice* dev)
920  #endif /* !DISCOVER_ONLY */
921  
922  static int
923 -_rawpart_cmp_type (MacRawPartition* raw_part, char* type)
924 +_rawpart_cmp_type (const MacRawPartition* raw_part, const char* type)
925  {
926         return strncasecmp (raw_part->type, type, 32) == 0;
927  }
928  
929  static int
930 -_rawpart_cmp_name (MacRawPartition* raw_part, char* name)
931 +_rawpart_cmp_name (const MacRawPartition* raw_part, const char* name)
932  {
933         return strncasecmp (raw_part->name, name, 32) == 0;
934  }
935  
936  static int
937 -_rawpart_is_partition_map (MacRawPartition* raw_part)
938 +_rawpart_is_partition_map (const MacRawPartition* raw_part)
939  {
940         return _rawpart_cmp_type (raw_part, "Apple_partition_map");
941  }
942 @@ -408,7 +408,7 @@ strncasestr (const char* haystack, const char* needle, int n)
943  }
944  
945  static int
946 -_rawpart_is_boot (MacRawPartition* raw_part)
947 +_rawpart_is_boot (const MacRawPartition* raw_part)
948  {
949         if (!strcasecmp(raw_part->type, "Apple_Bootstrap"))
950                 return 1;
951 @@ -420,7 +420,7 @@ _rawpart_is_boot (MacRawPartition* raw_part)
952  }
953  
954  static int
955 -_rawpart_is_driver (MacRawPartition* raw_part)
956 +_rawpart_is_driver (const MacRawPartition* raw_part)
957  {
958         if (strncmp (raw_part->type, "Apple_", 6) != 0)
959                 return 0;
960 @@ -430,7 +430,7 @@ _rawpart_is_driver (MacRawPartition* raw_part)
961  }
962  
963  static int
964 -_rawpart_has_driver (MacRawPartition* raw_part, MacDiskData* mac_disk_data)
965 +_rawpart_has_driver (const MacRawPartition* raw_part, MacDiskData* mac_disk_data)
966  {
967         MacDeviceDriver *driverlist;
968         uint16_t i, bsz;
969 diff --git a/libparted/tests/Makefile.am b/libparted/tests/Makefile.am
970 index 12ad29f..d526207 100644
971 --- a/libparted/tests/Makefile.am
972 +++ b/libparted/tests/Makefile.am
973 @@ -3,13 +3,17 @@
974  #
975  # This file may be modified and/or distributed without restriction.
976  
977 -TESTS = t1000-label.sh
978 +TESTS = t1000-label.sh t2000-disk.sh
979  EXTRA_DIST = $(TESTS)
980 -bin_PROGRAMS     = label
981 +bin_PROGRAMS     = label disk
982  label_CFLAGS    = $(CHECK_CFLAGS) -I$(top_srcdir)/include
983  label_LDADD     = $(CHECK_LIBS) $(top_builddir)/libparted/libparted.la
984  label_SOURCES   = common.h common.c label.c
985  
986 +disk_CFLAGS    = $(CHECK_CFLAGS) -I$(top_srcdir)/include
987 +disk_LDADD     = $(CHECK_LIBS) $(top_builddir)/libparted/libparted.la
988 +disk_SOURCES   = common.h common.c disk.c
989 +
990  MAINTAINERCLEANFILES = Makefile.in
991  
992  CLEANFILES = init.sh
993 diff --git a/libparted/tests/disk.c b/libparted/tests/disk.c
994 new file mode 100644
995 index 0000000..295ec05
996 --- /dev/null
997 +++ b/libparted/tests/disk.c
998 @@ -0,0 +1,111 @@
999 +#include <config.h>
1000 +#include <unistd.h>
1001 +
1002 +#include <check.h>
1003 +
1004 +#include <parted/parted.h>
1005 +
1006 +#include "common.h"
1007 +
1008 +static char* temporary_disk;
1009 +
1010 +static void
1011 +create_disk (void)
1012 +{
1013 +        temporary_disk = _create_disk (20);
1014 +        fail_if (temporary_disk == NULL, "Failed to create temporary disk");
1015 +}
1016 +
1017 +static void
1018 +destroy_disk (void)
1019 +{
1020 +        unlink (temporary_disk);
1021 +        free (temporary_disk);
1022 +}
1023 +
1024 +/* TEST: Create a disklabel on a simple disk image */
1025 +START_TEST (test_duplicate)
1026 +{
1027 +        PedDevice* dev = ped_device_get (temporary_disk);
1028 +        if (dev == NULL)
1029 +                return;
1030 +
1031 +        PedDiskType* type;
1032 +        PedDisk* disk;
1033 +        PedDisk* disk_dup;
1034 +        PedPartition *part;
1035 +        PedPartition *part_dup;
1036 +        PedConstraint *constraint;
1037 +
1038 +        int part_num[] = {1, 5, 6, 0};
1039 +
1040 +        disk = _create_disk_label (dev, ped_disk_type_get ("msdos"));
1041 +
1042 +        constraint = ped_constraint_any (dev);
1043 +
1044 +        /* Primary partition from 16,4kB to 15MB */
1045 +        part = ped_partition_new (disk, PED_PARTITION_EXTENDED,
1046 +                                  NULL,
1047 +                                  32, 29311);
1048 +        ped_disk_add_partition (disk, part, constraint);
1049 +
1050 +        /* Logical partition from 10MB to 15MB */
1051 +        part = ped_partition_new (disk, PED_PARTITION_LOGICAL,
1052 +                                  ped_file_system_type_get ("ext2"),
1053 +                                  19584, 29311);
1054 +        ped_disk_add_partition (disk, part, constraint);
1055 +
1056 +        /* Logical partition from 16,4kB to 4981kB */
1057 +        part = ped_partition_new (disk, PED_PARTITION_LOGICAL,
1058 +                                  ped_file_system_type_get ("ext2"),
1059 +                                  32, 9727);
1060 +        ped_disk_add_partition (disk, part, constraint);
1061 +
1062 +        ped_disk_commit (disk);
1063 +
1064 +        ped_constraint_destroy (constraint);
1065 +
1066 +        disk_dup = ped_disk_duplicate (disk);
1067 +
1068 +        /* Checks if both partitions match */
1069 +        for (int *i = part_num; *i != 0; i++) {
1070 +                part = ped_disk_get_partition (disk, *i);
1071 +                part_dup = ped_disk_get_partition (disk_dup, *i);
1072 +
1073 +                fail_if (part->geom.start != part_dup->geom.start ||
1074 +                         part->geom.end != part_dup->geom.end,
1075 +                         "Duplicated partition %d doesn't match. "
1076 +                         "Details are start: %d/%d end: %d/%d\n",
1077 +                         *i, part->geom.start, part_dup->geom.start,
1078 +                         part->geom.end, part_dup->geom.end);
1079 +        }
1080 +
1081 +        ped_disk_destroy (disk);
1082 +        ped_device_destroy (dev);
1083 +}
1084 +END_TEST
1085 +
1086 +int
1087 +main (void)
1088 +{
1089 +        int number_failed;
1090 +        Suite* suite = suite_create ("Disk");
1091 +        TCase* tcase_duplicate = tcase_create ("Duplicate");
1092 +
1093 +        /* Fail when an exception is raised */
1094 +        ped_exception_set_handler (_test_exception_handler);
1095 +
1096 +        tcase_add_checked_fixture (tcase_duplicate, create_disk, destroy_disk);
1097 +        tcase_add_test (tcase_duplicate, test_duplicate);
1098 +        /* Disable timeout for this test */
1099 +        tcase_set_timeout (tcase_duplicate, 0);
1100 +        suite_add_tcase (suite, tcase_duplicate);
1101 +
1102 +        SRunner* srunner = srunner_create (suite);
1103 +        srunner_run_all (srunner, CK_VERBOSE);
1104 +
1105 +        number_failed = srunner_ntests_failed (srunner);
1106 +        srunner_free (srunner);
1107 +
1108 +        return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
1109 +}
1110 diff --git a/libparted/tests/t2000-disk.sh b/libparted/tests/t2000-disk.sh
1111 new file mode 100755
1112 index 0000000..7a85b98
1113 --- /dev/null
1114 +++ b/libparted/tests/t2000-disk.sh
1115 @@ -0,0 +1,27 @@
1116 +#!/bin/sh
1117 +
1118 +# Copyright (C) 2007 Free Software Foundation, Inc.
1119 +
1120 +# This program is free software; you can redistribute it and/or modify
1121 +# it under the terms of the GNU General Public License as published by
1122 +# the Free Software Foundation; either version 3 of the License, or
1123 +# (at your option) any later version.
1124 +
1125 +# This program is distributed in the hope that it will be useful,
1126 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1127 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1128 +# GNU General Public License for more details.
1129 +
1130 +# You should have received a copy of the GNU General Public License
1131 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1132 +
1133 +test_description='run the disk unit tests in a directory supporting O_DIRECT'
1134 +# This wrapper around the ./label binary is used to find a directory
1135 +# in which one can open a file with the O_DIRECT flag.
1136 +
1137 +. ./init.sh
1138 +
1139 +test_expect_success \
1140 +    'run the actual tests' 'disk'
1141 +
1142 +test_done
1143 diff --git a/parted/parted.c b/parted/parted.c
1144 index 6a606ae..2afc2c1 100644
1145 --- a/parted/parted.c
1146 +++ b/parted/parted.c
1147 @@ -79,7 +79,7 @@ typedef struct {
1148          time_t  predicted_time_left;
1149  } TimerContext;
1150  
1151 -static struct option    options[] = {
1152 +static const struct option const options[] = {
1153          /* name, has-arg, string-return-val, char-return-val */
1154          {"help",        0, NULL, 'h'},
1155          {"list",        0, NULL, 'l'},
1156 @@ -90,7 +90,7 @@ static struct option    options[] = {
1157          {NULL,          0, NULL, 0}
1158  };
1159  
1160 -static char*    options_help [][2] = {
1161 +static const char *const options_help [][2] = {
1162          {"help",        N_("displays this help message")},
1163          {"list",        N_("lists partition layout on all block devices")},
1164          {"machine",     N_("displays machine parseable output")},
1165 @@ -107,26 +107,26 @@ int     opt_machine_mode = 0;
1166  int     disk_is_modified = 0;
1167  int     is_toggle_mode = 0;
1168  
1169 -static char* number_msg = N_(
1170 +static const char* number_msg = N_(
1171  "NUMBER is the partition number used by Linux.  On MS-DOS disk labels, the "
1172  "primary partitions number from 1 to 4, logical partitions from 5 onwards.\n");
1173  
1174 -static char* label_type_msg_start = N_("LABEL-TYPE is one of: ");
1175 -static char* flag_msg_start =   N_("FLAG is one of: ");
1176 -static char* unit_msg_start =   N_("UNIT is one of: ");
1177 -static char* part_type_msg =    N_("PART-TYPE is one of: primary, logical, "
1178 +static const char* label_type_msg_start = N_("LABEL-TYPE is one of: ");
1179 +static const char* flag_msg_start =   N_("FLAG is one of: ");
1180 +static const char* unit_msg_start =   N_("UNIT is one of: ");
1181 +static const char* part_type_msg =    N_("PART-TYPE is one of: primary, logical, "
1182                                     "extended\n");
1183 -static char* fs_type_msg_start = N_("FS-TYPE is one of: ");
1184 -static char* start_end_msg =    N_("START and END are disk locations, such as "
1185 +static const char* fs_type_msg_start = N_("FS-TYPE is one of: ");
1186 +static const char* start_end_msg =    N_("START and END are disk locations, such as "
1187                  "4GB or 10%.  Negative values count from the end of the disk.  "
1188                  "For example, -1s specifies exactly the last sector.\n");
1189 -static char* state_msg =        N_("STATE is one of: on, off\n");
1190 -static char* device_msg =       N_("DEVICE is usually /dev/hda or /dev/sda\n");
1191 -static char* name_msg =         N_("NAME is any word you want\n");
1192 -static char* resize_msg_start = N_("The partition must have one of the "
1193 +static const char* state_msg =        N_("STATE is one of: on, off\n");
1194 +static const char* device_msg =       N_("DEVICE is usually /dev/hda or /dev/sda\n");
1195 +static const char* name_msg =         N_("NAME is any word you want\n");
1196 +static const char* resize_msg_start = N_("The partition must have one of the "
1197                                     "following FS-TYPEs: ");
1198  
1199 -static char* copyright_msg = N_(
1200 +static const char* copyright_msg = N_(
1201  "Copyright (C) 1998 - 2006 Free Software Foundation, Inc.\n"
1202  "This program is free software, covered by the GNU General Public License.\n"
1203  "\n"
1204 @@ -1226,7 +1226,7 @@ partition_print (PedPartition* part)
1205          putchar ('\n');
1206  
1207          flags = partition_print_flags (part);
1208 -     
1209 +
1210          printf (_("Minor: %d\n"), part->num);
1211          printf (_("Flags: %s\n"), flags);
1212          printf (_("File System: %s\n"), fs->type->name);
1213 @@ -1264,15 +1264,17 @@ do_print (PedDevice** dev)
1214          int             has_free_arg = 0;
1215          int             has_list_arg = 0;
1216          int             has_num_arg = 0;
1217 -        char*           transport[13] = {"unknown", "scsi", "ide", "dac960",
1218 -                                         "cpqarray", "file", "ataraid", "i2o",
1219 -                                         "ubd", "dasd", "viodasd", "sx8", "dm"};
1220 +        const char *const transport[14] = {"unknown", "scsi", "ide", "dac960",
1221 +                                          "cpqarray", "file", "ataraid", "i2o",
1222 +                                          "ubd", "dasd", "viodasd", "sx8", "dm",
1223 +                                          "xvd"};
1224          char*           peek_word;
1225          char*           start;
1226          char*           end;
1227          char*           size;
1228          const char*     name;
1229          char*           tmp;
1230 +        char*           flags;
1231          wchar_t*        table_rendered;
1232  
1233          disk = ped_disk_new (*dev);
1234 @@ -1472,7 +1474,9 @@ do_print (PedDevice** dev)
1235                                      str_list_append (row, name);
1236                              }
1237  
1238 -                            str_list_append (row, partition_print_flags (part));
1239 +                            flags = partition_print_flags (part);
1240 +                            str_list_append (row, flags);
1241 +                            ped_free (flags);
1242                      } else {
1243                              if (has_extended)
1244                                      str_list_append (row, "");
1245 @@ -1485,6 +1489,10 @@ do_print (PedDevice** dev)
1246                      //PED_ASSERT (row.cols == caption.cols)
1247                      table_add_row_from_strlist (table, row);
1248                      str_list_destroy (row);
1249 +                    ped_free (tmp);
1250 +                    ped_free (start);
1251 +                    ped_free (end);
1252 +                    ped_free (size);
1253              }
1254  
1255              table_rendered = table_render (table); 
1256 diff --git a/parted/ui.c b/parted/ui.c
1257 index a53643f..f854a54 100644
1258 --- a/parted/ui.c
1259 +++ b/parted/ui.c
1260 @@ -154,17 +154,17 @@ struct siginfo_t {
1261  #  define ILL_BADSTK (INTMAX - 8)
1262  #endif
1263  
1264 -char* prog_name = "GNU Parted " VERSION "\n";
1265 +const char* prog_name = "GNU Parted " VERSION "\n";
1266  
1267 -static char* banner_msg = N_(
1268 +static const char* banner_msg = N_(
1269  "Welcome to GNU Parted! Type 'help' to view a list of commands.\n");
1270  
1271 -static char* usage_msg = N_(
1272 +static const char* usage_msg = N_(
1273  "Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]\n"
1274  "Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, "
1275  "run in\ninteractive mode.\n");
1276  
1277 -static char* bug_msg = N_(
1278 +static const char* bug_msg = N_(
1279  "\n\nYou found a bug in GNU Parted! Here's what you have to do:\n\n"
1280  "Don't panic! The bug has most likely not affected any of your data.\n"
1281  "Help us to fix this bug by doing the following:\n\n"
1282 @@ -218,7 +218,7 @@ screen_width ()
1283  
1284  /* HACK: don't specify termcap separately - it'll annoy the users. */
1285  #ifdef HAVE_LIBREADLINE
1286 -        width = tgetnum ("co");
1287 +        width = tgetnum ((char *) "co");
1288  #endif
1289  
1290          if (width <= 0)
1291 @@ -569,7 +569,9 @@ _readline (const char* prompt, const StrList* possibilities)
1292                          fputs (line, stdout);
1293                          fflush (stdout);
1294  #endif
1295 -                        line [strlen (line) - 1] = 0;    /* kill trailing CR */
1296 +                        /* kill trailing NL */
1297 +                        if (strlen (line))
1298 +                                line [strlen (line) - 1] = 0;
1299                  } else {
1300                          free (line);
1301                          line = NULL;
1302 diff --git a/parted/ui.h b/parted/ui.h
1303 index f5cf760..77bb194 100644
1304 --- a/parted/ui.h
1305 +++ b/parted/ui.h
1306 @@ -1,6 +1,6 @@
1307  /*
1308      parted - a frontend to libparted
1309 -    Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
1310 +    Copyright (C) 1999, 2000, 2001, 2007-2008 Free Software Foundation, Inc.
1311  
1312      This program is free software; you can redistribute it and/or modify
1313      it under the terms of the GNU General Public License as published by
1314 @@ -21,7 +21,7 @@
1315  
1316  #include "strlist.h"
1317  
1318 -extern char*   prog_name;
1319 +extern const char *prog_name;
1320  
1321  extern int init_ui ();
1322  extern int non_interactive_mode (PedDevice** dev, Command* cmd_list[],
1323 diff --git a/tests/Makefile.am b/tests/Makefile.am
1324 index 0a42a8d..3a694fe 100644
1325 --- a/tests/Makefile.am
1326 +++ b/tests/Makefile.am
1327 @@ -5,8 +5,10 @@ TESTS = \
1328    t1100-busy-label.sh \
1329    t1500-small-ext2.sh \
1330    t2000-mkfs.sh \
1331 +  t2200-dos-label-recog.sh \
1332    t3000-constraints.sh \
1333 -  t3100-resize-ext2-partion.sh
1334 +  t3100-resize-ext2-partion.sh \
1335 +  t5000-tags.sh
1336  
1337  EXTRA_DIST = \
1338    $(TESTS) test-lib.sh mkdtemp
1339 diff --git a/tests/t2200-dos-label-recog.sh b/tests/t2200-dos-label-recog.sh
1340 new file mode 100755
1341 index 0000000..d5d2670
1342 --- /dev/null
1343 +++ b/tests/t2200-dos-label-recog.sh
1344 @@ -0,0 +1,61 @@
1345 +#!/bin/sh
1346 +
1347 +# Copyright (C) 2008 Free Software Foundation, Inc.
1348 +
1349 +# This program is free software; you can redistribute it and/or modify
1350 +# it under the terms of the GNU General Public License as published by
1351 +# the Free Software Foundation; either version 3 of the License, or
1352 +# (at your option) any later version.
1353 +
1354 +# This program is distributed in the hope that it will be useful,
1355 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1356 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1357 +# GNU General Public License for more details.
1358 +
1359 +# You should have received a copy of the GNU General Public License
1360 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1361 +
1362 +test_description='improved MSDOS partition-table recognition'
1363 +
1364 +. ./init.sh
1365 +
1366 +######################################################################
1367 +# With vestiges of a preceding FAT file system boot sector in the MBR,
1368 +# parted 1.8.8.1.29 and earlier would fail to recognize a DOS
1369 +# partition table.
1370 +######################################################################
1371 +N=100k
1372 +dev=loop-file
1373 +test_expect_success \
1374 +    'create a file to simulate the underlying device' \
1375 +    'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null'
1376 +
1377 +test_expect_success \
1378 +    'label the test disk' \
1379 +    'parted -s $dev mklabel msdos > out 2>&1'
1380 +test_expect_success 'expect no output' '$compare out /dev/null'
1381 +
1382 +test_expect_success \
1383 +    'create two partition' \
1384 +    '
1385 +    parted -s $dev mkpart primary  1s 40s > out 2>&1 &&
1386 +    parted -s $dev mkpart primary 41s 80s > out 2>&1
1387 +
1388 +    '
1389 +test_expect_success 'expect no output' '$compare out /dev/null'
1390 +
1391 +test_expect_success \
1392 +    'write "FAT" where it would cause trouble' \
1393 +    'printf FAT|dd bs=1c seek=82 count=3 of=$dev conv=notrunc'
1394 +
1395 +test_expect_success \
1396 +    'print the partition table' \
1397 +    '
1398 +    parted -m -s $dev unit s p > out &&
1399 +    tail -2 out > k && mv k out &&
1400 +    printf "1:1s:40s:40s:::;\n2:41s:80s:40s:::;\n" > exp
1401 +
1402 +    '
1403 +test_expect_success 'expect two partitions' '$compare out exp'
1404 +
1405 +test_done
1406 diff --git a/tests/t5000-tags.sh b/tests/t5000-tags.sh
1407 new file mode 100755
1408 index 0000000..dab48ae
1409 --- /dev/null
1410 +++ b/tests/t5000-tags.sh
1411 @@ -0,0 +1,81 @@
1412 +#!/bin/sh
1413 +
1414 +# Copyright (C) 2007,2008 Free Software Foundation, Inc.
1415 +
1416 +# This program is free software; you can redistribute it and/or modify
1417 +# it under the terms of the GNU General Public License as published by
1418 +# the Free Software Foundation; either version 3 of the License, or
1419 +# (at your option) any later version.
1420 +
1421 +# This program is distributed in the hope that it will be useful,
1422 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1423 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1424 +# GNU General Public License for more details.
1425 +
1426 +# You should have received a copy of the GNU General Public License
1427 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1428 +
1429 +test_description="test bios_grub flag in gpt labels"
1430 +
1431 +. ./init.sh
1432 +
1433 +dev=loop-file
1434 +
1435 +test_expect_success \
1436 +    "setup: create zeroed device" \
1437 +    '{ dd if=/dev/zero bs=1024 count=64; } > $dev'
1438 +
1439 +test_expect_success \
1440 +    'create gpt label' \
1441 +    'parted -s $dev mklabel gpt >out 2>&1'
1442 +
1443 +test_expect_success \
1444 +    'add a partition' \
1445 +    'parted -s $dev mkpart primary 0 1 >>out 2>&1'
1446 +
1447 +test_expect_success \
1448 +    'print the table (before manual modification)' \
1449 +    'parted -s $dev print >>out 2>&1'
1450 +
1451 +# Using bios_boot_magic='\x48\x61' looks nicer, but isn't portable.
1452 +# dash's builtin printf doesn't recognize such \xHH hexadecimal escapes.
1453 +bios_boot_magic='\110\141\150\41\111\144\157\156\164\116\145\145\144\105\106\111'
1454 +
1455 +printf "$bios_boot_magic" | dd of=$dev bs=1024 seek=1 conv=notrunc
1456 +
1457 +test_expect_success \
1458 +    'print the table (after manual modification)' \
1459 +    'parted -s $dev print >>out 2>&1'
1460 +
1461 +pwd=`pwd`
1462 +
1463 +fail=0
1464 +{
1465 +  cat <<EOF
1466 +Model:  (file)
1467 +Disk .../$dev: 65.5kB
1468 +Sector size (logical/physical): 512B/512B
1469 +Partition Table: gpt
1470 +
1471 +Number  Start   End     Size    File system  Name     Flags
1472 + 1      17.4kB  48.6kB  31.2kB               primary       
1473 +
1474 +Model:  (file)
1475 +Disk .../$dev: 65.5kB
1476 +Sector size (logical/physical): 512B/512B
1477 +Partition Table: gpt
1478 +
1479 +Number  Start   End     Size    File system  Name     Flags    
1480 + 1      17.4kB  48.6kB  31.2kB               primary  bios_grub
1481 +
1482 +EOF
1483 +} > exp || fail=1
1484 +
1485 +test_expect_success \
1486 +    'prepare actual and expected output' \
1487 +    'test $fail = 0 &&
1488 +     mv out o2 && sed "s,^Disk .*/$dev:,Disk .../$dev:," o2 > out'
1489 +
1490 +test_expect_success 'check for expected output' '$compare out exp'
1491 +
1492 +test_done