add context for each directory
git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@361 766a2236-cff9-0310-b0c0-a81a5f92509a
This commit is contained in:
		
							parent
							
								
									5477409477
								
							
						
					
					
						commit
						f5d0dc0306
					
				
							
								
								
									
										7
									
								
								files.c
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								files.c
									
									
									
									
									
								
							@ -26,11 +26,10 @@ static int do_cmd(u32 cmd, u32 data)
 | 
				
			|||||||
/* generic open function for all pipe-like files */
 | 
					/* generic open function for all pipe-like files */
 | 
				
			||||||
static int fpgafs_open(struct inode *inode, struct file *file)
 | 
					static int fpgafs_open(struct inode *inode, struct file *file)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	//struct fpgafs_inode_info *i = FPGAFS_I(inode);
 | 
						struct fpgafs_inode_info *i = FPGAFS_I(inode);
 | 
				
			||||||
	//file->private_data = i->i_ctx;
 | 
						file->private_data = i->i_ctx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //return nonseekable_open(inode, file);
 | 
						return nonseekable_open(inode, file);
 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ssize_t fpgafs_stat_read(struct file *file, char __user *buf,
 | 
					static ssize_t fpgafs_stat_read(struct file *file, char __user *buf,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										14
									
								
								fpgafs.h
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								fpgafs.h
									
									
									
									
									
								
							@ -15,8 +15,8 @@ enum {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct fpga_context {
 | 
					struct fpga_context {
 | 
				
			||||||
	int bla1;
 | 
						char *load_buf;
 | 
				
			||||||
	int bla2;
 | 
						int bla;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct fpgafs_inode_info {
 | 
					struct fpgafs_inode_info {
 | 
				
			||||||
@ -40,11 +40,11 @@ struct fpgafs_lldrv {
 | 
				
			|||||||
	int (*init) (void);
 | 
						int (*init) (void);
 | 
				
			||||||
	int (*exit) (void);
 | 
						int (*exit) (void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int (*send) (const char __user *buf, int len);
 | 
						int (*send) (struct fpga_context *ctx, const char __user *buf, int len);
 | 
				
			||||||
	int (*recv) (unsigned char *buf, int len);
 | 
						int (*recv) (struct fpga_context *ctx, unsigned char *buf, int len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int (*read_load) (unsigned  char *buf, int len);
 | 
						int (*read_load) (struct fpga_context *ctx, unsigned  char *buf, int len);
 | 
				
			||||||
	int (*write_load) (const char __user *buf, int len);
 | 
						int (*write_load) (struct fpga_context *ctx, const char __user *buf, int len);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int fpgafs_register_lldrv(struct fpgafs_lldrv *drv);
 | 
					int fpgafs_register_lldrv(struct fpgafs_lldrv *drv);
 | 
				
			||||||
@ -60,4 +60,6 @@ ssize_t fpgafs_write_load(struct file *file, const char __user *buf,
 | 
				
			|||||||
ssize_t fpgafs_read_load(struct file *file, char __user *buf,
 | 
					ssize_t fpgafs_read_load(struct file *file, char __user *buf,
 | 
				
			||||||
                                size_t len, loff_t *pos);
 | 
					                                size_t len, loff_t *pos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct fpga_context* alloc_fpga_context(void);
 | 
				
			||||||
 | 
					void free_fpga_context(struct fpga_context *ctx);
 | 
				
			||||||
#endif /* FPGAFS_H */
 | 
					#endif /* FPGAFS_H */
 | 
				
			||||||
 | 
				
			|||||||
@ -6,13 +6,13 @@
 | 
				
			|||||||
#include <linux/init.h>
 | 
					#include <linux/init.h>
 | 
				
			||||||
#include "fpgafs.h"
 | 
					#include "fpgafs.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int fpgafs_send_data_cham(const char __user *buf, int len)
 | 
					static int fpgafs_send_data_cham(struct fpga_context *ctx, const char __user *buf, int len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	printk("fpgafs: send data CHAM\n");
 | 
						printk("fpgafs: send data CHAM\n");
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int fpgafs_recv_data_cham(unsigned char *buf, int len)
 | 
					static int fpgafs_recv_data_cham(struct fpga_context *ctx, unsigned char *buf, int len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	printk("fpgafs: receive data CHAM\n");
 | 
						printk("fpgafs: receive data CHAM\n");
 | 
				
			||||||
	return 4;
 | 
						return 4;
 | 
				
			||||||
 | 
				
			|||||||
@ -8,40 +8,37 @@
 | 
				
			|||||||
#include <linux/mm.h>
 | 
					#include <linux/mm.h>
 | 
				
			||||||
#include "fpgafs.h"
 | 
					#include "fpgafs.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int load = 0;
 | 
					static int fpgafs_send_data_dbg(struct fpga_context *ctx, const char __user *buf, int len)
 | 
				
			||||||
static unsigned char *load_buf;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int fpgafs_send_data_dbg(const char __user *buf, int len)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	printk("fpgafs: send data DEBUG\n");
 | 
						printk("fpgafs: send data DEBUG\n");
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int fpgafs_recv_data_dbg(unsigned char *buf, int len)
 | 
					static int fpgafs_recv_data_dbg(struct fpga_context *ctx, unsigned char *buf, int len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	printk("fpgafs: receive data DEBUG\n");
 | 
						printk("fpgafs: receive data DEBUG\n");
 | 
				
			||||||
	return 4;
 | 
						return 4;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int fpgafs_read_load_dbg(unsigned char *buf, int len)
 | 
					static int fpgafs_read_load_dbg(struct fpga_context *ctx, unsigned char *buf, int len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (load == 0)
 | 
						if (ctx->load_buf == NULL)
 | 
				
			||||||
		return -EBUSY;
 | 
							return -EBUSY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	len = len > sizeof(load_buf)?sizeof(load_buf):len;
 | 
						len = len > sizeof(ctx->load_buf)?sizeof(ctx->load_buf):len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (copy_to_user(buf, load_buf, len))
 | 
						if (copy_to_user(buf, ctx->load_buf, len))
 | 
				
			||||||
		return -EFAULT;
 | 
							return -EFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return len;
 | 
						return len;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int fpgafs_write_load_dbg(const char __user *buf, int len)
 | 
					static int fpgafs_write_load_dbg(struct fpga_context *ctx, const char __user *buf, int len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	u32 cp = 0;
 | 
						u32 cp = 0;
 | 
				
			||||||
	u8 __user *usr;
 | 
						u8 __user *usr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (load == 1)
 | 
						if (ctx->load_buf != NULL)
 | 
				
			||||||
		return -EBUSY;
 | 
							return -EBUSY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (len < 2)
 | 
						if (len < 2)
 | 
				
			||||||
@ -50,16 +47,15 @@ static int fpgafs_write_load_dbg(const char __user *buf, int len)
 | 
				
			|||||||
	if (!access_ok(VERIFY_READ, buf, len))
 | 
						if (!access_ok(VERIFY_READ, buf, len))
 | 
				
			||||||
		return -EFAULT;
 | 
							return -EFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	load_buf = kmalloc(len,GFP_USER);
 | 
						ctx->load_buf = kmalloc(len,GFP_USER);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (cp < len) {
 | 
						while (cp < len) {
 | 
				
			||||||
		usr = (u8*)&buf[cp];
 | 
							usr = (u8*)&buf[cp];
 | 
				
			||||||
		if (__get_user(load_buf[cp], usr))
 | 
							if (__get_user(ctx->load_buf[cp], usr))
 | 
				
			||||||
			return -EFAULT;
 | 
								return -EFAULT;
 | 
				
			||||||
		cp++;
 | 
							cp++;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	load = 1;
 | 
					 | 
				
			||||||
	return len;
 | 
						return len;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -81,8 +77,6 @@ int __init fpgafs_lldrv_dbg_init(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void __exit fpgafs_lldrv_dbg_exit(void)
 | 
					void __exit fpgafs_lldrv_dbg_exit(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	load = 0;
 | 
					 | 
				
			||||||
	kfree(load_buf);
 | 
					 | 
				
			||||||
	fpgafs_unregister_lldrv(&fpgafs_lldrv_dbg);
 | 
						fpgafs_unregister_lldrv(&fpgafs_lldrv_dbg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								inode.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								inode.c
									
									
									
									
									
								
							@ -166,10 +166,11 @@ int fpgafs_mkdir( struct inode *dir, struct dentry *dentry, int mode)
 | 
				
			|||||||
		inode->i_gid = dir->i_gid;
 | 
							inode->i_gid = dir->i_gid;
 | 
				
			||||||
		inode->i_mode &= S_ISGID;
 | 
							inode->i_mode &= S_ISGID;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// ctx = alloc fpga context ....
 | 
					
 | 
				
			||||||
	// FPGAFS_I(inode)->i_ctx = ctx;
 | 
						ctx = alloc_fpga_context();
 | 
				
			||||||
	//if (!ctx)
 | 
						FPGAFS_I(inode)->i_ctx = ctx;
 | 
				
			||||||
	//	goto unmutex;
 | 
						if (!ctx)
 | 
				
			||||||
 | 
							goto unmutex;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	inode->i_op = &fpgafs_simple_dir_inode_operations;
 | 
						inode->i_op = &fpgafs_simple_dir_inode_operations;
 | 
				
			||||||
	inode->i_fop = &simple_dir_operations;
 | 
						inode->i_fop = &simple_dir_operations;
 | 
				
			||||||
@ -186,7 +187,7 @@ int fpgafs_mkdir( struct inode *dir, struct dentry *dentry, int mode)
 | 
				
			|||||||
	dir->i_nlink++;
 | 
						dir->i_nlink++;
 | 
				
			||||||
	dentry->d_inode->i_nlink++;
 | 
						dentry->d_inode->i_nlink++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//unmutex:
 | 
					unmutex:
 | 
				
			||||||
	mutex_unlock(&inode->i_mutex);
 | 
						mutex_unlock(&inode->i_mutex);
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -217,6 +218,7 @@ static void fpgafs_prune_dir(struct dentry *dir)
 | 
				
			|||||||
static int fpgafs_rmdir(struct inode *dir, struct dentry *dentry)
 | 
					static int fpgafs_rmdir(struct inode *dir, struct dentry *dentry)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* remove all entries */
 | 
						/* remove all entries */
 | 
				
			||||||
 | 
						free_fpga_context(FPGAFS_I(dentry->d_inode)->i_ctx);
 | 
				
			||||||
	fpgafs_prune_dir(dentry);
 | 
						fpgafs_prune_dir(dentry);
 | 
				
			||||||
	//fpgafs_remove_inode
 | 
						//fpgafs_remove_inode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										38
									
								
								llmgmt.c
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								llmgmt.c
									
									
									
									
									
								
							@ -13,31 +13,61 @@ static struct fpgafs_lldrv *lldrv_cur;
 | 
				
			|||||||
static int lldrv_count = 0x0;
 | 
					static int lldrv_count = 0x0;
 | 
				
			||||||
static DEFINE_SPINLOCK(fpgafs_lldrv_lock);
 | 
					static DEFINE_SPINLOCK(fpgafs_lldrv_lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct fpga_context* alloc_fpga_context(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct fpga_context *ctx;
 | 
				
			||||||
 | 
						ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
 | 
				
			||||||
 | 
						if (!ctx)
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* do some stuff */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
 | 
						return ctx;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void free_fpga_context(struct fpga_context *ctx)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (ctx->load_buf)
 | 
				
			||||||
 | 
							kfree(ctx->load_buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						kfree(ctx);
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t fpgafs_send_data(struct file *file, const char __user *buf,
 | 
					ssize_t fpgafs_send_data(struct file *file, const char __user *buf,
 | 
				
			||||||
                                size_t len, loff_t *pos)
 | 
					                                size_t len, loff_t *pos)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return (lldrv_cur) ? lldrv_cur->send(buf, len) : -EBUSY;
 | 
						return (lldrv_cur) ?
 | 
				
			||||||
 | 
							lldrv_cur->send((struct fpga_context*)file->private_data, buf, len)
 | 
				
			||||||
 | 
							: -EBUSY;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(fpgafs_send_data);
 | 
					EXPORT_SYMBOL_GPL(fpgafs_send_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t fpgafs_recv_data(struct file *file, char __user *buf,
 | 
					ssize_t fpgafs_recv_data(struct file *file, char __user *buf,
 | 
				
			||||||
                                size_t len, loff_t *pos)
 | 
					                                size_t len, loff_t *pos)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return (lldrv_cur) ? lldrv_cur->recv(buf, len) : -EBUSY;
 | 
						return (lldrv_cur) ?
 | 
				
			||||||
 | 
							lldrv_cur->recv((struct fpga_context*)file->private_data, buf, len)
 | 
				
			||||||
 | 
							: -EBUSY;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(fpgafs_recv_data);
 | 
					EXPORT_SYMBOL_GPL(fpgafs_recv_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t fpgafs_write_load(struct file *file, const char __user *buf,
 | 
					ssize_t fpgafs_write_load(struct file *file, const char __user *buf,
 | 
				
			||||||
                                size_t len, loff_t *pos)
 | 
					                                size_t len, loff_t *pos)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return (lldrv_cur) ? lldrv_cur->write_load(buf, len) : -EBUSY;
 | 
						return (lldrv_cur) ?
 | 
				
			||||||
 | 
							lldrv_cur->write_load((struct fpga_context*)file->private_data, buf, len)
 | 
				
			||||||
 | 
							: -EBUSY;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(fpgafs_write_load);
 | 
					EXPORT_SYMBOL_GPL(fpgafs_write_load);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t fpgafs_read_load(struct file *file, char __user *buf,
 | 
					ssize_t fpgafs_read_load(struct file *file, char __user *buf,
 | 
				
			||||||
                                size_t len, loff_t *pos)
 | 
					                                size_t len, loff_t *pos)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return (lldrv_cur) ? lldrv_cur->read_load(buf, len) : -EBUSY;
 | 
						return (lldrv_cur) ?
 | 
				
			||||||
 | 
							lldrv_cur->read_load((struct fpga_context*)file->private_data, buf, len)
 | 
				
			||||||
 | 
							: -EBUSY;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(fpgafs_read_load);
 | 
					EXPORT_SYMBOL_GPL(fpgafs_read_load);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user