2001-09-18 15:38:54 +00:00
/*
* dmfs - table . c
*
* Copyright ( C ) 2001 Sistina Software
*
* This software is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation ; either version 2 , or ( at
* your option ) any later version .
*
* This software is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with GNU CC ; see the file COPYING . If not , write to
* the Free Software Foundation , 59 Temple Place - Suite 330 ,
* Boston , MA 02111 - 1307 , USA .
*/
# include <linux/config.h>
# include <linux/fs.h>
2001-09-19 21:27:46 +00:00
static int dmfs_release ( struct inode * inode , struct file * f )
2001-09-18 15:38:54 +00:00
{
2001-09-19 21:27:46 +00:00
struct dm_table * table ;
/* FIXME: we should lock the inode to
prevent someone else opening it while
we are parsing */
if ( ! ( f - > f_mode & S_IWUGO ) )
return 0 ;
2001-09-19 10:32:51 +00:00
2001-09-18 15:38:54 +00:00
}
2001-09-19 21:27:46 +00:00
static int dmfs_readpage ( struct file * file , struct page * page )
2001-09-18 15:38:54 +00:00
{
2001-09-19 21:27:46 +00:00
if ( ! PageUptodate ( page ) ) {
memset ( kmap ( page ) , 0 , PAGE_CACHE_SIZE ) ;
kunmap ( page ) ;
flush_dcache_page ( page ) ;
SetPageUptodate ( page ) ;
}
UnlockPage ( page ) ;
return 0 ;
2001-09-18 15:38:54 +00:00
}
2001-09-19 21:27:46 +00:00
static int dmfs_writepage ( struct page * page )
2001-09-18 15:38:54 +00:00
{
2001-09-19 21:27:46 +00:00
SetPageDirty ( page ) ;
UnlockPage ( page ) ;
return 0 ;
}
2001-09-18 15:38:54 +00:00
2001-09-19 21:27:46 +00:00
static int dmfs_prepare_write ( struct file * file , struct page * page ,
unsigned offset , unsigned to )
{
void * addr = kmap ( page ) ;
if ( ! Page_Uptodate ( page ) ) {
memset ( addr , 0 , PAGE_CACHE_SIZE ) ;
flush_dcache_page ( page ) ;
SetPageUptodate ( page ) ;
}
SetPageDirty ( page ) ;
return 0 ;
}
2001-09-19 10:32:51 +00:00
2001-09-19 21:27:46 +00:00
static int dmfs_commit_write ( struct file * file , struct page * page ,
unsigned offset , unsigned to )
{
struct inode * inode = page - > mapping - > host ;
loff_t pos = ( ( loff_t ) page - > index < < PAGE_CACHE_SHIFT ) + to ;
2001-09-18 15:38:54 +00:00
2001-09-19 21:27:46 +00:00
kunmap ( page ) ;
if ( pos > inode - > i_size )
inode - > i_size = pos ;
2001-09-18 15:38:54 +00:00
return 0 ;
}
static int dmfs_table_sync ( struct file * file , struct dentry * dentry , int datasync )
{
return 0 ;
}
2001-09-19 21:27:46 +00:00
static struct dm_table_address_space_operations = {
readpage : dmfs_readpage ,
writepage : dmfs_writepage ,
prepare_write : dmfs_prepare_write ,
commit_write : dmfs_commit_write ,
} ;
2001-09-18 15:38:54 +00:00
static struct dm_table_file_operations = {
2001-09-19 21:27:46 +00:00
llseek : generic_file_llseek ,
read : generic_file_read ,
write : generic_file_write ,
mmap : generic_file_mmap ,
2001-09-18 15:38:54 +00:00
fsync : dmfs_table_sync ,
2001-09-19 21:27:46 +00:00
release : dmfs_release ,
2001-09-18 15:38:54 +00:00
} ;
static struct dmfs_table_inode_operations = {
} ;
2001-09-19 21:27:46 +00:00
int dmfs_create_table ( struct inode * dir , int mode )
2001-09-18 15:38:54 +00:00
{
struct inode * inode = new_inode ( dir - > i_sb ) ;
if ( inode ) {
inode - > i_mode = mode | S_IFREG ;
inode - > i_uid = current - > fsuid ;
inode - > i_gid = current - > fsgid ;
inode - > i_blksize = PAGE_CACHE_SIZE ;
inode - > i_blocks = 0 ;
inode - > i_rdev = NODEV ;
inode - > i_atime = inode - > i_ctime = inode - > i_mtime = CURRENT_TIME ;
2001-09-19 21:27:46 +00:00
inode - > i_mapping - > a_ops = & dmfs_table_address_space_operations ;
2001-09-18 15:38:54 +00:00
inode - > i_fop = & dmfs_table_file_operations ;
inode - > i_op = & dmfs_table_inode_operations ;
}
return inode ;
}