Search
lxdream.org :: lxdream/src/vmu/vmuvol.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/vmu/vmuvol.c
changeset 1034:7044e01148f0
next1035:e3093fd7d1da
author nkeynes
date Wed Jun 24 02:41:12 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Add initial VMU support
file annotate diff log raw
nkeynes@1034
     1
/**
nkeynes@1034
     2
 * $Id: vmuvol.h 869 2008-09-08 07:56:33Z nkeynes $
nkeynes@1034
     3
 *
nkeynes@1034
     4
 * VMU volume (ie block device) support
nkeynes@1034
     5
 *
nkeynes@1034
     6
 * Copyright (c) 2009 Nathan Keynes.
nkeynes@1034
     7
 *
nkeynes@1034
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@1034
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@1034
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@1034
    11
 * (at your option) any later version.
nkeynes@1034
    12
 *
nkeynes@1034
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@1034
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@1034
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@1034
    16
 * GNU General Public License for more details.
nkeynes@1034
    17
 */
nkeynes@1034
    18
nkeynes@1034
    19
#include <glib/gmem.h>
nkeynes@1034
    20
#include <glib/gstrfuncs.h>
nkeynes@1034
    21
#include <string.h>
nkeynes@1034
    22
#include <stdio.h>
nkeynes@1034
    23
#include <fcntl.h>
nkeynes@1034
    24
#include <errno.h>
nkeynes@1034
    25
nkeynes@1034
    26
#include "vmu/vmuvol.h"
nkeynes@1034
    27
#include "dream.h"
nkeynes@1034
    28
nkeynes@1034
    29
#define VMU_MAX_PARTITIONS 256
nkeynes@1034
    30
#define VMU_MAX_BLOCKS 65536 /* Actually slightly less than this, but it'll do */
nkeynes@1034
    31
nkeynes@1034
    32
typedef struct vmu_partition {
nkeynes@1034
    33
    struct vmu_volume_metadata metadata;
nkeynes@1034
    34
    uint32_t block_count;
nkeynes@1034
    35
    char *blocks;
nkeynes@1034
    36
} *vmu_partition_t;
nkeynes@1034
    37
nkeynes@1034
    38
struct vmu_volume {
nkeynes@1034
    39
    const gchar *display_name;
nkeynes@1034
    40
    vmu_partnum_t part_count;
nkeynes@1034
    41
    gboolean dirty;
nkeynes@1034
    42
    struct vmu_partition part[0];
nkeynes@1034
    43
};
nkeynes@1034
    44
nkeynes@1034
    45
/* On-VMU structures, courtesy of Marcus Comstedt */ 
nkeynes@1034
    46
struct vmu_superblock {
nkeynes@1034
    47
    char magic[16];
nkeynes@1034
    48
    uint8_t colour_flag;
nkeynes@1034
    49
    uint8_t bgra[4];
nkeynes@1034
    50
    uint8_t pad1[27];
nkeynes@1034
    51
    char timestamp[8];
nkeynes@1034
    52
    char pad2[8];
nkeynes@1034
    53
    char unknown[6];
nkeynes@1034
    54
    uint16_t fat_block;
nkeynes@1034
    55
    uint16_t fat_size;
nkeynes@1034
    56
    uint16_t dir_block;
nkeynes@1034
    57
    uint16_t dir_size;
nkeynes@1034
    58
    uint16_t icon_shape;
nkeynes@1034
    59
    uint16_t user_size;
nkeynes@1034
    60
    /* remainder unknown */
nkeynes@1034
    61
};
nkeynes@1034
    62
nkeynes@1034
    63
struct vmu_direntry {
nkeynes@1034
    64
    uint8_t filetype;
nkeynes@1034
    65
    uint8_t copy_flag;
nkeynes@1034
    66
    uint16_t blkno;
nkeynes@1034
    67
    char filename[12];
nkeynes@1034
    68
    char timestamp[8];
nkeynes@1034
    69
    uint16_t blksize; /* Size in blocks*/
nkeynes@1034
    70
    uint16_t hdroff; /* Header offset in blocks */
nkeynes@1034
    71
    char pad[4];
nkeynes@1034
    72
};
nkeynes@1034
    73
nkeynes@1034
    74
