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