/* * Copyright (c) 2011 Maurizio Lombardi * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @addtogroup fs * @{ */ #include #include #include #include #include #include #include "mfs.h" #include "mfs_utils.h" #include "../../vfs/vfs.h" static bool check_magic_number(uint16_t magic, bool *native, mfs_version_t *version, bool *longfilenames); void mfs_mounted(ipc_callid_t rid, ipc_call_t *request) { devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); enum cache_mode cmode; struct mfs_superblock *sp; struct mfs3_superblock *sp3; bool native, longnames; mfs_version_t version; uint16_t magic; /* Accept the mount options */ char *opts; int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); if (rc != EOK) { mfsdebug("Can't accept async data write\n"); async_answer_0(rid, rc); return; } /* Check for option enabling write through. */ if (str_cmp(opts, "wtcache") == 0) cmode = CACHE_MODE_WT; else cmode = CACHE_MODE_WB; free(opts); /* initialize libblock */ rc = block_init(devmap_handle, 1024); if (rc != EOK) { mfsdebug("libblock initialization failed\n"); async_answer_0(rid, rc); return; } sp = (struct mfs_superblock *) malloc(MFS_SUPERBLOCK_SIZE); /* Read the superblock */ rc = block_read_direct(devmap_handle, MFS_SUPERBLOCK << 1, 1, sp); if (rc != EOK) { block_fini(devmap_handle); async_answer_0(rid, rc); return; } if (check_magic_number(sp->s_magic, &native, &version, &longnames)) { magic = sp->s_magic; goto recognized; } sp3 = (struct mfs3_superblock *) sp; if (!check_magic_number(sp3->s_magic, &native, &version, &longnames)) { mfsdebug("magic number not recognized\n"); block_fini(devmap_handle); async_answer_0(rid, ENOTSUP); return; } magic = sp3->s_magic; recognized: mfsdebug("magic number recognized = %04x\n", magic); free(sp); } static bool check_magic_number(uint16_t magic, bool *native, mfs_version_t *version, bool *longfilenames) { *longfilenames = false; if (magic == MFS_MAGIC_V1 || magic == MFS_MAGIC_V1R) { *native = magic == MFS_MAGIC_V1; *version = MFS_VERSION_V1; return true; } else if (magic == MFS_MAGIC_V1L || magic == MFS_MAGIC_V1LR) { *native = magic == MFS_MAGIC_V1L; *version = MFS_VERSION_V1; *longfilenames = true; return true; } else if (magic == MFS_MAGIC_V2 || magic == MFS_MAGIC_V2R) { *native = magic == MFS_MAGIC_V2; *version = MFS_VERSION_V2; return true; } else if (magic == MFS_MAGIC_V2L || magic == MFS_MAGIC_V2LR) { *native = magic == MFS_MAGIC_V2L; *version = MFS_VERSION_V2; *longfilenames = true; return true; } else if (magic == MFS_MAGIC_V3 || magic == MFS_MAGIC_V3R) { *native = magic == MFS_MAGIC_V3; *version = MFS_VERSION_V3; return true; } return false; } /** * @} */