www.pudn.com > cryptfs030905.rar > cryptfs.h


/*
 * Copyright (c) 1997-2003 Erez Zadok
 * Copyright (c) 2001-2003 Stony Brook University
 *
 * For specific licensing information, see the COPYING file distributed with
 * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
 *
 * This Copyright notice must be kept intact and distributed with all
 * fistgen sources INCLUDING sources generated by fistgen.
 */
/*
 *  $Id: cryptfs.h,v 1.23 2003/07/29 18:17:22 ezk Exp $
 */

#ifndef __CRYPTFS_H_
#define __CRYPTFS_H_

#ifdef __KERNEL__

/*
 * STRUCTURES:
 */


/* Turn this on to include code that counts writes and writes in the middle */
/* #undef FIST_COUNT_WRITES */

/* fist file systems superblock magic */
# define CRYPTFS_SUPER_MAGIC 0xf15f


/* cryptfs inode data in memory */
struct cryptfs_inode_info {
    inode_t *wii_inode;
};

/* cryptfs dentry data in memory */
struct cryptfs_dentry_info {
    dentry_t *wdi_dentry;
    BF_KEY *dentry_key;
};

typedef struct attached_entry {
    struct list_head list;
    struct dentry *e_dentry;
    BF_KEY e_key;
    uid_t e_uid;
    gid_t e_gid;
} attached_entry_t;

/* cryptfs super-block data in memory */
struct cryptfs_sb_info {
    super_block_t *wsi_sb;
    struct vfsmount *hidden_mnt;
    struct list_head attached; /* list of attached entries */
    rwlock_t attachlock;	/* lock for attach list */
//    	BF_KEY key;
};

/* file private data. */
struct cryptfs_file_info {
    struct file *wfi_file;
};

/*
 * MACROS:
 */

// File TO Private Data
# define ftopd(file) ((struct cryptfs_file_info *)((file)->private_data))
// File TO Hidden File
# define ftohf(file) ((ftopd(file))->wfi_file)
// Inode TO Private Data
# define itopd(ino) ((struct cryptfs_inode_info *)(ino)->u.generic_ip)
// Inode TO Hidden Inode
# define itohi(ino) (itopd(ino)->wii_inode)
# define vnode2lower itohi
// Superblock TO Private Data
# define stopd(super) ((struct cryptfs_sb_info *)(super)->u.generic_sbp)
# define vfs2priv stopd
// Superblock TO Hidden Superblock
# define stohs(super) (stopd(super)->wsi_sb)
// Dentry TO Hidden Dentry (and private data --- for the future)
# define dtopd(dentry) ((struct cryptfs_dentry_info *)(dentry)->d_fsdata)
# define dtohd(dent) (dtopd(dent)->wdi_dentry)
// Dentry To the key for encryption/decryption stored in the attached entrylist
# define dtokey(dent) (dtopd(dent)->dentry_key)
# define dir2lower dtohd
/* VMArea TO Hidden VMArea */
# define vmatohvma(vma) ((vm_area_t *)((vma)->vm_private_data))

# define sbt(sb) ((sb)->s_type->name)

/* macros to simplify non-SCA code */
#  define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
#  define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
#  define FREE_PAGE_POINTERS(hidden_pages, num)
#  define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
#  define FOR_EACH_PAGE
#  define CURRENT_HIDDEN_PAGE hidden_page
#  define CURRENT_HIDDEN_PAGEDATA hidden_page_data
#  define CURRENT_HIDDEN_PAGEINDEX page->index


/*
 * Flags for cryptfs_{en,de}code_filename
 * DO_DOTS means the special entries . and .. should be encoded (for symlink)
 * SKIP_DOTS means they should be preserved intact
 */
#  define DO_DOTS   0
#  define SKIP_DOTS 1

/*
 * EXTERNALS:
 */
