Revision 83f64091 block-cow.c

b/block-cow.c
62 62
        return 0;
63 63
}
64 64

  
65
static int cow_open(BlockDriverState *bs, const char *filename)
65
static int cow_open(BlockDriverState *bs, const char *filename, int flags)
66 66
{
67 67
    BDRVCowState *s = bs->opaque;
68 68
    int fd;
......
93 93
    pstrcpy(bs->backing_file, sizeof(bs->backing_file), 
94 94
            cow_header.backing_file);
95 95
    
96
#if 0
97
    if (cow_header.backing_file[0] != '\0') {
98
        if (stat(cow_header.backing_file, &st) != 0) {
99
            fprintf(stderr, "%s: could not find original disk image '%s'\n", filename, cow_header.backing_file);
100
            goto fail;
101
        }
102
        if (st.st_mtime != be32_to_cpu(cow_header.mtime)) {
103
            fprintf(stderr, "%s: original raw disk image '%s' does not match saved timestamp\n", filename, cow_header.backing_file);
104
            goto fail;
105
            }
106
        fd = open(cow_header.backing_file, O_RDONLY | O_LARGEFILE);
107
        if (fd < 0)
108
            goto fail;
109
        bs->fd = fd;
110
    }
111
#endif
112 96
    /* mmap the bitmap */
113 97
    s->cow_bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow_header);
114 98
    s->cow_bitmap_addr = mmap(get_mmap_addr(s->cow_bitmap_size), 
......
179 163
            if (ret != n * 512) 
180 164
                return -1;
181 165
        } else {
166
            if (bs->backing_hd) {
167
                /* read from the base image */
168
                ret = bdrv_read(bs->backing_hd, sector_num, buf, n);
169
                if (ret < 0)
170
                    return -1;
171
            } else {
182 172
            memset(buf, 0, n * 512);
183 173
        }
174
        }
184 175
        nb_sectors -= n;
185 176
        sector_num += n;
186 177
        buf += n * 512;
......
220 211
    if (flags)
221 212
        return -ENOTSUP;
222 213

  
223
    cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 
214
    cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 
224 215
              0644);
225 216
    if (cow_fd < 0)
226 217
        return -1;
......
228 219
    cow_header.magic = cpu_to_be32(COW_MAGIC);
229 220
    cow_header.version = cpu_to_be32(COW_VERSION);
230 221
    if (image_filename) {
222
        /* Note: if no file, we put a dummy mtime */
223
        cow_header.mtime = cpu_to_be32(0);
224

  
231 225
        fd = open(image_filename, O_RDONLY | O_BINARY);
232 226
        if (fd < 0) {
233 227
            close(cow_fd);
234
            return -1;
228
            goto mtime_fail;
235 229
        }
236 230
        if (fstat(fd, &st) != 0) {
237 231
            close(fd);
238
            return -1;
232
            goto mtime_fail;
239 233
        }
240 234
        close(fd);
241 235
        cow_header.mtime = cpu_to_be32(st.st_mtime);
242
        realpath(image_filename, cow_header.backing_file);
236
    mtime_fail:
237
        pstrcpy(cow_header.backing_file, sizeof(cow_header.backing_file),
238
                image_filename);
243 239
    }
244 240
    cow_header.sectorsize = cpu_to_be32(512);
245 241
    cow_header.size = cpu_to_be64(image_sectors * 512);

Also available in: Unified diff