Revision 5fafdf24 block-vpc.c

b/block-vpc.c
1 1
/*
2 2
 * Block driver for Conectix/Microsoft Virtual PC images
3
 * 
3
 *
4 4
 * Copyright (c) 2005 Alex Beregszaszi
5
 * 
5
 *
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
8 8
 * in the Software without restriction, including without limitation the rights
......
65 65

  
66 66
typedef struct BDRVVPCState {
67 67
    int fd;
68
    
68
   
69 69
    int pagetable_entries;
70 70
    uint32_t *pagetable;
71 71

  
......
74 74
    uint8_t *pageentry_u8;
75 75
    uint32_t *pageentry_u32;
76 76
    uint16_t *pageentry_u16;
77
    
77
   
78 78
    uint64_t last_bitmap;
79 79
#endif
80 80
} BDRVVPCState;
......
97 97
        return -1;
98 98

  
99 99
    bs->read_only = 1; // no write support yet
100
    
100
   
101 101
    s->fd = fd;
102 102

  
103 103
    if (read(fd, &header, HEADER_SIZE) != HEADER_SIZE)
......
153 153

  
154 154
    pagetable_index = offset / s->pageentry_size;
155 155
    pageentry_index = (offset % s->pageentry_size) / 512;
156
    
156
   
157 157
    if (pagetable_index > s->pagetable_entries || s->pagetable[pagetable_index] == 0xffffffff)
158 158
	return -1; // not allocated
159 159

  
160 160
    bitmap_offset = 512 * s->pagetable[pagetable_index];
161 161
    block_offset = bitmap_offset + 512 + (512 * pageentry_index);
162
    
162
   
163 163
//    printf("sector: %" PRIx64 ", index: %x, offset: %x, bioff: %" PRIx64 ", bloff: %" PRIx64 "\n",
164 164
//	sector_num, pagetable_index, pageentry_index,
165 165
//	bitmap_offset, block_offset);
......
172 172
	lseek(s->fd, bitmap_offset, SEEK_SET);
173 173

  
174 174
	s->last_bitmap = bitmap_offset;
175
	
175

  
176 176
	// Scary! Bitmap is stored as big endian 32bit entries,
177 177
	// while we used to look it up byte by byte
178 178
	read(s->fd, s->pageentry_u8, 512);
......
184 184
	return -1;
185 185
#else
186 186
    lseek(s->fd, bitmap_offset + (pageentry_index / 8), SEEK_SET);
187
	
187

  
188 188
    read(s->fd, &bitmap_entry, 1);
189 189

  
190 190
    if ((bitmap_entry >> (pageentry_index % 8)) & 1)
......
196 196
    return 0;
197 197
}
198 198

  
199
static int vpc_read(BlockDriverState *bs, int64_t sector_num, 
199
static int vpc_read(BlockDriverState *bs, int64_t sector_num,
200 200
                    uint8_t *buf, int nb_sectors)
201 201
{
202 202
    BDRVVPCState *s = bs->opaque;

Also available in: Unified diff