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