source: mainline/uspace/srv/fs/tmpfs/tmpfs_dump.c@ a35b458

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[40257f5]1/*
[1b20da0]2 * Copyright (c) 2008 Jakub Jermar
3 * Copyright (c) 2008 Martin Decky
[40257f5]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
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.
17 *
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.
28 */
29
30/** @addtogroup fs
31 * @{
[1b20da0]32 */
[40257f5]33
34/**
35 * @file tmpfs_dump.c
36 * @brief Support for loading TMPFS file system dump.
37 */
38
39#include "tmpfs.h"
40#include "../../vfs/vfs.h"
41#include <errno.h>
42#include <stdlib.h>
[19f857a]43#include <str.h>
[8d2dd7f2]44#include <stddef.h>
45#include <stdint.h>
[40257f5]46#include <as.h>
[f73b291]47#include <block.h>
[40257f5]48#include <byteorder.h>
49
[1ee00b7]50#define TMPFS_COMM_SIZE 1024
[40257f5]51
[4802dd7]52static uint8_t tmpfs_buf[TMPFS_COMM_SIZE];
53
[40257f5]54struct rdentry {
55 uint8_t type;
56 uint32_t len;
57} __attribute__((packed));
58
59static bool
[15f3c3f]60tmpfs_restore_recursion(service_id_t dsid, size_t *bufpos, size_t *buflen,
[ed903174]61 aoff64_t *pos, fs_node_t *pfn)
[40257f5]62{
63 struct rdentry entry;
64 libfs_ops_t *ops = &tmpfs_libfs_ops;
[b7fd2a0]65 errno_t rc;
[a35b458]66
[40257f5]67 do {
68 char *fname;
[b6035ba]69 fs_node_t *fn;
[cf95bc0]70 tmpfs_node_t *nodep;
[40257f5]71 uint32_t size;
[a35b458]72
[4802dd7]73 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, &entry,
[1ee00b7]74 sizeof(entry)) != EOK)
[40257f5]75 return false;
[a35b458]76
[40257f5]77 entry.len = uint32_t_le2host(entry.len);
[a35b458]78
[40257f5]79 switch (entry.type) {
[ade06b4]80 case TMPFS_NONE:
[40257f5]81 break;
[ade06b4]82 case TMPFS_FILE:
[40257f5]83 fname = malloc(entry.len + 1);
84 if (fname == NULL)
85 return false;
[a35b458]86
[15f3c3f]87 rc = ops->create(&fn, dsid, L_FILE);
[54e4479]88 if (rc != EOK || fn == NULL) {
[40257f5]89 free(fname);
90 return false;
91 }
[a35b458]92
[4802dd7]93 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, fname,
[1ee00b7]94 entry.len) != EOK) {
[54e4479]95 (void) ops->destroy(fn);
[40257f5]96 free(fname);
97 return false;
98 }
99 fname[entry.len] = 0;
[a35b458]100
[b6035ba]101 rc = ops->link(pfn, fn, fname);
[0013b9ce]102 if (rc != EOK) {
[54e4479]103 (void) ops->destroy(fn);
[40257f5]104 free(fname);
105 return false;
106 }
107 free(fname);
[a35b458]108
[4802dd7]109 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, &size,
[1ee00b7]110 sizeof(size)) != EOK)
[40257f5]111 return false;
[a35b458]112
[40257f5]113 size = uint32_t_le2host(size);
[a35b458]114
[b6035ba]115 nodep = TMPFS_NODE(fn);
116 nodep->data = malloc(size);
117 if (nodep->data == NULL)
[40257f5]118 return false;
[a35b458]119
[b6035ba]120 nodep->size = size;
[4802dd7]121 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, nodep->data,
[1ee00b7]122 size) != EOK)
[40257f5]123 return false;
[a35b458]124
[40257f5]125 break;
[ade06b4]126 case TMPFS_DIRECTORY:
[40257f5]127 fname = malloc(entry.len + 1);
128 if (fname == NULL)
129 return false;
[a35b458]130
[15f3c3f]131 rc = ops->create(&fn, dsid, L_DIRECTORY);
[54e4479]132 if (rc != EOK || fn == NULL) {
[40257f5]133 free(fname);
134 return false;
135 }
[a35b458]136
[4802dd7]137 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, fname,
[1ee00b7]138 entry.len) != EOK) {
[54e4479]139 (void) ops->destroy(fn);
[40257f5]140 free(fname);
141 return false;
142 }
143 fname[entry.len] = 0;
[0013b9ce]144
[b6035ba]145 rc = ops->link(pfn, fn, fname);
[0013b9ce]146 if (rc != EOK) {
[54e4479]147 (void) ops->destroy(fn);
[40257f5]148 free(fname);
149 return false;
150 }
151 free(fname);
[a35b458]152
[15f3c3f]153 if (!tmpfs_restore_recursion(dsid, bufpos, buflen, pos,
[b6035ba]154 fn))
[40257f5]155 return false;
[a35b458]156
[40257f5]157 break;
158 default:
159 return false;
160 }
[ade06b4]161 } while (entry.type != TMPFS_NONE);
[a35b458]162
[40257f5]163 return true;
164}
165
[15f3c3f]166bool tmpfs_restore(service_id_t dsid)
[40257f5]167{
168 libfs_ops_t *ops = &tmpfs_libfs_ops;
[54e4479]169 fs_node_t *fn;
[b7fd2a0]170 errno_t rc;
[40257f5]171
[fc22069]172 rc = block_init(dsid, TMPFS_COMM_SIZE);
[7858bc5f]173 if (rc != EOK)
[1b20da0]174 return false;
[a35b458]175
[ed903174]176 size_t bufpos = 0;
[40257f5]177 size_t buflen = 0;
[ed903174]178 aoff64_t pos = 0;
[a35b458]179
[40257f5]180 char tag[6];
[4802dd7]181 if (block_seqread(dsid, tmpfs_buf, &bufpos, &buflen, &pos, tag, 5) != EOK)
[40257f5]182 goto error;
[a35b458]183
[40257f5]184 tag[5] = 0;
[92fd52d7]185 if (str_cmp(tag, "TMPFS") != 0)
[40257f5]186 goto error;
[a35b458]187
[15f3c3f]188 rc = ops->root_get(&fn, dsid);
[54e4479]189 if (rc != EOK)
190 goto error;
191
[15f3c3f]192 if (!tmpfs_restore_recursion(dsid, &bufpos, &buflen, &pos, fn))
[40257f5]193 goto error;
[a35b458]194
[15f3c3f]195 block_fini(dsid);
[40257f5]196 return true;
[a35b458]197
[40257f5]198error:
[15f3c3f]199 block_fini(dsid);
[40257f5]200 return false;
201}
202
203/**
204 * @}
[1b20da0]205 */
Note: See TracBrowser for help on using the repository browser.