#define MD(vmu,ptno) ((vmu)->part[ptno].metadata)
nkeynes@1034
    75
nkeynes@1034
    76
#define VMU_BLOCK(vmu,ptno,blkno) (&(vmu)->part[ptno].blocks[(blkno)*VMU_BLOCK_SIZE])
nkeynes@1034
    77
nkeynes@1034
    78
#define VMU_FAT_ENTRY(vmu,pt,ent)  ((uint16_t *)VMU_BLOCK(vmu, pt, (MD(vmu,pt).fat_block - ((ent)>>8))))[(ent)&0xFF]
nkeynes@1034
    79
nkeynes@1034
    80
#define FAT_EMPTY 0xFFFC
nkeynes@1034
    81
#define FAT_EOF   0xFFFA
nkeynes@1034
    82
nkeynes@1034
    83
static const struct vmu_volume_metadata default_metadata = { 255, 255, 254, 1, 253, 13, 0, 200, 31, 0, 128 };
nkeynes@1034
    84
nkeynes@1034
    85
vmu_volume_t vmu_volume_new_default( const gchar *display_name )
nkeynes@1034
    86
{
nkeynes@1034
    87
    vmu_volume_t vol = g_malloc0( sizeof(struct vmu_volume) + sizeof(struct vmu_partition) );
nkeynes@1034
    88
    vol->part_count = 1;
nkeynes@1034
    89
    vol->dirty = FALSE;
nkeynes@1034
    90
    memcpy( &vol->part[0].metadata, &default_metadata, sizeof(struct vmu_volume_metadata) );
nkeynes@1034
    91
    vol->part[0].block_count = VMU_DEFAULT_VOL_BLOCKS;
nkeynes@1034
    92
    vol->part[0].blocks = g_malloc0( VMU_DEFAULT_VOL_BLOCKS * VMU_BLOCK_SIZE );
nkeynes@1034
    93
    vol->display_name = display_name == NULL ? NULL : g_strdup(display_name);
nkeynes@1034
    94
    vmu_volume_format( vol, 0, TRUE );
nkeynes@1034
    95
    return vol;
nkeynes@1034
    96
}
nkeynes@1034
    97
nkeynes@1034
    98
void vmu_volume_destroy( vmu_volume_t vol )
nkeynes@1034
    99
{
nkeynes@1034
   100
    int i;
nkeynes@1034
   101
    if( vol == NULL )
nkeynes@1034
   102
        return;
nkeynes@1034
   103
    
nkeynes@1034
   104
    for( i=0; i<vol->part_count; i++ ) {
nkeynes@1034
   105
        g_free( vol->part[i].blocks );
nkeynes@1034
   106
        vol->part[i].blocks = NULL;
nkeynes@1034
   107
    }
nkeynes@1034
   108
    if( vol->display_name ) {
nkeynes@1034
   109
        g_free( (char *)vol->display_name );
nkeynes@1034
   110
        vol->display_name = NULL;
nkeynes@1034
   111
    }
nkeynes@1034
   112
    g_free(vol);
nkeynes@1034
   113
}
nkeynes@1034
   114
nkeynes@1034
   115
