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 |
|
---|
33 | #include <libfs.h>
|
---|
34 | #include <stdlib.h>
|
---|
35 | #include <libblock.h>
|
---|
36 | #include <errno.h>
|
---|
37 | #include <str.h>
|
---|
38 | #include "mfs_super.h"
|
---|
39 | #include "mfs_utils.h"
|
---|
40 | #include "../../vfs/vfs.h"
|
---|
41 |
|
---|
42 | static bool check_magic_number(int16_t magic, bool *native, mfs_version_t *version);
|
---|
43 |
|
---|
44 | void mfs_mounted(ipc_callid_t rid, ipc_call_t *request)
|
---|
45 | {
|
---|
46 | devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
|
---|
47 | enum cache_mode cmode;
|
---|
48 | struct mfs_superblock *sp;
|
---|
49 | bool native;
|
---|
50 | mfs_version_t version;
|
---|
51 |
|
---|
52 | /* Accept the mount options */
|
---|
53 | char *opts;
|
---|
54 | int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
|
---|
55 |
|
---|
56 | if (rc != EOK) {
|
---|
57 | async_answer_0(rid, rc);
|
---|
58 | return;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /* Check for option enabling write through. */
|
---|
62 | if (str_cmp(opts, "wtcache") == 0)
|
---|
63 | cmode = CACHE_MODE_WT;
|
---|
64 | else
|
---|
65 | cmode = CACHE_MODE_WB;
|
---|
66 |
|
---|
67 | free(opts);
|
---|
68 |
|
---|
69 | /* initialize libblock */
|
---|
70 | rc = block_init(devmap_handle, MFS_SUPER_BLOCK_SIZE);
|
---|
71 | if (rc != EOK) {
|
---|
72 | async_answer_0(rid, rc);
|
---|
73 | return;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /* prepare the superblock */
|
---|
77 | rc = block_bb_read(devmap_handle, MFS_SUPER_BLOCK);
|
---|
78 | if (rc != EOK) {
|
---|
79 | block_fini(devmap_handle);
|
---|
80 | async_answer_0(rid, rc);
|
---|
81 | return;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /* get the buffer with the superblock */
|
---|
85 | sp = block_bb_get(devmap_handle);
|
---|
86 |
|
---|
87 | if (!check_magic_number(sp->s_magic, &native, &version)) {
|
---|
88 | /*Magic number is invalid!*/
|
---|
89 | block_fini(devmap_handle);
|
---|
90 | async_answer_0(rid, ENOTSUP);
|
---|
91 | return;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | static bool check_magic_number(int16_t magic, bool *native, mfs_version_t *version)
|
---|
96 | {
|
---|
97 | *native = true;
|
---|
98 |
|
---|
99 | repeat_check:
|
---|
100 |
|
---|
101 | switch (*native ? magic : conv16(false, magic)) {
|
---|
102 | case MFS_MAGIC_V1:
|
---|
103 | *version = MFS_VERSION_V1;
|
---|
104 | return true;
|
---|
105 | case MFS_MAGIC_V2:
|
---|
106 | *version = MFS_VERSION_V2;
|
---|
107 | return true;
|
---|
108 | case MFS_MAGIC_V3:
|
---|
109 | *version = MFS_VERSION_V3;
|
---|
110 | return true;
|
---|
111 | default:
|
---|
112 | ;
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (*native) {
|
---|
116 | *native = false;
|
---|
117 | goto repeat_check;
|
---|
118 | } else {
|
---|
119 | return false;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /*Should never happens*/
|
---|
123 | return false;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * @}
|
---|
129 | */
|
---|
130 |
|
---|