Re: unaligned accesses

From: jsoe0708@tiscali.be
Date: Fri Jan 10 2003 - 06:45:57 MST


>-- Original Message --
>From: jsoe0708@tiscali.be
>Subject: Re: [parisc-linux] unaligned accesses
>To: "Randolph Chung" <randolph@tausq.org>
>Cc: parisc-linux@lists.parisc-linux.org
>Date: Fri, 10 Jan 2003 09:24:40 +0100
>
>
>
>>-- Original Message --
>>Date: Thu, 9 Jan 2003 23:36:59 -0800
>>From: Randolph Chung <randolph@tausq.org>
>>To: jsoe0708@tiscali.be
>>Cc: parisc-linux@lists.parisc-linux.org
>>Subject: Re: [parisc-linux] unaligned accesses
>>Reply-To: Randolph Chung <randolph@tausq.org>
>>
>>
>...
>>> hmmm buggy: not always, the triky case is when you have to access to
>those
>>> kind of data encapsulated into a structure. I do not yet find any workaround
>>> or how to fix this kind of pb. Any idea (gcc-3.3?)?
>>
>>eh? what do you mean?
>>
>well I will try to find back the example I encounter (somewhere in jfs-1.0.23
>IIRC)
>
Yes here it was in evms(1.1.0 since the bug was fix but it is still a sample
:-)

[this small example was composed of code coming from evms-1.1.0]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

typedef u_int8_t BOOLEAN;

#ifndef TRUE
  #define TRUE 1
#endif
#ifndef FALSE
  #define FALSE 0
#endif

struct partition {
    unsigned char boot_ind; /* 0x80 - active */
    unsigned char head; /* starting head */
    unsigned char sector; /* starting sector */
    unsigned char cyl; /* starting cylinder */
    unsigned char sys_ind; /* What partition type */
    unsigned char end_head; /* end head */
    unsigned char end_sector; /* end sector */
    unsigned char end_cyl; /* end cylinder */
    unsigned int start_sect; /* starting sector counting from 0 */
    unsigned int nr_sects; /* nr of sectors in partition */
};

BOOLEAN isa_null_partition_record(struct partition *p)
{
    int i;
    u_int32_t *uip = (u_int32_t *) p;

    for (i=0; i<4; i++) {
        if (*uip!=0x00) return FALSE;
    }

    return TRUE;
}

int main(int argc, char * * argv, char * * env) {

    struct partition p1, p2;

    p1.boot_ind=0;
    p1.head=0;
    p1.sector=0;
    p1.cyl=0;
    p1.sys_ind=0;
    p1.end_head=0;
    p1.end_sector=0;
    p1.end_cyl=0;
    p1.start_sect=0;
    p1.nr_sects=0;
 
    printf("Is that p1 is a null partition: %u\n", isa_null_partition_record(&p1));

    p2.boot_ind=1;
    p2.head=2;
    p2.sector=3;
    p2.cyl=4;
    p2.sys_ind=5;
    p2.end_head=6;
    p2.end_sector=7;
    p2.end_cyl=8;
    p2.start_sect=9;
    p2.nr_sects=10;
 
    printf("Is that p2 is a null partition: %u\n", isa_null_partition_record(&p2));
    return 0;
}

Unfortunately this doesn't reproduce the actual problem of which I save
the following traces (from the evms_vgscan 1.1.0: once again this was fix
since next release):
...
(isa_valid_partition_record) file checks.c
part.start_sect add: 0x27116
part.start_sect : 0
part.nr_sects add: 0x2711a
part.nr_sects : 0
p add: 0x2710e
p.boot_ind add: 0x2710e
p.head add: 0x2710f
p.sector add: 0x27110
p.cyl add: 0x27111
p.sys_ind add: 0x27112
p.end_head add: 0x27113
p.end_sector add: 0x27114
p.end_cyl add: 0x27115
p.start_sect add: 0x27116
p.start_sect : 0
p.nr_sects add: 0x2711a
p.nr_sects : 0
p add: 0x2710e
p.boot_ind add: 0x2710e
p.head add: 0x2710f
p.sector add: 0x27110
p.cyl add: 0x27111
p.sys_ind add: 0x27112
p.end_head add: 0x27113
p.end_sector add: 0x27114
p.end_cyl add: 0x27115
p.start_sect add: 0x27116
p.start_sect : 0
p.nr_sects add: 0x2711a
p.nr_sects : 0
...

in which we can see that p.start_sect (an int) address (0x27166 == 160102)
is not well align (160102/4=40025.5).

HTH,
    Joel

********************************************
Promo Tiscali ADSL: 35 Euros/mois, 1er mois et activation = 0 Euro http://adsl.tiscali.be


List: parisc-linux@lists.parisc-linux.org