Rev 4419 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4419 | Rev 4420 | ||
---|---|---|---|
Line 53... | Line 53... | ||
53 | uint32_t len; |
53 | uint32_t len; |
54 | } __attribute__((packed)); |
54 | } __attribute__((packed)); |
55 | 55 | ||
56 | static bool |
56 | static bool |
57 | tmpfs_restore_recursion(int dev, off_t *bufpos, size_t *buflen, off_t *pos, |
57 | tmpfs_restore_recursion(int dev, off_t *bufpos, size_t *buflen, off_t *pos, |
58 | tmpfs_dentry_t *parent) |
58 | fs_node_t *pfn) |
59 | { |
59 | { |
60 | struct rdentry entry; |
60 | struct rdentry entry; |
61 | libfs_ops_t *ops = &tmpfs_libfs_ops; |
61 | libfs_ops_t *ops = &tmpfs_libfs_ops; |
62 | int rc; |
62 | int rc; |
63 | 63 | ||
64 | do { |
64 | do { |
65 | char *fname; |
65 | char *fname; |
- | 66 | fs_node_t *fn; |
|
66 | tmpfs_dentry_t *node; |
67 | tmpfs_node_t *nodep; |
67 | uint32_t size; |
68 | uint32_t size; |
68 | 69 | ||
69 | if (block_read(dev, bufpos, buflen, pos, &entry, sizeof(entry), |
70 | if (block_read(dev, bufpos, buflen, pos, &entry, sizeof(entry), |
70 | TMPFS_BLOCK_SIZE) != EOK) |
71 | TMPFS_BLOCK_SIZE) != EOK) |
71 | return false; |
72 | return false; |
Line 78... | Line 79... | ||
78 | case TMPFS_FILE: |
79 | case TMPFS_FILE: |
79 | fname = malloc(entry.len + 1); |
80 | fname = malloc(entry.len + 1); |
80 | if (fname == NULL) |
81 | if (fname == NULL) |
81 | return false; |
82 | return false; |
82 | 83 | ||
83 | node = (tmpfs_dentry_t *) ops->create(dev, L_FILE); |
84 | fn = ops->create(dev, L_FILE); |
84 | if (node == NULL) { |
85 | if (fn == NULL) { |
85 | free(fname); |
86 | free(fname); |
86 | return false; |
87 | return false; |
87 | } |
88 | } |
88 | 89 | ||
89 | if (block_read(dev, bufpos, buflen, pos, fname, |
90 | if (block_read(dev, bufpos, buflen, pos, fname, |
90 | entry.len, TMPFS_BLOCK_SIZE) != EOK) { |
91 | entry.len, TMPFS_BLOCK_SIZE) != EOK) { |
91 | ops->destroy((void *) node); |
92 | ops->destroy(fn); |
92 | free(fname); |
93 | free(fname); |
93 | return false; |
94 | return false; |
94 | } |
95 | } |
95 | fname[entry.len] = 0; |
96 | fname[entry.len] = 0; |
96 | 97 | ||
97 | rc = ops->link((void *) parent, (void *) node, fname); |
98 | rc = ops->link(pfn, fn, fname); |
98 | if (rc != EOK) { |
99 | if (rc != EOK) { |
99 | ops->destroy((void *) node); |
100 | ops->destroy(fn); |
100 | free(fname); |
101 | free(fname); |
101 | return false; |
102 | return false; |
102 | } |
103 | } |
103 | free(fname); |
104 | free(fname); |
104 | 105 | ||
Line 106... | Line 107... | ||
106 | sizeof(size), TMPFS_BLOCK_SIZE) != EOK) |
107 | sizeof(size), TMPFS_BLOCK_SIZE) != EOK) |
107 | return false; |
108 | return false; |
108 | 109 | ||
109 | size = uint32_t_le2host(size); |
110 | size = uint32_t_le2host(size); |
110 | 111 | ||
- | 112 | nodep = TMPFS_NODE(fn); |
|
111 | node->data = malloc(size); |
113 | nodep->data = malloc(size); |
112 | if (node->data == NULL) |
114 | if (nodep->data == NULL) |
113 | return false; |
115 | return false; |
114 | 116 | ||
115 | node->size = size; |
117 | nodep->size = size; |
116 | if (block_read(dev, bufpos, buflen, pos, node->data, |
118 | if (block_read(dev, bufpos, buflen, pos, nodep->data, |
117 | size, TMPFS_BLOCK_SIZE) != EOK) |
119 | size, TMPFS_BLOCK_SIZE) != EOK) |
118 | return false; |
120 | return false; |
119 | 121 | ||
120 | break; |
122 | break; |
121 | case TMPFS_DIRECTORY: |
123 | case TMPFS_DIRECTORY: |
122 | fname = malloc(entry.len + 1); |
124 | fname = malloc(entry.len + 1); |
123 | if (fname == NULL) |
125 | if (fname == NULL) |
124 | return false; |
126 | return false; |
125 | 127 | ||
126 | node = (tmpfs_dentry_t *) ops->create(dev, L_DIRECTORY); |
128 | fn = ops->create(dev, L_DIRECTORY); |
127 | if (node == NULL) { |
129 | if (fn == NULL) { |
128 | free(fname); |
130 | free(fname); |
129 | return false; |
131 | return false; |
130 | } |
132 | } |
131 | 133 | ||
132 | if (block_read(dev, bufpos, buflen, pos, fname, |
134 | if (block_read(dev, bufpos, buflen, pos, fname, |
133 | entry.len, TMPFS_BLOCK_SIZE) != EOK) { |
135 | entry.len, TMPFS_BLOCK_SIZE) != EOK) { |
134 | ops->destroy((void *) node); |
136 | ops->destroy(fn); |
135 | free(fname); |
137 | free(fname); |
136 | return false; |
138 | return false; |
137 | } |
139 | } |
138 | fname[entry.len] = 0; |
140 | fname[entry.len] = 0; |
139 | 141 | ||
140 | rc = ops->link((void *) parent, (void *) node, fname); |
142 | rc = ops->link(pfn, fn, fname); |
141 | if (rc != EOK) { |
143 | if (rc != EOK) { |
142 | ops->destroy((void *) node); |
144 | ops->destroy(fn); |
143 | free(fname); |
145 | free(fname); |
144 | return false; |
146 | return false; |
145 | } |
147 | } |
146 | free(fname); |
148 | free(fname); |
147 | 149 | ||
148 | if (!tmpfs_restore_recursion(dev, bufpos, buflen, pos, |
150 | if (!tmpfs_restore_recursion(dev, bufpos, buflen, pos, |
149 | node)) |
151 | fn)) |
150 | return false; |
152 | return false; |
151 | 153 | ||
152 | break; |
154 | break; |
153 | default: |
155 | default: |
154 | return false; |
156 | return false; |