[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GPT name overflow

From: Andreas Dilger
Subject: Re: GPT name overflow
Date: Mon, 18 Mar 2002 19:56:26 -0700
User-agent: Mutt/1.3.27i

On Mar 18, 2002  15:56 +0000, Richard Hirst wrote:
> On Sun, Mar 10, 2002 at 02:40:02PM -0700, Andreas Dilger wrote:
> > +static int
> > +bsd_partition_set_type_name (const PedPartition* part, const char* name)
> > +{
> > +   int ret = 0;
> > +
> > +   if (part && name) {
> > +           BSDPartitionData*       bsd_part_data = part->disk_specific;
> > +           BSDPartitionTypeName*   tmp;
> > +
> > +           if (!strcmp(name, "type-")) {
> In several places that needs to be strncmp()

Hmm, didn't notice that, but that doesn't mean I'm right...

> > +                   if (isdigit(name[5])) {
> > +                           bsd_part_data->type = name[5] - '0';
> Decimal conversion of type, see below..

Well, BSD partitions only have 8 types AFAICS, so it shouldn't matter
whether it is decimal or hex.  I could be wrong, as I've never used BSD
partition types, but that's what I saw in the code.

> > +                   sprintf(type_name, "type-%x", bsd_part_data->type);
> hex conversion of type..
> hex/dec may not matter; I don't know bsd.

This could just be a carry-over from the MSDOS partition code.  Like I
said above, I think there are only 8 types possible, so it is irrelevant.
That said, we should probably go to decimal to be consistent.

> API docs also need to note that the string returned from
> partition_get_type_name() is only valid until such time as someone calls
> the function again.

Actually, in most cases this is not true, because we are just pointing
to a static entry in the array.  Only for cases where we don't have a
matching entry in the named types array do we use the sprintf.

In general, I hate it when applications have to free memory allocated by
a library.  I'd rather we had to pass in an array (how to know size?)
and copy the name string into that.

> From a UI point of view, we would presumably need some way of querying
> each disk_*.c module for it's supported type names.

Yes, that is needed for it to be useful for parted.  In my code, we only
supported a subset of the available named types (I only put in the rest
of them for completeness) so this wasn't an issue for me.

Cheers, Andreas
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
                 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/               -- Dogbert

reply via email to

[Prev in Thread] Current Thread [Next in Thread]