void vmu_volume_format( vmu_volume_t vol, vmu_partnum_t pt, gboolean quick )
nkeynes@1034
   116
{
nkeynes@1034
   117
    if( pt >= vol->part_count ) {
nkeynes@1034
   118
        return;
nkeynes@1034
   119
    }
nkeynes@1034
   120
    
nkeynes@1034
   121
    if( !quick ) {
nkeynes@1034
   122
        /* Wipe it completely first */
nkeynes@1034
   123
        memset( vol->part[pt].blocks, 0, (vol->part[pt].block_count) * VMU_BLOCK_SIZE );
nkeynes@1034
   124
    }
nkeynes@1034
   125
    
nkeynes@1034
   126
    struct vmu_volume_metadata *meta = &vol->part[pt].metadata;
nkeynes@1034
   127
    unsigned int fatblkno = meta->fat_block;
nkeynes@1034
   128
    unsigned int dirblkno = meta->dir_block;
nkeynes@1034
   129
    
nkeynes@1034
   130
    /* Write superblock */
nkeynes@1034
   131
    struct vmu_superblock *super = (struct vmu_superblock *)VMU_BLOCK(vol,pt, meta->super_block);
nkeynes@1034
   132
    memset( super->magic, 0x55, 16 );
nkeynes@1034
   133
    memset( &super->colour_flag, 0, 240 ); /* Blank the rest for now */
nkeynes@1034
   134
    super->fat_block = meta->fat_block;
nkeynes@1034
   135
    super->fat_size = meta->fat_size;
nkeynes@1034
   136
    super->dir_block = meta->dir_block;
nkeynes@1034
   137
    super->user_size = meta->user_size;
nkeynes@1034
   138
    
nkeynes@1034
   139
    /* Write file allocation tables */
nkeynes@1034
   140
    int i,j;
nkeynes@1034
   141
    for( j=0; j<meta->fat_size; j++ ) {
nkeynes@1034
   142
        uint16_t *fat = (uint16_t *)VMU_BLOCK(vol,pt,fatblkno-j); 
nkeynes@1034
   143
        for( i=0; i<256; i++ ) {
nkeynes@1034
   144
            fat[i] = FAT_EMPTY;
nkeynes@1034
   145
        }
nkeynes@1034
   146
    }
nkeynes@1034
   147
    
nkeynes@1034
   148
    /* Fill in the system allocations in the FAT */
nkeynes@1034
   149
    for( i=0; i<meta->fat_size-1; i++ ) {
nkeynes@1034
   150
        VMU_FAT_ENTRY(vol,pt,fatblkno-i) = fatblkno-i-1;
nkeynes@1034
   151
    }
nkeynes@1034
   152
    VMU_FAT_ENTRY(vol,pt,fatblkno - i) = FAT_EOF;
nkeynes@1034
   153
    for( i=0; i<meta->dir_size-1; i++ ) {
nkeynes@1034
   154
        VMU_FAT_ENTRY(vol,pt,dirblkno-i) = dirblkno-i-1;
nkeynes@1034
   155
    }
nkeynes@1034
   156
    VMU_FAT_ENTRY(vol,pt,dirblkno-i) = FAT_EOF;
nkeynes@1034
   157
  
nkeynes@1034
   158
    /* If quick-format, blank the directory. Otherwise it's already been done */
nkeynes@1034
   159
    if( quick ) {
nkeynes@1034
   160
        memset( VMU_BLOCK(vol,pt,dirblkno-meta->dir_size+1),
nkeynes@1034
   161
                0, meta->dir_size * VMU_BLOCK_SIZE );
nkeynes@1034
   162
    }
nkeynes@1034
   163
}
nkeynes@1034
   164
nkeynes@1034
   165
/*************************** File load/save ********************************/
nkeynes@1034
   166
nkeynes@1034
   167
/**
nkeynes@1034
   168
 * Current file has 1 META chunk for all volume metadata, followed by a
nkeynes@1034
   169
 * DATA chunk for each partition's block data. The META chunk is required to
nkeynes@1034
   170
 * occur before any DATA blocks.
nkeynes@1034
   171
 * Unknown chunks are skipped to allow for forwards compatibility if/when
nkeynes@1034
   172
 * we add the VMU runtime side of things
nkeynes@1034
   173
 */
nkeynes@1034
   174
nkeynes@1034
   175
struct vmu_file_header {
nkeynes@1034
   176
    char magic[16];
nkeynes@1034
   177
    uint32_t version;
nkeynes@1034
   178
    uint32_t head_len;
nkeynes@1034
   179
    uint32_t part_count;
nkeynes@1034
   180
    uint32_t display_name_len;
nkeynes@1034
   181
    char display_name[0];
nkeynes@1034
   182
};
nkeynes@1034
   183
nkeynes@1034
   184
struct vmu_chunk_header {
nkeynes@1034
   185
    char name[4];
nkeynes@1034
   186
    uint32_t length;
nkeynes@1034
   187
};
nkeynes@1034
   188
nkeynes@1034
   189
nkeynes@1034
   190
nkeynes@1034
   191
