2 * Copyright (c) 2008 Jakub Jermar
3 * Copyright (c) 2008 Martin Decky
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * @brief Support for loading TMPFS file system dump.
40 #include "../../vfs/vfs.h"
48 #include <byteorder.h>
50 #define TMPFS_COMM_SIZE 1024
52 static uint8_t tmpfs_buf
[TMPFS_COMM_SIZE
];
57 } __attribute__((packed
));
60 tmpfs_restore_recursion(service_id_t dsid
, size_t *bufpos
, size_t *buflen
,
61 aoff64_t
*pos
, fs_node_t
*pfn
)
64 libfs_ops_t
*ops
= &tmpfs_libfs_ops
;
73 if (block_seqread(dsid
, tmpfs_buf
, bufpos
, buflen
, pos
, &entry
,
74 sizeof(entry
)) != EOK
)
77 entry
.len
= uint32_t_le2host(entry
.len
);
83 fname
= malloc(entry
.len
+ 1);
87 rc
= ops
->create(&fn
, dsid
, L_FILE
);
88 if (rc
!= EOK
|| fn
== NULL
) {
93 if (block_seqread(dsid
, tmpfs_buf
, bufpos
, buflen
, pos
, fname
,
95 (void) ops
->destroy(fn
);
101 rc
= ops
->link(pfn
, fn
, fname
);
103 (void) ops
->destroy(fn
);
109 if (block_seqread(dsid
, tmpfs_buf
, bufpos
, buflen
, pos
, &size
,
110 sizeof(size
)) != EOK
)
113 size
= uint32_t_le2host(size
);
115 nodep
= TMPFS_NODE(fn
);
116 nodep
->data
= malloc(size
);
117 if (nodep
->data
== NULL
)
121 if (block_seqread(dsid
, tmpfs_buf
, bufpos
, buflen
, pos
, nodep
->data
,
126 case TMPFS_DIRECTORY
:
127 fname
= malloc(entry
.len
+ 1);
131 rc
= ops
->create(&fn
, dsid
, L_DIRECTORY
);
132 if (rc
!= EOK
|| fn
== NULL
) {
137 if (block_seqread(dsid
, tmpfs_buf
, bufpos
, buflen
, pos
, fname
,
139 (void) ops
->destroy(fn
);
143 fname
[entry
.len
] = 0;
145 rc
= ops
->link(pfn
, fn
, fname
);
147 (void) ops
->destroy(fn
);
153 if (!tmpfs_restore_recursion(dsid
, bufpos
, buflen
, pos
,
161 } while (entry
.type
!= TMPFS_NONE
);
166 bool tmpfs_restore(service_id_t dsid
)
168 libfs_ops_t
*ops
= &tmpfs_libfs_ops
;
172 rc
= block_init(dsid
, TMPFS_COMM_SIZE
);
181 if (block_seqread(dsid
, tmpfs_buf
, &bufpos
, &buflen
, &pos
, tag
, 5) != EOK
)
185 if (str_cmp(tag
, "TMPFS") != 0)
188 rc
= ops
->root_get(&fn
, dsid
);
192 if (!tmpfs_restore_recursion(dsid
, &bufpos
, &buflen
, &pos
, fn
))