2001-09-17 19:42:59 +04:00
/*
* dmfs - root . 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 .
*/
/* Heavily based upon ramfs */
2001-09-18 19:38:54 +04:00
# include <linux/config.h>
# include <linux/ctype.h>
# include <linux/fs.h>
2001-10-11 01:49:21 +04:00
# include "dm.h"
2001-10-12 14:06:40 +04:00
extern struct inode * dmfs_create_lv ( struct inode * dir , int mode , struct dentry * dentry ) ;
2001-09-17 19:42:59 +04:00
static int is_identifier ( const char * str , int len )
{
while ( len - - ) {
if ( ! isalnum ( * str ) & & * str ! = ' _ ' )
return 0 ;
str + + ;
}
return 1 ;
}
static int dmfs_root_mkdir ( struct inode * dir , struct dentry * dentry , int mode )
{
2001-09-18 20:54:14 +04:00
struct inode * inode ;
2001-09-17 19:42:59 +04:00
2001-09-20 01:27:46 +04:00
if ( dentry - > d_name . len > = DM_NAME_LEN )
return - EINVAL ;
2001-10-12 14:06:40 +04:00
if ( ! is_identifier ( dentry - > d_name . name , dentry - > d_name . len ) )
2001-09-17 19:42:59 +04:00
return - EPERM ;
2001-10-12 14:06:40 +04:00
if ( dentry - > d_name . name [ 0 ] = = ' . ' )
2001-09-26 13:26:10 +04:00
return - EINVAL ;
2001-10-12 00:29:00 +04:00
inode = dmfs_create_lv ( dir , mode , dentry ) ;
2001-09-18 20:54:14 +04:00
if ( ! IS_ERR ( inode ) ) {
2001-10-12 00:29:00 +04:00
d_instantiate ( dentry , inode ) ;
dget ( dentry ) ;
return 0 ;
2001-09-17 19:42:59 +04:00
}
2001-09-18 20:54:14 +04:00
return PTR_ERR ( inode ) ;
2001-09-17 19:42:59 +04:00
}
2001-09-20 01:27:46 +04:00
/*
* if u . generic_ip is not NULL , then it indicates an inode which
* represents a table . If it is NULL then the inode is a virtual
* file and should be deleted along with the directory .
*/
2001-10-12 14:06:40 +04:00
static inline int positive ( struct dentry * dentry )
2001-09-17 19:42:59 +04:00
{
2001-09-26 13:26:10 +04:00
return dentry - > d_inode & & ! d_unhashed ( dentry ) ;
2001-09-17 19:42:59 +04:00
}
static int empty ( struct dentry * dentry )
{
struct list_head * list ;
spin_lock ( & dcache_lock ) ;
list = dentry - > d_subdirs . next ;
while ( list ! = & dentry - > d_subdirs ) {
struct dentry * de = list_entry ( list , struct dentry , d_child ) ;
if ( positive ( de ) ) {
spin_unlock ( & dcache_lock ) ;
return 0 ;
}
list = list - > next ;
}
spin_unlock ( & dcache_lock ) ;
return 1 ;
}
static int dmfs_root_rmdir ( struct inode * dir , struct dentry * dentry )
{
int ret = - ENOTEMPTY ;
if ( empty ( dentry ) ) {
struct inode * inode = dentry - > d_inode ;
2001-10-15 15:31:00 +04:00
ret = dm_deactivate ( DMFS_I ( inode ) - > md ) ;
2001-09-20 01:27:46 +04:00
if ( ret = = 0 ) {
inode - > i_nlink - - ;
dput ( dentry ) ;
}
2001-09-17 19:42:59 +04:00
}
2001-09-20 01:27:46 +04:00
return ret ;
2001-09-17 19:42:59 +04:00
}
static struct dentry * dmfs_root_lookup ( struct inode * dir , struct dentry * dentry )
{
d_add ( dentry , NULL ) ;
return NULL ;
}
static int dmfs_root_rename ( struct inode * old_dir , struct dentry * old_dentry ,
struct inode * new_dir , struct dentry * new_dentry )
{
/* Can only rename - not move between directories! */
if ( old_dir ! = new_dir )
return - EPERM ;
2001-09-18 19:38:54 +04:00
return - EINVAL ; /* FIXME: a change of LV name here */
2001-09-17 19:42:59 +04:00
}
static int dmfs_root_sync ( struct file * file , struct dentry * dentry , int datasync )
{
return 0 ;
}
2001-10-12 14:06:40 +04:00
static struct file_operations dmfs_root_file_operations = {
2001-09-17 19:42:59 +04:00
read : generic_read_dir ,
readdir : dcache_readdir ,
fsync : dmfs_root_sync ,
} ;
2001-10-12 14:06:40 +04:00
static struct inode_operations dmfs_root_inode_operations = {
2001-09-17 19:42:59 +04:00
lookup : dmfs_root_lookup ,
mkdir : dmfs_root_mkdir ,
rmdir : dmfs_root_rmdir ,
rename : dmfs_root_rename ,
} ;
struct inode * dmfs_create_root ( struct super_block * sb , int mode )
{
struct inode * inode = new_inode ( sb ) ;
if ( inode ) {
inode - > i_mode = mode | S_IFDIR ;
inode - > i_uid = current - > fsuid ;
inode - > i_gid = current - > fsgid ;
inode - > i_blksize = PAGE_CACHE_SIZE ;
inode - > i_blocks = 0 ;
inode - > i_rdev = NODEV ;
2001-09-17 23:05:49 +04:00
inode - > i_atime = inode - > i_ctime = inode - > i_mtime = CURRENT_TIME ;
2001-09-17 19:42:59 +04:00
inode - > i_fop = & dmfs_root_file_operations ;
2001-10-12 14:06:40 +04:00
inode - > i_op = & dmfs_root_inode_operations ;
2001-09-17 19:42:59 +04:00
}
return inode ;
}