[parted-devel] FAT_TYPE_FAT12 not handled in many switches

Jim Meyering jim at meyering.net
Fri Feb 16 15:07:24 CET 2007


David Cantrell <dcantrell at redhat.com> wrote:
> On Thu, 2007-02-15 at 17:52 +0100, Jim Meyering wrote:
>> There are several warnings about this:
>>
>>   table.c: In function '_test_code_bad':
>>   table.c:209: warning: enumeration value 'FAT_TYPE_FAT12' not handled in switch
>>
>> However, there are a few switch stmts that *do* handle that enum value.
>> Do any of you know how best to avoid those warnings?
>>
>>   - handle FAT_TYPE_FAT12 like FAT_TYPE_FAT16, as is done
>>     at least once in each of table.c and traverse.c.
>
> See doc/FAT for examples.

Thanks for the pointer.

I hope you'll understand if I don't learn everything
there is to know about FAT right away :-)

>>   - fall through (e.g., default: break, or FAT_TYPE_FAT12: break),
>>     which is equivalent to what the current code does, yet will
>>     avoid the warning.
>
> Don't do this.
>
>> Two examples:
...
> Add:
>
> case FAT_TYPE_FAT12:
> if (code == 0xff0) return 1;
> break;
>
...
> Add:
>
> case FAT_TYPE_FAT12:
> if (code >= 0xff7) return 1;
> break;

Done.  But it's looking like the switch-related changes
belong in a separate patch, since they're actually changing
the way things work.

I don't yet know enough to say whether we can put
FAT12 and FAT16 in the same case, e.g.,
                case FAT_TYPE_FAT12:
		case FAT_TYPE_FAT16:
but that may be better in some of the examples below:

FYI, there are 4 more in that same file (table.c).
Here's the first.  Currently I'm using PED_ASSERT:

	switch (ft->fat_type) {
+               case FAT_TYPE_FAT12:
+               PED_ASSERT (0, (void) 0);
+               break;

		case FAT_TYPE_FAT16:
		((unsigned short *) ft->table) [cluster]
			= PED_CPU_TO_LE16 (value);
		break;

		case FAT_TYPE_FAT32:
		((unsigned int *) ft->table) [cluster]
			= PED_CPU_TO_LE32 (value);
		break;
	}
	return 1;

and another in clearfat.c:

static int
_calc_fat_entry_offset (PedFileSystem* fs, FatCluster cluster)
{
	FatSpecific*	fs_info = FAT_SPECIFIC (fs);

	switch (fs_info->fat_type) {
+               case FAT_TYPE_FAT12:
+                       PED_ASSERT (0, (void) 0);
+                       break;

		case FAT_TYPE_FAT16:
			return cluster * 2;

		case FAT_TYPE_FAT32:
			return cluster * 4;
	}
	return 0;
}

And one in fat/resize.c:

static int
fat_construct_dir_tree (FatOpContext* ctx)
{
	FatSpecific*		new_fs_info = FAT_SPECIFIC (ctx->new_fs);
	FatSpecific*		old_fs_info = FAT_SPECIFIC (ctx->old_fs);

	if (new_fs_info->fat_type == old_fs_info->fat_type) {
		switch (old_fs_info->fat_type) {
+                       case FAT_TYPE_FAT12:
+                       PED_ASSERT (0, (void) 0);
+                       break;

			case FAT_TYPE_FAT16:
			return fat_construct_legacy_root (ctx);

			case FAT_TYPE_FAT32:
			return fat_construct_root (ctx);
		}



More information about the parted-devel mailing list