2 * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
37 /** A WIM virtual file */
39 /** Underlying virtual file */
40 struct vdisk_file
*file
;
42 struct wim_header header
;
44 struct wim_resource_header resource
;
47 /** Maximum number of WIM virtual files */
48 #define WIM_MAX_FILES 8
50 /** WIM virtual files */
51 static struct wim_file wim_files
[WIM_MAX_FILES
];
54 * Read from WIM virtual file
56 * @v file Virtual file
61 static void wim_read_file ( struct vdisk_file
*file
, void *data
,
62 size_t offset
, size_t len
) {
63 struct wim_file
*wfile
= file
->opaque
;
66 /* Read from resource */
67 if ( ( rc
= wim_read ( wfile
->file
, &wfile
->header
, &wfile
->resource
,
68 data
, offset
, len
) ) != 0 ) {
69 die ( "Could not read from WIM virtual file\n" );
74 * Add WIM virtual file
76 * @v file Underlying virtual file
77 * @v index Image index, or 0 to use boot image
78 * @v path Path to file within WIM
79 * @v wname New virtual file name
80 * @ret file Virtual file, or NULL if not found
82 struct vdisk_file
* wim_add_file ( struct vdisk_file
*file
, unsigned int index
,
83 const wchar_t *path
, const wchar_t *wname
) {
84 static unsigned int wim_file_idx
= 0;
85 struct wim_resource_header meta
;
86 struct wim_file
*wfile
;
87 char name
[ VDISK_NAME_LEN
+ 1 /* NUL */ ];
92 if ( wim_file_idx
>= WIM_MAX_FILES
)
93 die ( "Too many WIM files\n" );
94 wfile
= &wim_files
[wim_file_idx
];
96 /* Construct ASCII file name */
97 snprintf ( name
, sizeof ( name
), "%ls", wname
);
99 /* Skip files already added explicitly */
100 for ( i
= 0 ; i
< VDISK_MAX_FILES
; i
++ ) {
101 if ( strcasecmp ( name
, vdisk_files
[i
].name
) == 0 )
106 if ( ( rc
= wim_header ( file
, &wfile
->header
) ) != 0 )
109 /* Get image metadata */
110 if ( ( rc
= wim_metadata ( file
, &wfile
->header
, index
, &meta
) ) != 0 )
113 /* Get file resource */
114 if ( ( rc
= wim_file ( file
, &wfile
->header
, &meta
, path
,
115 &wfile
->resource
) ) != 0 )
118 /* Add virtual file */
121 return vdisk_add_file ( name
, wfile
, wfile
->resource
.len
,
126 * Add WIM virtual files
128 * @v file Underlying virtual file
129 * @v index Image index, or 0 to use boot image
130 * @v paths List of paths to files within WIM
132 void wim_add_files ( struct vdisk_file
*file
, unsigned int index
,
133 const wchar_t **paths
) {
134 const wchar_t **path
;
135 const wchar_t *wname
;
138 /* Add any existent files within the list */
139 for ( path
= paths
; *path
; path
++ ) {
141 /* Construct file name */
143 for ( tmp
= wname
; *tmp
; tmp
++ ) {
148 /* Add virtual file, if existent */
149 wim_add_file ( file
, index
, *path
, wname
);