super.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 692 行 · 第 1/2 页
C
692 行
/* * Copyright (C) International Business Machines Corp., 2000-2004 * Portions Copyright (C) Christoph Hellwig, 2001-2002 * * This program 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 of the License, or * (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <linux/fs.h>#include <linux/config.h>#include <linux/module.h>#include <linux/parser.h>#include <linux/completion.h>#include <linux/vfs.h>#include <linux/moduleparam.h>#include <asm/uaccess.h>#include "jfs_incore.h"#include "jfs_filsys.h"#include "jfs_metapage.h"#include "jfs_superblock.h"#include "jfs_dmap.h"#include "jfs_imap.h"#include "jfs_acl.h"#include "jfs_debug.h"MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM");MODULE_LICENSE("GPL");static kmem_cache_t * jfs_inode_cachep;static struct super_operations jfs_super_operations;static struct export_operations jfs_export_operations;static struct file_system_type jfs_fs_type;#define MAX_COMMIT_THREADS 64static int commit_threads = 0;module_param(commit_threads, int, 0);MODULE_PARM_DESC(commit_threads, "Number of commit threads");int jfs_stop_threads;static pid_t jfsIOthread;static pid_t jfsCommitThread[MAX_COMMIT_THREADS];static pid_t jfsSyncThread;DECLARE_COMPLETION(jfsIOwait);#ifdef CONFIG_JFS_DEBUGint jfsloglevel = JFS_LOGLEVEL_WARN;module_param(jfsloglevel, int, 0644);MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)");#endif/* * External declarations */extern int jfs_mount(struct super_block *);extern int jfs_mount_rw(struct super_block *, int);extern int jfs_umount(struct super_block *);extern int jfs_umount_rw(struct super_block *);extern int jfsIOWait(void *);extern int jfs_lazycommit(void *);extern int jfs_sync(void *);extern void jfs_read_inode(struct inode *inode);extern void jfs_dirty_inode(struct inode *inode);extern void jfs_delete_inode(struct inode *inode);extern int jfs_write_inode(struct inode *inode, int wait);extern struct dentry *jfs_get_parent(struct dentry *dentry);extern int jfs_extendfs(struct super_block *, s64, int);extern struct dentry_operations jfs_ci_dentry_operations;#ifdef PROC_FS_JFS /* see jfs_debug.h */extern void jfs_proc_init(void);extern void jfs_proc_clean(void);#endifextern wait_queue_head_t jfs_IO_thread_wait;extern wait_queue_head_t jfs_commit_thread_wait;extern wait_queue_head_t jfs_sync_thread_wait;static void jfs_handle_error(struct super_block *sb){ struct jfs_sb_info *sbi = JFS_SBI(sb); if (sb->s_flags & MS_RDONLY) return; updateSuper(sb, FM_DIRTY); if (sbi->flag & JFS_ERR_PANIC) panic("JFS (device %s): panic forced after error\n", sb->s_id); else if (sbi->flag & JFS_ERR_REMOUNT_RO) { jfs_err("ERROR: (device %s): remounting filesystem " "as read-only\n", sb->s_id); sb->s_flags |= MS_RDONLY; } /* nothing is done for continue beyond marking the superblock dirty */}void jfs_error(struct super_block *sb, const char * function, ...){ static char error_buf[256]; va_list args; va_start(args, function); vsprintf(error_buf, function, args); va_end(args); printk(KERN_ERR "ERROR: (device %s): %s\n", sb->s_id, error_buf); jfs_handle_error(sb);}static struct inode *jfs_alloc_inode(struct super_block *sb){ struct jfs_inode_info *jfs_inode; jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS); if (!jfs_inode) return NULL; return &jfs_inode->vfs_inode;}static void jfs_destroy_inode(struct inode *inode){ struct jfs_inode_info *ji = JFS_IP(inode); spin_lock_irq(&ji->ag_lock); if (ji->active_ag != -1) { struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap; atomic_dec(&bmap->db_active[ji->active_ag]); ji->active_ag = -1; } spin_unlock_irq(&ji->ag_lock);#ifdef CONFIG_JFS_POSIX_ACL if (ji->i_acl != JFS_ACL_NOT_CACHED) { posix_acl_release(ji->i_acl); ji->i_acl = JFS_ACL_NOT_CACHED; } if (ji->i_default_acl != JFS_ACL_NOT_CACHED) { posix_acl_release(ji->i_default_acl); ji->i_default_acl = JFS_ACL_NOT_CACHED; }#endif kmem_cache_free(jfs_inode_cachep, ji);}static int jfs_statfs(struct super_block *sb, struct kstatfs *buf){ struct jfs_sb_info *sbi = JFS_SBI(sb); s64 maxinodes; struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap; jfs_info("In jfs_statfs"); buf->f_type = JFS_SUPER_MAGIC; buf->f_bsize = sbi->bsize; buf->f_blocks = sbi->bmap->db_mapsize; buf->f_bfree = sbi->bmap->db_nfree; buf->f_bavail = sbi->bmap->db_nfree; /* * If we really return the number of allocated & free inodes, some * applications will fail because they won't see enough free inodes. * We'll try to calculate some guess as to how may inodes we can * really allocate * * buf->f_files = atomic_read(&imap->im_numinos); * buf->f_ffree = atomic_read(&imap->im_numfree); */ maxinodes = min((s64) atomic_read(&imap->im_numinos) + ((sbi->bmap->db_nfree >> imap->im_l2nbperiext) << L2INOSPEREXT), (s64) 0xffffffffLL); buf->f_files = maxinodes; buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) - atomic_read(&imap->im_numfree)); buf->f_namelen = JFS_NAME_MAX; return 0;}static void jfs_put_super(struct super_block *sb){ struct jfs_sb_info *sbi = JFS_SBI(sb); int rc; jfs_info("In jfs_put_super"); rc = jfs_umount(sb); if (rc) jfs_err("jfs_umount failed with return code %d", rc); if (sbi->nls_tab) unload_nls(sbi->nls_tab); sbi->nls_tab = NULL; kfree(sbi);}enum { Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize, Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err,};static match_table_t tokens = { {Opt_integrity, "integrity"}, {Opt_nointegrity, "nointegrity"}, {Opt_iocharset, "iocharset=%s"}, {Opt_resize, "resize=%u"}, {Opt_resize_nosize, "resize"}, {Opt_errors, "errors=%s"}, {Opt_ignore, "noquota"}, {Opt_ignore, "quota"}, {Opt_ignore, "usrquota"}, {Opt_ignore, "grpquota"}, {Opt_err, NULL}};static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, int *flag){ void *nls_map = NULL; char *p; struct jfs_sb_info *sbi = JFS_SBI(sb); *newLVSize = 0; if (!options) return 1; while ((p = strsep(&options, ",")) != NULL) { substring_t args[MAX_OPT_ARGS]; int token; if (!*p) continue; token = match_token(p, tokens, args); switch (token) { case Opt_integrity: *flag &= ~JFS_NOINTEGRITY; break; case Opt_nointegrity: *flag |= JFS_NOINTEGRITY; break; case Opt_ignore: /* Silently ignore the quota options */ /* Don't do anything ;-) */ break; case Opt_iocharset: if (nls_map) /* specified iocharset twice! */ unload_nls(nls_map); nls_map = load_nls(args[0].from); if (!nls_map) { printk(KERN_ERR "JFS: charset not found\n"); goto cleanup; } break; case Opt_resize: { char *resize = args[0].from; *newLVSize = simple_strtoull(resize, &resize, 0); break; } case Opt_resize_nosize: { *newLVSize = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; if (*newLVSize == 0) printk(KERN_ERR "JFS: Cannot determine volume size\n"); break; } case Opt_errors: { char *errors = args[0].from; if (!errors || !*errors) goto cleanup; if (!strcmp(errors, "continue")) { *flag &= ~JFS_ERR_REMOUNT_RO; *flag &= ~JFS_ERR_PANIC; *flag |= JFS_ERR_CONTINUE; } else if (!strcmp(errors, "remount-ro")) { *flag &= ~JFS_ERR_CONTINUE; *flag &= ~JFS_ERR_PANIC; *flag |= JFS_ERR_REMOUNT_RO; } else if (!strcmp(errors, "panic")) { *flag &= ~JFS_ERR_CONTINUE; *flag &= ~JFS_ERR_REMOUNT_RO; *flag |= JFS_ERR_PANIC; } else { printk(KERN_ERR "JFS: %s is an invalid error handler\n", errors); goto cleanup; } break; } default: printk("jfs: Unrecognized mount option \"%s\" " " or missing value\n", p); goto cleanup; } } if (nls_map) { /* Discard old (if remount) */ if (sbi->nls_tab) unload_nls(sbi->nls_tab); sbi->nls_tab = nls_map; } return 1;cleanup: if (nls_map) unload_nls(nls_map); return 0;}static int jfs_remount(struct super_block *sb, int *flags, char *data){ s64 newLVSize = 0; int rc = 0; int flag = JFS_SBI(sb)->flag; if (!parse_options(data, sb, &newLVSize, &flag)) { return -EINVAL; } if (newLVSize) { if (sb->s_flags & MS_RDONLY) { printk(KERN_ERR
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?