2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "vfs_posix.h"
27 /* UNIX filetype mappings. */
28 #define UNIX_TYPE_FILE 0
29 #define UNIX_TYPE_DIR 1
30 #define UNIX_TYPE_SYMLINK 2
31 #define UNIX_TYPE_CHARDEV 3
32 #define UNIX_TYPE_BLKDEV 4
33 #define UNIX_TYPE_FIFO 5
34 #define UNIX_TYPE_SOCKET 6
35 #define UNIX_TYPE_UNKNOWN 0xFFFFFFFF
38 /****************************************************************************
39 Change a unix mode to a dos mode.
40 ****************************************************************************/
41 static uint32_t dos_mode_from_stat(struct pvfs_state *pvfs, struct stat *st)
45 if ((st->st_mode & S_IWUSR) == 0)
46 result |= FILE_ATTRIBUTE_READONLY;
48 if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE)) {
49 if ((pvfs->flags & PVFS_FLAG_MAP_ARCHIVE) && ((st->st_mode & S_IXUSR) != 0))
50 result |= FILE_ATTRIBUTE_ARCHIVE;
52 if ((pvfs->flags & PVFS_FLAG_MAP_SYSTEM) && ((st->st_mode & S_IXGRP) != 0))
53 result |= FILE_ATTRIBUTE_SYSTEM;
55 if ((pvfs->flags & PVFS_FLAG_MAP_HIDDEN) && ((st->st_mode & S_IXOTH) != 0))
56 result |= FILE_ATTRIBUTE_HIDDEN;
59 if (S_ISDIR(st->st_mode))
60 result = FILE_ATTRIBUTE_DIRECTORY | (result & FILE_ATTRIBUTE_READONLY);
63 (FILE_ATTRIBUTE_READONLY|
64 FILE_ATTRIBUTE_ARCHIVE|
65 FILE_ATTRIBUTE_SYSTEM|
66 FILE_ATTRIBUTE_HIDDEN|
67 FILE_ATTRIBUTE_DIRECTORY))) {
68 result |= FILE_ATTRIBUTE_NORMAL;
77 fill in the dos file attributes for a file
79 NTSTATUS pvfs_fill_dos_info(struct pvfs_state *pvfs, struct pvfs_filename *name, int fd)
81 /* make directories appear as size 0 */
82 if (S_ISDIR(name->st.st_mode)) {
86 /* for now just use the simple samba mapping */
87 unix_to_nt_time(&name->dos.create_time, name->st.st_ctime);
88 unix_to_nt_time(&name->dos.access_time, name->st.st_atime);
89 unix_to_nt_time(&name->dos.write_time, name->st.st_mtime);
90 unix_to_nt_time(&name->dos.change_time, name->st.st_ctime);
91 #ifdef HAVE_STAT_TV_NSEC
92 name->dos.create_time += name->st.st_ctim.tv_nsec / 100;
93 name->dos.access_time += name->st.st_atim.tv_nsec / 100;
94 name->dos.write_time += name->st.st_mtim.tv_nsec / 100;
95 name->dos.change_time += name->st.st_ctim.tv_nsec / 100;
97 name->dos.attrib = dos_mode_from_stat(pvfs, &name->st);
98 name->dos.alloc_size = name->st.st_size;
99 name->dos.nlink = name->st.st_nlink;
100 name->dos.ea_size = 0;
101 name->dos.file_id = (((uint64_t)name->st.st_dev)<<32) | name->st.st_ino;
103 #if HAVE_XATTR_SUPPORT
104 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
105 return pvfs_xattr_load(pvfs, name, fd);
114 return a set of unix file permissions for a new file or directory
116 mode_t pvfs_fileperms(struct pvfs_state *pvfs, uint32 attrib)
118 mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
120 if (attrib & FILE_ATTRIBUTE_DIRECTORY) {
121 mode |= S_IXUSR | S_IXGRP | S_IXOTH;
124 if (!(attrib & FILE_ATTRIBUTE_READONLY)) {
128 if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE)) {
129 if ((attrib & FILE_ATTRIBUTE_ARCHIVE) &&
130 (pvfs->flags & PVFS_FLAG_MAP_ARCHIVE)) {
134 if ((attrib & FILE_ATTRIBUTE_SYSTEM) &&
135 (pvfs->flags & PVFS_FLAG_MAP_SYSTEM)) {
139 if ((attrib & FILE_ATTRIBUTE_HIDDEN) &&
140 (pvfs->flags & PVFS_FLAG_MAP_HIDDEN)) {