* Linux module support routines.
*
*/
-#include "../afs/param.h"
-#include "../afs/sysincludes.h"
-#include "../afs/afsincludes.h"
-#include "../h/unistd.h" /* For syscall numbers. */
-#include "../h/mm.h"
+#include <afsconfig.h>
+#include "afs/param.h"
-#include <linux/module.h>
+RCSID
+ ("$Header$");
+#include <linux/module.h> /* early to avoid printf->printk mapping */
+#include "afs/sysincludes.h"
+#include "afsincludes.h"
+#include "h/unistd.h" /* For syscall numbers. */
+#include "h/mm.h"
-
-asmlinkage int (*sys_settimeofdayp)(struct timeval *tv, struct timezone *tz);
-#if !defined(AFS_ALPHA_LINUX20_ENV)
-asmlinkage int (*sys_socketcallp)(int call, long *args);
-#endif /* no socketcall on alpha */
-asmlinkage int (*sys_killp)(int pid, int signal);
-asmlinkage int (*sys_setgroupsp)(int gidsetsize, gid_t *grouplist);
-
+#ifdef AFS_AMD64_LINUX20_ENV
+#include <asm/ia32_unistd.h>
+#endif
#ifdef AFS_SPARC64_LINUX20_ENV
-extern unsigned int sys_call_table[]; /* changed to uint because SPARC64 has syscaltable of 32bit items */
-#else
-extern void * sys_call_table[]; /* safer for other linuces */
+#include <linux/ioctl32.h>
#endif
-extern struct file_system_type afs_file_system;
+#include <linux/proc_fs.h>
+#include <linux/slab.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#endif
+
+extern struct file_system_type afs_fs_type;
+
+#if !defined(AFS_LINUX24_ENV)
static long get_page_offset(void);
+#endif
-#if defined(AFS_LINUX24_ENV)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
+DEFINE_MUTEX(afs_global_lock);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
DECLARE_MUTEX(afs_global_lock);
#else
struct semaphore afs_global_lock = MUTEX;
#endif
int afs_global_owner = 0;
-unsigned long afs_linux_page_offset = 0; /* contains the PAGE_OFFSET value */
-
-/* Since sys_ni_syscall is not exported, I need to cache it in order to restore
- * it.
- */
-static unsigned int afs_ni_syscall = 0;
-
-#ifdef AFS_SPARC64_LINUX20_ENV
-static unsigned int afs_ni_syscall32 = 0;
-asmlinkage int (*sys_setgroupsp32)(int gidsetsize, __kernel_gid_t32 *grouplist);
-extern unsigned int sys_call_table32[];
-
-asmlinkage int afs_syscall32(long syscall, long parm1, long parm2, long parm3,
- long parm4, long parm5)
-{
-__asm__ __volatile__ ("
- srl %o4, 0, %o4
- mov %o7, %i7
- call afs_syscall
- srl %o5, 0, %o5
- ret
- nop
-");
-}
+#if !defined(AFS_LINUX24_ENV)
+unsigned long afs_linux_page_offset = 0; /* contains the PAGE_OFFSET value */
#endif
-#ifdef AFS_SPARC64_LINUX20_ENV
-#define POINTER2SYSCALL (unsigned int)(unsigned long)
-#define SYSCALL2POINTER (void *)(long)
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+int __init
+afs_init(void)
#else
-#define POINTER2SYSCALL (void *)
-#define SYSCALL2POINTER (void *)
+int
+init_module(void)
#endif
-
-int init_module(void)
{
- extern int afs_syscall();
- extern int afs_xsetgroups();
-#ifdef AFS_SPARC64_LINUX20_ENV
- extern int afs_xsetgroups32();
-#endif
+ int err;
+ RWLOCK_INIT(&afs_xosi, "afs_xosi");
+#if !defined(AFS_LINUX24_ENV)
/* obtain PAGE_OFFSET value */
afs_linux_page_offset = get_page_offset();
#ifndef AFS_S390_LINUX22_ENV
if (afs_linux_page_offset == 0) {
- /* couldn't obtain page offset so can't continue */
- printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
- return -EIO;
+ /* couldn't obtain page offset so can't continue */
+ printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
+ return -EIO;
}
-#endif
-
- /* Initialize pointers to kernel syscalls. */
- sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday];
-#if !defined(AFS_ALPHA_LINUX20_ENV)
- sys_socketcallp = SYSCALL2POINTER sys_call_table[__NR_socketcall];
-#endif /* no socketcall on alpha */
- sys_killp = SYSCALL2POINTER sys_call_table[__NR_kill];
-
- /* setup AFS entry point. */
- if (SYSCALL2POINTER sys_call_table[__NR_afs_syscall] == afs_syscall) {
- printf("AFS syscall entry point already in use!\n");
- return -EBUSY;
- }
-
-
- afs_ni_syscall = sys_call_table[__NR_afs_syscall];
- sys_call_table[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall;
-#ifdef AFS_SPARC64_LINUX20_ENV
- afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall];
- sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32;
-#endif
+#endif /* AFS_S390_LINUX22_ENV */
+#endif /* !defined(AFS_LINUX24_ENV) */
osi_Init();
- register_filesystem(&afs_file_system);
+#ifdef AFS_LINUX26_ENV
+#if !defined(AFS_NONFSTRANS)
+ osi_linux_nfssrv_init();
+#endif
+#endif
- /* Intercept setgroups calls */
- sys_setgroupsp = SYSCALL2POINTER sys_call_table[__NR_setgroups];
- sys_call_table[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups;
-#ifdef AFS_SPARC64_LINUX20_ENV
- sys_setgroupsp32 = SYSCALL2POINTER sys_call_table32[__NR_setgroups];
- sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups32;
+#ifndef LINUX_KEYRING_SUPPORT
+ err = osi_syscall_init();
+ if (err)
+ return err;
+#endif
+ err = afs_init_inodecache();
+ if (err)
+ return err;
+ register_filesystem(&afs_fs_type);
+ osi_sysctl_init();
+#ifdef LINUX_KEYRING_SUPPORT
+ osi_keyring_init();
+#endif
+#ifdef AFS_LINUX24_ENV
+ osi_proc_init();
+ osi_ioctl_init();
#endif
return 0;
}
-void cleanup_module(void)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+void __exit
+afs_cleanup(void)
+#else
+void
+cleanup_module(void)
+#endif
{
- struct task_struct *t;
-
- sys_call_table[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp;
- sys_call_table[__NR_afs_syscall] = afs_ni_syscall;
-#ifdef AFS_SPARC64_LINUX20_ENV
- sys_call_table32[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp32;
- sys_call_table32[__NR_afs_syscall] = afs_ni_syscall32;
+ osi_keyring_shutdown();
+ osi_sysctl_clean();
+ osi_syscall_clean();
+ unregister_filesystem(&afs_fs_type);
+
+ afs_destroy_inodecache();
+#ifdef AFS_LINUX26_ENV
+#if !defined(AFS_NONFSTRANS)
+ osi_linux_nfssrv_shutdown();
+#endif
#endif
-
- unregister_filesystem(&afs_file_system);
-
- osi_linux_free_inode_pages(); /* Invalidate all pages using AFS inodes. */
osi_linux_free_afs_memory();
+#ifdef AFS_LINUX24_ENV
+ osi_ioctl_clean();
+ osi_proc_clean();
+#endif
return;
}
-static long get_page_offset(void)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+MODULE_LICENSE("http://www.openafs.org/dl/license10.html");
+module_init(afs_init);
+module_exit(afs_cleanup);
+#endif
+
+
+#if !defined(AFS_LINUX24_ENV)
+static long
+get_page_offset(void)
{
-#if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_S390_LINUX22_ENV)
+#if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_S390_LINUX22_ENV) || defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PARISC_LINUX24_ENV) || defined(AFS_AMD64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV)
return PAGE_OFFSET;
#else
- struct task_struct *p;
+ struct task_struct *p, *q;
/* search backward thru the circular list */
- for(p = current; p; p = p->prev_task)
- if (p->pid == 1)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ read_lock(&tasklist_lock);
+#endif
+ /* search backward thru the circular list */
+#ifdef DEFINED_PREV_TASK
+ for (q = current; p = q; q = prev_task(p)) {
+#else
+ for (p = current; p; p = p->prev_task) {
+#endif
+ if (p->pid == 1) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ read_unlock(&tasklist_lock);
+#endif
return p->addr_limit.seg;
+ }
+ }
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ read_unlock(&tasklist_lock);
+#endif
return 0;
#endif
}
+#endif /* !AFS_LINUX24_ENV */