/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * lib/simple.c * * Copyright (C) 2002 Cluster File Systems, Inc. * * This code is issued under the GNU General Public License. * See the file COPYING in this distribution * * by Peter Braam * and Andreas Dilger */ #define EXPORT_SYMTAB #include #include #include #define DEBUG_SUBSYSTEM S_FILTER #include #include #include /* push / pop to root of obd store */ void push_ctxt(struct obd_run_ctxt *save, struct obd_run_ctxt *new) { save->fs = get_fs(); save->pwd = dget(current->fs->pwd); save->pwdmnt = mntget(current->fs->pwdmnt); set_fs(new->fs); set_fs_pwd(current->fs, new->pwdmnt, new->pwd); } void pop_ctxt(struct obd_run_ctxt *saved) { set_fs(saved->fs); set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd); dput(saved->pwd); mntput(saved->pwdmnt); } /* utility to make a directory */ struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode) { struct dentry *dchild; int err; ENTRY; CDEBUG(D_INODE, "creating directory %*s\n", strlen(name), name); dchild = lookup_one_len(name, dir, strlen(name)); if (IS_ERR(dchild)) RETURN(dchild); if (dchild->d_inode) { if (!S_ISDIR(dchild->d_inode->i_mode)) GOTO(out, err = -ENOTDIR); RETURN(dchild); } err = vfs_mkdir(dir->d_inode, dchild, mode); EXIT; out: if (err) { dput(dchild); RETURN(ERR_PTR(err)); } RETURN(dchild); } int lustre_fread(struct file *file, char *str, int len, loff_t *off) { if (!file || !file->f_op || !file->f_op->read || !off) RETURN(-ENOSYS); return file->f_op->read(file, str, len, off); } int lustre_fwrite(struct file *file, const char *str, int len, loff_t *off) { if (!file || !file->f_op || !off) RETURN(-ENOSYS); if (!file->f_op->write) RETURN(-EROFS); return file->f_op->write(file, str, len, off); } int lustre_fsync(struct file *file) { if (!file || !file->f_op || !file->f_op->fsync) RETURN(-ENOSYS); return file->f_op->fsync(file, file->f_dentry, 0); }