524 static int
bdev_set(struct inode *inode, void *data) 525 { 526 BDEV_I(inode)->bdev.bd_dev = *(dev_t *)data; 527 return 0; 528 } 529 530 static LIST_HEAD(all_bdevs); 531 532 struct block_device *bdget(dev_t dev) 533 { 534 struct block_device *bdev; 535 struct inode *inode; 536 537 inode = iget5_locked(blockdev_superblock, hash(dev), 538 bdev_test, bdev_set, &dev); 539 540 if (!inode) 541 return NULL; 542 543 bdev = &BDEV_I(inode)->bdev; 544 545 if (inode->i_state & I_NEW) { 546 bdev->bd_contains = NULL; 547 bdev->bd_inode = inode; 548 bdev->bd_block_size = (1 << inode->i_blkbits); 549 bdev->bd_part_count = 0; 550 bdev->bd_invalidated = 0; 551 inode->i_mode = S_IFBLK; 552 inode->i_rdev = dev; 553 inode->i_bdev = bdev; 554 inode->i_data.a_ops = &def_blk_aops; 555 mapping_set_gfp_mask(&inode->i_data, GFP_USER); 556 inode->i_data.backing_dev_info = &default_backing_dev_info; 557 spin_lock(&bdev_lock); 558 list_add(&bdev->bd_list, &all_bdevs); 559 spin_unlock(&bdev_lock); 560 unlock_new_inode(inode); 561 } 562 return bdev; 563 } 564 565 EXPORT_SYMBOL(bdget); 566 |