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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "vfs_posix.h"
25 /****************************************************************************
26 Change a unix mode to a dos mode.
27 ****************************************************************************/
28 static uint32_t dos_mode_from_stat(struct pvfs_state *pvfs, struct stat *st)
32 if ((st->st_mode & S_IWUSR) == 0)
33 result |= FILE_ATTRIBUTE_READONLY;
35 if ((pvfs->flags & PVFS_FLAG_MAP_ARCHIVE) && ((st->st_mode & S_IXUSR) != 0))
36 result |= FILE_ATTRIBUTE_ARCHIVE;
38 if ((pvfs->flags & PVFS_FLAG_MAP_SYSTEM) && ((st->st_mode & S_IXGRP) != 0))
39 result |= FILE_ATTRIBUTE_SYSTEM;
41 if ((pvfs->flags & PVFS_FLAG_MAP_HIDDEN) && ((st->st_mode & S_IXOTH) != 0))
42 result |= FILE_ATTRIBUTE_HIDDEN;
44 if (S_ISDIR(st->st_mode))
45 result = FILE_ATTRIBUTE_DIRECTORY | (result & FILE_ATTRIBUTE_READONLY);
53 fill in the dos file attributes for a file
55 NTSTATUS pvfs_fill_dos_info(struct pvfs_state *pvfs, struct pvfs_filename *name, int fd)
57 /* make directories appear as size 0 with 1 link */
58 if (S_ISDIR(name->st.st_mode)) {
60 name->st.st_nlink = 1;
63 /* for now just use the simple samba mapping */
64 unix_to_nt_time(&name->dos.create_time, name->st.st_ctime);
65 unix_to_nt_time(&name->dos.access_time, name->st.st_atime);
66 unix_to_nt_time(&name->dos.write_time, name->st.st_mtime);
67 unix_to_nt_time(&name->dos.change_time, name->st.st_ctime);
68 #ifdef HAVE_STAT_TV_NSEC
69 name->dos.create_time += name->st.st_ctim.tv_nsec / 100;
70 name->dos.access_time += name->st.st_atim.tv_nsec / 100;
71 name->dos.write_time += name->st.st_mtim.tv_nsec / 100;
72 name->dos.change_time += name->st.st_ctim.tv_nsec / 100;
74 name->dos.attrib = dos_mode_from_stat(pvfs, &name->st);
75 name->dos.alloc_size = pvfs_round_alloc_size(pvfs, name->st.st_size);
76 name->dos.nlink = name->st.st_nlink;
77 name->dos.ea_size = 4;
78 name->dos.file_id = (((uint64_t)name->st.st_dev)<<32) | name->st.st_ino;
81 return pvfs_dosattrib_load(pvfs, name, fd);
86 return a set of unix file permissions for a new file or directory
88 mode_t pvfs_fileperms(struct pvfs_state *pvfs, uint32_t attrib)
90 mode_t mode = (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH);
92 if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE) &&
93 (attrib & FILE_ATTRIBUTE_READONLY)) {
94 mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
97 if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE)) {
98 if ((attrib & FILE_ATTRIBUTE_ARCHIVE) &&
99 (pvfs->flags & PVFS_FLAG_MAP_ARCHIVE)) {
102 if ((attrib & FILE_ATTRIBUTE_SYSTEM) &&
103 (pvfs->flags & PVFS_FLAG_MAP_SYSTEM)) {
106 if ((attrib & FILE_ATTRIBUTE_HIDDEN) &&
107 (pvfs->flags & PVFS_FLAG_MAP_HIDDEN)) {
112 if (attrib & FILE_ATTRIBUTE_DIRECTORY) {
113 mode |= (S_IFDIR | S_IWUSR);
114 mode |= (S_IXUSR | S_IXGRP | S_IXOTH);
115 mode &= pvfs->options.dir_mask;
116 mode |= pvfs->options.force_dir_mode;
118 mode &= pvfs->options.create_mask;
119 mode |= pvfs->options.force_create_mode;