Changeset 155f792 in mainline
- Timestamp:
- 2011-03-20T11:30:25Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6adba0a8
- Parents:
- 930baca
- Location:
- uspace/srv/fs/minixfs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/minixfs/mfs.h
r930baca r155f792 82 82 }; 83 83 84 /*Generic MinixFS inode*/ 85 struct mfs_ino_info { 86 uint16_t i_mode; 87 uint16_t i_nlinks; 88 int16_t i_uid; 89 uint16_t i_gid; 90 int32_t i_size; 91 int32_t i_atime; 92 int32_t i_mtime; 93 int32_t i_ctime; 94 /*Block numbers for direct zones*/ 95 uint32_t i_dzone[V2_NR_DIRECT_ZONES]; 96 /*Block numbers for indirect zones*/ 97 uint32_t i_izone[V2_NR_INDIRECT_ZONES]; 98 }; 99 84 100 struct mfs_instance { 85 101 link_t link; … … 90 106 /*MinixFS node in core*/ 91 107 struct mfs_node { 92 union { 93 struct mfs_inode *ino; 94 struct mfs2_inode *ino2; 95 }; 96 108 struct mfs_ino_info *ino_i; 97 109 struct mfs_instance *instance; 98 110 }; … … 115 127 /*mfs_inode.c*/ 116 128 extern 117 struct mfs_ino de*mfs_read_inode_raw(const struct mfs_instance *instance,129 struct mfs_ino_info *mfs_read_inode_raw(const struct mfs_instance *instance, 118 130 uint16_t inum); 119 131 extern 120 struct mfs 2_inode*mfs2_read_inode_raw(const struct mfs_instance *instance,132 struct mfs_ino_info *mfs2_read_inode_raw(const struct mfs_instance *instance, 121 133 uint32_t inum); 122 134 -
uspace/srv/fs/minixfs/mfs_inode.c
r930baca r155f792 1 1 #include <stdlib.h> 2 2 #include <assert.h> 3 #include <errno.h> 3 4 #include <mem.h> 4 5 #include "mfs.h" 5 6 #include "mfs_utils.h" 6 7 7 struct mfs_ino de*mfs_read_inode_raw(const struct mfs_instance *instance,8 struct mfs_ino_info *mfs_read_inode_raw(const struct mfs_instance *instance, 8 9 uint16_t inum) 9 10 { 10 struct mfs_inode *ino; 11 struct mfs_inode *ino = NULL; 12 struct mfs_ino_info *ino_i = NULL; 11 13 struct mfs_sb_info *sbi; 12 14 block_t *b; … … 16 18 const size_t ino_size = sizeof(struct mfs_inode); 17 19 20 ino_i = (struct mfs_ino_info *) malloc(sizeof(struct mfs_ino_info)); 18 21 ino = (struct mfs_inode *) malloc(ino_size); 19 22 20 if (!ino )21 return NULL;23 if (!ino || !ino_i) 24 goto out_err; 22 25 23 26 sbi = instance->sbi; … … 26 29 const int itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks; 27 30 28 block_get(&b, instance->handle, itable_off + inum / V1_INODES_PER_BLOCK, 29 BLOCK_FLAGS_NONE); 31 if (block_get(&b, instance->handle, itable_off + inum / V1_INODES_PER_BLOCK, 32 BLOCK_FLAGS_NONE) != EOK) 33 goto out_err; 30 34 31 35 memcpy(ino, ((uint8_t *) b->data) + ino_off * ino_size, ino_size); 32 36 33 ino ->i_mode = conv16(sbi->native, ino->i_mode);34 ino ->i_uid = conv16(sbi->native, ino->i_uid);35 ino ->i_size = conv32(sbi->native, ino->i_size);36 ino ->i_mtime = conv32(sbi->native, ino->i_mtime);37 ino_i->i_mode = conv16(sbi->native, ino->i_mode); 38 ino_i->i_uid = conv16(sbi->native, ino->i_uid); 39 ino_i->i_size = conv32(sbi->native, ino->i_size); 40 ino_i->i_mtime = conv32(sbi->native, ino->i_mtime); 37 41 38 42 for (i = 0; i < V1_NR_DIRECT_ZONES; ++i) 39 ino ->i_dzone[i] = conv16(sbi->native, ino->i_dzone[i]);43 ino_i->i_dzone[i] = conv16(sbi->native, ino->i_dzone[i]); 40 44 41 45 for (i = 0; i < V1_NR_INDIRECT_ZONES; ++i) 42 ino ->i_izone[i] = conv16(sbi->native, ino->i_izone[i]);46 ino_i->i_izone[i] = conv16(sbi->native, ino->i_izone[i]); 43 47 44 48 block_put(b); 45 49 46 return ino; 50 free(ino); 51 return ino_i; 52 53 out_err: 54 if (ino) 55 free(ino); 56 if (ino_i) 57 free(ino_i); 58 return NULL; 47 59 } 48 60 49 struct mfs 2_inode*mfs2_read_inode_raw(const struct mfs_instance *instance,61 struct mfs_ino_info *mfs2_read_inode_raw(const struct mfs_instance *instance, 50 62 uint32_t inum) 51 63 { 52 struct mfs2_inode *ino; 64 struct mfs2_inode *ino = NULL; 65 struct mfs_ino_info *ino_i = NULL; 53 66 struct mfs_sb_info *sbi; 54 67 block_t *b; … … 58 71 59 72 ino = (struct mfs2_inode *) malloc(ino_size); 73 ino_i = (struct mfs_ino_info *) malloc(sizeof(struct mfs_ino_info)); 60 74 61 if (!ino )62 return NULL;75 if (!ino || !ino_i) 76 goto out_err; 63 77 64 78 sbi = instance->sbi; … … 68 82 const int ino_off = inum % V3_INODES_PER_BLOCK(sbi->block_size); 69 83 70 block_get(&b, instance->handle,84 if (block_get(&b, instance->handle, 71 85 itable_off + inum / V3_INODES_PER_BLOCK(sbi->block_size), 72 BLOCK_FLAGS_NONE); 86 BLOCK_FLAGS_NONE) != EOK) 87 goto out_err; 73 88 74 89 memcpy(ino, ((uint8_t *)b->data) + ino_off * ino_size, ino_size); 75 90 76 ino ->i_mode = conv16(sbi->native, ino->i_mode);77 ino ->i_nlinks = conv16(sbi->native, ino->i_nlinks);78 ino ->i_uid = conv16(sbi->native, ino->i_uid);79 ino ->i_gid = conv16(sbi->native, ino->i_gid);80 ino ->i_size = conv32(sbi->native, ino->i_size);81 ino ->i_atime = conv32(sbi->native, ino->i_atime);82 ino ->i_mtime = conv32(sbi->native, ino->i_mtime);83 ino ->i_ctime = conv32(sbi->native, ino->i_ctime);91 ino_i->i_mode = conv16(sbi->native, ino->i_mode); 92 ino_i->i_nlinks = conv16(sbi->native, ino->i_nlinks); 93 ino_i->i_uid = conv16(sbi->native, ino->i_uid); 94 ino_i->i_gid = conv16(sbi->native, ino->i_gid); 95 ino_i->i_size = conv32(sbi->native, ino->i_size); 96 ino_i->i_atime = conv32(sbi->native, ino->i_atime); 97 ino_i->i_mtime = conv32(sbi->native, ino->i_mtime); 98 ino_i->i_ctime = conv32(sbi->native, ino->i_ctime); 84 99 85 100 for (i = 0; i < V2_NR_DIRECT_ZONES; ++i) 86 ino ->i_dzone[i] = conv32(sbi->native, ino->i_dzone[i]);101 ino_i->i_dzone[i] = conv32(sbi->native, ino->i_dzone[i]); 87 102 88 103 for (i = 0; i < V2_NR_INDIRECT_ZONES; ++i) 89 ino ->i_izone[i] = conv32(sbi->native, ino->i_izone[i]);104 ino_i->i_izone[i] = conv32(sbi->native, ino->i_izone[i]); 90 105 91 106 block_put(b); 92 107 93 return ino; 108 free(ino); 109 return ino_i; 110 111 out_err: 112 if (ino) 113 free(ino); 114 if (ino_i) 115 free(ino_i); 116 return NULL; 94 117 } 95 118 -
uspace/srv/fs/minixfs/mfs_ops.c
r930baca r155f792 212 212 aoff64_t mfs_size_get(fs_node_t *node) 213 213 { 214 aoff64_t size;215 216 214 mfsdebug("request for inode size\n"); 217 215 assert(node); … … 219 217 const struct mfs_node *mnode = node->data; 220 218 assert(mnode); 221 222 const struct mfs_instance *inst = mnode->instance; 223 assert(inst); 224 225 const struct mfs_sb_info *sbi = inst->sbi; 226 assert(sbi); 227 228 if (sbi->fs_version == MFS_VERSION_V1) { 229 struct mfs_inode *ino; 230 ino = mnode->ino; 231 size = ino->i_size; 232 } else { 233 struct mfs2_inode *ino2; 234 ino2 = mnode->ino2; 235 size = ino2->i_size; 236 } 237 238 return size; 219 assert(mnode->ino_i); 220 221 return mnode->ino_i->i_size; 239 222 } 240 223 … … 282 265 } 283 266 267 struct mfs_ino_info *ino_i; 268 284 269 if (sbi->fs_version == MFS_VERSION_V1) { 285 270 /*Read MFS V1 inode*/ 286 struct mfs_inode *ino; 287 288 ino = mfs_read_inode_raw(inst, index); 289 mnode->ino = ino; 271 ino_i = mfs_read_inode_raw(inst, index); 290 272 } else { 291 273 /*Read MFS V2/V3 inode*/ 292 struct mfs2_inode *ino2; 293 294 ino2 = mfs2_read_inode_raw(inst, index); 295 mnode->ino2 = ino2; 296 } 274 ino_i = mfs2_read_inode_raw(inst, index); 275 } 276 277 if (!ino_i) 278 return -1; 279 280 mnode->ino_i = ino_i; 297 281 298 282 mnode->instance = inst; … … 313 297 { 314 298 const struct mfs_node *node = fsnode->data; 315 const struct mfs_sb_info *sbi = node->instance->sbi; 316 317 if (sbi->fs_version == MFS_VERSION_V1) 318 return S_ISDIR(node->ino->i_mode); 319 else 320 return S_ISDIR(node->ino2->i_mode); 299 return S_ISDIR(node->ino_i->i_mode); 321 300 } 322 301 … … 324 303 { 325 304 struct mfs_node *node = fsnode->data; 326 struct mfs_sb_info *sbi = node->instance->sbi; 327 328 if (sbi->fs_version == MFS_VERSION_V1) 329 return S_ISREG(node->ino->i_mode); 330 else 331 return S_ISREG(node->ino2->i_mode); 305 return S_ISREG(node->ino_i->i_mode); 332 306 } 333 307 -
uspace/srv/fs/minixfs/mfs_read.c
r930baca r155f792 4 4 #include "mfs_utils.h" 5 5 6 static int read_map_v1(uint16_t *b, const struct mfs_node *mnode, int rblock); 7 static int read_map_v2(uint32_t *b, const struct mfs_node *mnode, int rblock); 6 static int read_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock); 8 7 9 8 /*Given the position in the file expressed in … … 22 21 assert(sbi); 23 22 24 const mfs_version_t fs_version = sbi->fs_version;25 23 const int block_size = sbi->block_size; 26 24 … … 28 26 int rblock = pos / block_size; 29 27 30 if (fs_version == MFS_VERSION_V1) { 31 if (mnode->ino->i_size < (int32_t) pos) 32 return -1; 33 34 uint16_t b16 = 0; 35 r = read_map_v1(&b16, mnode, rblock); 36 *b = b16; 37 } else { 38 if (mnode->ino2->i_size < (int32_t) pos) 39 return -1; 40 41 r = read_map_v2(b, mnode, rblock); 42 } 43 44 return r; 45 } 46 47 static int read_map_v1(uint16_t *b, const struct mfs_node *mnode, int rblock) 48 { 49 const int ptrs_per_block = MFS_BLOCKSIZE / sizeof(uint16_t); 50 block_t *bi1, *bi2; 51 const struct mfs_inode *ino = mnode->ino; 52 int r; 53 54 assert(ino); 55 assert(mnode->instance); 56 57 if (rblock < V1_NR_DIRECT_ZONES) { 58 *b = ino->i_dzone[rblock]; 28 if (mnode->ino_i->i_size < (int32_t) pos) { 59 29 r = EOK; 30 *b = 0; 60 31 goto out; 61 32 } 62 33 63 rblock -= V1_NR_DIRECT_ZONES - 1; 64 65 /*Check if the wanted block is in the single indirect zone*/ 66 if (rblock < ptrs_per_block) { 67 if (ino->i_izone[0] == 0) { 68 r = -1; 69 goto out; 70 } 71 72 r = read_ind_block(bi1, mnode->instance, ino->i_izone[0]); 73 74 if (r != EOK) 75 goto out; 76 77 *b = ((uint16_t *) bi1->data)[rblock]; 78 goto out_block; 79 } 80 81 rblock -= ptrs_per_block - 1; 82 83 /*The wanted block is in the double indirect zone*/ 84 uint16_t di_block = rblock / ptrs_per_block; 85 86 /*read the first indirect zone*/ 87 if (ino->i_izone[1] == 0) { 88 r = -1; 89 goto out; 90 } 91 92 r = read_ind_block(bi1, mnode->instance, ino->i_izone[1]); 93 94 if (r != EOK) 95 goto out; 96 97 /*read the dobule indirect zone*/ 98 r = read_ind_block(bi2, mnode->instance, 99 ((uint16_t *) bi1->data)[di_block]); 100 101 if (r != EOK) 102 goto out_block; 103 104 *b = ((uint16_t *) bi2->data)[rblock % ptrs_per_block]; 105 block_put(bi2); 106 107 out_block: 108 block_put(bi1); 34 r = read_map_ondisk(b, mnode, rblock); 109 35 out: 110 36 return r; 111 37 } 112 38 113 static int read_map_ v2(uint32_t *b, const struct mfs_node *mnode, int rblock)39 static int read_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock) 114 40 { 115 41 block_t *bi1, *bi2; 116 int r; 42 int r, nr_direct, nr_indirect; 43 int ptrs_per_block; 117 44 118 45 assert(mnode); 119 const struct mfs 2_inode *ino2 = mnode->ino2;46 const struct mfs_ino_info *ino_i = mnode->ino_i; 120 47 121 assert(ino 2);48 assert(ino_i); 122 49 assert(mnode->instance); 123 50 … … 125 52 assert(sbi); 126 53 127 const int ptrs_per_block = sbi->block_size / sizeof(uint32_t);54 const int fs_version = sbi->fs_version; 128 55 129 if (rblock < V2_NR_DIRECT_ZONES) { 130 *b = ino2->i_dzone[rblock]; 56 if (fs_version == MFS_VERSION_V1) { 57 nr_direct = V1_NR_DIRECT_ZONES; 58 nr_indirect = V1_NR_INDIRECT_ZONES; 59 ptrs_per_block = MFS_BLOCKSIZE / sizeof(uint16_t); 60 } else { 61 nr_direct = V2_NR_DIRECT_ZONES; 62 nr_indirect = V2_NR_INDIRECT_ZONES; 63 ptrs_per_block = sbi->block_size / sizeof(uint32_t); 64 } 65 66 if (rblock < nr_direct) { 67 *b = ino_i->i_dzone[rblock]; 131 68 r = EOK; 132 69 goto out; 133 70 } 134 rblock -= V2_NR_DIRECT_ZONES- 1;71 rblock -= nr_direct - 1; 135 72 136 73 /*Check if the wanted block is in the single indirect zone*/ 137 74 if (rblock < ptrs_per_block) { 138 if (ino 2->i_izone[0] == 0) {75 if (ino_i->i_izone[0] == 0) { 139 76 r = -1; 140 77 goto out; 141 78 } 142 79 143 r = read_ind_block(bi2, mnode->instance, ino 2->i_izone[0]);80 r = read_ind_block(bi2, mnode->instance, ino_i->i_izone[0]); 144 81 145 82 if (r != EOK) 146 83 goto out; 147 84 148 *b = ((uint32_t *) bi1->data)[rblock]; 85 *b = fs_version == MFS_VERSION_V1 ? 86 ((uint16_t *) bi1->data)[rblock] : 87 ((uint32_t *) bi1->data)[rblock]; 149 88 goto out_block; 150 89 } … … 156 95 157 96 /*read the first indirect zone*/ 158 if (ino 2->i_izone[1] == 0) {97 if (ino_i->i_izone[1] == 0) { 159 98 r = -1; 160 99 goto out; 161 100 } 162 101 163 r = read_ind_block(bi1, mnode->instance, ino 2->i_izone[1]);102 r = read_ind_block(bi1, mnode->instance, ino_i->i_izone[1]); 164 103 165 104 if (r != EOK) … … 167 106 168 107 /*read the second indirect zone*/ 169 r = read_ind_block(bi2, mnode->instance, 108 if (fs_version == MFS_VERSION_V1) { 109 r = read_ind_block(bi2, mnode->instance, 110 ((uint16_t *) bi1->data)[di_block]); 111 112 if (r != EOK) 113 goto out_block; 114 115 *b = ((uint16_t *) bi2->data)[rblock % ptrs_per_block]; 116 } else { 117 r = read_ind_block(bi2, mnode->instance, 170 118 ((uint32_t *) bi1->data)[di_block]); 171 119 172 if (r != EOK)173 goto out_block;120 if (r != EOK) 121 goto out_block; 174 122 175 *b = ((uint32_t *) bi2->data)[rblock % ptrs_per_block]; 123 *b = ((uint32_t *) bi2->data)[rblock % ptrs_per_block]; 124 } 176 125 block_put(bi2); 177 126
Note:
See TracChangeset
for help on using the changeset viewer.