Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'befs-v4.9-rc1' of git://github.com/luisbg/linux-befs

Pull befs fixes from Luis de Bethencourt:
"I recently took maintainership of the befs file system [0]. This is
the first time I send you a git pull request, so please let me know if
all the below is OK.

Salah Triki and myself have been cleaning the code and fixing a few
small bugs.

Sorry I couldn't send this sooner in the merge window, I was waiting
to have my GPG key signed by kernel members at ELCE in Berlin a few
days ago."

[0] https://lkml.org/lkml/2016/7/27/502

* tag 'befs-v4.9-rc1' of git://github.com/luisbg/linux-befs: (39 commits)
befs: befs: fix style issues in datastream.c
befs: improve documentation in datastream.c
befs: fix typos in datastream.c
befs: fix typos in btree.c
befs: fix style issues in super.c
befs: fix comment style
befs: add check for ag_shift in superblock
befs: dump inode_size superblock information
befs: remove unnecessary initialization
befs: fix typo in befs_sb_info
befs: add flags field to validate superblock state
befs: fix typo in befs_find_key
befs: remove unused BEFS_BT_PARMATCH
fs: befs: remove ret variable
fs: befs: remove in vain variable assignment
fs: befs: remove unnecessary *befs_sb variable
fs: befs: remove useless initialization to zero
fs: befs: remove in vain variable assignment
fs: befs: Insert NULL inode to dentry
fs: befs: Remove useless calls to brelse in befs_find_brun_dblindirect
...

