2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/fs/ufs/util.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998
|
|
|
|
* Daniel Pirkl <daniel.pirkl@email.cz>
|
|
|
|
* Charles University, Faculty of Mathematics and Physics
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
|
2008-02-08 20:21:31 +08:00
|
|
|
#include "ufs_fs.h"
|
2007-10-17 14:26:51 +08:00
|
|
|
#include "ufs.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "swab.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
struct ufs_buffer_head * _ubh_bread_ (struct ufs_sb_private_info * uspi,
|
|
|
|
struct super_block *sb, u64 fragment, u64 size)
|
|
|
|
{
|
|
|
|
struct ufs_buffer_head * ubh;
|
|
|
|
unsigned i, j ;
|
|
|
|
u64 count = 0;
|
|
|
|
if (size & ~uspi->s_fmask)
|
|
|
|
return NULL;
|
|
|
|
count = size >> uspi->s_fshift;
|
|
|
|
if (count > UFS_MAXFRAG)
|
|
|
|
return NULL;
|
2013-03-12 13:37:05 +08:00
|
|
|
ubh = kmalloc (sizeof (struct ufs_buffer_head), GFP_NOFS);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ubh)
|
|
|
|
return NULL;
|
|
|
|
ubh->fragment = fragment;
|
|
|
|
ubh->count = count;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
if (!(ubh->bh[i] = sb_bread(sb, fragment + i)))
|
|
|
|
goto failed;
|
|
|
|
for (; i < UFS_MAXFRAG; i++)
|
|
|
|
ubh->bh[i] = NULL;
|
|
|
|
return ubh;
|
|
|
|
failed:
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
brelse (ubh->bh[j]);
|
|
|
|
kfree(ubh);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ufs_buffer_head * ubh_bread_uspi (struct ufs_sb_private_info * uspi,
|
|
|
|
struct super_block *sb, u64 fragment, u64 size)
|
|
|
|
{
|
|
|
|
unsigned i, j;
|
|
|
|
u64 count = 0;
|
|
|
|
if (size & ~uspi->s_fmask)
|
|
|
|
return NULL;
|
|
|
|
count = size >> uspi->s_fshift;
|
|
|
|
if (count <= 0 || count > UFS_MAXFRAG)
|
|
|
|
return NULL;
|
2006-06-25 20:47:22 +08:00
|
|
|
USPI_UBH(uspi)->fragment = fragment;
|
|
|
|
USPI_UBH(uspi)->count = count;
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < count; i++)
|
2006-06-25 20:47:22 +08:00
|
|
|
if (!(USPI_UBH(uspi)->bh[i] = sb_bread(sb, fragment + i)))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto failed;
|
|
|
|
for (; i < UFS_MAXFRAG; i++)
|
2006-06-25 20:47:22 +08:00
|
|
|
USPI_UBH(uspi)->bh[i] = NULL;
|
|
|
|
return USPI_UBH(uspi);
|
2005-04-17 06:20:36 +08:00
|
|
|
failed:
|
|
|
|
for (j = 0; j < i; j++)
|
2006-06-25 20:47:22 +08:00
|
|
|
brelse (USPI_UBH(uspi)->bh[j]);
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ubh_brelse (struct ufs_buffer_head * ubh)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
if (!ubh)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < ubh->count; i++)
|
|
|
|
brelse (ubh->bh[i]);
|
|
|
|
kfree (ubh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ubh_brelse_uspi (struct ufs_sb_private_info * uspi)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2006-06-25 20:47:22 +08:00
|
|
|
if (!USPI_UBH(uspi))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2006-06-25 20:47:22 +08:00
|
|
|
for ( i = 0; i < USPI_UBH(uspi)->count; i++ ) {
|
|
|
|
brelse (USPI_UBH(uspi)->bh[i]);
|
|
|
|
USPI_UBH(uspi)->bh[i] = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ubh_mark_buffer_dirty (struct ufs_buffer_head * ubh)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
if (!ubh)
|
|
|
|
return;
|
|
|
|
for ( i = 0; i < ubh->count; i++ )
|
|
|
|
mark_buffer_dirty (ubh->bh[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ubh_mark_buffer_uptodate (struct ufs_buffer_head * ubh, int flag)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
if (!ubh)
|
|
|
|
return;
|
|
|
|
if (flag) {
|
|
|
|
for ( i = 0; i < ubh->count; i++ )
|
|
|
|
set_buffer_uptodate (ubh->bh[i]);
|
|
|
|
} else {
|
|
|
|
for ( i = 0; i < ubh->count; i++ )
|
|
|
|
clear_buffer_uptodate (ubh->bh[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-11 23:06:24 +08:00
|
|
|
void ubh_sync_block(struct ufs_buffer_head *ubh)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-08-11 23:06:24 +08:00
|
|
|
if (ubh) {
|
|
|
|
unsigned i;
|
2006-06-25 20:47:31 +08:00
|
|
|
|
2010-08-11 23:06:24 +08:00
|
|
|
for (i = 0; i < ubh->count; i++)
|
2016-06-06 03:31:43 +08:00
|
|
|
write_dirty_buffer(ubh->bh[i], 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-08-11 23:06:24 +08:00
|
|
|
for (i = 0; i < ubh->count; i++)
|
|
|
|
wait_on_buffer(ubh->bh[i]);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ubh_bforget (struct ufs_buffer_head * ubh)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
if (!ubh)
|
|
|
|
return;
|
|
|
|
for ( i = 0; i < ubh->count; i++ ) if ( ubh->bh[i] )
|
|
|
|
bforget (ubh->bh[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ubh_buffer_dirty (struct ufs_buffer_head * ubh)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
unsigned result = 0;
|
|
|
|
if (!ubh)
|
|
|
|
return 0;
|
|
|
|
for ( i = 0; i < ubh->count; i++ )
|
|
|
|
result |= buffer_dirty(ubh->bh[i]);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _ubh_ubhcpymem_(struct ufs_sb_private_info * uspi,
|
|
|
|
unsigned char * mem, struct ufs_buffer_head * ubh, unsigned size)
|
|
|
|
{
|
|
|
|
unsigned len, bhno;
|
|
|
|
if (size > (ubh->count << uspi->s_fshift))
|
|
|
|
size = ubh->count << uspi->s_fshift;
|
|
|
|
bhno = 0;
|
|
|
|
while (size) {
|
|
|
|
len = min_t(unsigned int, size, uspi->s_fsize);
|
|
|
|
memcpy (mem, ubh->bh[bhno]->b_data, len);
|
|
|
|
mem += uspi->s_fsize;
|
|
|
|
size -= len;
|
|
|
|
bhno++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _ubh_memcpyubh_(struct ufs_sb_private_info * uspi,
|
|
|
|
struct ufs_buffer_head * ubh, unsigned char * mem, unsigned size)
|
|
|
|
{
|
|
|
|
unsigned len, bhno;
|
|
|
|
if (size > (ubh->count << uspi->s_fshift))
|
|
|
|
size = ubh->count << uspi->s_fshift;
|
|
|
|
bhno = 0;
|
|
|
|
while (size) {
|
|
|
|
len = min_t(unsigned int, size, uspi->s_fsize);
|
|
|
|
memcpy (ubh->bh[bhno]->b_data, mem, len);
|
|
|
|
mem += uspi->s_fsize;
|
|
|
|
size -= len;
|
|
|
|
bhno++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_t
|
|
|
|
ufs_get_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi)
|
|
|
|
{
|
2006-08-13 13:54:30 +08:00
|
|
|
__u32 fs32;
|
2005-04-17 06:20:36 +08:00
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
|
2006-08-13 13:54:30 +08:00
|
|
|
fs32 = fs32_to_cpu(sb, ufsi->i_u1.i_data[1]);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2006-08-13 13:54:30 +08:00
|
|
|
fs32 = fs32_to_cpu(sb, ufsi->i_u1.i_data[0]);
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
|
|
|
|
case UFS_ST_SUNx86:
|
|
|
|
case UFS_ST_SUN:
|
|
|
|
if ((fs32 & 0xffff0000) == 0 ||
|
|
|
|
(fs32 & 0xffff0000) == 0xffff0000)
|
|
|
|
dev = old_decode_dev(fs32 & 0x7fff);
|
|
|
|
else
|
|
|
|
dev = MKDEV(sysv_major(fs32), sysv_minor(fs32));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dev = old_decode_dev(fs32);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ufs_set_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi, dev_t dev)
|
|
|
|
{
|
2006-08-13 13:54:30 +08:00
|
|
|
__u32 fs32;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
|
|
|
|
case UFS_ST_SUNx86:
|
|
|
|
case UFS_ST_SUN:
|
|
|
|
fs32 = sysv_encode_dev(dev);
|
|
|
|
if ((fs32 & 0xffff8000) == 0) {
|
|
|
|
fs32 = old_encode_dev(dev);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fs32 = old_encode_dev(dev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
|
2006-08-13 13:54:30 +08:00
|
|
|
ufsi->i_u1.i_data[1] = cpu_to_fs32(sb, fs32);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2006-08-13 13:54:30 +08:00
|
|
|
ufsi->i_u1.i_data[0] = cpu_to_fs32(sb, fs32);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-07-01 19:36:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ufs_get_locked_page() - locate, pin and lock a pagecache page, if not exist
|
|
|
|
* read it from disk.
|
|
|
|
* @mapping: the address_space to search
|
|
|
|
* @index: the page index
|
|
|
|
*
|
|
|
|
* Locates the desired pagecache page, if not exist we'll read it,
|
|
|
|
* locks it, increments its reference
|
|
|
|
* count and returns its address.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct page *ufs_get_locked_page(struct address_space *mapping,
|
|
|
|
pgoff_t index)
|
|
|
|
{
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
page = find_lock_page(mapping, index);
|
|
|
|
if (!page) {
|
2007-05-07 05:49:04 +08:00
|
|
|
page = read_mapping_page(mapping, index, NULL);
|
2006-08-06 03:13:55 +08:00
|
|
|
|
2006-07-01 19:36:24 +08:00
|
|
|
if (IS_ERR(page)) {
|
|
|
|
printk(KERN_ERR "ufs_change_blocknr: "
|
2007-05-07 05:49:04 +08:00
|
|
|
"read_mapping_page error: ino %lu, index: %lu\n",
|
2006-07-01 19:36:24 +08:00
|
|
|
mapping->host->i_ino, index);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
lock_page(page);
|
|
|
|
|
2006-08-06 03:13:55 +08:00
|
|
|
if (unlikely(page->mapping == NULL)) {
|
|
|
|
/* Truncate got there first */
|
|
|
|
unlock_page(page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
put_page(page);
|
2006-08-06 03:13:57 +08:00
|
|
|
page = NULL;
|
|
|
|
goto out;
|
2006-08-06 03:13:55 +08:00
|
|
|
}
|
|
|
|
|
2006-07-01 19:36:24 +08:00
|
|
|
if (!PageUptodate(page) || PageError(page)) {
|
|
|
|
unlock_page(page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
put_page(page);
|
2006-07-01 19:36:24 +08:00
|
|
|
|
|
|
|
printk(KERN_ERR "ufs_change_blocknr: "
|
|
|
|
"can not read page: ino %lu, index: %lu\n",
|
|
|
|
mapping->host->i_ino, index);
|
|
|
|
|
|
|
|
page = ERR_PTR(-EIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return page;
|
|
|
|
}
|