オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Diff of /trunk/1.6.x/ccs-patch/fs/syaoran_2.6.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/ccs-patch/fs/syaoran_2.6.c revision 141 by kumaneko, Mon Mar 19 13:29:09 2007 UTC trunk/1.6.x/ccs-patch/fs/syaoran_2.6.c revision 1458 by kumaneko, Mon Aug 18 07:19:53 2008 UTC
# Line 3  Line 3 
3   *   *
4   * Implementation of the Tamper-Proof Device Filesystem.   * Implementation of the Tamper-Proof Device Filesystem.
5   *   *
6   * Portions Copyright (C) 2005-2007  NTT DATA CORPORATION   * Portions Copyright (C) 2005-2008  NTT DATA CORPORATION
7   *   *
8   * Version: 1.3.3   2007/04/01   * Version: 1.6.3+   2008/08/18
9   *   *
10   * This file is applicable to 2.6.11 and later.   * This file is applicable to 2.6.11 and later.
11   * See README.ccs for ChangeLog.   * See README.ccs for ChangeLog.
# Line 50  Line 50 
50    
51  #include <linux/namei.h>  #include <linux/namei.h>
52  #include <linux/version.h>  #include <linux/version.h>
53    #include <linux/sched.h>
54    #include <linux/mm.h>
55    
56  static struct super_operations syaoran_ops;  static struct super_operations syaoran_ops;
57  static struct address_space_operations syaoran_aops;  static struct address_space_operations syaoran_aops;
# Line 59  static struct inode_operations syaoran_s Line 61  static struct inode_operations syaoran_s
61  static struct file_operations syaoran_file_operations;  static struct file_operations syaoran_file_operations;
62    
63  static struct backing_dev_info syaoran_backing_dev_info = {  static struct backing_dev_info syaoran_backing_dev_info = {
64          .ra_pages = 0,        /* No readahead */          .ra_pages      = 0,    /* No readahead */
65  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)  #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 12)
66          .memory_backed  = 1,    /* Does not contribute to dirty memory */          .memory_backed = 1,    /* Does not contribute to dirty memory */
67  #else  #else
68          .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK |          .capabilities  = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK |
69                                          BDI_CAP_MAP_DIRECT | BDI_CAP_MAP_COPY |          BDI_CAP_MAP_DIRECT | BDI_CAP_MAP_COPY |
70                                          BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP,          BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP |
71            BDI_CAP_EXEC_MAP,
72  #endif  #endif
73  };  };
74    
75  #include <linux/syaoran.h>  #include <linux/syaoran.h>
76    
77  struct inode *syaoran_get_inode(struct super_block *sb, int mode, dev_t dev)  static struct inode *syaoran_get_inode(struct super_block *sb, int mode,
78                                           dev_t dev)
79  {  {
80          struct inode * inode = new_inode(sb);          struct inode *inode = new_inode(sb);
81    
82          if (inode) {          if (inode) {
83                  inode->i_mode = mode;                  inode->i_mode = mode;
84                  inode->i_uid = current->fsuid;                  inode->i_uid = current->fsuid;
85                  inode->i_gid = current->fsgid;                  inode->i_gid = current->fsgid;
86  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)  #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
87    #if !defined(RHEL_MAJOR) || RHEL_MAJOR != 5
88                  inode->i_blksize = PAGE_CACHE_SIZE;                  inode->i_blksize = PAGE_CACHE_SIZE;
89  #endif  #endif
90    #endif
91                  inode->i_blocks = 0;                  inode->i_blocks = 0;
92                  inode->i_mapping->a_ops = &syaoran_aops;                  inode->i_mapping->a_ops = &syaoran_aops;
93                  inode->i_mapping->backing_dev_info = &syaoran_backing_dev_info;                  inode->i_mapping->backing_dev_info = &syaoran_backing_dev_info;
94                  inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;                  inode->i_ctime = CURRENT_TIME;
95                    inode->i_mtime = inode->i_ctime;
96                    inode->i_atime = inode->i_mtime;
97                  switch (mode & S_IFMT) {                  switch (mode & S_IFMT) {
98                  default:                  default:
99                          init_special_inode(inode, mode, dev);                          init_special_inode(inode, mode, dev);
100                          if (S_ISBLK(mode)) inode->i_fop = &wrapped_def_blk_fops;                          if (S_ISBLK(mode))
101                          else if (S_ISCHR(mode)) inode->i_fop = &wrapped_def_chr_fops;                                  inode->i_fop = &wrapped_def_blk_fops;
102                            else if (S_ISCHR(mode))
103                                    inode->i_fop = &wrapped_def_chr_fops;
104                          inode->i_op = &syaoran_file_inode_operations;                          inode->i_op = &syaoran_file_inode_operations;
105                          break;                          break;
106                  case S_IFREG:                  case S_IFREG:
# Line 100  struct inode *syaoran_get_inode(struct s Line 110  struct inode *syaoran_get_inode(struct s
110                  case S_IFDIR:                  case S_IFDIR:
111                          inode->i_op = &syaoran_dir_inode_operations;                          inode->i_op = &syaoran_dir_inode_operations;
112                          inode->i_fop = &simple_dir_operations;                          inode->i_fop = &simple_dir_operations;
113                            /*
114                          /* directory inodes start off with i_nlink == 2 (for "." entry) */                           * directory inodes start off with i_nlink == 2
115                             * (for "." entry)
116                             */
117                          inode->i_nlink++;                          inode->i_nlink++;
118                          break;                          break;
119                  case S_IFLNK:                  case S_IFLNK:
# Line 116  struct inode *syaoran_get_inode(struct s Line 128  struct inode *syaoran_get_inode(struct s
128   * File creation. Allocate an inode, and we're done..   * File creation. Allocate an inode, and we're done..
129   */   */
130  /* SMP-safe */  /* SMP-safe */
131  static int  static int syaoran_mknod(struct inode *dir, struct dentry *dentry, int mode,
132  syaoran_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)                           dev_t dev)
133  {  {
134          struct inode * inode;          struct inode *inode;
135          int error = -ENOSPC;          int error = -ENOSPC;
136          if (MayCreateNode(dentry, mode, dev) < 0) return -EPERM;          if (syaoran_may_create_node(dentry, mode, dev) < 0)
137                    return -EPERM;
138          inode = syaoran_get_inode(dir->i_sb, mode, dev);          inode = syaoran_get_inode(dir->i_sb, mode, dev);
139          if (inode) {          if (inode) {
140                  if (dir->i_mode & S_ISGID) {                  if (dir->i_mode & S_ISGID) {
# Line 136  syaoran_mknod(struct inode *dir, struct Line 149  syaoran_mknod(struct inode *dir, struct
149          return error;          return error;
150  }  }
151    
152  static int syaoran_mkdir(struct inode * dir, struct dentry * dentry, int mode)  static int syaoran_mkdir(struct inode *dir, struct dentry *dentry, int mode)
153  {  {
154          int retval = syaoran_mknod(dir, dentry, mode | S_IFDIR, 0);          int retval = syaoran_mknod(dir, dentry, mode | S_IFDIR, 0);
155          if (!retval)          if (!retval)
# Line 144  static int syaoran_mkdir(struct inode * Line 157  static int syaoran_mkdir(struct inode *
157          return retval;          return retval;
158  }  }
159    
160  static int syaoran_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)  static int syaoran_create(struct inode *dir, struct dentry *dentry, int mode,
161                              struct nameidata *nd)
162  {  {
163          return syaoran_mknod(dir, dentry, mode | S_IFREG, 0);          return syaoran_mknod(dir, dentry, mode | S_IFREG, 0);
164  }  }
165    
166  static int syaoran_symlink(struct inode * dir, struct dentry *dentry, const char * symname)  static int syaoran_symlink(struct inode *dir, struct dentry *dentry,
167                               const char *symname)
168  {  {
169          struct inode *inode;          struct inode *inode;
170          int error = -ENOSPC;          int error = -ENOSPC;
171          if (MayCreateNode(dentry, S_IFLNK, 0) < 0) return -EPERM;          if (syaoran_may_create_node(dentry, S_IFLNK, 0) < 0)
172                    return -EPERM;
173          inode = syaoran_get_inode(dir->i_sb, S_IFLNK|S_IRWXUGO, 0);          inode = syaoran_get_inode(dir->i_sb, S_IFLNK|S_IRWXUGO, 0);
174          if (inode) {          if (inode) {
175                  int l = strlen(symname)+1;                  int l = strlen(symname)+1;
# Line 169  static int syaoran_symlink(struct inode Line 185  static int syaoran_symlink(struct inode
185          return error;          return error;
186  }  }
187    
188  static int syaoran_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)  static int syaoran_link(struct dentry *old_dentry, struct inode *dir,
189                            struct dentry *dentry)
190  {  {
191          struct inode *inode = old_dentry->d_inode;          struct inode *inode = old_dentry->d_inode;
192          if (!inode || MayCreateNode(dentry, inode->i_mode, inode->i_rdev) < 0) return -EPERM;          if (!inode || syaoran_may_create_node(dentry, inode->i_mode,
193                                                  inode->i_rdev) < 0)
194                    return -EPERM;
195          return simple_link(old_dentry, dir, dentry);          return simple_link(old_dentry, dir, dentry);
196  }  }
197    
198  static int syaoran_unlink(struct inode * dir, struct dentry *dentry)  static int syaoran_unlink(struct inode *dir, struct dentry *dentry)
199  {  {
200          if (MayModifyNode(dentry, MAY_DELETE) < 0) return -EPERM;          if (syaoran_may_modify_node(dentry, MAY_DELETE) < 0)
201                    return -EPERM;
202          return simple_unlink(dir, dentry);          return simple_unlink(dir, dentry);
203  }  }
204    
205  static int syaoran_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)  static int syaoran_rename(struct inode *old_dir, struct dentry *old_dentry,
206                              struct inode *new_dir, struct dentry *new_dentry)
207  {  {
208          struct inode *inode = old_dentry->d_inode;          struct inode *inode = old_dentry->d_inode;
209          if (!inode || MayModifyNode(old_dentry, MAY_DELETE) < 0 || MayCreateNode(new_dentry, inode->i_mode, inode->i_rdev) < 0) return -EPERM;          if (!inode || syaoran_may_modify_node(old_dentry, MAY_DELETE) < 0 ||
210                syaoran_may_create_node(new_dentry, inode->i_mode,
211                                        inode->i_rdev) < 0)
212                    return -EPERM;
213          return simple_rename(old_dir, old_dentry, new_dir, new_dentry);          return simple_rename(old_dir, old_dentry, new_dir, new_dentry);
214  }  }
215    
216  static int syaoran_rmdir(struct inode *dir, struct dentry *dentry)  static int syaoran_rmdir(struct inode *dir, struct dentry *dentry)
217  {  {
218          if (MayModifyNode(dentry, MAY_DELETE) < 0) return -EPERM;          if (syaoran_may_modify_node(dentry, MAY_DELETE) < 0)
219                    return -EPERM;
220          return simple_rmdir(dir, dentry);          return simple_rmdir(dir, dentry);
221  }  }
222    
223  static int syaoran_setattr(struct dentry * dentry, struct iattr * attr)  static int syaoran_setattr(struct dentry *dentry, struct iattr *attr)
224  {  {
225          struct inode *inode = dentry->d_inode;          struct inode *inode = dentry->d_inode;
226          int error = inode_change_ok(inode, attr);          int error = inode_change_ok(inode, attr);
227          if (!error) {          if (!error) {
228                  unsigned int ia_valid = attr->ia_valid;                  unsigned int ia_valid = attr->ia_valid;
229                  unsigned int flags = 0;                  unsigned int flags = 0;
230                  if (ia_valid & (ATTR_UID | ATTR_GID)) flags |= MAY_CHOWN;                  if (ia_valid & (ATTR_UID | ATTR_GID))
231                  if (ia_valid & ATTR_MODE) flags |= MAY_CHMOD;                          flags |= MAY_CHOWN;
232                  if (MayModifyNode(dentry, flags) < 0) return -EPERM;                  if (ia_valid & ATTR_MODE)
233                  if (!error) error = inode_setattr(inode, attr);                          flags |= MAY_CHMOD;
234                    if (syaoran_may_modify_node(dentry, flags) < 0)
235                            return -EPERM;
236                    if (!error)
237                            error = inode_setattr(inode, attr);
238          }          }
239          return error;          return error;
240  }  }
241    
242    #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
243  static struct address_space_operations syaoran_aops = {  static struct address_space_operations syaoran_aops = {
244          .readpage       = simple_readpage,          .readpage       = simple_readpage,
245          .prepare_write  = simple_prepare_write,          .prepare_write  = simple_prepare_write,
246          .commit_write   = simple_commit_write          .commit_write   = simple_commit_write
247  };  };
248    #else
249    static int syaoran_set_page_dirty_no_writeback(struct page *page)
250    {
251            if (!PageDirty(page))
252                    SetPageDirty(page);
253            return 0;
254    }
255    static struct address_space_operations syaoran_aops = {
256            .readpage       = simple_readpage,
257            .write_begin    = simple_write_begin,
258            .write_end      = simple_write_end,
259            .set_page_dirty = syaoran_set_page_dirty_no_writeback,
260    };
261    #endif
262    
263  static struct file_operations syaoran_file_operations = {  static struct file_operations syaoran_file_operations = {
264  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)  #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
265          .read       = generic_file_read,          .read        = generic_file_read,
266          .write      = generic_file_write,          .write       = generic_file_write,
267  #else  #else
268          .aio_read   = generic_file_aio_read,          .aio_read    = generic_file_aio_read,
269          .read       = do_sync_read,          .read        = do_sync_read,
270          .aio_write  = generic_file_aio_write,          .aio_write   = generic_file_aio_write,
271          .write      = do_sync_write,          .write       = do_sync_write,
272  #endif  #endif
273          .mmap       = generic_file_mmap,          .mmap        = generic_file_mmap,
274          .fsync      = simple_sync_file,          .fsync       = simple_sync_file,
275          .sendfile   = generic_file_sendfile,  #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
276          .llseek     = generic_file_llseek,          .sendfile    = generic_file_sendfile,
277    #else
278            .splice_read = generic_file_splice_read,
279    #endif
280            .llseek      = generic_file_llseek,
281  };  };
282    
283  static struct inode_operations syaoran_file_inode_operations = {  static struct inode_operations syaoran_file_inode_operations = {
# Line 263  static struct super_operations syaoran_o Line 311  static struct super_operations syaoran_o
311          .put_super  = syaoran_put_super,          .put_super  = syaoran_put_super,
312  };  };
313    
314  static int syaoran_fill_super(struct super_block * sb, void * data, int silent)  static int syaoran_fill_super(struct super_block *sb, void *data, int silent)
315  {  {
316          struct inode * inode;          struct inode *inode;
317          struct dentry * root;          struct dentry *root;
318    
319          sb->s_maxbytes = MAX_LFS_FILESIZE;          sb->s_maxbytes = MAX_LFS_FILESIZE;
320          sb->s_blocksize = PAGE_CACHE_SIZE;          sb->s_blocksize = PAGE_CACHE_SIZE;
321          sb->s_blocksize_bits = PAGE_CACHE_SHIFT;          sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
322          sb->s_magic = SYAORAN_MAGIC;          sb->s_magic = SYAORAN_MAGIC;
323          sb->s_op = &syaoran_ops;          sb->s_op = &syaoran_ops;
324  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 9)
325          sb->s_time_gran = 1;          sb->s_time_gran = 1;
326  #endif  #endif
327          {          {
328                  int error;                  int error = syaoran_initialize(sb, data);
329                  if ((error = Syaoran_Initialize(sb, data)) < 0) return error;                  if (error < 0)
330                            return error;
331          }          }
332          inode = syaoran_get_inode(sb, S_IFDIR | 0755, 0);          inode = syaoran_get_inode(sb, S_IFDIR | 0755, 0);
333          if (!inode)          if (!inode)
# Line 290  static int syaoran_fill_super(struct sup Line 339  static int syaoran_fill_super(struct sup
339                  return -ENOMEM;                  return -ENOMEM;
340          }          }
341          sb->s_root = root;          sb->s_root = root;
342          MakeInitialNodes(sb);          syaoran_make_initial_nodes(sb);
343          return 0;          return 0;
344  }  }
345    
346  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)  #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
347  struct super_block *syaoran_get_sb(struct file_system_type *fs_type,  static struct super_block *syaoran_get_sb(struct file_system_type *fs_type,
348          int flags, const char *dev_name, void *data)                                            int flags, const char *dev_name,
349                                              void *data)
350  {  {
351          return get_sb_nodev(fs_type, flags, data, syaoran_fill_super);          return get_sb_nodev(fs_type, flags, data, syaoran_fill_super);
352  }  }
353  #else  #else
354  int syaoran_get_sb(struct file_system_type *fs_type,  static int syaoran_get_sb(struct file_system_type *fs_type,
355          int flags, const char *dev_name, void *data, struct vfsmount *mnt)                            int flags, const char *dev_name, void *data,
356                              struct vfsmount *mnt)
357  {  {
358          return get_sb_nodev(fs_type, flags, data, syaoran_fill_super, mnt);          return get_sb_nodev(fs_type, flags, data, syaoran_fill_super, mnt);
359  }  }
# Line 325  static void __exit exit_syaoran_fs(void) Line 376  static void __exit exit_syaoran_fs(void)
376          unregister_filesystem(&syaoran_fs_type);          unregister_filesystem(&syaoran_fs_type);
377  }  }
378    
379  module_init(init_syaoran_fs)  module_init(init_syaoran_fs);
380  module_exit(exit_syaoran_fs)  module_exit(exit_syaoran_fs);
381    
382  MODULE_LICENSE("GPL");  MODULE_LICENSE("GPL");
   
 EXPORT_SYMBOL(syaoran_get_sb);  

Legend:
Removed from v.141  
changed lines
  Added in v.1458

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26