Changes in uspace/srv/fs/mfs/mfs_ops.c [5bf76c1:36cb22f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs_ops.c
r5bf76c1 r36cb22f 143 143 { 144 144 enum cache_mode cmode; 145 struct mfs_superblock *sb ;146 struct mfs3_superblock *sb3 ;147 struct mfs_sb_info *sbi ;148 struct mfs_instance *instance ;145 struct mfs_superblock *sb = NULL; 146 struct mfs3_superblock *sb3 = NULL; 147 struct mfs_sb_info *sbi = NULL; 148 struct mfs_instance *instance = NULL; 149 149 bool native, longnames; 150 150 mfs_version_t version; … … 166 166 sbi = malloc(sizeof(*sbi)); 167 167 if (!sbi) { 168 block_fini(service_id);169 return ENOMEM;168 rc = ENOMEM; 169 goto out_error; 170 170 } 171 171 … … 173 173 instance = malloc(sizeof(*instance)); 174 174 if (!instance) { 175 free(sbi); 176 block_fini(service_id); 177 return ENOMEM; 175 rc = ENOMEM; 176 goto out_error; 178 177 } 179 178 180 179 sb = malloc(MFS_SUPERBLOCK_SIZE); 181 180 if (!sb) { 182 free(instance); 183 free(sbi); 184 block_fini(service_id); 185 return ENOMEM; 181 rc = ENOMEM; 182 goto out_error; 186 183 } 187 184 188 185 /* Read the superblock */ 189 186 rc = block_read_direct(service_id, MFS_SUPERBLOCK << 1, 2, sb); 190 if (rc != EOK) { 191 free(instance); 192 free(sbi); 193 free(sb); 194 block_fini(service_id); 195 return rc; 196 } 187 if (rc != EOK) 188 goto out_error; 197 189 198 190 sb3 = (struct mfs3_superblock *) sb; … … 207 199 /*Not recognized*/ 208 200 mfsdebug("magic number not recognized\n"); 209 free(instance); 210 free(sbi); 211 free(sb); 212 block_fini(service_id); 213 return ENOTSUP; 201 rc = ENOTSUP; 202 goto out_error; 214 203 } 215 204 … … 256 245 MFS_MAX_NAME_LEN; 257 246 } 247 248 if (sbi->log2_zone_size != 0) { 249 /* In MFS, file space is allocated per zones. 250 * Zones are a collection of consecutive blocks on disk. 251 * 252 * The current MFS implementation supports only filesystems 253 * where the size of a zone is equal to the 254 * size of a block. 255 */ 256 rc = ENOTSUP; 257 goto out_error; 258 } 259 258 260 sbi->itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks; 259 260 free(sb);261 261 262 262 rc = block_cache_init(service_id, sbi->block_size, 0, cmode); 263 263 if (rc != EOK) { 264 free(instance);265 free(sbi);266 block_cache_fini(service_id);267 block_fini(service_id);268 264 mfsdebug("block cache initialization failed\n"); 269 return EINVAL; 265 rc = EINVAL; 266 goto out_error; 270 267 } 271 268 … … 295 292 *linkcnt = 1; 296 293 294 free(sb); 295 297 296 return mfs_node_put(fn); 297 298 out_error: 299 block_fini(service_id); 300 if (sb) 301 free(sb); 302 if (sbi) 303 free(sbi); 304 if(instance) 305 free(instance); 306 return rc; 298 307 } 299 308 … … 880 889 struct mfs_ino_info *ino_i = mnode->ino_i; 881 890 const size_t bs = sbi->block_size; 882 size_t bytes = min(len, bs - pos % bs); 883 size_t boundary = ROUND_UP(ino_i->i_size, bs); 891 size_t bytes = min(len, bs - (pos % bs)); 884 892 uint32_t block; 885 893 … … 887 895 flags = BLOCK_FLAGS_NOREAD; 888 896 889 if (pos < boundary) { 890 r = mfs_read_map(&block, mnode, pos); 891 if (r != EOK) 892 goto out_err; 893 894 if (block == 0) { 895 /*Writing in a sparse block*/ 896 r = mfs_alloc_zone(mnode->instance, &block); 897 if (r != EOK) 898 goto out_err; 899 flags = BLOCK_FLAGS_NOREAD; 900 } 901 } else { 897 r = mfs_read_map(&block, mnode, pos); 898 if (r != EOK) 899 goto out_err; 900 901 if (block == 0) { 902 /*Writing in a sparse block*/ 902 903 uint32_t dummy; 903 904 … … 905 906 if (r != EOK) 906 907 goto out_err; 907 908 908 909 r = mfs_write_map(mnode, pos, block, &dummy); 909 910 if (r != EOK) 910 911 goto out_err; 912 913 flags = BLOCK_FLAGS_NOREAD; 911 914 } 912 915 … … 916 919 goto out_err; 917 920 918 async_data_write_finalize(callid, b->data + pos % bs, bytes); 921 if (flags == BLOCK_FLAGS_NOREAD) 922 memset(b->data, 0, sbi->block_size); 923 924 async_data_write_finalize(callid, b->data + (pos % bs), bytes); 919 925 b->dirty = true; 920 926 … … 925 931 } 926 932 927 ino_i->i_size = pos + bytes; 928 ino_i->dirty = true; 933 if (pos + bytes > ino_i->i_size) { 934 ino_i->i_size = pos + bytes; 935 ino_i->dirty = true; 936 } 929 937 r = mfs_node_put(fn); 930 *nsize = pos + bytes;938 *nsize = ino_i->i_size; 931 939 *wbytes = bytes; 932 940 return r;
Note:
See TracChangeset
for help on using the changeset viewer.