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

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

cstyle

  • 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,
64 itable_off + inum / V1_INODES_PER_BLOCK,
65 BLOCK_FLAGS_NONE) != EOK)
66 goto out_err;
67
68 memcpy(ino, ((uint8_t *) b->data) + ino_off * ino_size, ino_size);
69
70 ino_i->i_mode = conv16(sbi->native, ino->i_mode);
71 ino_i->i_uid = conv16(sbi->native, ino->i_uid);
72 ino_i->i_size = conv32(sbi->native, ino->i_size);
73 ino_i->i_mtime = conv32(sbi->native, ino->i_mtime);
74 ino_i->i_nlinks = ino->i_nlinks;
75
76 for (i = 0; i < V1_NR_DIRECT_ZONES; ++i)
77 ino_i->i_dzone[i] = conv16(sbi->native, ino->i_dzone[i]);
78
79 for (i = 0; i < V1_NR_INDIRECT_ZONES; ++i)
80 ino_i->i_izone[i] = conv16(sbi->native, ino->i_izone[i]);
81
82 block_put(b);
83 free(ino);
84 ino_i->dirty = false;
85
86 return ino_i;
87
88out_err:
89 if (ino)
90 free(ino);
91 if (ino_i)
92 free(ino_i);
93 return NULL;
94}
95
96struct mfs_ino_info *mfs2_read_inode_raw(const struct mfs_instance *instance,
97 uint32_t inum)
98{
99 struct mfs2_inode *ino = NULL;
100 struct mfs_ino_info *ino_i = NULL;
101 struct mfs_sb_info *sbi;
102 block_t *b;
103 int i;
104
105 const size_t ino_size = sizeof(struct mfs2_inode);
106
107 ino = (struct mfs2_inode *) malloc(ino_size);
108 ino_i = (struct mfs_ino_info *) malloc(sizeof(struct mfs_ino_info));
109
110 if (!ino || !ino_i)
111 goto out_err;
112
113 sbi = instance->sbi;
114 assert(sbi);
115
116 const int itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks;
117 const int ino_off = inum % V3_INODES_PER_BLOCK(sbi->block_size);
118
119 if (block_get(&b, instance->handle,
120 itable_off + inum / V3_INODES_PER_BLOCK(sbi->block_size),
121 BLOCK_FLAGS_NONE) != EOK)
122 goto out_err;
123
124 memcpy(ino, ((uint8_t *)b->data) + ino_off * ino_size, ino_size);
125
126 ino_i->i_mode = conv16(sbi->native, ino->i_mode);
127 ino_i->i_nlinks = conv16(sbi->native, ino->i_nlinks);
128 ino_i->i_uid = conv16(sbi->native, ino->i_uid);
129 ino_i->i_gid = conv16(sbi->native, ino->i_gid);
130 ino_i->i_size = conv32(sbi->native, ino->i_size);
131 ino_i->i_atime = conv32(sbi->native, ino->i_atime);
132 ino_i->i_mtime = conv32(sbi->native, ino->i_mtime);
133 ino_i->i_ctime = conv32(sbi->native, ino->i_ctime);
134
135 for (i = 0; i < V2_NR_DIRECT_ZONES; ++i)
136 ino_i->i_dzone[i] = conv32(sbi->native, ino->i_dzone[i]);
137
138 for (i = 0; i < V2_NR_INDIRECT_ZONES; ++i)
139 ino_i->i_izone[i] = conv32(sbi->native, ino->i_izone[i]);
140
141 block_put(b);
142 free(ino);
143 ino_i->dirty = false;
144
145 return ino_i;
146
147out_err:
148 if (ino)
149 free(ino);
150 if (ino_i)
151 free(ino_i);
152 return NULL;
153}
154
155/**
156 * @}
157 */
158
Note: See TracBrowser for help on using the repository browser.