⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aux.c

📁 Solaris操作系统下的过滤驱动程序, C源码程序.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 1997-2003 Erez Zadok * Copyright (c) 2001-2003 Stony Brook University * Copyright (c) 1997-2000 Columbia 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: aux.c,v 1.59 2002/12/27 20:19:01 ezk Exp $ */#ifdef HAVE_CONFIG_H# include <config.h>#endif /* HAVE_CONFIG_H */#ifdef FISTGEN# include "fist_wrapfs.h"#endif /* FISTGEN */#include "fist.h"#include "wrapfs.h"#ifdef FIST_USE_AUX_SRC/* * Read "len" bytes from "filename" into "buf". * "buf" is in kernel space. */intwrapfs_read_file(const char *filename, void *buf, int len){    file_t *filp;    mm_segment_t oldfs;    int bytes;    				/* Chroot? Maybe NULL isn't right here */    filp = filp_open(filename, O_RDONLY, 0);    if (!filp || IS_ERR(filp)) {	printk("wrapfs_read_file err %d\n", (int) PTR_ERR(filp));	return -1;  /* or do something else */    }    if (!filp->f_op->read)	return -2;  /* file(system) doesn't allow reads */    /* now read len bytes from offset 0 */    filp->f_pos = 0;		/* start offset */    oldfs = get_fs();    set_fs(KERNEL_DS);    bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);    set_fs(oldfs);    /* close the file */    fput(filp);    return bytes;}/* * Write "len" bytes from "buf" to "filename" * "buf" is in kernel space. */intwrapfs_write_file(const char *filename, void *buf, int len){    file_t *filp;    mm_segment_t oldfs;    int bytes;				/* Chroot? Maybe NULL isn't right here */    filp = filp_open(filename, O_RDWR|O_CREAT, 0640);    if (!filp || IS_ERR(filp)) {	printk("wrapfs_write_file err %d\n", (int) PTR_ERR(filp));	return -1;  /* or do something else */    }    if (!filp->f_op->write)	return -2;  /* file(system) doesn't allow writes */    /* now write len bytes from offset 0 */    filp->f_pos = 0;		/* start offset */    oldfs = get_fs();    set_fs(KERNEL_DS);    bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);    set_fs(oldfs);    /* close the file */    fput(filp);    return bytes;}/* * perform a special lookup with special permissions */dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid){    uid_t saved_uid;    gid_t saved_gid;    dentry_t *new_dentry;    saved_uid = dir->d_inode->i_uid;    saved_gid = dir->d_inode->i_gid;    dir->d_inode->i_uid = uid;    dir->d_inode->i_gid = gid;    new_dentry = lookup_one(name, dir);    dir->d_inode->i_uid = saved_uid;    dir->d_inode->i_gid = saved_gid;    return new_dentry;}#endif /* FIST_USE_AUX_SRC */#ifdef FIST_FILTER_SCA/* * get one page from cache or lower f/s, err otherwise. * returns unlocked, up-to-date page (if ok), with increased refcnt. */page_t *wrapfs_get1page(file_t *file, int index){    page_t *page;    dentry_t *dentry = file->f_dentry;    inode_t *inode = dentry->d_inode;    struct address_space *mapping = inode->i_mapping;    int err;    print_entry_location();    fist_dprint(8, "wrapfs_get1page: read page index %d\n", index);    if (index < 0) {	printk("wrapfs_get1page BUG: index=%d\n", index);	page = ERR_PTR(-EIO);	goto out;    }    page = read_cache_page(mapping,			   index,			   (filler_t *) mapping->a_ops->readpage,			   (void *) file);    if (IS_ERR(page))	goto out;    wait_on_page(page);    if (!Page_Uptodate(page)) {	lock_page(page);	err = mapping->a_ops->readpage(file, page);	if (err) {	    page = ERR_PTR(err);	    goto out;	}	wait_on_page(page);	if (!Page_Uptodate(page)) {	    page = ERR_PTR(-EIO);	    goto out;	}    } out:    print_exit_pointer(page);    return page;}/* lookup an index file, given a hidden dentry */dentry_t *wrapfs_idx_lookup(dentry_t *hidden_dentry){    unsigned int namelen;    dentry_t *idx_dentry = NULL, *dir_dentry;    char *name;    int err = 0;    print_entry_location();    namelen = hidden_dentry->d_name.len;    name = kmalloc(namelen + INDEX_EXTENSION_LEN, GFP_KERNEL);    if (!name) {	err = -ENOMEM;	goto out;    }    memcpy(name, hidden_dentry->d_name.name, namelen);    memcpy(name + namelen, INDEX_EXTENSION, INDEX_EXTENSION_LEN);    dir_dentry = dget(hidden_dentry->d_parent);    idx_dentry = lookup_one(name, dir_dentry);    if (IS_ERR(idx_dentry)) {	printk("ERR from looup_dentry on idx_dentry!\n");	err = PTR_ERR(idx_dentry);	goto out;    }    /* note that returned idx_dentry may be a negative dentry */ out:    if (err)	idx_dentry = ERR_PTR(err);    print_exit_status(err);    return idx_dentry;}/* create a new index inode */intwrapfs_idx_create(inode_t *hidden_dir, dentry_t *dentry, int mode){    int err;    print_entry_location();    /* we don't have to lock hidden_dir. already locked in wrapfs_create */    err = vfs_create(hidden_dir, dtopd(dentry)->idx_dentry, mode);    print_exit_status(err);    return err;}/* open an index file (that should exist) given a regular file dentry */intwrapfs_idx_open(dentry_t *dentry, mode_t mode, unsigned int flags){    int err = 0;    file_t *idx_file;    dentry_t *idx_dentry;    print_entry_location();    /* don't reopen an existing idx file */    if (itopd(dentry->d_inode)->idx_file)	goto out;    idx_dentry = dtopd(dentry)->idx_dentry;    dget(idx_dentry);    /*     * dentry_open will decrement mnt refcnt if err.     * otherwise fput() will do an mntput() for us upon file close.     */    mntget(stopd(dentry->d_sb)->hidden_mnt);    idx_file = dentry_open(idx_dentry, stopd(dentry->d_sb)->hidden_mnt, mode, flags);    if (IS_ERR(idx_file)) {	printk("Error opening (mode %d) index file %s\n", mode, idx_dentry->d_name.name);	err = PTR_ERR(idx_file);	goto out;    }    itopd(dentry->d_inode)->idx_file = idx_file;    /* all is ok */out:    print_exit_status(err);    return err;}/* XXX this is inefficient, for stat() it really doesn't need the entire index table *//* This function return 0 on success, negative on error */intwrapfs_idx_read(inode_t *inode){    mm_segment_t oldfs;    int len, err = 0, i;    struct scafs_header *hdr = NULL;    file_t *idx_file;    print_entry_location();    idx_file = itopd(inode)->idx_file;    ASSERT(idx_file != NULL);    if (!idx_file->f_op->read) {	/* This is highly unlikely, but... */	err = -ENOSYS;	goto out;    }    len = idx_file->f_dentry->d_inode->i_size;    /* Special case for empty file */    if (len == 0 && itohi(inode)->i_size == 0) {	inode->i_size = inode->i_blocks = 0;	goto out;    }    /* small (corrupted) index? */    if (len < (3 * sizeof(off_t))) {	err = -EIO;	goto out;    }    oldfs = get_fs();    set_fs(KERNEL_DS);    hdr = &(itopd(inode)->hdr);    /* Read in the number of pages and the real size */    err = idx_file->f_op->read(idx_file, (void *) &hdr->num_chunks,			       sizeof(off_t) << 1, &idx_file->f_pos);    if (err < 0) {	printk("Error in read\n");	goto out_setfs;    }    /* XXX check to see that we got all 2 * sizeof(off_t) bytes */    /* separate flags from num_chunks */    hdr->flags = hdr->num_chunks & SCA_FLAG_MASK;    hdr->num_chunks &= ~SCA_FLAG_MASK;    hdr->num_pageslots = (hdr->num_chunks + OFFSET_MASK) >> OFFSET_SHIFT;    /* allocate page pointers array */    hdr->offsets = (off_t **)kmalloc(sizeof(off_t *) * hdr->num_pageslots, GFP_KERNEL);    if (hdr->offsets == NULL) {	err = -ENOMEM;	goto out;    }    hdr->num_alloc = hdr->num_pageslots << OFFSET_SHIFT;    for (i = 0; i < hdr->num_pageslots; i++) {	hdr->offsets[i] = (off_t *)__get_free_page(GFP_KERNEL);	if (hdr->offsets[i] == NULL) {	    err = -ENOMEM;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -