[096c8835] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Maurizio Lombardi
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup fs
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
[9e3dc95] | 33 | #include <stdlib.h>
|
---|
[953a823] | 34 | #include <fibril_synch.h>
|
---|
[bb7e8382] | 35 | #include <align.h>
|
---|
[7413683] | 36 | #include "mfs.h"
|
---|
[9e3dc95] | 37 | #include "mfs_utils.h"
|
---|
| 38 |
|
---|
[8ceba1e] | 39 | static bool check_magic_number(uint16_t magic, bool *native,
|
---|
[44c6091f] | 40 | mfs_version_t *version, bool *longfilenames);
|
---|
[44c0f5b] | 41 | static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
|
---|
[44c6091f] | 42 | fs_index_t index);
|
---|
[096c8835] | 43 |
|
---|
[41202a9] | 44 | static int mfs_node_put(fs_node_t *fsnode);
|
---|
| 45 | static int mfs_node_open(fs_node_t *fsnode);
|
---|
| 46 | static fs_index_t mfs_index_get(fs_node_t *fsnode);
|
---|
| 47 | static unsigned mfs_lnkcnt_get(fs_node_t *fsnode);
|
---|
[ac28650] | 48 | static char mfs_plb_get_char(unsigned pos);
|
---|
| 49 | static bool mfs_is_directory(fs_node_t *fsnode);
|
---|
| 50 | static bool mfs_is_file(fs_node_t *fsnode);
|
---|
| 51 | static int mfs_has_children(bool *has_children, fs_node_t *fsnode);
|
---|
| 52 | static int mfs_root_get(fs_node_t **rfn, devmap_handle_t handle);
|
---|
| 53 | static devmap_handle_t mfs_device_get(fs_node_t *fsnode);
|
---|
| 54 | static aoff64_t mfs_size_get(fs_node_t *node);
|
---|
[bd64680] | 55 | static int mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component);
|
---|
[10eb754] | 56 | static int mfs_create_node(fs_node_t **rfn, devmap_handle_t handle, int flags);
|
---|
[88ccd8b8] | 57 | static int mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name);
|
---|
[53eb588] | 58 | static int mfs_unlink(fs_node_t *, fs_node_t *, const char *name);
|
---|
[d8af1bd] | 59 | static int mfs_destroy_node(fs_node_t *fn);
|
---|
[ac28650] | 60 |
|
---|
[668f1949] | 61 | static int mfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle,
|
---|
[ac28650] | 62 | fs_index_t index);
|
---|
| 63 |
|
---|
[41202a9] | 64 |
|
---|
[953a823] | 65 | static LIST_INITIALIZE(inst_list);
|
---|
| 66 | static FIBRIL_MUTEX_INITIALIZE(inst_list_mutex);
|
---|
| 67 |
|
---|
[e54ba607] | 68 | libfs_ops_t mfs_libfs_ops = {
|
---|
[0d6ab10] | 69 | .size_get = mfs_size_get,
|
---|
[fe4ac35] | 70 | .root_get = mfs_root_get,
|
---|
[5a58ae2] | 71 | .device_get = mfs_device_get,
|
---|
[7d04324] | 72 | .is_directory = mfs_is_directory,
|
---|
[44c0f5b] | 73 | .is_file = mfs_is_file,
|
---|
[cfbcd86] | 74 | .node_get = mfs_node_get,
|
---|
[41202a9] | 75 | .node_put = mfs_node_put,
|
---|
| 76 | .node_open = mfs_node_open,
|
---|
| 77 | .index_get = mfs_index_get,
|
---|
[bd64680] | 78 | .match = mfs_match,
|
---|
[10eb754] | 79 | .create = mfs_create_node,
|
---|
[88ccd8b8] | 80 | .link = mfs_link,
|
---|
[53eb588] | 81 | .unlink = mfs_unlink,
|
---|
[d8af1bd] | 82 | .destroy = mfs_destroy_node,
|
---|
[54caa41b] | 83 | .plb_get_char = mfs_plb_get_char,
|
---|
[41202a9] | 84 | .has_children = mfs_has_children,
|
---|
| 85 | .lnkcnt_get = mfs_lnkcnt_get
|
---|
[e54ba607] | 86 | };
|
---|
[3b08178] | 87 |
|
---|
[096c8835] | 88 | void mfs_mounted(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 89 | {
|
---|
| 90 | devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
|
---|
[44c6091f] | 91 | enum cache_mode cmode;
|
---|
[953a823] | 92 | struct mfs_superblock *sb;
|
---|
| 93 | struct mfs3_superblock *sb3;
|
---|
| 94 | struct mfs_sb_info *sbi;
|
---|
| 95 | struct mfs_instance *instance;
|
---|
[8ceba1e] | 96 | bool native, longnames;
|
---|
[9e3dc95] | 97 | mfs_version_t version;
|
---|
[245eb02d] | 98 | uint16_t magic;
|
---|
[096c8835] | 99 |
|
---|
| 100 | /* Accept the mount options */
|
---|
| 101 | char *opts;
|
---|
| 102 | int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
|
---|
[44c6091f] | 103 |
|
---|
[096c8835] | 104 | if (rc != EOK) {
|
---|
[92dd5c8] | 105 | mfsdebug("Can't accept async data write\n");
|
---|
[096c8835] | 106 | async_answer_0(rid, rc);
|
---|
| 107 | return;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | /* Check for option enabling write through. */
|
---|
| 111 | if (str_cmp(opts, "wtcache") == 0)
|
---|
| 112 | cmode = CACHE_MODE_WT;
|
---|
| 113 | else
|
---|
| 114 | cmode = CACHE_MODE_WB;
|
---|
| 115 |
|
---|
| 116 | free(opts);
|
---|
| 117 |
|
---|
| 118 | /* initialize libblock */
|
---|
[1affcdf3] | 119 | rc = block_init(EXCHANGE_SERIALIZE, devmap_handle, 1024);
|
---|
[096c8835] | 120 | if (rc != EOK) {
|
---|
[92dd5c8] | 121 | mfsdebug("libblock initialization failed\n");
|
---|
[096c8835] | 122 | async_answer_0(rid, rc);
|
---|
| 123 | return;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[953a823] | 126 | /*Allocate space for generic MFS superblock*/
|
---|
[b438804] | 127 | sbi = malloc(sizeof(*sbi));
|
---|
[953a823] | 128 |
|
---|
| 129 | if (!sbi) {
|
---|
| 130 | async_answer_0(rid, ENOMEM);
|
---|
| 131 | return;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | /*Allocate space for filesystem instance*/
|
---|
[b438804] | 135 | instance = malloc(sizeof(*instance));
|
---|
[953a823] | 136 |
|
---|
| 137 | if (!instance) {
|
---|
| 138 | async_answer_0(rid, ENOMEM);
|
---|
| 139 | return;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[b438804] | 142 | sb = malloc(MFS_SUPERBLOCK_SIZE);
|
---|
[953a823] | 143 |
|
---|
| 144 | if (!sb) {
|
---|
| 145 | async_answer_0(rid, ENOMEM);
|
---|
| 146 | return;
|
---|
| 147 | }
|
---|
[92dd5c8] | 148 |
|
---|
| 149 | /* Read the superblock */
|
---|
[953a823] | 150 | rc = block_read_direct(devmap_handle, MFS_SUPERBLOCK << 1, 1, sb);
|
---|
[096c8835] | 151 | if (rc != EOK) {
|
---|
| 152 | block_fini(devmap_handle);
|
---|
| 153 | async_answer_0(rid, rc);
|
---|
| 154 | return;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[953a823] | 157 | sb3 = (struct mfs3_superblock *) sb;
|
---|
| 158 |
|
---|
| 159 | if (check_magic_number(sb->s_magic, &native, &version, &longnames)) {
|
---|
[7a96476] | 160 | /*This is a V1 or V2 Minix filesystem*/
|
---|
[953a823] | 161 | magic = sb->s_magic;
|
---|
[245eb02d] | 162 | goto recognized;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[953a823] | 165 | if (!check_magic_number(sb3->s_magic, &native, &version, &longnames)) {
|
---|
[92dd5c8] | 166 | mfsdebug("magic number not recognized\n");
|
---|
[9e3dc95] | 167 | block_fini(devmap_handle);
|
---|
| 168 | async_answer_0(rid, ENOTSUP);
|
---|
| 169 | return;
|
---|
| 170 | }
|
---|
[92dd5c8] | 171 |
|
---|
[7a96476] | 172 | /*This is a V3 Minix filesystem*/
|
---|
| 173 |
|
---|
[953a823] | 174 | magic = sb3->s_magic;
|
---|
[245eb02d] | 175 |
|
---|
| 176 | recognized:
|
---|
| 177 |
|
---|
| 178 | mfsdebug("magic number recognized = %04x\n", magic);
|
---|
[953a823] | 179 |
|
---|
| 180 | /*Fill superblock info structure*/
|
---|
| 181 |
|
---|
| 182 | sbi->fs_version = version;
|
---|
| 183 | sbi->long_names = longnames;
|
---|
| 184 | sbi->native = native;
|
---|
| 185 | sbi->magic = magic;
|
---|
[ef76d72] | 186 | sbi->isearch = 0;
|
---|
| 187 | sbi->zsearch = 0;
|
---|
[953a823] | 188 |
|
---|
| 189 | if (version == MFS_VERSION_V3) {
|
---|
| 190 | sbi->ninodes = conv32(native, sb3->s_ninodes);
|
---|
| 191 | sbi->ibmap_blocks = conv16(native, sb3->s_ibmap_blocks);
|
---|
| 192 | sbi->zbmap_blocks = conv16(native, sb3->s_zbmap_blocks);
|
---|
| 193 | sbi->firstdatazone = conv16(native, sb3->s_first_data_zone);
|
---|
| 194 | sbi->log2_zone_size = conv16(native, sb3->s_log2_zone_size);
|
---|
| 195 | sbi->max_file_size = conv32(native, sb3->s_max_file_size);
|
---|
| 196 | sbi->nzones = conv32(native, sb3->s_nzones);
|
---|
| 197 | sbi->block_size = conv16(native, sb3->s_block_size);
|
---|
[10eb754] | 198 | sbi->ino_per_block = V3_INODES_PER_BLOCK(sbi->block_size);
|
---|
[a04b62d] | 199 | sbi->dirsize = MFS3_DIRSIZE;
|
---|
[bd64680] | 200 | sbi->max_name_len = MFS3_MAX_NAME_LEN;
|
---|
[953a823] | 201 | } else {
|
---|
| 202 | sbi->ninodes = conv16(native, sb->s_ninodes);
|
---|
| 203 | sbi->ibmap_blocks = conv16(native, sb->s_ibmap_blocks);
|
---|
| 204 | sbi->zbmap_blocks = conv16(native, sb->s_zbmap_blocks);
|
---|
| 205 | sbi->firstdatazone = conv16(native, sb->s_first_data_zone);
|
---|
| 206 | sbi->log2_zone_size = conv16(native, sb->s_log2_zone_size);
|
---|
| 207 | sbi->max_file_size = conv32(native, sb->s_max_file_size);
|
---|
[3b08178] | 208 | sbi->block_size = MFS_BLOCKSIZE;
|
---|
[5a841a4] | 209 | if (version == MFS_VERSION_V2) {
|
---|
[953a823] | 210 | sbi->nzones = conv32(native, sb->s_nzones2);
|
---|
[5a841a4] | 211 | sbi->ino_per_block = V2_INODES_PER_BLOCK;
|
---|
| 212 | } else {
|
---|
| 213 | sbi->nzones = conv16(native, sb->s_nzones);
|
---|
| 214 | sbi->ino_per_block = V1_INODES_PER_BLOCK;
|
---|
| 215 | }
|
---|
[a04b62d] | 216 | sbi->dirsize = longnames ? MFSL_DIRSIZE : MFS_DIRSIZE;
|
---|
[bd64680] | 217 | sbi->max_name_len = longnames ? MFS_L_MAX_NAME_LEN :
|
---|
[44c6091f] | 218 | MFS_MAX_NAME_LEN;
|
---|
[953a823] | 219 | }
|
---|
[10eb754] | 220 | sbi->itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks;
|
---|
[44c6091f] | 221 |
|
---|
[953a823] | 222 | free(sb);
|
---|
| 223 |
|
---|
[586f123] | 224 | rc = block_cache_init(devmap_handle, sbi->block_size, 0, cmode);
|
---|
[3b08178] | 225 |
|
---|
| 226 | if (rc != EOK) {
|
---|
| 227 | block_fini(devmap_handle);
|
---|
| 228 | async_answer_0(rid, EINVAL);
|
---|
| 229 | mfsdebug("block cache initialization failed\n");
|
---|
| 230 | return;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
[953a823] | 233 | /*Initialize the instance structure and add it to the list*/
|
---|
| 234 | link_initialize(&instance->link);
|
---|
| 235 | instance->handle = devmap_handle;
|
---|
| 236 | instance->sbi = sbi;
|
---|
| 237 |
|
---|
| 238 | fibril_mutex_lock(&inst_list_mutex);
|
---|
| 239 | list_append(&instance->link, &inst_list);
|
---|
| 240 | fibril_mutex_unlock(&inst_list_mutex);
|
---|
| 241 |
|
---|
| 242 | mfsdebug("mount successful\n");
|
---|
| 243 |
|
---|
| 244 | async_answer_0(rid, EOK);
|
---|
[9e3dc95] | 245 | }
|
---|
| 246 |
|
---|
[3b08178] | 247 | void mfs_mount(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 248 | {
|
---|
| 249 | libfs_mount(&mfs_libfs_ops, mfs_reg.fs_handle, rid, request);
|
---|
| 250 | }
|
---|
| 251 |
|
---|
[e54ba607] | 252 | devmap_handle_t mfs_device_get(fs_node_t *fsnode)
|
---|
| 253 | {
|
---|
| 254 | struct mfs_node *node = fsnode->data;
|
---|
| 255 | return node->instance->handle;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
[10eb754] | 258 | static int mfs_create_node(fs_node_t **rfn, devmap_handle_t handle, int flags)
|
---|
| 259 | {
|
---|
[88ccd8b8] | 260 | int r;
|
---|
| 261 | struct mfs_instance *inst;
|
---|
| 262 | struct mfs_node *mnode;
|
---|
| 263 | fs_node_t *fsnode;
|
---|
| 264 | uint32_t inum;
|
---|
[44c6091f] | 265 |
|
---|
[88ccd8b8] | 266 | r = mfs_instance_get(handle, &inst);
|
---|
[cfac897] | 267 | on_error(r, return r);
|
---|
[88ccd8b8] | 268 |
|
---|
| 269 | /*Alloc a new inode*/
|
---|
[70ac0af] | 270 | r = mfs_alloc_inode(inst, &inum);
|
---|
[cfac897] | 271 | on_error(r, return r);
|
---|
[88ccd8b8] | 272 |
|
---|
| 273 | struct mfs_ino_info *ino_i;
|
---|
| 274 |
|
---|
| 275 | ino_i = malloc(sizeof(*ino_i));
|
---|
| 276 | if (!ino_i) {
|
---|
| 277 | r = ENOMEM;
|
---|
| 278 | goto out_err;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | mnode = malloc(sizeof(*mnode));
|
---|
| 282 | if (!mnode) {
|
---|
| 283 | r = ENOMEM;
|
---|
| 284 | goto out_err_1;
|
---|
| 285 | }
|
---|
[44c6091f] | 286 |
|
---|
[88ccd8b8] | 287 | fsnode = malloc(sizeof(fs_node_t));
|
---|
| 288 | if (!fsnode) {
|
---|
| 289 | r = ENOMEM;
|
---|
| 290 | goto out_err_2;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
[13ecdac9] | 293 | if (flags & L_DIRECTORY)
|
---|
| 294 | ino_i->i_mode = S_IFDIR;
|
---|
| 295 | else
|
---|
| 296 | ino_i->i_mode = S_IFREG;
|
---|
| 297 |
|
---|
[88ccd8b8] | 298 | ino_i->i_nlinks = 1;
|
---|
| 299 | ino_i->i_uid = 0;
|
---|
| 300 | ino_i->i_gid = 0;
|
---|
| 301 | ino_i->i_size = 0;
|
---|
| 302 | ino_i->i_atime = 0;
|
---|
| 303 | ino_i->i_mtime = 0;
|
---|
| 304 | ino_i->i_ctime = 0;
|
---|
| 305 |
|
---|
| 306 | memset(ino_i->i_dzone, 0, sizeof(uint32_t) * V2_NR_DIRECT_ZONES);
|
---|
| 307 | memset(ino_i->i_izone, 0, sizeof(uint32_t) * V2_NR_INDIRECT_ZONES);
|
---|
| 308 |
|
---|
[58c36ac] | 309 | mfsdebug("new node idx = %d\n", (int) inum);
|
---|
| 310 |
|
---|
[88ccd8b8] | 311 | ino_i->index = inum;
|
---|
| 312 | ino_i->dirty = true;
|
---|
| 313 | mnode->ino_i = ino_i;
|
---|
| 314 | mnode->instance = inst;
|
---|
| 315 |
|
---|
[58c36ac] | 316 | r = put_inode(mnode);
|
---|
[cfac897] | 317 | on_error(r, goto out_err_2);
|
---|
[88ccd8b8] | 318 |
|
---|
| 319 | fs_node_initialize(fsnode);
|
---|
| 320 | fsnode->data = mnode;
|
---|
| 321 | *rfn = fsnode;
|
---|
| 322 |
|
---|
| 323 | return EOK;
|
---|
| 324 |
|
---|
| 325 | out_err_2:
|
---|
| 326 | free(mnode);
|
---|
| 327 | out_err_1:
|
---|
| 328 | free(ino_i);
|
---|
| 329 | out_err:
|
---|
| 330 | return r;
|
---|
[10eb754] | 331 | }
|
---|
| 332 |
|
---|
[bd64680] | 333 | static int mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
|
---|
| 334 | {
|
---|
| 335 | struct mfs_node *mnode = pfn->data;
|
---|
| 336 | struct mfs_ino_info *ino_i = mnode->ino_i;
|
---|
[e80c2ff] | 337 | struct mfs_dentry_info d_info;
|
---|
[488f7ed] | 338 | int r;
|
---|
[bd64680] | 339 |
|
---|
| 340 | if (!S_ISDIR(ino_i->i_mode))
|
---|
| 341 | return ENOTDIR;
|
---|
| 342 |
|
---|
| 343 | struct mfs_sb_info *sbi = mnode->instance->sbi;
|
---|
| 344 | const size_t comp_size = str_size(component);
|
---|
| 345 |
|
---|
[e80c2ff] | 346 | unsigned i;
|
---|
| 347 | for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
|
---|
| 348 | r = read_directory_entry(mnode, &d_info, i);
|
---|
[cfac897] | 349 | on_error(r, return r);
|
---|
[488f7ed] | 350 |
|
---|
[e80c2ff] | 351 | if (!d_info.d_inum) {
|
---|
[bd64680] | 352 | /*This entry is not used*/
|
---|
| 353 | continue;
|
---|
| 354 | }
|
---|
| 355 |
|
---|
[e80c2ff] | 356 | if (!bcmp(component, d_info.d_name, min(sbi->max_name_len,
|
---|
[bd64680] | 357 | comp_size))) {
|
---|
| 358 | /*Hit!*/
|
---|
| 359 | mfs_node_core_get(rfn, mnode->instance,
|
---|
[e80c2ff] | 360 | d_info.d_inum);
|
---|
[bd64680] | 361 | goto found;
|
---|
| 362 | }
|
---|
| 363 | }
|
---|
| 364 | *rfn = NULL;
|
---|
| 365 | found:
|
---|
| 366 | return EOK;
|
---|
| 367 | }
|
---|
| 368 |
|
---|
[ac28650] | 369 | static aoff64_t mfs_size_get(fs_node_t *node)
|
---|
[0d6ab10] | 370 | {
|
---|
| 371 | assert(node);
|
---|
| 372 |
|
---|
| 373 | const struct mfs_node *mnode = node->data;
|
---|
| 374 | assert(mnode);
|
---|
[155f792] | 375 | assert(mnode->ino_i);
|
---|
[0d6ab10] | 376 |
|
---|
[155f792] | 377 | return mnode->ino_i->i_size;
|
---|
[0d6ab10] | 378 | }
|
---|
| 379 |
|
---|
| 380 | void mfs_stat(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 381 | {
|
---|
| 382 | libfs_stat(&mfs_libfs_ops, mfs_reg.fs_handle, rid, request);
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[ac28650] | 385 | static int mfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle,
|
---|
[44c0f5b] | 386 | fs_index_t index)
|
---|
| 387 | {
|
---|
| 388 | int rc;
|
---|
| 389 | struct mfs_instance *instance;
|
---|
| 390 |
|
---|
| 391 | rc = mfs_instance_get(devmap_handle, &instance);
|
---|
[cfac897] | 392 | on_error(rc, return rc);
|
---|
[44c0f5b] | 393 |
|
---|
| 394 | return mfs_node_core_get(rfn, instance, index);
|
---|
| 395 | }
|
---|
| 396 |
|
---|
[41202a9] | 397 | static int mfs_node_put(fs_node_t *fsnode)
|
---|
| 398 | {
|
---|
| 399 | struct mfs_node *mnode = fsnode->data;
|
---|
| 400 |
|
---|
[ae8541d] | 401 | put_inode(mnode);
|
---|
[41202a9] | 402 | free(mnode->ino_i);
|
---|
| 403 | free(mnode);
|
---|
| 404 |
|
---|
| 405 | return EOK;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | static int mfs_node_open(fs_node_t *fsnode)
|
---|
| 409 | {
|
---|
| 410 | /*
|
---|
| 411 | * Opening a file is stateless, nothing
|
---|
| 412 | * to be done here.
|
---|
| 413 | */
|
---|
| 414 | return EOK;
|
---|
| 415 | }
|
---|
| 416 |
|
---|
| 417 | static fs_index_t mfs_index_get(fs_node_t *fsnode)
|
---|
| 418 | {
|
---|
| 419 | struct mfs_node *mnode = fsnode->data;
|
---|
| 420 |
|
---|
| 421 | assert(mnode->ino_i);
|
---|
| 422 | return mnode->ino_i->index;
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | static unsigned mfs_lnkcnt_get(fs_node_t *fsnode)
|
---|
| 426 | {
|
---|
| 427 | struct mfs_node *mnode = fsnode->data;
|
---|
| 428 |
|
---|
| 429 | assert(mnode);
|
---|
| 430 | assert(mnode->ino_i);
|
---|
| 431 |
|
---|
[53eb588] | 432 | return mnode->ino_i->i_nlinks;;
|
---|
[41202a9] | 433 | }
|
---|
| 434 |
|
---|
[44c0f5b] | 435 | static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
|
---|
[44c6091f] | 436 | fs_index_t index)
|
---|
[44c0f5b] | 437 | {
|
---|
| 438 | fs_node_t *node = NULL;
|
---|
| 439 | struct mfs_node *mnode = NULL;
|
---|
| 440 | int rc;
|
---|
| 441 |
|
---|
[b438804] | 442 | node = malloc(sizeof(fs_node_t));
|
---|
[44c0f5b] | 443 | if (!node) {
|
---|
| 444 | rc = ENOMEM;
|
---|
| 445 | goto out_err;
|
---|
| 446 | }
|
---|
| 447 |
|
---|
| 448 | fs_node_initialize(node);
|
---|
| 449 |
|
---|
[b438804] | 450 | mnode = malloc(sizeof(*mnode));
|
---|
[44c0f5b] | 451 | if (!mnode) {
|
---|
| 452 | rc = ENOMEM;
|
---|
| 453 | goto out_err;
|
---|
| 454 | }
|
---|
| 455 |
|
---|
[155f792] | 456 | struct mfs_ino_info *ino_i;
|
---|
| 457 |
|
---|
[c922bc7] | 458 | rc = get_inode(inst, &ino_i, index);
|
---|
[cfac897] | 459 | on_error(rc, goto out_err);
|
---|
[155f792] | 460 |
|
---|
[41202a9] | 461 | ino_i->index = index;
|
---|
[155f792] | 462 | mnode->ino_i = ino_i;
|
---|
| 463 |
|
---|
[44c0f5b] | 464 | mnode->instance = inst;
|
---|
| 465 | node->data = mnode;
|
---|
| 466 | *rfn = node;
|
---|
| 467 |
|
---|
| 468 | return EOK;
|
---|
| 469 |
|
---|
| 470 | out_err:
|
---|
| 471 | if (node)
|
---|
| 472 | free(node);
|
---|
| 473 | if (mnode)
|
---|
| 474 | free(mnode);
|
---|
| 475 | return rc;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
[ac28650] | 478 | static bool mfs_is_directory(fs_node_t *fsnode)
|
---|
[5a58ae2] | 479 | {
|
---|
[44c0f5b] | 480 | const struct mfs_node *node = fsnode->data;
|
---|
[155f792] | 481 | return S_ISDIR(node->ino_i->i_mode);
|
---|
[5a58ae2] | 482 | }
|
---|
| 483 |
|
---|
[ac28650] | 484 | static bool mfs_is_file(fs_node_t *fsnode)
|
---|
[7d04324] | 485 | {
|
---|
| 486 | struct mfs_node *node = fsnode->data;
|
---|
[155f792] | 487 | return S_ISREG(node->ino_i->i_mode);
|
---|
[7d04324] | 488 | }
|
---|
| 489 |
|
---|
[ac28650] | 490 | static int mfs_root_get(fs_node_t **rfn, devmap_handle_t handle)
|
---|
[fe4ac35] | 491 | {
|
---|
[41202a9] | 492 | int rc = mfs_node_get(rfn, handle, MFS_ROOT_INO);
|
---|
| 493 | return rc;
|
---|
[fe4ac35] | 494 | }
|
---|
| 495 |
|
---|
[54caa41b] | 496 | void mfs_lookup(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 497 | {
|
---|
| 498 | libfs_lookup(&mfs_libfs_ops, mfs_reg.fs_handle, rid, request);
|
---|
| 499 | }
|
---|
| 500 |
|
---|
[ac28650] | 501 | static char mfs_plb_get_char(unsigned pos)
|
---|
[cfbcd86] | 502 | {
|
---|
| 503 | return mfs_reg.plb_ro[pos % PLB_SIZE];
|
---|
| 504 | }
|
---|
| 505 |
|
---|
[88ccd8b8] | 506 | static int mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
|
---|
| 507 | {
|
---|
[afd9c3b] | 508 | struct mfs_node *parent = pfn->data;
|
---|
| 509 | struct mfs_node *child = cfn->data;
|
---|
[48de019] | 510 | struct mfs_sb_info *sbi = parent->instance->sbi;
|
---|
| 511 |
|
---|
| 512 | if (str_size(name) > sbi->max_name_len)
|
---|
| 513 | return ENAMETOOLONG;
|
---|
[afd9c3b] | 514 |
|
---|
| 515 | int r = insert_dentry(parent, name, child->ino_i->index);
|
---|
[13ecdac9] | 516 | on_error(r, goto exit_error);
|
---|
| 517 |
|
---|
| 518 | if (S_ISDIR(child->ino_i->i_mode)) {
|
---|
| 519 | r = insert_dentry(child, ".", child->ino_i->index);
|
---|
| 520 | on_error(r, goto exit_error);
|
---|
| 521 | r = insert_dentry(child, "..", parent->ino_i->index);
|
---|
| 522 | }
|
---|
[afd9c3b] | 523 |
|
---|
[13ecdac9] | 524 | exit_error:
|
---|
[afd9c3b] | 525 | return r;
|
---|
[88ccd8b8] | 526 | }
|
---|
| 527 |
|
---|
[53eb588] | 528 | static int
|
---|
| 529 | mfs_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *name)
|
---|
| 530 | {
|
---|
| 531 | struct mfs_node *parent = pfn->data;
|
---|
| 532 | struct mfs_node *child = cfn->data;
|
---|
| 533 | bool has_children;
|
---|
| 534 | int r;
|
---|
| 535 |
|
---|
| 536 | if (!parent)
|
---|
| 537 | return EBUSY;
|
---|
| 538 |
|
---|
| 539 | r = mfs_has_children(&has_children, cfn);
|
---|
| 540 | on_error(r, return r);
|
---|
| 541 | if (has_children)
|
---|
| 542 | return ENOTEMPTY;
|
---|
| 543 |
|
---|
| 544 | r = remove_dentry(parent, name);
|
---|
| 545 | on_error(r, return r);
|
---|
| 546 |
|
---|
| 547 | struct mfs_ino_info *chino = child->ino_i;
|
---|
| 548 |
|
---|
| 549 | assert(chino->i_nlinks >= 1);
|
---|
| 550 | --chino->i_nlinks;
|
---|
| 551 |
|
---|
| 552 | chino->dirty = true;
|
---|
| 553 |
|
---|
| 554 | return EOK;
|
---|
| 555 | }
|
---|
| 556 |
|
---|
[ac28650] | 557 | static int mfs_has_children(bool *has_children, fs_node_t *fsnode)
|
---|
[54caa41b] | 558 | {
|
---|
| 559 | struct mfs_node *mnode = fsnode->data;
|
---|
[e80c2ff] | 560 | struct mfs_sb_info *sbi = mnode->instance->sbi;
|
---|
[488f7ed] | 561 | int r;
|
---|
[54caa41b] | 562 |
|
---|
| 563 | *has_children = false;
|
---|
| 564 |
|
---|
| 565 | if (!S_ISDIR(mnode->ino_i->i_mode))
|
---|
| 566 | goto out;
|
---|
| 567 |
|
---|
[e80c2ff] | 568 | struct mfs_dentry_info d_info;
|
---|
[44c6091f] | 569 |
|
---|
[ac28650] | 570 | /* The first two dentries are always . and .. */
|
---|
[e80c2ff] | 571 | unsigned i;
|
---|
| 572 | for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
|
---|
| 573 | r = read_directory_entry(mnode, &d_info, i);
|
---|
[cfac897] | 574 | on_error(r, return r);
|
---|
[54caa41b] | 575 |
|
---|
[e80c2ff] | 576 | if (d_info.d_inum) {
|
---|
[7a96476] | 577 | /*A valid entry has been found*/
|
---|
[54caa41b] | 578 | *has_children = true;
|
---|
| 579 | break;
|
---|
| 580 | }
|
---|
| 581 | }
|
---|
[41202a9] | 582 | out:
|
---|
| 583 |
|
---|
[54caa41b] | 584 | return EOK;
|
---|
| 585 | }
|
---|
| 586 |
|
---|
[668f1949] | 587 | void
|
---|
| 588 | mfs_read(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 589 | {
|
---|
| 590 | int rc;
|
---|
| 591 | devmap_handle_t handle = (devmap_handle_t) IPC_GET_ARG1(*request);
|
---|
| 592 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
|
---|
| 593 | aoff64_t pos = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request),
|
---|
[44c6091f] | 594 | IPC_GET_ARG4(*request));
|
---|
[668f1949] | 595 | fs_node_t *fn;
|
---|
| 596 |
|
---|
| 597 | rc = mfs_node_get(&fn, handle, index);
|
---|
| 598 | if (rc != EOK) {
|
---|
| 599 | async_answer_0(rid, rc);
|
---|
| 600 | return;
|
---|
| 601 | }
|
---|
| 602 | if (!fn) {
|
---|
| 603 | async_answer_0(rid, ENOENT);
|
---|
| 604 | return;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | struct mfs_node *mnode;
|
---|
| 608 | struct mfs_ino_info *ino_i;
|
---|
| 609 | size_t len, bytes = 0;
|
---|
| 610 | ipc_callid_t callid;
|
---|
| 611 |
|
---|
| 612 | mnode = fn->data;
|
---|
| 613 | ino_i = mnode->ino_i;
|
---|
| 614 |
|
---|
| 615 | if (!async_data_read_receive(&callid, &len)) {
|
---|
[230229de] | 616 | rc = EINVAL;
|
---|
| 617 | goto out_error;
|
---|
[668f1949] | 618 | }
|
---|
| 619 |
|
---|
| 620 | if (S_ISDIR(ino_i->i_mode)) {
|
---|
| 621 | aoff64_t spos = pos;
|
---|
[e80c2ff] | 622 | struct mfs_dentry_info d_info;
|
---|
| 623 | struct mfs_sb_info *sbi = mnode->instance->sbi;
|
---|
[668f1949] | 624 |
|
---|
[e80c2ff] | 625 | unsigned i;
|
---|
| 626 | for (i = pos; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
|
---|
[488f7ed] | 627 | rc = read_directory_entry(mnode, &d_info, pos);
|
---|
[cfac897] | 628 | on_error(rc, goto out_error);
|
---|
[488f7ed] | 629 |
|
---|
[e80c2ff] | 630 | if (d_info.d_inum) {
|
---|
[668f1949] | 631 | /*Dentry found!*/
|
---|
| 632 | goto found;
|
---|
| 633 | }
|
---|
| 634 | pos++;
|
---|
| 635 | }
|
---|
| 636 |
|
---|
| 637 | rc = mfs_node_put(fn);
|
---|
| 638 | async_answer_0(callid, rc != EOK ? rc : ENOENT);
|
---|
| 639 | async_answer_1(rid, rc != EOK ? rc : ENOENT, 0);
|
---|
| 640 | return;
|
---|
| 641 | found:
|
---|
[e80c2ff] | 642 | async_data_read_finalize(callid, d_info.d_name,
|
---|
| 643 | str_size(d_info.d_name) + 1);
|
---|
[668f1949] | 644 | bytes = ((pos - spos) + 1);
|
---|
[230229de] | 645 | } else {
|
---|
| 646 | struct mfs_sb_info *sbi = mnode->instance->sbi;
|
---|
| 647 |
|
---|
| 648 | if (pos >= (size_t) ino_i->i_size) {
|
---|
| 649 | /*Trying to read beyond the end of file*/
|
---|
| 650 | bytes = 0;
|
---|
| 651 | (void) async_data_read_finalize(callid, NULL, 0);
|
---|
| 652 | goto out_success;
|
---|
| 653 | }
|
---|
| 654 |
|
---|
| 655 | bytes = min(len, sbi->block_size - pos % sbi->block_size);
|
---|
| 656 | bytes = min(bytes, ino_i->i_size - pos);
|
---|
| 657 |
|
---|
| 658 | uint32_t zone;
|
---|
| 659 | block_t *b;
|
---|
[668f1949] | 660 |
|
---|
[230229de] | 661 | rc = read_map(&zone, mnode, pos);
|
---|
[cfac897] | 662 | on_error(rc, goto out_error);
|
---|
[230229de] | 663 |
|
---|
| 664 | if (zone == 0) {
|
---|
| 665 | /*sparse file*/
|
---|
| 666 | uint8_t *buf = malloc(sbi->block_size);
|
---|
| 667 | if (!buf) {
|
---|
| 668 | rc = ENOMEM;
|
---|
| 669 | goto out_error;
|
---|
| 670 | }
|
---|
[6fc5262] | 671 | memset(buf, 0, sizeof(sbi->block_size));
|
---|
[230229de] | 672 | async_data_read_finalize(callid,
|
---|
[44c6091f] | 673 | buf + pos % sbi->block_size, bytes);
|
---|
[230229de] | 674 | free(buf);
|
---|
| 675 | goto out_success;
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | rc = block_get(&b, handle, zone, BLOCK_FLAGS_NONE);
|
---|
[cfac897] | 679 | on_error(rc, goto out_error);
|
---|
[230229de] | 680 |
|
---|
| 681 | async_data_read_finalize(callid, b->data +
|
---|
[44c6091f] | 682 | pos % sbi->block_size, bytes);
|
---|
[230229de] | 683 |
|
---|
| 684 | rc = block_put(b);
|
---|
| 685 | if (rc != EOK) {
|
---|
| 686 | mfs_node_put(fn);
|
---|
| 687 | async_answer_0(rid, rc);
|
---|
| 688 | return;
|
---|
| 689 | }
|
---|
| 690 | }
|
---|
| 691 | out_success:
|
---|
[668f1949] | 692 | rc = mfs_node_put(fn);
|
---|
| 693 | async_answer_1(rid, rc, (sysarg_t)bytes);
|
---|
[230229de] | 694 | return;
|
---|
[44c6091f] | 695 | out_error:
|
---|
| 696 | ;
|
---|
[230229de] | 697 | int tmp = mfs_node_put(fn);
|
---|
| 698 | async_answer_0(callid, tmp != EOK ? tmp : rc);
|
---|
| 699 | async_answer_0(rid, tmp != EOK ? tmp : rc);
|
---|
[668f1949] | 700 | }
|
---|
| 701 |
|
---|
[bb7e8382] | 702 | void
|
---|
| 703 | mfs_write(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 704 | {
|
---|
| 705 | devmap_handle_t handle = (devmap_handle_t) IPC_GET_ARG1(*request);
|
---|
| 706 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
|
---|
| 707 | aoff64_t pos = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request),
|
---|
[44c6091f] | 708 | IPC_GET_ARG4(*request));
|
---|
[bb7e8382] | 709 |
|
---|
| 710 | fs_node_t *fn;
|
---|
| 711 | int r;
|
---|
| 712 | int flags = BLOCK_FLAGS_NONE;
|
---|
| 713 |
|
---|
| 714 | r = mfs_node_get(&fn, handle, index);
|
---|
| 715 | if (r != EOK) {
|
---|
| 716 | async_answer_0(rid, r);
|
---|
| 717 | return;
|
---|
| 718 | }
|
---|
| 719 |
|
---|
| 720 | if (!fn) {
|
---|
| 721 | async_answer_0(rid, ENOENT);
|
---|
| 722 | return;
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 | ipc_callid_t callid;
|
---|
| 726 | size_t len;
|
---|
| 727 |
|
---|
| 728 | if (!async_data_write_receive(&callid, &len)) {
|
---|
| 729 | r = EINVAL;
|
---|
| 730 | goto out_err;
|
---|
| 731 | }
|
---|
| 732 |
|
---|
| 733 | struct mfs_node *mnode = fn->data;
|
---|
| 734 | struct mfs_sb_info *sbi = mnode->instance->sbi;
|
---|
| 735 | struct mfs_ino_info *ino_i = mnode->ino_i;
|
---|
| 736 | const size_t bs = sbi->block_size;
|
---|
| 737 | size_t bytes = min(len, bs - pos % bs);
|
---|
| 738 | size_t boundary = ROUND_UP(ino_i->i_size, bs);
|
---|
| 739 | uint32_t block;
|
---|
| 740 |
|
---|
| 741 | if (bytes == bs)
|
---|
| 742 | flags = BLOCK_FLAGS_NOREAD;
|
---|
| 743 |
|
---|
| 744 | if (pos < boundary) {
|
---|
| 745 | r = read_map(&block, mnode, pos);
|
---|
| 746 | on_error(r, goto out_err);
|
---|
| 747 |
|
---|
| 748 | if (block == 0) {
|
---|
| 749 | /*Writing in a sparse block*/
|
---|
[70ac0af] | 750 | r = mfs_alloc_zone(mnode->instance, &block);
|
---|
[bb7e8382] | 751 | on_error(r, goto out_err);
|
---|
| 752 | flags = BLOCK_FLAGS_NOREAD;
|
---|
| 753 | }
|
---|
| 754 | } else {
|
---|
| 755 | uint32_t dummy;
|
---|
| 756 |
|
---|
[70ac0af] | 757 | r = mfs_alloc_zone(mnode->instance, &block);
|
---|
[bb7e8382] | 758 | on_error(r, goto out_err);
|
---|
| 759 |
|
---|
| 760 | r = write_map(mnode, pos, block, &dummy);
|
---|
| 761 | on_error(r, goto out_err);
|
---|
| 762 | }
|
---|
| 763 |
|
---|
| 764 | block_t *b;
|
---|
| 765 | r = block_get(&b, handle, block, flags);
|
---|
| 766 | on_error(r, goto out_err);
|
---|
| 767 |
|
---|
| 768 | async_data_write_finalize(callid, b->data + pos % bs, bytes);
|
---|
| 769 | b->dirty = true;
|
---|
| 770 |
|
---|
| 771 | r = block_put(b);
|
---|
| 772 | if (r != EOK) {
|
---|
| 773 | mfs_node_put(fn);
|
---|
| 774 | async_answer_0(rid, r);
|
---|
| 775 | return;
|
---|
| 776 | }
|
---|
| 777 |
|
---|
| 778 | ino_i->i_size = pos + bytes;
|
---|
| 779 | ino_i->dirty = true;
|
---|
| 780 | r = mfs_node_put(fn);
|
---|
| 781 | async_answer_2(rid, r, bytes, pos + bytes);
|
---|
| 782 | return;
|
---|
| 783 |
|
---|
| 784 | out_err:
|
---|
| 785 | mfs_node_put(fn);
|
---|
| 786 | async_answer_0(callid, r);
|
---|
| 787 | async_answer_0(rid, r);
|
---|
| 788 | }
|
---|
| 789 |
|
---|
[d8af1bd] | 790 | void
|
---|
| 791 | mfs_destroy(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 792 | {
|
---|
| 793 | devmap_handle_t handle = (devmap_handle_t)IPC_GET_ARG1(*request);
|
---|
| 794 | fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
|
---|
| 795 | fs_node_t *fn;
|
---|
| 796 | int r;
|
---|
| 797 |
|
---|
| 798 | r = mfs_node_get(&fn, handle, index);
|
---|
| 799 | if (r != EOK) {
|
---|
| 800 | async_answer_0(rid, r);
|
---|
| 801 | return;
|
---|
| 802 | }
|
---|
| 803 | if (!fn) {
|
---|
| 804 | async_answer_0(rid, ENOENT);
|
---|
| 805 | return;
|
---|
| 806 | }
|
---|
| 807 |
|
---|
| 808 | /*Destroy the inode*/
|
---|
| 809 | r = mfs_destroy_node(fn);
|
---|
| 810 | async_answer_0(rid, r);
|
---|
| 811 | }
|
---|
| 812 |
|
---|
| 813 | static int
|
---|
| 814 | mfs_destroy_node(fs_node_t *fn)
|
---|
| 815 | {
|
---|
| 816 | struct mfs_node *mnode = fn->data;
|
---|
| 817 | bool has_children;
|
---|
| 818 | int r;
|
---|
| 819 |
|
---|
[a5bad72] | 820 | mfsdebug("mfs_destroy_node %d\n", mnode->ino_i->index);
|
---|
| 821 |
|
---|
[d8af1bd] | 822 | r = mfs_has_children(&has_children, fn);
|
---|
| 823 | on_error(r, return r);
|
---|
| 824 |
|
---|
| 825 | assert(!has_children);
|
---|
| 826 |
|
---|
| 827 | /*Free the entire inode content*/
|
---|
| 828 | r = inode_shrink(mnode, mnode->ino_i->i_size);
|
---|
| 829 | on_error(r, return r);
|
---|
[70ac0af] | 830 | r = mfs_free_inode(mnode->instance, mnode->ino_i->index);
|
---|
[d8af1bd] | 831 | on_error(r, return r);
|
---|
| 832 |
|
---|
| 833 | free(mnode->ino_i);
|
---|
| 834 | free(mnode);
|
---|
| 835 | return r;
|
---|
| 836 | }
|
---|
| 837 |
|
---|
[8a49fed] | 838 | void
|
---|
| 839 | mfs_truncate(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 840 | {
|
---|
| 841 | devmap_handle_t handle = (devmap_handle_t) IPC_GET_ARG1(*request);
|
---|
| 842 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
|
---|
| 843 | aoff64_t size = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request),
|
---|
| 844 | IPC_GET_ARG4(*request));
|
---|
| 845 | fs_node_t *fn;
|
---|
| 846 | int r;
|
---|
| 847 |
|
---|
| 848 | r = mfs_node_get(&fn, handle, index);
|
---|
| 849 | if (r != EOK) {
|
---|
| 850 | async_answer_0(rid, r);
|
---|
| 851 | return;
|
---|
| 852 | }
|
---|
| 853 |
|
---|
| 854 | if (!fn) {
|
---|
| 855 | async_answer_0(rid, r);
|
---|
| 856 | return;
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | struct mfs_node *mnode = fn->data;
|
---|
| 860 | struct mfs_ino_info *ino_i = mnode->ino_i;
|
---|
| 861 |
|
---|
| 862 | if (ino_i->i_size == size)
|
---|
| 863 | r = EOK;
|
---|
| 864 | else
|
---|
| 865 | r = inode_shrink(mnode, ino_i->i_size - size);
|
---|
| 866 |
|
---|
| 867 | async_answer_0(rid, r);
|
---|
| 868 | mfs_node_put(fn);
|
---|
| 869 | }
|
---|
| 870 |
|
---|
[44c0f5b] | 871 | int mfs_instance_get(devmap_handle_t handle, struct mfs_instance **instance)
|
---|
[3b08178] | 872 | {
|
---|
| 873 | link_t *link;
|
---|
| 874 | struct mfs_instance *instance_ptr;
|
---|
| 875 |
|
---|
| 876 | fibril_mutex_lock(&inst_list_mutex);
|
---|
| 877 |
|
---|
| 878 | for (link = inst_list.next; link != &inst_list; link = link->next) {
|
---|
[bd64680] | 879 | instance_ptr = list_get_instance(link, struct mfs_instance,
|
---|
[44c6091f] | 880 | link);
|
---|
| 881 |
|
---|
[3b08178] | 882 | if (instance_ptr->handle == handle) {
|
---|
| 883 | *instance = instance_ptr;
|
---|
| 884 | fibril_mutex_unlock(&inst_list_mutex);
|
---|
| 885 | return EOK;
|
---|
| 886 | }
|
---|
| 887 | }
|
---|
| 888 |
|
---|
| 889 | mfsdebug("Instance not found\n");
|
---|
| 890 |
|
---|
| 891 | fibril_mutex_unlock(&inst_list_mutex);
|
---|
| 892 | return EINVAL;
|
---|
| 893 | }
|
---|
| 894 |
|
---|
[8ceba1e] | 895 | static bool check_magic_number(uint16_t magic, bool *native,
|
---|
[44c6091f] | 896 | mfs_version_t *version, bool *longfilenames)
|
---|
[9e3dc95] | 897 | {
|
---|
[cfac897] | 898 | bool rc = true;
|
---|
[8ceba1e] | 899 | *longfilenames = false;
|
---|
| 900 |
|
---|
[57640e7] | 901 | if (magic == MFS_MAGIC_V1 || magic == MFS_MAGIC_V1R) {
|
---|
| 902 | *native = magic == MFS_MAGIC_V1;
|
---|
[9e3dc95] | 903 | *version = MFS_VERSION_V1;
|
---|
[8ceba1e] | 904 | } else if (magic == MFS_MAGIC_V1L || magic == MFS_MAGIC_V1LR) {
|
---|
| 905 | *native = magic == MFS_MAGIC_V1L;
|
---|
| 906 | *version = MFS_VERSION_V1;
|
---|
| 907 | *longfilenames = true;
|
---|
[57640e7] | 908 | } else if (magic == MFS_MAGIC_V2 || magic == MFS_MAGIC_V2R) {
|
---|
| 909 | *native = magic == MFS_MAGIC_V2;
|
---|
[9e3dc95] | 910 | *version = MFS_VERSION_V2;
|
---|
[8ceba1e] | 911 | } else if (magic == MFS_MAGIC_V2L || magic == MFS_MAGIC_V2LR) {
|
---|
| 912 | *native = magic == MFS_MAGIC_V2L;
|
---|
| 913 | *version = MFS_VERSION_V2;
|
---|
| 914 | *longfilenames = true;
|
---|
[57640e7] | 915 | } else if (magic == MFS_MAGIC_V3 || magic == MFS_MAGIC_V3R) {
|
---|
| 916 | *native = magic == MFS_MAGIC_V3;
|
---|
[9e3dc95] | 917 | *version = MFS_VERSION_V3;
|
---|
[cfac897] | 918 | } else
|
---|
| 919 | rc = false;
|
---|
[9e3dc95] | 920 |
|
---|
[7a96476] | 921 | return rc;
|
---|
[096c8835] | 922 | }
|
---|
| 923 |
|
---|
[e700970] | 924 | void
|
---|
| 925 | mfs_close(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 926 | {
|
---|
| 927 | async_answer_0(rid, EOK);
|
---|
| 928 | }
|
---|
| 929 |
|
---|
| 930 | void
|
---|
| 931 | mfs_open_node(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 932 | {
|
---|
| 933 | libfs_open_node(&mfs_libfs_ops, mfs_reg.fs_handle, rid, request);
|
---|
| 934 | }
|
---|
| 935 |
|
---|
[096c8835] | 936 | /**
|
---|
| 937 | * @}
|
---|
[44c6091f] | 938 | */
|
---|
[096c8835] | 939 |
|
---|