Statistics
| Branch: | Revision:

root / include / libvhd-index.h @ abdb293f

History | View | Annotate | Download (4 kB)

1
/*
2
 * Copyright (c) 2008, XenSource Inc.
3
 * Copyright (c) 2010, Citrix Systems, Inc.
4
 *
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions are met:
9
 *     * Redistributions of source code must retain the above copyright
10
 *       notice, this list of conditions and the following disclaimer.
11
 *     * Redistributions in binary form must reproduce the above copyright
12
 *       notice, this list of conditions and the following disclaimer in the
13
 *       documentation and/or other materials provided with the distribution.
14
 *     * Neither the name of XenSource Inc. nor the names of its contributors
15
 *       may be used to endorse or promote products derived from this software
16
 *       without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
#ifndef _LIB_VHDI_H_
31
#define _LIB_VHDI_H_
32

    
33
#include <inttypes.h>
34
#include <uuid/uuid.h>
35

    
36
#define VHD_MAX_NAME_LEN                    1024
37

    
38
typedef struct vhdi_context                 vhdi_context_t;
39
typedef struct vhdi_bat                     vhdi_bat_t;
40
typedef struct vhdi_block                   vhdi_block_t;
41
typedef struct vhdi_entry                   vhdi_entry_t;
42
typedef uint32_t                            vhdi_file_id_t;
43
typedef struct vhdi_file_ref                vhdi_file_ref_t;
44
typedef struct vhdi_file_table              vhdi_file_table_t;
45

    
46
struct vhdi_context {
47
        int                                 fd;
48
        int                                 spb;
49
        char                               *name;
50
        uint32_t                            vhd_block_size;
51
};
52

    
53
struct vhdi_bat {
54
        uint32_t                           *table;
55
        uint64_t                            vhd_blocks;
56
        uint32_t                            vhd_block_size;
57
        char                                vhd_path[VHD_MAX_NAME_LEN];
58
        char                                index_path[VHD_MAX_NAME_LEN];
59
        char                                file_table_path[VHD_MAX_NAME_LEN];
60
};
61

    
62
struct vhdi_entry {
63
        vhdi_file_id_t                      file_id;
64
        uint32_t                            offset;
65
};
66

    
67
struct vhdi_block {
68
        int                                 entries;
69
        vhdi_entry_t                       *table;
70
};
71

    
72
struct vhdi_file_ref {
73
        vhdi_file_id_t                      file_id;
74
        char                               *path;
75
        uuid_t                              vhd_uuid;
76
        uint32_t                            vhd_timestamp;
77
};
78

    
79
struct vhdi_file_table {
80
        int                                 entries;
81
        vhdi_file_ref_t                    *table;
82
};
83

    
84
void vhdi_entry_in(vhdi_entry_t *);
85

    
86
int vhdi_create(const char *, uint32_t);
87
int vhdi_open(vhdi_context_t *, const char *, int);
88
void vhdi_close(vhdi_context_t *);
89
int vhdi_read_block(vhdi_context_t *, vhdi_block_t *, uint32_t);
90
int vhdi_write_block(vhdi_context_t *, vhdi_block_t *, uint32_t);
91
int vhdi_append_block(vhdi_context_t *, vhdi_block_t *, uint32_t *);
92

    
93
int vhdi_bat_create(const char *, const char *, const char *, const char *);
94
int vhdi_bat_load(const char *, vhdi_bat_t *);
95
int vhdi_bat_write(const char *, vhdi_bat_t *);
96

    
97
int vhdi_file_table_create(const char *);
98
int vhdi_file_table_load(const char *, vhdi_file_table_t *);
99
int vhdi_file_table_add(const char *, const char *, vhdi_file_id_t *);
100
void vhdi_file_table_free(vhdi_file_table_t *);
101

    
102
#endif