gboolean vmu_volume_save( const gchar *filename, vmu_volume_t vol, gboolean create_only )
nkeynes@1034
   192
{
nkeynes@1034
   193
    struct vmu_file_header head;
nkeynes@1034
   194
    struct vmu_chunk_header chunk;
nkeynes@1034
   195
    int i;
nkeynes@1034
   196
    
nkeynes@1034
   197
    FILE *f = fopen( filename, (create_only ? "wx" : "w") ); /* Portable? */
nkeynes@1034
   198
    if( f == NULL ) {
nkeynes@1034
   199
        return FALSE;
nkeynes@1034
   200
    }
nkeynes@1034
   201
    
nkeynes@1034
   202
    /* File header */
nkeynes@1034
   203
    memcpy( head.magic, VMU_FILE_MAGIC, 16 );
nkeynes@1034
   204
    head.version = VMU_FILE_VERSION;
nkeynes@1034
   205
    head.part_count = vol->part_count;
nkeynes@1034
   206
    head.display_name_len = vol->display_name == NULL ? 0 : (strlen(vol->display_name)+1);
nkeynes@1034
   207
    head.head_len = sizeof(head) + head.display_name_len;
nkeynes@1034
   208
    fwrite( &head, sizeof(head), 1, f );
nkeynes@1034
   209
    if( vol->display_name != NULL ) {
nkeynes@1034
   210
        fwrite( vol->display_name, head.display_name_len, 1, f );
nkeynes@1034
   211
    }
nkeynes@1034
   212
    
nkeynes@1034
   213
    /* METAdata chunk */
nkeynes@1034
   214
    memcpy( chunk.name, "META", 4 );
nkeynes@1034
   215
    chunk.length = sizeof(struct vmu_volume_metadata) * vol->part_count;
nkeynes@1034
   216
    fwrite( &chunk, sizeof(chunk), 1, f );
nkeynes@1034
   217
    for( i=0; i < vol->part_count; i++ ) {
nkeynes@1034
   218
        fwrite( &vol->part[i].metadata, sizeof(struct vmu_volume_metadata), 1, f );
nkeynes@1034
   219
    }
nkeynes@1034
   220
    
nkeynes@1034
   221
    /* partition DATA chunks */
nkeynes@1034
   222
    for( i=0; i< vol->part_count; i++ ) {
nkeynes@1034
   223
        memcpy( chunk.name, "DATA", 4 );
nkeynes@1034
   224
        chunk.length = 0;
nkeynes@1034
   225
        fwrite( &chunk, sizeof(chunk), 1, f );
nkeynes@1034
   226
        long posn = ftell(f);
nkeynes@1034
   227
        fwrite( &vol->part[i].block_count, sizeof(vol->part[i].block_count), 1, f );
nkeynes@1034
   228
        fwrite_gzip( vol->part[i].blocks, vol->part[i].block_count, VMU_BLOCK_SIZE, f );
nkeynes@1034
   229
        long end = ftell(f);
nkeynes@1034
   230
        fseek( f, posn - sizeof(chunk.length), SEEK_SET );
nkeynes@1034
   231
        chunk.length = end-posn;
nkeynes@1034
   232
        fwrite( &chunk.length, sizeof(chunk.length), 1, f );
nkeynes@1034
   233
        fseek( f, end, SEEK_SET );
nkeynes@1034
   234
    }
nkeynes@1034
   235
    fclose(f);
nkeynes@1034
   236
    vol->dirty = FALSE;
nkeynes@1034
   237
    return TRUE;
nkeynes@1034
   238
}
nkeynes@1034
   239
nkeynes@1034
   240
