source: mainline/uspace/srv/fs/minixfs/mfs_super.c@ 245eb02d

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

Check for V3 magic number when a mount is performed

  • Property mode set to 100644
File size: 4.2 KB
Line 
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 <stdio.h>
35#include <stdlib.h>
36#include <libblock.h>
37#include <errno.h>
38#include <str.h>
39#include "mfs.h"
40#include "mfs_utils.h"
41#include "../../vfs/vfs.h"
42
43static bool check_magic_number(uint16_t magic, bool *native,
44 mfs_version_t *version, bool *longfilenames);
45
46void mfs_mounted(ipc_callid_t rid, ipc_call_t *request)
47{
48 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
49 enum cache_mode cmode;
50 struct mfs_superblock *sp;
51 struct mfs3_superblock *sp3;
52 bool native, longnames;
53 mfs_version_t version;
54 uint16_t magic;
55
56 /* Accept the mount options */
57 char *opts;
58 int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
59
60 if (rc != EOK) {
61 mfsdebug("Can't accept async data write\n");
62 async_answer_0(rid, rc);
63 return;
64 }
65
66 /* Check for option enabling write through. */
67 if (str_cmp(opts, "wtcache") == 0)
68 cmode = CACHE_MODE_WT;
69 else
70 cmode = CACHE_MODE_WB;
71
72 free(opts);
73
74 /* initialize libblock */
75 rc = block_init(devmap_handle, 1024);
76 if (rc != EOK) {
77 mfsdebug("libblock initialization failed\n");
78 async_answer_0(rid, rc);
79 return;
80 }
81
82 sp = (struct mfs_superblock *) malloc(MFS_SUPERBLOCK_SIZE);
83
84 /* Read the superblock */
85 rc = block_read_direct(devmap_handle, MFS_SUPERBLOCK << 1, 1, sp);
86 if (rc != EOK) {
87 block_fini(devmap_handle);
88 async_answer_0(rid, rc);
89 return;
90 }
91
92 if (check_magic_number(sp->s_magic, &native, &version, &longnames)) {
93 magic = sp->s_magic;
94 goto recognized;
95 }
96
97 sp3 = (struct mfs3_superblock *) sp;
98
99 if (!check_magic_number(sp3->s_magic, &native, &version, &longnames)) {
100 mfsdebug("magic number not recognized\n");
101 block_fini(devmap_handle);
102 async_answer_0(rid, ENOTSUP);
103 return;
104 }
105
106 magic = sp3->s_magic;
107
108recognized:
109
110 mfsdebug("magic number recognized = %04x\n", magic);
111 free(sp);
112}
113
114static bool check_magic_number(uint16_t magic, bool *native,
115 mfs_version_t *version, bool *longfilenames)
116{
117 *longfilenames = false;
118
119 if (magic == MFS_MAGIC_V1 || magic == MFS_MAGIC_V1R) {
120 *native = magic == MFS_MAGIC_V1;
121 *version = MFS_VERSION_V1;
122 return true;
123 } else if (magic == MFS_MAGIC_V1L || magic == MFS_MAGIC_V1LR) {
124 *native = magic == MFS_MAGIC_V1L;
125 *version = MFS_VERSION_V1;
126 *longfilenames = true;
127 return true;
128 } else if (magic == MFS_MAGIC_V2 || magic == MFS_MAGIC_V2R) {
129 *native = magic == MFS_MAGIC_V2;
130 *version = MFS_VERSION_V2;
131 return true;
132 } else if (magic == MFS_MAGIC_V2L || magic == MFS_MAGIC_V2LR) {
133 *native = magic == MFS_MAGIC_V2L;
134 *version = MFS_VERSION_V2;
135 *longfilenames = true;
136 return true;
137 } else if (magic == MFS_MAGIC_V3 || magic == MFS_MAGIC_V3R) {
138 *native = magic == MFS_MAGIC_V3;
139 *version = MFS_VERSION_V3;
140 return true;
141 }
142
143 return false;
144}
145
146
147/**
148 * @}
149 */
150
Note: See TracBrowser for help on using the repository browser.