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