source: mainline/uspace/srv/fs/minixfs/mfs_super.c@ 55c51c28

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 55c51c28 was 63ffffd, checked in by Maurizio Lombardi <m.lombardi85@…>, 14 years ago

MFSv3 superblock structure is different than V1/V2 superblock

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[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 <libfs.h>
34#include <stdlib.h>
35#include <libblock.h>
36#include <errno.h>
37#include <str.h>
[7413683]38#include "mfs.h"
[096c8835]39#include "mfs_super.h"
[9e3dc95]40#include "mfs_utils.h"
41#include "../../vfs/vfs.h"
42
43static bool check_magic_number(int16_t magic, bool *native, mfs_version_t *version);
[096c8835]44
45void mfs_mounted(ipc_callid_t rid, ipc_call_t *request)
46{
47 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
48 enum cache_mode cmode;
[63ffffd]49 struct mfs3_superblock *sp;
[9e3dc95]50 bool native;
51 mfs_version_t version;
[096c8835]52
53 /* Accept the mount options */
54 char *opts;
55 int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
56
57 if (rc != EOK) {
58 async_answer_0(rid, rc);
59 return;
60 }
61
62 /* Check for option enabling write through. */
63 if (str_cmp(opts, "wtcache") == 0)
64 cmode = CACHE_MODE_WT;
65 else
66 cmode = CACHE_MODE_WB;
67
68 free(opts);
69
70 /* initialize libblock */
71 rc = block_init(devmap_handle, MFS_SUPER_BLOCK_SIZE);
72 if (rc != EOK) {
73 async_answer_0(rid, rc);
74 return;
75 }
76
77 /* prepare the superblock */
78 rc = block_bb_read(devmap_handle, MFS_SUPER_BLOCK);
79 if (rc != EOK) {
80 block_fini(devmap_handle);
81 async_answer_0(rid, rc);
82 return;
83 }
84
85 /* get the buffer with the superblock */
86 sp = block_bb_get(devmap_handle);
[9e3dc95]87
88 if (!check_magic_number(sp->s_magic, &native, &version)) {
89 /*Magic number is invalid!*/
90 block_fini(devmap_handle);
91 async_answer_0(rid, ENOTSUP);
92 return;
93 }
94}
95
96static bool check_magic_number(int16_t magic, bool *native, mfs_version_t *version)
97{
[57640e7]98 if (magic == MFS_MAGIC_V1 || magic == MFS_MAGIC_V1R) {
99 *native = magic == MFS_MAGIC_V1;
[9e3dc95]100 *version = MFS_VERSION_V1;
101 return true;
[57640e7]102 } else if (magic == MFS_MAGIC_V2 || magic == MFS_MAGIC_V2R) {
103 *native = magic == MFS_MAGIC_V2;
[9e3dc95]104 *version = MFS_VERSION_V2;
105 return true;
[57640e7]106 } else if (magic == MFS_MAGIC_V3 || magic == MFS_MAGIC_V3R) {
107 *native = magic == MFS_MAGIC_V3;
[9e3dc95]108 *version = MFS_VERSION_V3;
109 return true;
110 }
111
112 return false;
[096c8835]113}
114
115
116/**
117 * @}
118 */
119
Note: See TracBrowser for help on using the repository browser.