/*
 * (C) Copyright Fuji Xerox Co., Ltd. All rights are reserved.
 * 
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * 2017/12/15	nobuo.iwata@fujixerox.co.jp
 */

#ifndef __FXLSM_OPS_H
#define __FXLSM_OPS_H

#include "fxlsm_prof.h"
#include <linux/security.h>
#include <linux/version.h>

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)
#define FXLSM_PATH_CONST const
#else
#define FXLSM_PATH_CONST
#endif

#define FXLSM_CRMX_DISABLED 0
#define FXLSM_CRMX_ENABLED 1
#define FXLSM_CRMX_THROUGH 2

int fxlsm_get_enabled(void);
int fxlsm_get_through(void);
const char *fxlsm_get_enabled_string(void);
const char * fxlsm_get_through_string(void);
int fxlsm_get_comms(void);
int fxlsm_get_lds(void);
int fxlsm_get_creatx(void);
int fxlsm_get_chmodx(void);
int fxlsm_set_enabled(const char *s);
int fxlsm_set_through(const char *s);
int fxlsm_set_comms(int stat);
int fxlsm_set_lds(int stat);
void fxlsm_set_creatx(int stat);
void fxlsm_set_chmodx(int stat);
int fxlsm_file_open(struct file *file, const struct cred *cred);
int fxlsm_path_unlink(FXLSM_PATH_CONST struct path *dir, struct dentry *dentry);
int fxlsm_path_mkdir(FXLSM_PATH_CONST struct path *dir, struct dentry *dentry,
		umode_t mode);
int fxlsm_path_rmdir(FXLSM_PATH_CONST struct path *dir, struct dentry *dentry);
int fxlsm_path_mknod(FXLSM_PATH_CONST struct path *dir, struct dentry *dentry,
		umode_t mode, unsigned int dev);
int fxlsm_path_symlink(FXLSM_PATH_CONST struct path *dir, struct dentry *dentry,
		const char *old_name);
int fxlsm_path_link(struct dentry *old_dentry,
		FXLSM_PATH_CONST struct path *new_dir,
		struct dentry *new_dentry);
int fxlsm_path_rename(FXLSM_PATH_CONST struct path *old_dir,
		struct dentry *old_dentry,
		FXLSM_PATH_CONST struct path *new_dir,
		struct dentry *new_dentry);
int fxlsm_path_chmod(FXLSM_PATH_CONST struct path *path, umode_t mode);
int fxlsm_path_chown(FXLSM_PATH_CONST struct path *path,
		kuid_t uid, kgid_t gid);
int fxlsm_path_chroot(FXLSM_PATH_CONST struct path *path);
int fxlsm_path_truncate(FXLSM_PATH_CONST struct path *path);

static inline const char *__comm(void)
{
	if (!current->group_leader)
		return current->comm;
	return current->group_leader->comm;
}

#ifdef FXLSM_USE_PROF_TIME
extern struct fxlsm_prof_time_id fxlsm_ops_prof_times[];
extern struct fxlsm_prof_time_id fxlsm_ops_prof_funcs[];
extern struct fxlsm_prof_time_id fxlsm_ops_prof_sums[];
#endif /* FXLSM_USE_PROF_TIME */

#endif /* !__FXLSM_OPS_H */
