Beispiel #1
0
int edit_record(char *device_name, uint64_t offset) {
    if (offset == 0) {
        mbr_t mbr;

        read_mbr(device_name, &mbr);

        if (OKAY == edit_mbr_loop(&mbr) && are_you_sure() == YES) {
            write_mbr(device_name, &mbr);
        }
    }
    else {
        ebr_t ebr;

        read_ebr(device_name, offset, &ebr);

        if (OKAY == edit_ebr_loop(&ebr) && are_you_sure() == YES) {
            write_ebr(device_name, offset, &ebr);
        }
    }
    return OKAY;
} 
Beispiel #2
0
// ---------------------------------------------------------------------------
//
// Read Master Boot Record (partitions)
//
static Cyg_ErrNo 
read_mbr(disk_channel *chan)
{
    cyg_disk_info_t *info = chan->info;
    disk_funs       *funs = chan->funs;
    disk_controller *ctlr = chan->controller;
    cyg_uint8 *buf = (cyg_uint8*)malloc(info->block_size);
    Cyg_ErrNo res = ENOERR;
    int i;

    D(("read MBR\n"));
    
    for (i = 0; i < info->partitions_num; i++)
        info->partitions[i].type = 0x00;  


    
    cyg_drv_mutex_lock( &ctlr->lock );

    while( ctlr->busy )
        cyg_drv_cond_wait( &ctlr->queue );

    ctlr->busy = true;
    
    ctlr->result = -EWOULDBLOCK;

    for( i = 0; i < sizeof(buf); i++ )
        buf[i] = 0;
    //diag_printf("buf = %p\n",buf);
    res = (funs->read)(chan, (void *)buf, 1, 0);
    
    if( res == -EWOULDBLOCK )
    {
        // If the driver replys EWOULDBLOCK, then the transfer is
        // being handled asynchronously and when it is finished it
        // will call disk_transfer_done(). This will wake us up here
        // to continue.

        while( ctlr->result == -EWOULDBLOCK )
            cyg_drv_cond_wait( &ctlr->async );

        res = ctlr->result;
    }
        
    ctlr->busy = false;
    
    cyg_drv_mutex_unlock( &ctlr->lock );

    if (ENOERR != res)
        return res;

#ifdef DEBUG
    diag_dump_buf_with_offset( buf, 512, buf );
#endif
    //for test
    //buf[MBR_SIG_ADDR+0]=0x55;buf[MBR_SIG_ADDR+1]=0xAA;
    if (MBR_SIG_BYTE0 == buf[MBR_SIG_ADDR+0] && MBR_SIG_BYTE1 == buf[MBR_SIG_ADDR+1])
    {
        int npart;

        D(("disk MBR found\n")); 
 
        npart = info->partitions_num < MBR_PART_NUM ? 
            info->partitions_num : MBR_PART_NUM;

        for (i = 0; i < MBR_PART_NUM; i++)
        {
            cyg_disk_partition_t *part = &info->partitions[i];
            part->index = i+1;
            
            read_partition(&buf[MBR_PART_ADDR+MBR_PART_SIZE*i], info, part);
            //read_partition(&buftest[MBR_PART_SIZE*i], info, part);
#ifdef DEBUG
            if (0x00 != part->type)
            {
                D(("\ndisk MBR partition %d:\n", i));
                D(("      type  = %02X\n", part->type));
                D(("      state = %02X\n", part->state));
                D(("      start = %d\n",   part->start));
                D(("      end   = %d\n",   part->end));
                D(("      size  = %d\n\n", part->size));
            }
#endif    
#if EBR
            if(part->type == 0x05 || part->type == 0x0F)
            read_ebr(chan,part);
#endif
        } 
    }
    free(buf);
    return ENOERR;
}