Remove pre-Linux 2.6 support
[openafs.git] / src / afs / LINUX / osi_misc.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * Linux support routines.
12  *
13  */
14 #include <afsconfig.h>
15 #include "afs/param.h"
16
17
18 #include <linux/module.h> /* early to avoid printf->printk mapping */
19 #include "h/dcache.h"
20 #include "h/namei.h"
21 #include "h/kthread.h"
22 #include "afs/sysincludes.h"
23 #include "afsincludes.h"
24 #include "afs/afs_stats.h"
25 #include "h/smp_lock.h"
26
27 int afs_osicred_initialized = 0;
28 AFS_UCRED afs_osi_cred;
29
30 void
31 afs_osi_SetTime(osi_timeval_t * tvp)
32 {
33     struct timespec tv;
34     tv.tv_sec = tvp->tv_sec;
35     tv.tv_nsec = tvp->tv_usec * NSEC_PER_USEC;
36
37     AFS_STATCNT(osi_SetTime);
38
39     do_settimeofday(&tv);
40 }
41
42 void
43 osi_linux_mask(void)
44 {
45     SIG_LOCK(current);
46     sigfillset(&current->blocked);
47     RECALC_SIGPENDING(current);
48     SIG_UNLOCK(current);
49 }
50
51 /* LOOKUP_POSITIVE is becoming the default */
52 #ifndef LOOKUP_POSITIVE
53 #define LOOKUP_POSITIVE 0
54 #endif
55 /* Lookup name and return vnode for same. */
56 int
57 osi_lookupname_internal(char *aname, int followlink, struct vfsmount **mnt,
58                         struct dentry **dpp)
59 {
60     int code;
61     struct nameidata nd;
62     int flags = LOOKUP_POSITIVE;
63     code = ENOENT;
64
65     if (followlink)
66        flags |= LOOKUP_FOLLOW;
67     code = path_lookup(aname, flags, &nd);
68
69     if (!code) {
70 #if defined(STRUCT_NAMEIDATA_HAS_PATH)
71         *dpp = dget(nd.path.dentry);
72         if (mnt)
73             *mnt = mntget(nd.path.mnt);
74         path_put(&nd.path);
75 #else
76         *dpp = dget(nd.dentry);
77         if (mnt)
78            *mnt = mntget(nd.mnt);
79         path_release(&nd);
80 #endif
81     }
82     return code;
83 }
84
85 int
86 osi_lookupname(char *aname, uio_seg_t seg, int followlink, 
87                struct dentry **dpp)
88 {
89     int code;
90     char *tname;
91     code = ENOENT;
92     if (seg == AFS_UIOUSER) {
93         tname = getname(aname);
94         if (IS_ERR(tname)) 
95             return PTR_ERR(tname);
96     } else {
97         tname = aname;
98     }
99     code = osi_lookupname_internal(tname, followlink, NULL, dpp);   
100     if (seg == AFS_UIOUSER) {
101         putname(tname);
102     }
103     return code;
104 }
105
106 int osi_abspath(char *aname, char *buf, int buflen,
107                 int followlink, char **pathp)
108 {
109     struct dentry *dp = NULL;
110     struct vfsmount *mnt = NULL;
111     char *tname, *path;
112     int code;
113
114     code = ENOENT;
115     tname = getname(aname);
116     if (IS_ERR(tname)) 
117         return -PTR_ERR(tname);
118     code = osi_lookupname_internal(tname, followlink, &mnt, &dp);   
119     if (!code) {
120 #if defined(D_PATH_TAKES_STRUCT_PATH)
121         struct path p = { mnt, dp };
122         path = d_path(&p, buf, buflen);
123 #else
124         path = d_path(dp, mnt, buf, buflen);
125 #endif
126
127         if (IS_ERR(path)) {
128             code = -PTR_ERR(path);
129         } else {
130             *pathp = path;
131         }
132
133         dput(dp);
134         mntput(mnt);
135     }
136
137     putname(tname);
138     return code;
139 }
140
141
142 /* This could use some work, and support on more platforms. */
143 int afs_thread_wrapper(void *rock)
144 {
145     void (*proc)(void) = rock;
146     __module_get(THIS_MODULE);
147     AFS_GLOCK();
148     (*proc)();
149     AFS_GUNLOCK();
150     module_put(THIS_MODULE);
151     return 0;
152 }
153
154 void afs_start_thread(void (*proc)(void), char *name)
155 {
156     kthread_run(afs_thread_wrapper, proc, "%s", name);
157 }