extern struct file_operations cryptfs_main_fops;
extern struct file_operations cryptfs_dir_fops;
extern struct inode_operations cryptfs_main_iops;
extern struct inode_operations cryptfs_dir_iops;
extern struct inode_operations cryptfs_dir_attach_iops;
extern struct dentry_operations cryptfs_attach_dops;
extern struct file_operations cryptfs_dir_attach_fops;
extern super_block_t * cryptfs_read_super(super_block_t *sb, void *raw_data, int silent);
extern int cryptfs_statfs(super_block_t *sb, struct statfs *buf);
extern dentry_t *cryptfs_parse_options(super_block_t *sb, char *options);
extern void cryptfs_d_release(dentry_t *dentry);
extern int cryptfs_d_delete(dentry_t *dentry);
extern void cryptfs_d_iput(dentry_t *dentry, inode_t *inode);
extern struct inode_operations cryptfs_symlink_iops;
extern struct super_operations cryptfs_sops;
extern struct dentry_operations cryptfs_dops;
extern struct vm_operations_struct cryptfs_shared_vmops;
extern struct vm_operations_struct cryptfs_private_vmops;
extern struct address_space_operations cryptfs_aops;

extern int cryptfs_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
extern page_t *cryptfs_get1page(file_t *file, int index);
extern int cryptfs_fill_zeros(file_t *file, page_t *page, unsigned from);
# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
extern int cryptfs_decode_block(const char *from, char *to, int len, const vnode_t *vp, const vfs_t *vfsp, u_long pagenum);
extern int cryptfs_encode_block(const char *from, char *to, int len, const vnode_t *vp, const vfs_t *vfsp, u_long pagenum);
extern int cryptfs_decode_filename(const char *name, int length, char **decoded_name, int skip_dots, const vnode_t *vp, const vfs_t *vfsp);
extern int cryptfs_encode_filename(const char *name, int length, char **encoded_name, int skip_dots, const vnode_t *vp, const vfs_t *vfsp);
extern ino_t cryptfs_iunique(struct super_block *sb, ino_t maxreserved);

#  define cryptfs_hidden_dentry(d) __cryptfs_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
extern dentry_t *__cryptfs_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);




#  define copy_inode_size(dst, src) \
    dst->i_size = src->i_size; \
    dst->i_blocks = src->i_blocks;

static inline void
fist_copy_attr_atime(inode_t *dest, const inode_t *src)
{
    ASSERT(dest != NULL);
    ASSERT(src != NULL);
    dest->i_atime = src->i_atime;
}
static inline void
fist_copy_attr_times(inode_t *dest, const inode_t *src)
{
    ASSERT(dest != NULL);
    ASSERT(src != NULL);
    dest->i_atime = src->i_atime;
    dest->i_mtime = src->i_mtime;
    dest->i_ctime = src->i_ctime;
}
static inline void
fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
{
    ASSERT(dest != NULL);
    ASSERT(src != NULL);
    dest->i_atime = src->i_atime;
    dest->i_mtime = src->i_mtime;
    dest->i_ctime = src->i_ctime;
    copy_inode_size(dest, src);
}
static inline void
fist_copy_attr_all(inode_t *dest, const inode_t *src)
{
    print_entry_location();
    ASSERT(dest != NULL);
    ASSERT(src != NULL);
    dest->i_mode = src->i_mode;
    dest->i_nlink = src->i_nlink;
    dest->i_uid = src->i_uid;
    dest->i_gid = src->i_gid;
    dest->i_rdev = src->i_rdev;
    dest->i_atime = src->i_atime;
    dest->i_mtime = src->i_mtime;
    dest->i_ctime = src->i_ctime;
    dest->i_blksize = src->i_blksize;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
    dest->i_blkbits = src->i_blkbits;
# endif /* linux 2.4.12 and newer */
    copy_inode_size(dest, src);

    dest->i_attr_flags = src->i_attr_flags;
    print_exit_location();
}

/* auto-generated extern definitions */

/* auto-generated externs */
extern int fist_get_ioctl_data_SETKEY_ukey(char *buf, int buflen, uid_t *uid, void *arg);
extern int fist_set_ioctl_data_GETIV_outiv(void *in, int len, void *arg);


#endif /* __KERNEL__ */

/*
 * Definitions for user and kernel code
 */

/* ioctls */
struct _fist_ioctl_SETKEY {
	char ukey [16];
	int uid;
};

#define FIST_IOCTL_SETKEY	_IOW(0x15, 10, struct _fist_ioctl_SETKEY)
struct _fist_ioctl_GETIV {
	char outiv [8];
};
#define FIST_IOCTL_GETIV	_IOR(0x15, 11, struct _fist_ioctl_GETIV)


#endif	/* not __CRYPTFS_H_ */

/*
 * Local variables:
 * c-basic-offset: 4
 * End:
 */