2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * Linux support routines.
14 #include <afsconfig.h>
15 #include "afs/param.h"
18 #include <linux/module.h> /* early to avoid printf->printk mapping */
19 #if defined(AFS_LINUX26_ENV)
22 #include "h/kthread.h"
24 #include "afs/sysincludes.h"
25 #include "afsincludes.h"
26 #include "afs/afs_stats.h"
27 #if defined(AFS_LINUX24_ENV)
28 #include "h/smp_lock.h"
31 int afs_osicred_initialized = 0;
32 struct AFS_UCRED afs_osi_cred;
35 afs_osi_SetTime(osi_timeval_t * tvp)
37 #if defined(AFS_LINUX24_ENV)
39 #if defined(AFS_LINUX26_ENV)
41 tv.tv_sec = tvp->tv_sec;
42 tv.tv_nsec = tvp->tv_usec * NSEC_PER_USEC;
45 tv.tv_sec = tvp->tv_sec;
46 tv.tv_usec = tvp->tv_usec;
49 AFS_STATCNT(osi_SetTime);
53 extern int (*sys_settimeofdayp) (struct timeval * tv,
54 struct timezone * tz);
58 AFS_STATCNT(osi_SetTime);
61 if (sys_settimeofdayp)
62 (void)(*sys_settimeofdayp) (tvp, NULL);
71 sigfillset(¤t->blocked);
72 RECALC_SIGPENDING(current);
76 #if defined(AFS_LINUX24_ENV)
77 /* LOOKUP_POSITIVE is becoming the default */
78 #ifndef LOOKUP_POSITIVE
79 #define LOOKUP_POSITIVE 0
81 /* Lookup name and return vnode for same. */
83 osi_lookupname_internal(char *aname, int followlink, struct vfsmount **mnt,
88 int flags = LOOKUP_POSITIVE;
92 flags |= LOOKUP_FOLLOW;
93 #if defined(AFS_LINUX26_ENV)
94 code = path_lookup(aname, flags, &nd);
96 if (path_init(aname, flags, &nd))
97 code = path_walk(aname, &nd);
101 #if defined(STRUCT_NAMEIDATA_HAS_PATH)
102 *dpp = dget(nd.path.dentry);
104 *mnt = mntget(nd.path.mnt);
107 *dpp = dget(nd.dentry);
109 *mnt = mntget(nd.mnt);
116 osi_lookupname(char *aname, uio_seg_t seg, int followlink,
122 if (seg == AFS_UIOUSER) {
123 tname = getname(aname);
125 return PTR_ERR(tname);
129 code = osi_lookupname_internal(tname, followlink, NULL, dpp);
130 if (seg == AFS_UIOUSER) {
137 osi_lookupname(char *aname, uio_seg_t seg, int followlink, struct dentry **dpp)
139 struct dentry *dp = NULL;
143 if (seg == AFS_UIOUSER) {
144 dp = followlink ? namei(aname) : lnamei(aname);
146 dp = lookup_dentry(aname, NULL, followlink ? 1 : 0);
149 if (dp && !IS_ERR(dp)) {
162 #ifdef AFS_LINUX26_ENV
163 /* This is right even for Linux 2.4, but on that version d_path is inline
164 * and implemented in terms of __d_path, which is not exported.
166 int osi_abspath(char *aname, char *buf, int buflen,
167 int followlink, char **pathp)
169 struct dentry *dp = NULL;
170 struct vfsmount *mnt = NULL;
175 tname = getname(aname);
177 return -PTR_ERR(tname);
178 code = osi_lookupname_internal(tname, followlink, &mnt, &dp);
180 #if defined(D_PATH_TAKES_STRUCT_PATH)
181 struct path p = { mnt, dp };
182 path = d_path(&p, buf, buflen);
184 path = d_path(dp, mnt, buf, buflen);
188 code = -PTR_ERR(path);
202 /* This could use some work, and support on more platforms. */
203 int afs_thread_wrapper(void *rock)
205 void (*proc)(void) = rock;
206 __module_get(THIS_MODULE);
210 module_put(THIS_MODULE);
214 void afs_start_thread(void (*proc)(void), char *name)
216 kthread_run(afs_thread_wrapper, proc, "%s", name);