fs_dir.c

Go to the documentation of this file.
00001 
00018 #ifndef __KERNEL__
00019 #       define __KERNEL__
00020 #endif
00021 
00022 
00023 #include <linux/init.h>
00024 #include <linux/kernel.h>
00025 #include <linux/module.h>
00026 #include <linux/version.h>
00027 #include <linux/fs.h>
00028 #include <linux/sched.h>
00029 #include <linux/statfs.h>
00030 #include <linux/mm.h>
00031 #include <asm/uaccess.h>
00032 #include <asm/errno.h>
00033 #include <linux/buffer_head.h>
00034 #include <linux/pagemap.h> /* unlock_page */
00035 #include <linux/proc_fs.h>
00036 #include <asm/atomic.h>
00037 #include <linux/string.h>
00038 
00039 
00040 #include "fsc_device.h"
00041 #include "rkfs.h"
00042 #include "parser.h"
00043 
00044 
00046 struct file_operations rkfs_dops = {
00047         read: generic_read_dir,
00048         readdir: rkfs_file_readdir,
00049         fsync: simple_sync_file
00050 };
00051 
00052 
00064 int rkfs_mkdir(struct inode * dir, struct dentry *dentry, int mode) {
00065         struct inode * inode;
00066         struct super_block *sb = dir->i_sb;
00067         int err = -EMLINK;
00068         char query_string[MAX_QUERY_LENGTH + 1];
00069 
00070         snprintf(query_string, MAX_QUERY_LENGTH + 1, "MYSQL1.1 MD %lu %s", dir->i_ino, dentry->d_name.name);
00071 
00072         if (query(query_string, strlen(query_string)) != RKFS_DEF_QUERY_OK) {           
00073                 return err;
00074         } 
00075         else {
00076                 if (ret_command.command_nr == CMD_ER_NR) {
00077                         return err;
00078                 }
00079         }
00080 
00081         inode_inc_link_count(dir);
00082         
00083         /* allocate an inode */
00084         inode = iget(sb, rkfs_atoi(ret_command.param));
00085         
00086         err = PTR_ERR(inode);
00087         if (IS_ERR(inode)) {
00088                 inode_dec_link_count(dir);
00089                 return err;
00090         }
00091         /* size of the new directory is 0 - no files inside */
00092         inode->i_size = 0; 
00093         
00094         /* create as dir, with wanted mode */
00095         inode->i_mode = S_IFDIR | mode; 
00096         
00097         /* set the directory ops */
00098         inode->i_fop = &rkfs_dops;
00099         
00100         /* set the inode ops */ 
00101         inode->i_op = &rkfs_iops;
00102         
00103         /* number of hardlinks for the new directory is 2 - one for . and one for .. directory */ 
00104         inode->i_nlink =2; 
00105 
00106         d_instantiate(dentry, inode);
00107         
00108         /* parent directory size increases by one for this new directory */ 
00109         dir->i_size++;
00110         return 0; /* ok */
00111 }
00112 
00113 
00124 int rkfs_rmdir(struct inode * dir, struct dentry *dentry) {
00125         /* get pointer to a coresponding inode */
00126         struct inode * inode = dentry->d_inode;
00127         int err = -ENOTEMPTY;
00128         char query_string[MAX_QUERY_LENGTH + 1];
00129 
00130         FSPDEBUG("rkfs_rmdir for file '%s'\n", dentry->d_name.name);
00131 
00132         if (inode->i_size == 0) {
00133                 snprintf(query_string, MAX_QUERY_LENGTH + 1, "MYSQL1.1 RD %lu", inode->i_ino);
00134                 if (query(query_string, strlen(query_string)) != RKFS_DEF_QUERY_OK) {
00135                         return -EFAULT;
00136                 } 
00137                 else {
00138                         if (ret_command.command_nr == CMD_ER_NR) {
00139                                 return -EFAULT;
00140                         }
00141                 }
00142                 inode->i_size = 0;
00143                 inode_dec_link_count(inode);
00144                 inode_dec_link_count(dir);
00145                 
00146                 /* parent directory size decreases by one for this removed directory */ 
00147                 dir->i_size--;
00148                 return 0;
00149         } 
00150         else {
00151                 /* directory was not empty */
00152                 return err;
00153         } 
00154 }
00155 
00156 

Generated on Mon May 28 13:33:08 2007 for MYSQLFS by  doxygen 1.5.0