source: mainline/uspace/srv/fs/minixfs/mfs_inode.c@ ac28650

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

Bug fix: the driver didn't read the number of hard links of version 1 inodes.

  • Property mode set to 100644
File size: 4.5 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 <stdlib.h>
34#include <assert.h>
35#include <errno.h>
36#include <mem.h>
37#include "mfs.h"
38#include "mfs_utils.h"
39
40struct mfs_ino_info *mfs_read_inode_raw(const struct mfs_instance *instance,
41 uint16_t inum)
42{
43 struct mfs_inode *ino = NULL;
44 struct mfs_ino_info *ino_i = NULL;
45 struct mfs_sb_info *sbi;
46 block_t *b;
47 int i;
48
49 const int ino_off = inum % V1_INODES_PER_BLOCK;
50 const size_t ino_size = sizeof(struct mfs_inode);
51
52 ino_i = (struct mfs_ino_info *) malloc(sizeof(struct mfs_ino_info));
53 ino = (struct mfs_inode *) malloc(ino_size);
54
55 if (!ino || !ino_i)
56 goto out_err;
57
58 sbi = instance->sbi;
59 assert(sbi);
60
61 const int itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks;
62
63 if (block_get(&b, instance->handle, itable_off + inum / V1_INODES_PER_BLOCK,
64 BLOCK_FLAGS_NONE) != EOK)
65 goto out_err;
66
67 memcpy(ino, ((uint8_t *) b->data) + ino_off * ino_size, ino_size);
68
69 ino_i->i_mode = conv16(sbi->native, ino->i_mode);
70 ino_i->i_uid = conv16(sbi->native, ino->i_uid);
71 ino_i->i_size = conv32(sbi->native, ino->i_size);
72 ino_i->i_mtime = conv32(sbi->native, ino->i_mtime);
73 ino_i->i_nlinks = ino->i_nlinks;
74
75 for (i = 0; i < V1_NR_DIRECT_ZONES; ++i)
76 ino_i->i_dzone[i] = conv16(sbi->native, ino->i_dzone[i]);
77
78 for (i = 0; i < V1_NR_INDIRECT_ZONES; ++i)
79 ino_i->i_izone[i] = conv16(sbi->native, ino->i_izone[i]);
80
81 block_put(b);
82 free(ino);
83 ino_i->dirty = false;
84
85 return ino_i;
86
87out_err:
88 if (ino)
89 free(ino);
90 if (ino_i)
91 free(ino_i);
92 return NULL;
93}
94
95struct mfs_ino_info *mfs2_read_inode_raw(const struct mfs_instance *instance,
96 uint32_t inum)
97{
98 struct mfs2_inode *ino = NULL;
99 struct mfs_ino_info *ino_i = NULL;
100 struct mfs_sb_info *sbi;
101 block_t *b;
102 int i;
103
104 const size_t ino_size = sizeof(struct mfs2_inode);
105
106 ino = (struct mfs2_inode *) malloc(ino_size);
107 ino_i = (struct mfs_ino_info *) malloc(sizeof(struct mfs_ino_info));
108
109 if (!ino || !ino_i)
110 goto out_err;
111
112 sbi = instance->sbi;
113 assert(sbi);
114
115 const int itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks;
116 const int ino_off = inum % V3_INODES_PER_BLOCK(sbi->block_size);
117
118 if (block_get(&b, instance->handle,
119 itable_off + inum / V3_INODES_PER_BLOCK(sbi->block_size),
120 BLOCK_FLAGS_NONE) != EOK)
121 goto out_err;
122
123 memcpy(ino, ((uint8_t *)b->data) + ino_off * ino_size, ino_size);
124
125 ino_i->i_mode = conv16(sbi->native, ino->i_mode);
126 ino_i->i_nlinks = conv16(sbi->native, ino->i_nlinks);
127 ino_i->i_uid = conv16(sbi->native, ino->i_uid);
128 ino_i->i_gid = conv16(sbi->native, ino->i_gid);
129 ino_i->i_size = conv32(sbi->native, ino->i_size);
130 ino_i->i_atime = conv32(sbi->native, ino->i_atime);
131 ino_i->i_mtime = conv32(sbi->native, ino->i_mtime);
132 ino_i->i_ctime = conv32(sbi->native, ino->i_ctime);
133
134 for (i = 0; i < V2_NR_DIRECT_ZONES; ++i)
135 ino_i->i_dzone[i] = conv32(sbi->native, ino->i_dzone[i]);
136
137 for (i = 0; i < V2_NR_INDIRECT_ZONES; ++i)
138 ino_i->i_izone[i] = conv32(sbi->native, ino->i_izone[i]);
139
140 block_put(b);
141 free(ino);
142 ino_i->dirty = false;
143
144 return ino_i;
145
146out_err:
147 if (ino)
148 free(ino);
149 if (ino_i)
150 free(ino_i);
151 return NULL;
152}
153
154/**
155 * @}
156 */
157
Note: See TracBrowser for help on using the repository browser.