df177bcea0a9bf134ce5d4131d3c6066c0d52b76
[ira/wip.git] / source3 / lib / error.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 1.9
4  *  Unix/DOS/NT error code conversions
5  *  Copyright (C) Tim Potter 2000
6  *  
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *  
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *  
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include "includes.h"
23
24 /* Mapping between Unix, DOS and NT error numbers */
25
26 struct unix_error_map unix_dos_nt_errmap[] = {
27         { EPERM, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED },
28         { EACCES, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED },
29         { ENOENT, ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE },
30         { ENOTDIR, ERRDOS, ERRbadpath, NT_STATUS_NOT_A_DIRECTORY },
31         { EIO, ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR },
32         { EBADF, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE },
33         { EINVAL, ERRSRV, ERRsrverror, NT_STATUS_INVALID_HANDLE },
34         { EEXIST, ERRDOS, ERRfilexists, NT_STATUS_ACCESS_DENIED},
35         { ENFILE, ERRDOS, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES },
36         { EMFILE, ERRDOS, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES },
37         { ENOSPC, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL },
38 #ifdef EDQUOT
39         { EDQUOT, ERRHRD, ERRdiskfull, NT_STATUS_DISK_FULL },
40 #endif
41 #ifdef ENOTEMPTY
42         { ENOTEMPTY, ERRDOS, ERRnoaccess, NT_STATUS_DIRECTORY_NOT_EMPTY },
43 #endif
44 #ifdef EXDEV
45         { EXDEV, ERRDOS, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE },
46 #endif
47 #ifdef EROFS
48         { EROFS, ERRHRD, ERRnowrite, NT_STATUS_ACCESS_DENIED },
49 #endif
50         { 0, 0, 0, NT_STATUS_OK }
51 };
52
53 /*********************************************************************
54  Map an NT error code from a Unix error code.
55 *********************************************************************/
56
57 NTSTATUS map_nt_error_from_unix(int unix_error)
58 {
59         int i = 0;
60
61         if (unix_error == 0)
62                 return NT_STATUS_OK;
63
64         /* Look through list */
65         while(unix_dos_nt_errmap[i].unix_error != 0) {
66                 if (unix_dos_nt_errmap[i].unix_error == unix_error)
67                         return unix_dos_nt_errmap[i].nt_error;
68                 i++;
69         }
70
71         /* Default return */
72         return NT_STATUS_ACCESS_DENIED;
73 }