source: mainline/uspace/srv/fs/minixfs/mfs_dentry.c@ 147c9f6

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

Fix possible data corruption when readind directory entries from disk

  • Property mode set to 100644
File size: 2.6 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 <assert.h>
34#include <errno.h>
35#include "mfs.h"
36#include "mfs_utils.h"
37
38struct mfs_dentry_info *
39read_directory_entry(struct mfs_node *mnode, unsigned index)
40{
41 const struct mfs_instance *inst = mnode->instance;
42 const struct mfs_sb_info *sbi = inst->sbi;
43 const bool longnames = sbi->long_names;
44 uint32_t block;
45 block_t *b;
46
47 struct mfs_dentry_info *d_info = malloc(sizeof *d_info);
48
49 if (!d_info)
50 return NULL;
51
52 int r = read_map(&block, mnode, index * sbi->dirsize);
53
54 if (r != EOK || block == 0)
55 goto out_err;
56
57 r = block_get(&b, inst->handle, block, BLOCK_FLAGS_NONE);
58
59 if (r != EOK)
60 goto out_err;
61
62 if (sbi->fs_version == MFS_VERSION_V3) {
63 struct mfs3_dentry *d3;
64
65 d3 = b->data;
66 d_info->d_inum = conv32(sbi->native, d3->d_inum);
67 memcpy(d_info->d_name, d3->d_name, MFS3_MAX_NAME_LEN);
68 } else {
69 const int namelen = longnames ? MFS_L_MAX_NAME_LEN :
70 MFS_MAX_NAME_LEN;
71
72 struct mfs_dentry *d;
73
74 d = b->data;
75 d_info->d_inum = conv16(sbi->native, d->d_inum);
76 memcpy(d_info->d_name, d->d_name, namelen);
77 }
78
79 block_put(b);
80
81 d_info->dirty = false;
82 return d_info;
83
84out_err:
85 free(d_info);
86 return NULL;
87}
88
89/**
90 * @}
91 */
92
Note: See TracBrowser for help on using the repository browser.