vmu_volume_t vmu_volume_load( const gchar *filename )
nkeynes@1034
   241
{
nkeynes@1034
   242
    struct vmu_file_header head;
nkeynes@1034
   243
    struct vmu_chunk_header chunk;
nkeynes@1034
   244
    vmu_volume_t vol;
nkeynes@1034
   245
    int i;
nkeynes@1034
   246
    
nkeynes@1034
   247
    FILE *f = fopen( filename, "ro" );
nkeynes@1034
   248
    if( f == NULL ) {
nkeynes@1034
   249
        ERROR( "Unable to open VMU file '%s': %s", filename, strerror(errno) );
nkeynes@1034
   250
        return FALSE;
nkeynes@1034
   251
    }
nkeynes@1034
   252
    
nkeynes@1034
   253
    if( fread( &head, sizeof(head), 1, f ) != 1 ||
nkeynes@1034
   254
        memcmp(head.magic, VMU_FILE_MAGIC, 16) != 0 ||
nkeynes@1034
   255
        head.part_count > VMU_MAX_PARTITIONS || 
nkeynes@1034
   256
        head.head_len < (sizeof(head) + head.display_name_len) )  {
nkeynes@1034
   257
        fclose(f);
nkeynes@1034
   258
        ERROR( "Unable to load VMU '%s': bad file header", filename );
nkeynes@1034
   259
        return NULL;
nkeynes@1034
   260
    }
nkeynes@1034
   261
    
nkeynes@1034
   262
    vol = (vmu_volume_t)g_malloc0( sizeof(struct vmu_volume) + sizeof(struct vmu_partition)*head.part_count );
nkeynes@1034
   263
    vol->part_count = head.part_count;
nkeynes@1034
   264
    vol->dirty = FALSE;
nkeynes@1034
   265
    if( head.display_name_len != 0 ) {
nkeynes@1034
   266
        vol->display_name = g_malloc( head.display_name_len );
nkeynes@1034
   267
        fread( (char *)vol->display_name, head.display_name_len, 1, f );
nkeynes@1034
   268
    }
nkeynes@1034
   269
    fseek( f, head.head_len, SEEK_SET );
nkeynes@1034
   270
    
nkeynes@1034
   271
    gboolean have_meta = FALSE;
nkeynes@1034
   272
    int next_part = 0;
nkeynes@1034
   273
    while( !feof(f) && fread( &chunk, sizeof(chunk), 1, f ) == 1 ) {
nkeynes@1034
   274
        if( memcmp( &chunk.name, "META", 4 ) == 0 ) {
nkeynes@1034
   275
            if( have_meta || chunk.length != head.part_count * sizeof(struct vmu_volume_metadata) ) {
nkeynes@1034
   276
                vmu_volume_destroy(vol);
nkeynes@1034
   277
                fclose(f);
nkeynes@1034
   278
                ERROR( "Unable to load VMU '%s': bad metadata size (expected %d but was %d)", filename,
nkeynes@1034
   279
                       head.part_count * sizeof(struct vmu_volume_metadata), chunk.length );
nkeynes@1034
   280
                return NULL;
nkeynes@1034
   281
            }
nkeynes@1034
   282
            for( i=0; i<head.part_count; i++ ) {
nkeynes@1034
   283
                fread( &vol->part[i].metadata, sizeof(struct vmu_volume_metadata), 1, f );
nkeynes@1034
   284
            }
nkeynes@1034
   285
            have_meta = TRUE;
nkeynes@1034
   286
        } else if( memcmp( &chunk.name, "DATA", 4 ) == 0 ) {
nkeynes@1034
   287
            uint32_t block_count;
nkeynes@1034
   288
            fread( &block_count, sizeof(block_count), 1, f );
nkeynes@1034
   289
            if( next_part >= vol->part_count || block_count >= VMU_MAX_BLOCKS ) {
nkeynes@1034
   290
                // Too many partitions / blocks
nkeynes@1034
   291
                vmu_volume_destroy(vol);
nkeynes@1034
   292
                fclose(f);
nkeynes@1034
   293
                ERROR( "Unable to load VMU '%s': too large (%d/%d)", filename, next_part, block_count );
nkeynes@1034
   294
                return NULL;
nkeynes@1034
   295
            }
nkeynes@1034
   296
            vol->part[next_part].block_count = block_count;
nkeynes@1034
   297
            vol->part[next_part].blocks = g_malloc(block_count*VMU_BLOCK_SIZE);
nkeynes@1034
   298
            fread_gzip(vol->part[next_part].blocks, VMU_BLOCK_SIZE, block_count, f );
nkeynes@1034
   299
            next_part++;
nkeynes@1034
   300
        } else {
nkeynes@1034
   301
            // else skip unknown block
nkeynes@1034
   302
            fseek( f, SEEK_CUR, chunk.length );
nkeynes@1034
   303
            WARN( "Unexpected VMU data chunk: '%4.4s'", chunk.name );
nkeynes@1034
   304
        }
nkeynes@1034
   305
    }
nkeynes@1034
   306
    
nkeynes@1034
   307
    fclose(f);
nkeynes@1034
   308
    
nkeynes@1034
   309
    if( !have_meta || next_part != vol->part_count ) {
nkeynes@1034
   310
        vmu_volume_destroy( vol );
nkeynes@1034
   311
        return NULL;
nkeynes@1034
   312
    }
nkeynes@1034
   313
    
nkeynes@1034
   314
    return vol;
nkeynes@1034
   315
}
nkeynes@1034
   316
