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"
20 #include <linux/module.h> /* early to avoid printf->printk mapping */
21 #include "afs/sysincludes.h"
22 #include "afsincludes.h"
23 #include "afs/afs_stats.h"
24 #if defined(AFS_LINUX24_ENV)
25 #include "h/smp_lock.h"
27 #if defined(AFS_LINUX26_ENV)
29 #include "h/kthread.h"
32 int afs_osicred_initialized = 0;
33 struct AFS_UCRED afs_osi_cred;
36 afs_osi_SetTime(osi_timeval_t * tvp)
38 #if defined(AFS_LINUX24_ENV)
40 #if defined(AFS_LINUX26_ENV)
42 tv.tv_sec = tvp->tv_sec;
43 tv.tv_nsec = tvp->tv_usec * NSEC_PER_USEC;
46 tv.tv_sec = tvp->tv_sec;
47 tv.tv_usec = tvp->tv_usec;
50 AFS_STATCNT(osi_SetTime);
54 extern int (*sys_settimeofdayp) (struct timeval * tv,
55 struct timezone * tz);
59 AFS_STATCNT(osi_SetTime);
62 if (sys_settimeofdayp)
63 (void)(*sys_settimeofdayp) (tvp, NULL);
72 sigfillset(¤t->blocked);
73 RECALC_SIGPENDING(current);
77 #if defined(AFS_LINUX24_ENV)
78 /* LOOKUP_POSITIVE is becoming the default */
79 #ifndef LOOKUP_POSITIVE
80 #define LOOKUP_POSITIVE 0
82 /* Lookup name and return vnode for same. */
84 osi_lookupname_internal(char *aname, int followlink, struct vfsmount **mnt,
89 int flags = LOOKUP_POSITIVE;
93 flags |= LOOKUP_FOLLOW;
94 #if defined(AFS_LINUX26_ENV)
95 code = path_lookup(aname, flags, &nd);
97 if (path_init(aname, flags, &nd))
98 code = path_walk(aname, &nd);
102 #if defined(STRUCT_NAMEIDATA_HAS_PATH)
103 *dpp = dget(nd.path.dentry);
105 *mnt = mntget(nd.path.mnt);
108 *dpp = dget(nd.dentry);
110 *mnt = mntget(nd.mnt);
117 osi_lookupname(char *aname, uio_seg_t seg, int followlink,
123 if (seg == AFS_UIOUSER) {
124 tname = getname(aname);
126 return PTR_ERR(tname);
130 code = osi_lookupname_internal(tname, followlink, NULL, dpp);
131 if (seg == AFS_UIOUSER) {
138 osi_lookupname(char *aname, uio_seg_t seg, int followlink, struct dentry **dpp)
140 struct dentry *dp = NULL;
144 if (seg == AFS_UIOUSER) {
145 dp = followlink ? namei(aname) : lnamei(aname);
147 dp = lookup_dentry(aname, NULL, followlink ? 1 : 0);
150 if (dp && !IS_ERR(dp)) {
163 #ifdef AFS_LINUX26_ENV
164 /* This is right even for Linux 2.4, but on that version d_path is inline
165 * and implemented in terms of __d_path, which is not exported.
167 int osi_abspath(char *aname, char *buf, int buflen,
168 int followlink, char **pathp)
170 struct dentry *dp = NULL;
171 struct vfsmount *mnt = NULL;
176 tname = getname(aname);
178 return -PTR_ERR(tname);
179 code = osi_lookupname_internal(tname, followlink, &mnt, &dp);
181 #if defined(D_PATH_TAKES_STRUCT_PATH)
182 struct path p = { mnt, dp };
183 path = d_path(&p, buf, buflen);
185 path = d_path(dp, mnt, buf, buflen);
189 code = -PTR_ERR(path);
203 /* This could use some work, and support on more platforms. */
204 int afs_thread_wrapper(void *rock)
206 void (*proc)(void) = rock;
207 __module_get(THIS_MODULE);
211 module_put(THIS_MODULE);
215 void afs_start_thread(void (*proc)(void), char *name)
217 kthread_run(afs_thread_wrapper, proc, "%s", name);