source: mainline/uspace/srv/fs/minixfs/mfs_super.c@ 197b671

lfn serial ticket/834-toolchain-update topic/fix-logger-deadlock topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 197b671 was 8ceba1e, checked in by Maurizio Lombardi <m.lombardi85@…>, 15 years ago

Improve minixfs server check_magic_number() function

  • Property mode set to 100644
File size: 3.8 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 <stdlib.h>
35#include <libblock.h>
36#include <errno.h>
37#include <str.h>
38#include "mfs.h"
39#include "mfs_utils.h"
40#include "../../vfs/vfs.h"
41
42static bool check_magic_number(uint16_t magic, bool *native,
43 mfs_version_t *version, bool *longfilenames);
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;
49 struct mfs3_superblock *sp;
50 bool native, longnames;
51 mfs_version_t version;
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_SUPERBLOCK_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_SUPERBLOCK);
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);
87
88 if (!check_magic_number(sp->s_magic, &native, &version, &longnames)) {
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(uint16_t magic, bool *native,
97 mfs_version_t *version, bool *longfilenames)
98{
99 *longfilenames = false;
100
101 if (magic == MFS_MAGIC_V1 || magic == MFS_MAGIC_V1R) {
102 *native = magic == MFS_MAGIC_V1;
103 *version = MFS_VERSION_V1;
104 return true;
105 } else if (magic == MFS_MAGIC_V1L || magic == MFS_MAGIC_V1LR) {
106 *native = magic == MFS_MAGIC_V1L;
107 *version = MFS_VERSION_V1;
108 *longfilenames = true;
109 return true;
110 } else if (magic == MFS_MAGIC_V2 || magic == MFS_MAGIC_V2R) {
111 *native = magic == MFS_MAGIC_V2;
112 *version = MFS_VERSION_V2;
113 return true;
114 } else if (magic == MFS_MAGIC_V2L || magic == MFS_MAGIC_V2LR) {
115 *native = magic == MFS_MAGIC_V2L;
116 *version = MFS_VERSION_V2;
117 *longfilenames = true;
118 return true;
119 } else if (magic == MFS_MAGIC_V3 || magic == MFS_MAGIC_V3R) {
120 *native = magic == MFS_MAGIC_V3;
121 *version = MFS_VERSION_V3;
122 return true;
123 }
124
125 return false;
126}
127
128
129/**
130 * @}
131 */
132
Note: See TracBrowser for help on using the repository browser.