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.
23 #include "include/includes.h"
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
39 Return the major devicenumber for UNIX extensions.
41 static uint32_t unix_dev_major(dev_t dev)
43 #if defined(HAVE_DEVICE_MAJOR_FN)
44 return (uint32)major(dev);
46 return (uint32)(dev >> 8);
51 Return the minor devicenumber for UNIX extensions.
53 static uint32_t unix_dev_minor(dev_t dev)
55 #if defined(HAVE_DEVICE_MINOR_FN)
56 return (uint32)minor(dev);
58 return (uint32)(dev & 0xff);
63 Return the filetype for UNIX extensions
65 static uint32_t unix_filetype(mode_t mode)
67 if (S_ISREG(mode)) return UNIX_TYPE_FILE;
68 if (S_ISDIR(mode)) return UNIX_TYPE_DIR;
70 if (S_ISLNK(mode)) return UNIX_TYPE_SYMLINK;
73 if (S_ISCHR(mode)) return UNIX_TYPE_CHARDEV;
76 if (S_ISBLK(mode)) return UNIX_TYPE_BLKDEV;
79 if (S_ISFIFO(mode)) return UNIX_TYPE_FIFO;
82 if (S_ISSOCK(mode)) return UNIX_TYPE_SOCKET;
85 DEBUG(0,("unix_filetype: unknown filetype %u", (unsigned)mode));
86 return UNIX_TYPE_UNKNOWN;
90 /****************************************************************************
91 Change a unix mode to a dos mode.
92 ****************************************************************************/
93 static uint32_t dos_mode_from_stat(struct pvfs_state *pvfs, struct stat *st)
97 if ((st->st_mode & S_IWUSR) == 0)
98 result |= FILE_ATTRIBUTE_READONLY;
100 if ((pvfs->flags & PVFS_FLAG_MAP_ARCHIVE) && ((st->st_mode & S_IXUSR) != 0))
101 result |= FILE_ATTRIBUTE_ARCHIVE;
103 if ((pvfs->flags & PVFS_FLAG_MAP_SYSTEM) && ((st->st_mode & S_IXGRP) != 0))
104 result |= FILE_ATTRIBUTE_SYSTEM;
106 if ((pvfs->flags & PVFS_FLAG_MAP_HIDDEN) && ((st->st_mode & S_IXOTH) != 0))
107 result |= FILE_ATTRIBUTE_HIDDEN;
109 if (S_ISDIR(st->st_mode))
110 result = FILE_ATTRIBUTE_DIRECTORY | (result & FILE_ATTRIBUTE_READONLY);
112 #if defined (HAVE_STAT_ST_BLOCKS) && defined (HAVE_STAT_ST_BLKSIZE)
113 if (st->st_size > st->st_blocks * (off_t)st->st_blksize) {
114 result |= FILE_ATTRIBUTE_SPARSE;
119 (FILE_ATTRIBUTE_READONLY|
120 FILE_ATTRIBUTE_ARCHIVE|
121 FILE_ATTRIBUTE_SYSTEM|
122 FILE_ATTRIBUTE_HIDDEN|
123 FILE_ATTRIBUTE_DIRECTORY))) {
124 result |= FILE_ATTRIBUTE_NORMAL;
133 fill in the dos file attributes for a file
135 NTSTATUS pvfs_fill_dos_info(struct pvfs_state *pvfs, struct pvfs_filename *name)
137 /* for now just use the simple samba mapping */
138 unix_to_nt_time(&name->dos.create_time, name->st.st_ctime);
139 unix_to_nt_time(&name->dos.access_time, name->st.st_atime);
140 unix_to_nt_time(&name->dos.write_time, name->st.st_mtime);
141 unix_to_nt_time(&name->dos.change_time, name->st.st_mtime);
142 name->dos.attrib = dos_mode_from_stat(pvfs, &name->st);
143 name->dos.alloc_size = name->st.st_size;
144 name->dos.nlink = name->st.st_nlink;
145 name->dos.ea_size = 0;
146 name->dos.file_id = (((uint64_t)name->st.st_dev)<<32) | name->st.st_ino;