+245 -284
+5 -14
fs/befs/befs.h
··· 43 43 u32 ag_shift; 44 44 u32 num_ags; 45 45 46 - /* jornal log entry */ 46 + /* State of the superblock */ 47 + u32 flags; 48 + 49 + /* Journal log entry */ 47 50 befs_block_run log_blocks; 48 51 befs_off_t log_start; 49 52 befs_off_t log_end; ··· 82 79 BEFS_BT_END, 83 80 BEFS_BT_EMPTY, 84 81 BEFS_BT_MATCH, 85 - BEFS_BT_PARMATCH, 82 + BEFS_BT_OVERFLOW, 86 83 BEFS_BT_NOT_FOUND 87 84 }; 88 85 ··· 141 138 befs_iaddrs_per_block(struct super_block *sb) 142 139 { 143 140 return BEFS_SB(sb)->block_size / sizeof (befs_disk_inode_addr); 144 - } 145 - 146 - static inline int 147 - befs_iaddr_is_empty(const befs_inode_addr *iaddr) 148 - { 149 - return (!iaddr->allocation_group) && (!iaddr->start) && (!iaddr->len); 150 - } 151 - 152 - static inline size_t 153 - befs_brun_size(struct super_block *sb, befs_block_run run) 154 - { 155 - return BEFS_SB(sb)->block_size * run.len; 156 141 } 157 142 158 143 #include "endian.h"
+27 -33
fs/befs/btree.c
··· 85 85 }; 86 86 87 87 /* local constants */ 88 - static const befs_off_t befs_bt_inval = 0xffffffffffffffffULL; 88 + static const befs_off_t BEFS_BT_INVAL = 0xffffffffffffffffULL; 89 89 90 90 /* local functions */ 91 91 static int befs_btree_seekleaf(struct super_block *sb, const befs_data_stream *ds, ··· 156 156 sup->max_depth = fs32_to_cpu(sb, od_sup->max_depth); 157 157 sup->data_type = fs32_to_cpu(sb, od_sup->data_type); 158 158 sup->root_node_ptr = fs64_to_cpu(sb, od_sup->root_node_ptr); 159 - sup->free_node_ptr = fs64_to_cpu(sb, od_sup->free_node_ptr); 160 - sup->max_size = fs64_to_cpu(sb, od_sup->max_size); 161 159 162 160 brelse(bh); 163 161 if (sup->magic != BEFS_BTREE_MAGIC) { ··· 181 183 * Calls befs_read_datastream to read in the indicated btree node and 182 184 * makes sure its header fields are in cpu byteorder, byteswapping if 183 185 * necessary. 184 - * Note: node->bh must be NULL when this function called first 185 - * time. Don't forget brelse(node->bh) after last call. 186 + * Note: node->bh must be NULL when this function is called the first time. 187 + * Don't forget brelse(node->bh) after last call. 186 188 * 187 189 * On success, returns BEFS_OK and *@node contains the btree node that 188 190 * starts at @node_off, with the node->head fields in cpu byte order. ··· 242 244 * Read the superblock and rootnode of the b+tree. 243 245 * Drill down through the interior nodes using befs_find_key(). 244 246 * Once at the correct leaf node, use befs_find_key() again to get the 245 - * actuall value stored with the key. 247 + * actual value stored with the key. 246 248 */ 247 249 int 248 250 befs_btree_find(struct super_block *sb, const befs_data_stream *ds, ··· 281 283 282 284 while (!befs_leafnode(this_node)) { 283 285 res = befs_find_key(sb, this_node, key, &node_off); 284 - if (res == BEFS_BT_NOT_FOUND) 286 + /* if no key set, try the overflow node */ 287 + if (res == BEFS_BT_OVERFLOW) 285 288 node_off = this_node->head.overflow; 286 - /* if no match, go to overflow node */ 287 289 if (befs_bt_read_node(sb, ds, this_node, node_off) != BEFS_OK) { 288 290 befs_error(sb, "befs_btree_find() failed to read " 289 291 "node at %llu", node_off); ··· 291 293 } 292 294 } 293 295 294 - /* at the correct leaf node now */ 295 - 296 + /* at a leaf node now, check if it is correct */ 296 297 res = befs_find_key(sb, this_node, key, value); 297 298 298 299 brelse(this_node->bh); 299 300 kfree(this_node); 300 301 301 302 if (res != BEFS_BT_MATCH) { 302 - befs_debug(sb, "<--- %s Key %s not found", __func__, key); 303 + befs_error(sb, "<--- %s Key %s not found", __func__, key); 304 + befs_debug(sb, "<--- %s ERROR", __func__); 303 305 *value = 0; 304 306 return BEFS_BT_NOT_FOUND; 305 307 } ··· 322 324 * @findkey: Keystring to search for 323 325 * @value: If key is found, the value stored with the key is put here 324 326 * 325 - * finds exact match if one exists, and returns BEFS_BT_MATCH 326 - * If no exact match, finds first key in node that is greater 327 - * (alphabetically) than the search key and returns BEFS_BT_PARMATCH 328 - * (for partial match, I guess). Can you think of something better to 329 - * call it? 327 + * Finds exact match if one exists, and returns BEFS_BT_MATCH. 328 + * If there is no match and node's value array is too small for key, return 329 + * BEFS_BT_OVERFLOW. 330 + * If no match and node should countain this key, return BEFS_BT_NOT_FOUND. 330 331 * 331 - * If no key was a match or greater than the search key, return 332 - * BEFS_BT_NOT_FOUND. 333 - * 334 - * Use binary search instead of a linear. 332 + * Uses binary search instead of a linear. 335 333 */ 336 334 static int 337 335 befs_find_key(struct super_block *sb, struct befs_btree_node *node, ··· 342 348 343 349 befs_debug(sb, "---> %s %s", __func__, findkey); 344 350 345 - *value = 0; 346 - 347 351 findkey_len = strlen(findkey); 348 352 349 - /* if node can not contain key, just skeep this node */ 353 + /* if node can not contain key, just skip this node */ 350 354 last = node->head.all_key_count - 1; 351 355 thiskey = befs_bt_get_key(sb, node, last, &keylen); 352 356 353 357 eq = befs_compare_strings(thiskey, keylen, findkey, findkey_len); 354 358 if (eq < 0) { 355 - befs_debug(sb, "<--- %s %s not found", __func__, findkey); 356 - return BEFS_BT_NOT_FOUND; 359 + befs_debug(sb, "<--- node can't contain %s", findkey); 360 + return BEFS_BT_OVERFLOW; 357 361 } 358 362 359 363 valarray = befs_bt_valarray(node); ··· 379 387 else 380 388 first = mid + 1; 381 389 } 390 + 391 + /* return an existing value so caller can arrive to a leaf node */ 382 392 if (eq < 0) 383 393 *value = fs64_to_cpu(sb, valarray[mid + 1]); 384 394 else 385 395 *value = fs64_to_cpu(sb, valarray[mid]); 386 - befs_debug(sb, "<--- %s found %s at %d", __func__, thiskey, mid); 387 - return BEFS_BT_PARMATCH; 396 + befs_error(sb, "<--- %s %s not found", __func__, findkey); 397 + befs_debug(sb, "<--- %s ERROR", __func__); 398 + return BEFS_BT_NOT_FOUND; 388 399 } 389 400 390 401 /** ··· 400 405 * @keysize: Length of the returned key 401 406 * @value: Value stored with the returned key 402 407 * 403 - * Heres how it works: Key_no is the index of the key/value pair to 408 + * Here's how it works: Key_no is the index of the key/value pair to 404 409 * return in keybuf/value. 405 410 * Bufsize is the size of keybuf (BEFS_NAME_LEN+1 is a good size). Keysize is 406 411 * the number of characters in the key (just a convenience). ··· 417 422 { 418 423 struct befs_btree_node *this_node; 419 424 befs_btree_super bt_super; 420 - befs_off_t node_off = 0; 425 + befs_off_t node_off; 421 426 int cur_key; 422 427 fs64 *valarray; 423 428 char *keystart; ··· 462 467 while (key_sum + this_node->head.all_key_count <= key_no) { 463 468 464 469 /* no more nodes to look in: key_no is too large */ 465 - if (this_node->head.right == befs_bt_inval) { 470 + if (this_node->head.right == BEFS_BT_INVAL) { 466 471 *keysize = 0; 467 472 *value = 0; 468 473 befs_debug(sb, ··· 536 541 * @node_off: Pointer to offset of current node within datastream. Modified 537 542 * by the function. 538 543 * 539 - * 540 544 * Helper function for btree traverse. Moves the current position to the 541 545 * start of the first leaf node. 542 546 * ··· 602 608 befs_leafnode(struct befs_btree_node *node) 603 609 { 604 610 /* all interior nodes (and only interior nodes) have an overflow node */ 605 - if (node->head.overflow == befs_bt_inval) 611 + if (node->head.overflow == BEFS_BT_INVAL) 606 612 return 1; 607 613 else 608 614 return 0; ··· 709 715 * 710 716 * Returns 0 if @key1 and @key2 are equal. 711 717 * Returns >0 if @key1 is greater. 712 - * Returns <0 if @key2 is greater.. 718 + * Returns <0 if @key2 is greater. 713 719 */ 714 720 static int 715 721 befs_compare_strings(const void *key1, int keylen1,
+125 -128
fs/befs/datastream.c
··· 22 22 23 23 static int befs_find_brun_direct(struct super_block *sb, 24 24 const befs_data_stream *data, 25 - befs_blocknr_t blockno, befs_block_run * run); 25 + befs_blocknr_t blockno, befs_block_run *run); 26 26 27 27 static int befs_find_brun_indirect(struct super_block *sb, 28 28 const befs_data_stream *data, 29 29 befs_blocknr_t blockno, 30 - befs_block_run * run); 30 + befs_block_run *run); 31 31 32 32 static int befs_find_brun_dblindirect(struct super_block *sb, 33 33 const befs_data_stream *data, 34 34 befs_blocknr_t blockno, 35 - befs_block_run * run); 35 + befs_block_run *run); 36 36 37 37 /** 38 38 * befs_read_datastream - get buffer_head containing data, starting from pos. 39 39 * @sb: Filesystem superblock 40 - * @ds: datastrem to find data with 40 + * @ds: datastream to find data with 41 41 * @pos: start of data 42 42 * @off: offset of data in buffer_head->b_data 43 43 * ··· 46 46 */ 47 47 struct buffer_head * 48 48 befs_read_datastream(struct super_block *sb, const befs_data_stream *ds, 49 - befs_off_t pos, uint * off) 49 + befs_off_t pos, uint *off) 50 50 { 51 51 struct buffer_head *bh; 52 52 befs_block_run run; ··· 75 75 return bh; 76 76 } 77 77 78 - /* 78 + /** 79 + * befs_fblock2brun - give back block run for fblock 80 + * @sb: the superblock 81 + * @data: datastream to read from 82 + * @fblock: the blocknumber with the file position to find 83 + * @run: The found run is passed back through this pointer 84 + * 79 85 * Takes a file position and gives back a brun who's starting block 80 86 * is block number fblock of the file. 81 87 * ··· 94 88 */ 95 89 int 96 90 befs_fblock2brun(struct super_block *sb, const befs_data_stream *data, 97 - befs_blocknr_t fblock, befs_block_run * run) 91 + befs_blocknr_t fblock, befs_block_run *run) 98 92 { 99 93 int err; 100 94 befs_off_t pos = fblock << BEFS_SB(sb)->block_shift; ··· 121 115 /** 122 116 * befs_read_lsmylink - read long symlink from datastream. 123 117 * @sb: Filesystem superblock 124 - * @ds: Datastrem to read from 118 + * @ds: Datastream to read from 125 119 * @buff: Buffer in which to place long symlink data 126 120 * @len: Length of the long symlink in bytes 127 121 * ··· 134 128 befs_off_t bytes_read = 0; /* bytes readed */ 135 129 u16 plen; 136 130 struct buffer_head *bh; 131 + 137 132 befs_debug(sb, "---> %s length: %llu", __func__, len); 138 133 139 134 while (bytes_read < len) { ··· 190 183 metablocks += ds->indirect.len; 191 184 192 185 /* 193 - Double indir block, plus all the indirect blocks it mapps 194 - In the double-indirect range, all block runs of data are 195 - BEFS_DBLINDIR_BRUN_LEN blocks long. Therefore, we know 196 - how many data block runs are in the double-indirect region, 197 - and from that we know how many indirect blocks it takes to 198 - map them. We assume that the indirect blocks are also 199 - BEFS_DBLINDIR_BRUN_LEN blocks long. 186 + * Double indir block, plus all the indirect blocks it maps. 187 + * In the double-indirect range, all block runs of data are 188 + * BEFS_DBLINDIR_BRUN_LEN blocks long. Therefore, we know 189 + * how many data block runs are in the double-indirect region, 190 + * and from that we know how many indirect blocks it takes to 191 + * map them. We assume that the indirect blocks are also 192 + * BEFS_DBLINDIR_BRUN_LEN blocks long. 200 193 */ 201 194 if (ds->size > ds->max_indirect_range && ds->max_indirect_range != 0) { 202 195 uint dbl_bytes; ··· 219 212 return blocks; 220 213 } 221 214 222 - /* 223 - Finds the block run that starts at file block number blockno 224 - in the file represented by the datastream data, if that 225 - blockno is in the direct region of the datastream. 226 - 227 - sb: the superblock 228 - data: the datastream 229 - blockno: the blocknumber to find 230 - run: The found run is passed back through this pointer 231 - 232 - Return value is BEFS_OK if the blockrun is found, BEFS_ERR 233 - otherwise. 234 - 235 - Algorithm: 236 - Linear search. Checks each element of array[] to see if it 237 - contains the blockno-th filesystem block. This is necessary 238 - because the block runs map variable amounts of data. Simply 239 - keeps a count of the number of blocks searched so far (sum), 240 - incrementing this by the length of each block run as we come 241 - across it. Adds sum to *count before returning (this is so 242 - you can search multiple arrays that are logicaly one array, 243 - as in the indirect region code). 244 - 245 - When/if blockno is found, if blockno is inside of a block 246 - run as stored on disk, we offset the start and length members 247 - of the block run, so that blockno is the start and len is 248 - still valid (the run ends in the same place). 249 - 250 - 2001-11-15 Will Dyson 251 - */ 215 + /** 216 + * befs_find_brun_direct - find a direct block run in the datastream 217 + * @sb: the superblock 218 + * @data: the datastream 219 + * @blockno: the blocknumber to find 220 + * @run: The found run is passed back through this pointer 221 + * 222 + * Finds the block run that starts at file block number blockno 223 + * in the file represented by the datastream data, if that 224 + * blockno is in the direct region of the datastream. 225 + * 226 + * Return value is BEFS_OK if the blockrun is found, BEFS_ERR 227 + * otherwise. 228 + * 229 + * Algorithm: 230 + * Linear search. Checks each element of array[] to see if it 231 + * contains the blockno-th filesystem block. This is necessary 232 + * because the block runs map variable amounts of data. Simply 233 + * keeps a count of the number of blocks searched so far (sum), 234 + * incrementing this by the length of each block run as we come 235 + * across it. Adds sum to *count before returning (this is so 236 + * you can search multiple arrays that are logicaly one array, 237 + * as in the indirect region code). 238 + * 239 + * When/if blockno is found, if blockno is inside of a block 240 + * run as stored on disk, we offset the start and length members 241 + * of the block run, so that blockno is the start and len is 242 + * still valid (the run ends in the same place). 243 + */ 252 244 static int 253 245 befs_find_brun_direct(struct super_block *sb, const befs_data_stream *data, 254 - befs_blocknr_t blockno, befs_block_run * run) 246 + befs_blocknr_t blockno, befs_block_run *run) 255 247 { 256 248 int i; 257 249 const befs_block_run *array = data->direct; 258 250 befs_blocknr_t sum; 259 - befs_blocknr_t max_block = 260 - data->max_direct_range >> BEFS_SB(sb)->block_shift; 261 251 262 252 befs_debug(sb, "---> %s, find %lu", __func__, (unsigned long)blockno); 263 - 264 - if (blockno > max_block) { 265 - befs_error(sb, "%s passed block outside of direct region", 266 - __func__); 267 - return BEFS_ERR; 268 - } 269 253 270 254 for (i = 0, sum = 0; i < BEFS_NUM_DIRECT_BLOCKS; 271 255 sum += array[i].len, i++) { 272 256 if (blockno >= sum && blockno < sum + (array[i].len)) { 273 257 int offset = blockno - sum; 258 + 274 259 run->allocation_group = array[i].allocation_group; 275 260 run->start = array[i].start + offset; 276 261 run->len = array[i].len - offset; ··· 274 275 } 275 276 } 276 277 278 + befs_error(sb, "%s failed to find file block %lu", __func__, 279 + (unsigned long)blockno); 277 280 befs_debug(sb, "---> %s ERROR", __func__); 278 281 return BEFS_ERR; 279 282 } 280 283 281 - /* 282 - Finds the block run that starts at file block number blockno 283 - in the file represented by the datastream data, if that 284 - blockno is in the indirect region of the datastream. 285 - 286 - sb: the superblock 287 - data: the datastream 288 - blockno: the blocknumber to find 289 - run: The found run is passed back through this pointer 290 - 291 - Return value is BEFS_OK if the blockrun is found, BEFS_ERR 292 - otherwise. 293 - 294 - Algorithm: 295 - For each block in the indirect run of the datastream, read 296 - it in and search through it for search_blk. 297 - 298 - XXX: 299 - Really should check to make sure blockno is inside indirect 300 - region. 301 - 302 - 2001-11-15 Will Dyson 303 - */ 284 + /** 285 + * befs_find_brun_indirect - find a block run in the datastream 286 + * @sb: the superblock 287 + * @data: the datastream 288 + * @blockno: the blocknumber to find 289 + * @run: The found run is passed back through this pointer 290 + * 291 + * Finds the block run that starts at file block number blockno 292 + * in the file represented by the datastream data, if that 293 + * blockno is in the indirect region of the datastream. 294 + * 295 + * Return value is BEFS_OK if the blockrun is found, BEFS_ERR 296 + * otherwise. 297 + * 298 + * Algorithm: 299 + * For each block in the indirect run of the datastream, read 300 + * it in and search through it for search_blk. 301 + * 302 + * XXX: 303 + * Really should check to make sure blockno is inside indirect 304 + * region. 305 + */ 304 306 static int 305 307 befs_find_brun_indirect(struct super_block *sb, 306 308 const befs_data_stream *data, 307 309 befs_blocknr_t blockno, 308 - befs_block_run * run) 310 + befs_block_run *run) 309 311 { 310 312 int i, j; 311 313 befs_blocknr_t sum = 0; ··· 326 326 327 327 /* Examine blocks of the indirect run one at a time */ 328 328 for (i = 0; i < indirect.len; i++) { 329 - indirblock = befs_bread(sb, indirblockno + i); 329 + indirblock = sb_bread(sb, indirblockno + i); 330 330 if (indirblock == NULL) { 331 - befs_debug(sb, "---> %s failed to read " 331 + befs_error(sb, "---> %s failed to read " 332 332 "disk block %lu from the indirect brun", 333 333 __func__, (unsigned long)indirblockno + i); 334 + befs_debug(sb, "<--- %s ERROR", __func__); 334 335 return BEFS_ERR; 335 336 } 336 337 ··· 371 370 return BEFS_ERR; 372 371 } 373 372 374 - /* 375 - Finds the block run that starts at file block number blockno 376 - in the file represented by the datastream data, if that 377 - blockno is in the double-indirect region of the datastream. 378 - 379 - sb: the superblock 380 - data: the datastream 381 - blockno: the blocknumber to find 382 - run: The found run is passed back through this pointer 383 - 384 - Return value is BEFS_OK if the blockrun is found, BEFS_ERR 385 - otherwise. 386 - 387 - Algorithm: 388 - The block runs in the double-indirect region are different. 389 - They are always allocated 4 fs blocks at a time, so each 390 - block run maps a constant amount of file data. This means 391 - that we can directly calculate how many block runs into the 392 - double-indirect region we need to go to get to the one that 393 - maps a particular filesystem block. 394 - 395 - We do this in two stages. First we calculate which of the 396 - inode addresses in the double-indirect block will point us 397 - to the indirect block that contains the mapping for the data, 398 - then we calculate which of the inode addresses in that 399 - indirect block maps the data block we are after. 400 - 401 - Oh, and once we've done that, we actually read in the blocks 402 - that contain the inode addresses we calculated above. Even 403 - though the double-indirect run may be several blocks long, 404 - we can calculate which of those blocks will contain the index 405 - we are after and only read that one. We then follow it to 406 - the indirect block and perform a similar process to find 407 - the actual block run that maps the data block we are interested 408 - in. 409 - 410 - Then we offset the run as in befs_find_brun_array() and we are 411 - done. 412 - 413 - 2001-11-15 Will Dyson 414 - */ 373 + /** 374 + * befs_find_brun_dblindirect - find a block run in the datastream 375 + * @sb: the superblock 376 + * @data: the datastream 377 + * @blockno: the blocknumber to find 378 + * @run: The found run is passed back through this pointer 379 + * 380 + * Finds the block run that starts at file block number blockno 381 + * in the file represented by the datastream data, if that 382 + * blockno is in the double-indirect region of the datastream. 383 + * 384 + * Return value is BEFS_OK if the blockrun is found, BEFS_ERR 385 + * otherwise. 386 + * 387 + * Algorithm: 388 + * The block runs in the double-indirect region are different. 389 + * They are always allocated 4 fs blocks at a time, so each 390 + * block run maps a constant amount of file data. This means 391 + * that we can directly calculate how many block runs into the 392 + * double-indirect region we need to go to get to the one that 393 + * maps a particular filesystem block. 394 + * 395 + * We do this in two stages. First we calculate which of the 396 + * inode addresses in the double-indirect block will point us 397 + * to the indirect block that contains the mapping for the data, 398 + * then we calculate which of the inode addresses in that 399 + * indirect block maps the data block we are after. 400 + * 401 + * Oh, and once we've done that, we actually read in the blocks 402 + * that contain the inode addresses we calculated above. Even 403 + * though the double-indirect run may be several blocks long, 404 + * we can calculate which of those blocks will contain the index 405 + * we are after and only read that one. We then follow it to 406 + * the indirect block and perform a similar process to find 407 + * the actual block run that maps the data block we are interested 408 + * in. 409 + * 410 + * Then we offset the run as in befs_find_brun_array() and we are 411 + * done. 412 + */ 415 413 static int 416 414 befs_find_brun_dblindirect(struct super_block *sb, 417 415 const befs_data_stream *data, 418 416 befs_blocknr_t blockno, 419 - befs_block_run * run) 417 + befs_block_run *run) 420 418 { 421 419 int dblindir_indx; 422 420 int indir_indx; ··· 430 430 struct buffer_head *indir_block; 431 431 befs_block_run indir_run; 432 432 befs_disk_inode_addr *iaddr_array; 433 - struct befs_sb_info *befs_sb = BEFS_SB(sb); 434 433 435 434 befs_blocknr_t indir_start_blk = 436 - data->max_indirect_range >> befs_sb->block_shift; 435 + data->max_indirect_range >> BEFS_SB(sb)->block_shift; 437 436 438 437 off_t dbl_indir_off = blockno - indir_start_blk; 439 438 ··· 470 471 } 471 472 472 473 dbl_indir_block = 473 - befs_bread(sb, iaddr2blockno(sb, &data->double_indirect) + 474 + sb_bread(sb, iaddr2blockno(sb, &data->double_indirect) + 474 475 dbl_which_block); 475 476 if (dbl_indir_block == NULL) { 476 477 befs_error(sb, "%s couldn't read the " ··· 478 479 (unsigned long) 479 480 iaddr2blockno(sb, &data->double_indirect) + 480 481 dbl_which_block); 481 - brelse(dbl_indir_block); 482 482 return BEFS_ERR; 483 483 } 484 484 ··· 497 499 } 498 500 499 501 indir_block = 500 - befs_bread(sb, iaddr2blockno(sb, &indir_run) + which_block); 502 + sb_bread(sb, iaddr2blockno(sb, &indir_run) + which_block); 501 503 if (indir_block == NULL) { 502 504 befs_error(sb, "%s couldn't read the indirect block " 503 505 "at blockno %lu", __func__, (unsigned long) 504 506 iaddr2blockno(sb, &indir_run) + which_block); 505 - brelse(indir_block); 506 507 return BEFS_ERR; 507 508 } 508 509
+1
fs/befs/debug.c
··· 169 169 170 170 befs_debug(sb, " num_blocks %llu", fs64_to_cpu(sb, sup->num_blocks)); 171 171 befs_debug(sb, " used_blocks %llu", fs64_to_cpu(sb, sup->used_blocks)); 172 + befs_debug(sb, " inode_size %u", fs32_to_cpu(sb, sup->inode_size)); 172 173 173 174 befs_debug(sb, " magic2 %08x", fs32_to_cpu(sb, sup->magic2)); 174 175 befs_debug(sb, " blocks_per_ag %u",
+1 -25
fs/befs/io.c
··· 27 27 befs_bread_iaddr(struct super_block *sb, befs_inode_addr iaddr) 28 28 { 29 29 struct buffer_head *bh; 30 - befs_blocknr_t block = 0; 30 + befs_blocknr_t block; 31 31 struct befs_sb_info *befs_sb = BEFS_SB(sb); 32 32 33 33 befs_debug(sb, "---> Enter %s " ··· 53 53 } 54 54 55 55 befs_debug(sb, "<--- %s", __func__); 56 - return bh; 57 - 58 - error: 59 - befs_debug(sb, "<--- %s ERROR", __func__); 60 - return NULL; 61 - } 62 - 63 - struct buffer_head * 64 - befs_bread(struct super_block *sb, befs_blocknr_t block) 65 - { 66 - struct buffer_head *bh; 67 - 68 - befs_debug(sb, "---> Enter %s %lu", __func__, (unsigned long)block); 69 - 70 - bh = sb_bread(sb, block); 71 - 72 - if (bh == NULL) { 73 - befs_error(sb, "Failed to read block %lu", 74 - (unsigned long)block); 75 - goto error; 76 - } 77 - 78 - befs_debug(sb, "<--- %s", __func__); 79 - 80 56 return bh; 81 57 82 58 error:
-2
fs/befs/io.h
··· 5 5 struct buffer_head *befs_bread_iaddr(struct super_block *sb, 6 6 befs_inode_addr iaddr); 7 7 8 - struct buffer_head *befs_bread(struct super_block *sb, befs_blocknr_t block); 9 -
+65 -67
fs/befs/linuxvfs.c
··· 120 120 struct super_block *sb = inode->i_sb; 121 121 befs_data_stream *ds = &BEFS_I(inode)->i_data.ds; 122 122 befs_block_run run = BAD_IADDR; 123 - int res = 0; 123 + int res; 124 124 ulong disk_off; 125 125 126 126 befs_debug(sb, "---> befs_get_block() for inode %lu, block %ld", ··· 179 179 kfree(utfname); 180 180 181 181 } else { 182 - ret = befs_btree_find(sb, ds, dentry->d_name.name, &offset); 182 + ret = befs_btree_find(sb, ds, name, &offset); 183 183 } 184 184 185 185 if (ret == BEFS_BT_NOT_FOUND) { 186 186 befs_debug(sb, "<--- %s %pd not found", __func__, dentry); 187 + d_add(dentry, NULL); 187 188 return ERR_PTR(-ENOENT); 188 189 189 190 } else if (ret != BEFS_OK || offset == 0) { 190 - befs_warning(sb, "<--- %s Error", __func__); 191 + befs_error(sb, "<--- %s Error", __func__); 191 192 return ERR_PTR(-ENODATA); 192 193 } 193 194 ··· 212 211 befs_off_t value; 213 212 int result; 214 213 size_t keysize; 215 - unsigned char d_type; 216 214 char keybuf[BEFS_NAME_LEN + 1]; 217 215 218 216 befs_debug(sb, "---> %s name %pD, inode %ld, ctx->pos %lld", 219 217 __func__, file, inode->i_ino, ctx->pos); 220 218 221 - more: 222 - result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1, 223 - keybuf, &keysize, &value); 219 + while (1) { 220 + result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1, 221 + keybuf, &keysize, &value); 224 222 225 - if (result == BEFS_ERR) { 226 - befs_debug(sb, "<--- %s ERROR", __func__); 227 - befs_error(sb, "IO error reading %pD (inode %lu)", 228 - file, inode->i_ino); 229 - return -EIO; 230 - 231 - } else if (result == BEFS_BT_END) { 232 - befs_debug(sb, "<--- %s END", __func__); 233 - return 0; 234 - 235 - } else if (result == BEFS_BT_EMPTY) { 236 - befs_debug(sb, "<--- %s Empty directory", __func__); 237 - return 0; 238 - } 239 - 240 - d_type = DT_UNKNOWN; 241 - 242 - /* Convert to NLS */ 243 - if (BEFS_SB(sb)->nls) { 244 - char *nlsname; 245 - int nlsnamelen; 246 - result = 247 - befs_utf2nls(sb, keybuf, keysize, &nlsname, &nlsnamelen); 248 - if (result < 0) { 223 + if (result == BEFS_ERR) { 249 224 befs_debug(sb, "<--- %s ERROR", __func__); 250 - return result; 225 + befs_error(sb, "IO error reading %pD (inode %lu)", 226 + file, inode->i_ino); 227 + return -EIO; 228 + 229 + } else if (result == BEFS_BT_END) { 230 + befs_debug(sb, "<--- %s END", __func__); 231 + return 0; 232 + 233 + } else if (result == BEFS_BT_EMPTY) { 234 + befs_debug(sb, "<--- %s Empty directory", __func__); 235 + return 0; 251 236 } 252 - if (!dir_emit(ctx, nlsname, nlsnamelen, 253 - (ino_t) value, d_type)) { 237 + 238 + /* Convert to NLS */ 239 + if (BEFS_SB(sb)->nls) { 240 + char *nlsname; 241 + int nlsnamelen; 242 + 243 + result = 244 + befs_utf2nls(sb, keybuf, keysize, &nlsname, 245 + &nlsnamelen); 246 + if (result < 0) { 247 + befs_debug(sb, "<--- %s ERROR", __func__); 248 + return result; 249 + } 250 + if (!dir_emit(ctx, nlsname, nlsnamelen, 251 + (ino_t) value, DT_UNKNOWN)) { 252 + kfree(nlsname); 253 + return 0; 254 + } 254 255 kfree(nlsname); 255 - return 0; 256 + } else { 257 + if (!dir_emit(ctx, keybuf, keysize, 258 + (ino_t) value, DT_UNKNOWN)) 259 + return 0; 256 260 } 257 - kfree(nlsname); 258 - } else { 259 - if (!dir_emit(ctx, keybuf, keysize, 260 - (ino_t) value, d_type)) 261 - return 0; 261 + ctx->pos++; 262 262 } 263 - ctx->pos++; 264 - goto more; 265 263 } 266 264 267 265 static struct inode * ··· 299 299 struct befs_sb_info *befs_sb = BEFS_SB(sb); 300 300 struct befs_inode_info *befs_ino; 301 301 struct inode *inode; 302 - long ret = -EIO; 303 302 304 303 befs_debug(sb, "---> %s inode = %lu", __func__, ino); 305 304 ··· 317 318 befs_ino->i_inode_num.allocation_group, 318 319 befs_ino->i_inode_num.start, befs_ino->i_inode_num.len); 319 320 320 - bh = befs_bread(sb, inode->i_ino); 321 + bh = sb_bread(sb, inode->i_ino); 321 322 if (!bh) { 322 323 befs_error(sb, "unable to read inode block - " 323 324 "inode = %lu", inode->i_ino); ··· 420 421 unacquire_none: 421 422 iget_failed(inode); 422 423 befs_debug(sb, "<--- %s - Bad inode", __func__); 423 - return ERR_PTR(ret); 424 + return ERR_PTR(-EIO); 424 425 } 425 426 426 427 /* Initialize the inode cache. Called at fs setup. ··· 435 436 0, (SLAB_RECLAIM_ACCOUNT| 436 437 SLAB_MEM_SPREAD|SLAB_ACCOUNT), 437 438 init_once); 438 - if (befs_inode_cachep == NULL) { 439 - pr_err("%s: Couldn't initialize inode slabcache\n", __func__); 439 + if (befs_inode_cachep == NULL) 440 440 return -ENOMEM; 441 - } 441 + 442 442 return 0; 443 443 } 444 444 ··· 522 524 523 525 *out = result = kmalloc(maxlen, GFP_NOFS); 524 526 if (!*out) { 525 - befs_error(sb, "%s cannot allocate memory", __func__); 526 - *out_len = 0; 527 527 return -ENOMEM; 528 528 } 529 529 ··· 600 604 601 605 *out = result = kmalloc(maxlen, GFP_NOFS); 602 606 if (!*out) { 603 - befs_error(sb, "%s cannot allocate memory", __func__); 604 607 *out_len = 0; 605 608 return -ENOMEM; 606 609 } ··· 632 637 return -EILSEQ; 633 638 } 634 639 635 - /** 636 - * Use the 637 - * 638 - */ 639 640 enum { 640 641 Opt_uid, Opt_gid, Opt_charset, Opt_debug, Opt_err, 641 642 }; ··· 751 760 long ret = -EINVAL; 752 761 const unsigned long sb_block = 0; 753 762 const off_t x86_sb_off = 512; 763 + int blocksize; 754 764 755 765 save_mount_options(sb, data); 756 766 757 767 sb->s_fs_info = kzalloc(sizeof(*befs_sb), GFP_KERNEL); 758 - if (sb->s_fs_info == NULL) { 759 - pr_err("(%s): Unable to allocate memory for private " 760 - "portion of superblock. Bailing.\n", sb->s_id); 768 + if (sb->s_fs_info == NULL) 761 769 goto unacquire_none; 762 - } 770 + 763 771 befs_sb = BEFS_SB(sb); 764 772 765 773 if (!parse_options((char *) data, &befs_sb->mount_opts)) { 766 - befs_error(sb, "cannot parse mount options"); 774 + if (!silent) 775 + befs_error(sb, "cannot parse mount options"); 767 776 goto unacquire_priv_sbp; 768 777 } 769 778 ··· 784 793 * least 1k to get the second 512 bytes of the volume. 785 794 * -WD 10-26-01 786 795 */ 787 - sb_min_blocksize(sb, 1024); 796 + blocksize = sb_min_blocksize(sb, 1024); 797 + if (!blocksize) { 798 + if (!silent) 799 + befs_error(sb, "unable to set blocksize"); 800 + goto unacquire_priv_sbp; 801 + } 788 802 789 803 if (!(bh = sb_bread(sb, sb_block))) { 790 - befs_error(sb, "unable to read superblock"); 804 + if (!silent) 805 + befs_error(sb, "unable to read superblock"); 791 806 goto unacquire_priv_sbp; 792 807 } 793 808 ··· 817 820 brelse(bh); 818 821 819 822 if( befs_sb->num_blocks > ~((sector_t)0) ) { 820 - befs_error(sb, "blocks count: %llu " 821 - "is larger than the host can use", 822 - befs_sb->num_blocks); 823 + if (!silent) 824 + befs_error(sb, "blocks count: %llu is larger than the host can use", 825 + befs_sb->num_blocks); 823 826 goto unacquire_priv_sbp; 824 827 } 825 828 ··· 838 841 } 839 842 sb->s_root = d_make_root(root); 840 843 if (!sb->s_root) { 841 - befs_error(sb, "get root inode failed"); 844 + if (!silent) 845 + befs_error(sb, "get root inode failed"); 842 846 goto unacquire_priv_sbp; 843 847 } 844 848 ··· 868 870 unacquire_priv_sbp: 869 871 kfree(befs_sb->mount_opts.iocharset); 870 872 kfree(sb->s_fs_info); 873 + sb->s_fs_info = NULL; 871 874 872 875 unacquire_none: 873 - sb->s_fs_info = NULL; 874 876 return ret; 875 877 } 876 878
+21 -15
fs/befs/super.c
··· 13 13 #include "befs.h" 14 14 #include "super.h" 15 15 16 - /** 17 - * load_befs_sb -- Read from disk and properly byteswap all the fields 16 + /* 17 + * befs_load_sb -- Read from disk and properly byteswap all the fields 18 18 * of the befs superblock 19 - * 20 - * 21 - * 22 - * 23 19 */ 24 20 int 25 - befs_load_sb(struct super_block *sb, befs_super_block * disk_sb) 21 + befs_load_sb(struct super_block *sb, befs_super_block *disk_sb) 26 22 { 27 23 struct befs_sb_info *befs_sb = BEFS_SB(sb); 28 24 29 25 /* Check the byte order of the filesystem */ 30 26 if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE) 31 - befs_sb->byte_order = BEFS_BYTESEX_LE; 27 + befs_sb->byte_order = BEFS_BYTESEX_LE; 32 28 else if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_BE) 33 - befs_sb->byte_order = BEFS_BYTESEX_BE; 29 + befs_sb->byte_order = BEFS_BYTESEX_BE; 34 30 35 31 befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1); 36 32 befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2); ··· 40 44 befs_sb->blocks_per_ag = fs32_to_cpu(sb, disk_sb->blocks_per_ag); 41 45 befs_sb->ag_shift = fs32_to_cpu(sb, disk_sb->ag_shift); 42 46 befs_sb->num_ags = fs32_to_cpu(sb, disk_sb->num_ags); 47 + 48 + befs_sb->flags = fs32_to_cpu(sb, disk_sb->flags); 43 49 44 50 befs_sb->log_blocks = fsrun_to_cpu(sb, disk_sb->log_blocks); 45 51 befs_sb->log_start = fs64_to_cpu(sb, disk_sb->log_start); ··· 82 84 } 83 85 84 86 if (befs_sb->block_size > PAGE_SIZE) { 85 - befs_error(sb, "blocksize(%u) cannot be larger" 87 + befs_error(sb, "blocksize(%u) cannot be larger " 86 88 "than system pagesize(%lu)", befs_sb->block_size, 87 89 PAGE_SIZE); 88 90 return BEFS_ERR; 89 91 } 90 92 91 93 /* 92 - * block_shift and block_size encode the same information 93 - * in different ways as a consistency check. 94 + * block_shift and block_size encode the same information 95 + * in different ways as a consistency check. 94 96 */ 95 97 96 98 if ((1 << befs_sb->block_shift) != befs_sb->block_size) { ··· 99 101 return BEFS_ERR; 100 102 } 101 103 102 - if (befs_sb->log_start != befs_sb->log_end) { 104 + 105 + /* ag_shift also encodes the same information as blocks_per_ag in a 106 + * different way, non-fatal consistency check 107 + */ 108 + if ((1 << befs_sb->ag_shift) != befs_sb->blocks_per_ag) 109 + befs_error(sb, "ag_shift disagrees with blocks_per_ag."); 110 + 111 + if (befs_sb->log_start != befs_sb->log_end || 112 + befs_sb->flags == BEFS_DIRTY) { 103 113 befs_error(sb, "Filesystem not clean! There are blocks in the " 104 - "journal. You must boot into BeOS and mount this volume " 105 - "to make it clean."); 114 + "journal. You must boot into BeOS and mount this " 115 + "volume to make it clean."); 106 116 return BEFS_ERR; 107 117 } 108 118