diff options
Diffstat (limited to 'fs/cramfs')
-rw-r--r-- | fs/cramfs/inode.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c index 8ad52f5bf255..acc1b2c10a86 100644 --- a/fs/cramfs/inode.c +++ b/fs/cramfs/inode.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/cramfs_fs_sb.h> | 22 | #include <linux/cramfs_fs_sb.h> |
23 | #include <linux/buffer_head.h> | 23 | #include <linux/buffer_head.h> |
24 | #include <linux/vfs.h> | 24 | #include <linux/vfs.h> |
25 | #include <linux/mutex.h> | ||
25 | #include <asm/semaphore.h> | 26 | #include <asm/semaphore.h> |
26 | 27 | ||
27 | #include <asm/uaccess.h> | 28 | #include <asm/uaccess.h> |
@@ -31,7 +32,7 @@ static struct inode_operations cramfs_dir_inode_operations; | |||
31 | static struct file_operations cramfs_directory_operations; | 32 | static struct file_operations cramfs_directory_operations; |
32 | static struct address_space_operations cramfs_aops; | 33 | static struct address_space_operations cramfs_aops; |
33 | 34 | ||
34 | static DECLARE_MUTEX(read_mutex); | 35 | static DEFINE_MUTEX(read_mutex); |
35 | 36 | ||
36 | 37 | ||
37 | /* These two macros may change in future, to provide better st_ino | 38 | /* These two macros may change in future, to provide better st_ino |
@@ -250,20 +251,20 @@ static int cramfs_fill_super(struct super_block *sb, void *data, int silent) | |||
250 | memset(sbi, 0, sizeof(struct cramfs_sb_info)); | 251 | memset(sbi, 0, sizeof(struct cramfs_sb_info)); |
251 | 252 | ||
252 | /* Invalidate the read buffers on mount: think disk change.. */ | 253 | /* Invalidate the read buffers on mount: think disk change.. */ |
253 | down(&read_mutex); | 254 | mutex_lock(&read_mutex); |
254 | for (i = 0; i < READ_BUFFERS; i++) | 255 | for (i = 0; i < READ_BUFFERS; i++) |
255 | buffer_blocknr[i] = -1; | 256 | buffer_blocknr[i] = -1; |
256 | 257 | ||
257 | /* Read the first block and get the superblock from it */ | 258 | /* Read the first block and get the superblock from it */ |
258 | memcpy(&super, cramfs_read(sb, 0, sizeof(super)), sizeof(super)); | 259 | memcpy(&super, cramfs_read(sb, 0, sizeof(super)), sizeof(super)); |
259 | up(&read_mutex); | 260 | mutex_unlock(&read_mutex); |
260 | 261 | ||
261 | /* Do sanity checks on the superblock */ | 262 | /* Do sanity checks on the superblock */ |
262 | if (super.magic != CRAMFS_MAGIC) { | 263 | if (super.magic != CRAMFS_MAGIC) { |
263 | /* check at 512 byte offset */ | 264 | /* check at 512 byte offset */ |
264 | down(&read_mutex); | 265 | mutex_lock(&read_mutex); |
265 | memcpy(&super, cramfs_read(sb, 512, sizeof(super)), sizeof(super)); | 266 | memcpy(&super, cramfs_read(sb, 512, sizeof(super)), sizeof(super)); |
266 | up(&read_mutex); | 267 | mutex_unlock(&read_mutex); |
267 | if (super.magic != CRAMFS_MAGIC) { | 268 | if (super.magic != CRAMFS_MAGIC) { |
268 | if (!silent) | 269 | if (!silent) |
269 | printk(KERN_ERR "cramfs: wrong magic\n"); | 270 | printk(KERN_ERR "cramfs: wrong magic\n"); |
@@ -366,7 +367,7 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
366 | mode_t mode; | 367 | mode_t mode; |
367 | int namelen, error; | 368 | int namelen, error; |
368 | 369 | ||
369 | down(&read_mutex); | 370 | mutex_lock(&read_mutex); |
370 | de = cramfs_read(sb, OFFSET(inode) + offset, sizeof(*de)+256); | 371 | de = cramfs_read(sb, OFFSET(inode) + offset, sizeof(*de)+256); |
371 | name = (char *)(de+1); | 372 | name = (char *)(de+1); |
372 | 373 | ||
@@ -379,7 +380,7 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
379 | memcpy(buf, name, namelen); | 380 | memcpy(buf, name, namelen); |
380 | ino = CRAMINO(de); | 381 | ino = CRAMINO(de); |
381 | mode = de->mode; | 382 | mode = de->mode; |
382 | up(&read_mutex); | 383 | mutex_unlock(&read_mutex); |
383 | nextoffset = offset + sizeof(*de) + namelen; | 384 | nextoffset = offset + sizeof(*de) + namelen; |
384 | for (;;) { | 385 | for (;;) { |
385 | if (!namelen) { | 386 | if (!namelen) { |
@@ -410,7 +411,7 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s | |||
410 | unsigned int offset = 0; | 411 | unsigned int offset = 0; |
411 | int sorted; | 412 | int sorted; |
412 | 413 | ||
413 | down(&read_mutex); | 414 | mutex_lock(&read_mutex); |
414 | sorted = CRAMFS_SB(dir->i_sb)->flags & CRAMFS_FLAG_SORTED_DIRS; | 415 | sorted = CRAMFS_SB(dir->i_sb)->flags & CRAMFS_FLAG_SORTED_DIRS; |
415 | while (offset < dir->i_size) { | 416 | while (offset < dir->i_size) { |
416 | struct cramfs_inode *de; | 417 | struct cramfs_inode *de; |
@@ -433,7 +434,7 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s | |||
433 | 434 | ||
434 | for (;;) { | 435 | for (;;) { |
435 | if (!namelen) { | 436 | if (!namelen) { |
436 | up(&read_mutex); | 437 | mutex_unlock(&read_mutex); |
437 | return ERR_PTR(-EIO); | 438 | return ERR_PTR(-EIO); |
438 | } | 439 | } |
439 | if (name[namelen-1]) | 440 | if (name[namelen-1]) |
@@ -447,7 +448,7 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s | |||
447 | continue; | 448 | continue; |
448 | if (!retval) { | 449 | if (!retval) { |
449 | struct cramfs_inode entry = *de; | 450 | struct cramfs_inode entry = *de; |
450 | up(&read_mutex); | 451 | mutex_unlock(&read_mutex); |
451 | d_add(dentry, get_cramfs_inode(dir->i_sb, &entry)); | 452 | d_add(dentry, get_cramfs_inode(dir->i_sb, &entry)); |
452 | return NULL; | 453 | return NULL; |
453 | } | 454 | } |
@@ -455,7 +456,7 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s | |||
455 | if (sorted) | 456 | if (sorted) |
456 | break; | 457 | break; |
457 | } | 458 | } |
458 | up(&read_mutex); | 459 | mutex_unlock(&read_mutex); |
459 | d_add(dentry, NULL); | 460 | d_add(dentry, NULL); |
460 | return NULL; | 461 | return NULL; |
461 | } | 462 | } |
@@ -474,21 +475,21 @@ static int cramfs_readpage(struct file *file, struct page * page) | |||
474 | u32 start_offset, compr_len; | 475 | u32 start_offset, compr_len; |
475 | 476 | ||
476 | start_offset = OFFSET(inode) + maxblock*4; | 477 | start_offset = OFFSET(inode) + maxblock*4; |
477 | down(&read_mutex); | 478 | mutex_lock(&read_mutex); |
478 | if (page->index) | 479 | if (page->index) |
479 | start_offset = *(u32 *) cramfs_read(sb, blkptr_offset-4, 4); | 480 | start_offset = *(u32 *) cramfs_read(sb, blkptr_offset-4, 4); |
480 | compr_len = (*(u32 *) cramfs_read(sb, blkptr_offset, 4) - start_offset); | 481 | compr_len = (*(u32 *) cramfs_read(sb, blkptr_offset, 4) - start_offset); |
481 | up(&read_mutex); | 482 | mutex_unlock(&read_mutex); |
482 | pgdata = kmap(page); | 483 | pgdata = kmap(page); |
483 | if (compr_len == 0) | 484 | if (compr_len == 0) |
484 | ; /* hole */ | 485 | ; /* hole */ |
485 | else { | 486 | else { |
486 | down(&read_mutex); | 487 | mutex_lock(&read_mutex); |
487 | bytes_filled = cramfs_uncompress_block(pgdata, | 488 | bytes_filled = cramfs_uncompress_block(pgdata, |
488 | PAGE_CACHE_SIZE, | 489 | PAGE_CACHE_SIZE, |
489 | cramfs_read(sb, start_offset, compr_len), | 490 | cramfs_read(sb, start_offset, compr_len), |
490 | compr_len); | 491 | compr_len); |
491 | up(&read_mutex); | 492 | mutex_unlock(&read_mutex); |
492 | } | 493 | } |
493 | } else | 494 | } else |
494 | pgdata = kmap(page); | 495 | pgdata = kmap(page); |