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