Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / libcfs / libcfs / winnt / winnt-utils.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see [sun.com URL with a
20  * copy of GPLv2].
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37
38 /*
39  * miscellaneous libcfs stuff
40  */
41 #define DEBUG_SUBSYSTEM S_LNET
42 #include <lnet/types.h>
43
44 /*
45  * Convert server error code to client format. Error codes are from
46  * Linux errno.h, so for Linux client---identity.
47  */
48 int convert_server_error(__u64 ecode)
49 {
50         return cfs_error_code((NTSTATUS)ecode);
51 }
52
53 /*
54  * convert <fcntl.h> flag from client to server.
55  * 
56  * nt kernel uses several members to describe the open flags
57  * such as DesiredAccess/ShareAccess/CreateDisposition/CreateOptions
58  * so it's better to convert when using, not here.
59  */
60
61 int convert_client_oflag(int cflag, int *result)
62 {
63     *result = 0;
64         return 0;
65 }
66
67
68 int cfs_error_code(NTSTATUS Status)
69 {
70     switch (Status) {
71
72         case STATUS_ACCESS_DENIED:
73             return (-EACCES);
74
75         case STATUS_ACCESS_VIOLATION:
76             return (-EFAULT);
77     
78         case STATUS_BUFFER_TOO_SMALL:
79             return (-ETOOSMALL);
80
81         case STATUS_INVALID_PARAMETER:
82             return (-EINVAL);
83
84         case STATUS_NOT_IMPLEMENTED:
85         case STATUS_NOT_SUPPORTED:
86             return (-EOPNOTSUPP);
87
88         case STATUS_INVALID_ADDRESS:
89         case STATUS_INVALID_ADDRESS_COMPONENT:
90             return (-EADDRNOTAVAIL);
91
92         case STATUS_NO_SUCH_DEVICE:
93         case STATUS_NO_SUCH_FILE:
94         case STATUS_OBJECT_NAME_NOT_FOUND:
95         case STATUS_OBJECT_PATH_NOT_FOUND:  
96         case STATUS_NETWORK_BUSY:
97         case STATUS_INVALID_NETWORK_RESPONSE:
98         case STATUS_UNEXPECTED_NETWORK_ERROR:
99             return (-ENETDOWN);
100
101         case STATUS_BAD_NETWORK_PATH:
102         case STATUS_NETWORK_UNREACHABLE:
103         case STATUS_PROTOCOL_UNREACHABLE:     
104             return (-ENETUNREACH);
105
106         case STATUS_LOCAL_DISCONNECT:
107         case STATUS_TRANSACTION_ABORTED:
108         case STATUS_CONNECTION_ABORTED:
109             return (-ECONNABORTED);
110
111         case STATUS_REMOTE_DISCONNECT:
112         case STATUS_LINK_FAILED:
113         case STATUS_CONNECTION_DISCONNECTED:
114         case STATUS_CONNECTION_RESET:
115         case STATUS_PORT_UNREACHABLE:
116             return (-ECONNRESET);
117
118         case STATUS_PAGEFILE_QUOTA:
119         case STATUS_NO_MEMORY:
120         case STATUS_CONFLICTING_ADDRESSES:
121         case STATUS_QUOTA_EXCEEDED:
122         case STATUS_TOO_MANY_PAGING_FILES:
123         case STATUS_INSUFFICIENT_RESOURCES:
124         case STATUS_WORKING_SET_QUOTA:
125         case STATUS_COMMITMENT_LIMIT:
126         case STATUS_TOO_MANY_ADDRESSES:
127         case STATUS_REMOTE_RESOURCES:
128             return (-ENOBUFS);
129
130         case STATUS_INVALID_CONNECTION:
131             return (-ENOTCONN);
132
133         case STATUS_PIPE_DISCONNECTED:
134             return (-ESHUTDOWN);
135
136         case STATUS_TIMEOUT:
137         case STATUS_IO_TIMEOUT:
138         case STATUS_LINK_TIMEOUT:
139             return (-ETIMEDOUT);
140
141         case STATUS_REMOTE_NOT_LISTENING:
142         case STATUS_CONNECTION_REFUSED:
143             return (-ECONNREFUSED);
144
145         case STATUS_HOST_UNREACHABLE:
146             return (-EHOSTUNREACH);
147
148         case STATUS_PENDING:
149         case STATUS_DEVICE_NOT_READY:
150             return (-EAGAIN);
151
152         case STATUS_CANCELLED:
153         case STATUS_REQUEST_ABORTED:
154             return (-EINTR);
155
156         case STATUS_BUFFER_OVERFLOW:
157         case STATUS_INVALID_BUFFER_SIZE:
158             return (-EMSGSIZE);
159
160     }
161
162     if (NT_SUCCESS(Status)) 
163         return 0;
164
165     return (-EINVAL);
166 }
167
168
169 void cfs_stack_trace_fill(struct cfs_stack_trace *trace)
170 {
171 }
172
173 void *cfs_stack_trace_frame(struct cfs_stack_trace *trace, int frame_no)
174 {
175     return NULL;
176 }