nkeynes@1034
   317
/*************************** Accessing data ********************************/
nkeynes@1034
   318
const char *vmu_volume_get_display_name( vmu_volume_t vol ) 
nkeynes@1034
   319
{
nkeynes@1034
   320
    return vol->display_name;
nkeynes@1034
   321
}
nkeynes@1034
   322
nkeynes@1034
   323
void vmu_volume_set_display_name( vmu_volume_t vol, const gchar *name )
nkeynes@1034
   324
{
nkeynes@1034
   325
    if( vol->display_name != NULL ) {
nkeynes@1034
   326
        g_free( (char *)vol->display_name );
nkeynes@1034
   327
    }
nkeynes@1034
   328
    if( name == NULL ) {
nkeynes@1034
   329
        vol->display_name = NULL;
nkeynes@1034
   330
    } else {
nkeynes@1034
   331
        vol->display_name = g_strdup(name);
nkeynes@1034
   332
    }
nkeynes@1034
   333
}
nkeynes@1034
   334
    
nkeynes@1034
   335
gboolean vmu_volume_is_dirty( vmu_volume_t vol )
nkeynes@1034
   336
{
nkeynes@1034
   337
    return vol->dirty;
nkeynes@1034
   338
}
nkeynes@1034
   339
nkeynes@1034
   340
gboolean vmu_volume_read_block( vmu_volume_t vol, vmu_partnum_t pt, unsigned int block, unsigned char *out )
nkeynes@1034
   341
{
nkeynes@1034
   342
    if( pt >= vol->part_count || block >= vol->part[pt].block_count ) {
nkeynes@1034
   343
        return FALSE;
nkeynes@1034
   344
    }
nkeynes@1034
   345
nkeynes@1034
   346
    memcpy( out, VMU_BLOCK(vol,pt,block), VMU_BLOCK_SIZE );
nkeynes@1034
   347
    return TRUE;
nkeynes@1034
   348
}
nkeynes@1034
   349
nkeynes@1034
   350
gboolean vmu_volume_write_block( vmu_volume_t vol, vmu_partnum_t pt, unsigned int block, unsigned char *in )
nkeynes@1034
   351
{
nkeynes@1034
   352
    if( pt >= vol->part_count || block >= vol->part[pt].block_count ) {
nkeynes@1034
   353
        return FALSE;
nkeynes@1034
   354
    }
nkeynes@1034
   355
    memcpy( VMU_BLOCK(vol,pt,block), in, VMU_BLOCK_SIZE );
nkeynes@1034
   356
    vol->dirty = TRUE;
nkeynes@1034
   357
}
nkeynes@1034
   358
nkeynes@1034
   359
gboolean vmu_volume_write_phase( vmu_volume_t vol, vmu_partnum_t pt, unsigned int block, unsigned int phase, unsigned char *in )
nkeynes@1034
   360
{
nkeynes@1034
   361
    if( pt >= vol->part_count || block >= vol->part[pt].block_count || phase >= 4 ) {
nkeynes@1034
   362
        return FALSE;
nkeynes@1034
   363
    }
nkeynes@1034
   364
    memcpy( VMU_BLOCK(vol,pt,block) + (phase*128), in, VMU_BLOCK_SIZE/4 );
nkeynes@1034
   365
    vol->dirty = TRUE;
nkeynes@1034
   366
}
nkeynes@1034
   367
nkeynes@1034
   368
const struct vmu_volume_metadata *vmu_volume_get_metadata( vmu_volume_t vol, vmu_partnum_t partition )
nkeynes@1034
   369
{
nkeynes@1034
   370
    if( partition >= vol->part_count ) {
nkeynes@1034
   371
        return NULL;
nkeynes@1034
   372
    } else {
nkeynes@1034
   373
        return &vol->part[partition].metadata;
nkeynes@1034
   374
    }
nkeynes@1034
   375
}
.