2 Unix SMB/Netbios implementation.
4 SMB wrapper stat functions
5 Copyright (C) Andrew Tridgell 1998
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.
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.
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.
24 extern int DEBUGLEVEL;
29 /*****************************************************
30 setup basic info in a stat structure
31 *******************************************************/
32 void smbw_setup_stat(struct stat *st, char *fname, size_t size, int mode)
38 if (IS_DOS_DIR(mode)) {
39 st->st_mode = SMBW_DIR_MODE;
41 st->st_mode = SMBW_FILE_MODE;
44 if (IS_DOS_ARCHIVE(mode)) st->st_mode |= S_IXUSR;
45 if (IS_DOS_SYSTEM(mode)) st->st_mode |= S_IXGRP;
46 if (IS_DOS_HIDDEN(mode)) st->st_mode |= S_IXOTH;
47 if (!IS_DOS_READONLY(mode)) st->st_mode |= S_IWUSR;
51 st->st_blocks = (size+511)/512;
52 st->st_uid = getuid();
53 st->st_gid = getgid();
54 st->st_ino = smbw_inode(fname);
58 /*****************************************************
59 try to do a QPATHINFO and if that fails then do a getatr
60 this is needed because win95 sometimes refuses the qpathinfo
61 *******************************************************/
62 BOOL smbw_getatr(struct smbw_server *srv, char *path,
63 uint32 *mode, size_t *size,
64 time_t *c_time, time_t *a_time, time_t *m_time)
66 DEBUG(4,("sending qpathinfo\n"));
68 if (!srv->no_pathinfo2 &&
69 cli_qpathinfo2(&srv->cli, path, c_time, a_time, m_time, NULL,
70 size, mode)) return True;
72 /* if this is NT then don't bother with the getatr */
73 if (srv->cli.capabilities & CAP_NT_SMBS) return False;
75 if (cli_getatr(&srv->cli, path, mode, size, m_time)) {
76 a_time = c_time = m_time;
77 srv->no_pathinfo2 = True;
84 static struct print_job_info printjob;
86 /*****************************************************
87 gather info from a printjob listing
88 *******************************************************/
89 static void smbw_printjob_stat(struct print_job_info *job)
91 if (strcmp(job->name, printjob.name) == 0) {
96 /*****************************************************
98 *******************************************************/
99 int smbw_stat_printjob(struct smbw_server *srv,char *path,
100 size_t *size, time_t *m_time)
102 if (path[0] == '\\') path++;
104 ZERO_STRUCT(printjob);
106 fstrcpy(printjob.name, path);
107 cli_print_queue(&srv->cli, smbw_printjob_stat);
110 *size = printjob.size;
113 *m_time = printjob.t;
119 /*****************************************************
120 a wrapper for fstat()
121 *******************************************************/
122 int smbw_fstat(int fd, struct stat *st)
124 struct smbw_file *file;
125 time_t c_time, a_time, m_time;
131 file = smbw_file(fd);
133 int ret = smbw_dir_fstat(fd, st);
138 DEBUG(4,("sending qfileinfo\n"));
140 if (!cli_qfileinfo(&file->srv->cli, file->f->cli_fd,
141 &mode, &size, &c_time, &a_time, &m_time) &&
142 !cli_getattrE(&file->srv->cli, file->f->cli_fd,
143 &mode, &size, &c_time, &a_time, &m_time)) {
149 smbw_setup_stat(st, file->f->fname, size, mode);
151 st->st_atime = a_time;
152 st->st_ctime = c_time;
153 st->st_mtime = m_time;
154 st->st_dev = file->srv->dev;
161 /*****************************************************
163 *******************************************************/
164 int smbw_stat(const char *fname, struct stat *st)
166 struct smbw_server *srv;
167 fstring server, share;
169 time_t m_time=0, a_time=0, c_time=0;
178 DEBUG(4,("stat(%s)\n", fname));
184 /* work out what server they are after */
185 smbw_parse_path(fname, server, share, path);
187 /* get a connection to the server */
188 srv = smbw_server(server, share);
190 /* smbw_server sets errno */
194 DEBUG(4,("smbw_stat\n"));
196 if (strncmp(srv->cli.dev,"IPC",3) == 0) {
197 mode = aDIR | aRONLY;
198 } else if (strncmp(srv->cli.dev,"LPT",3) == 0) {
199 if (strcmp(path,"\\") == 0) {
200 mode = aDIR | aRONLY;
203 smbw_stat_printjob(srv, path, &size, &m_time);
204 c_time = a_time = m_time;
207 if (!smbw_getatr(srv, path,
208 &mode, &size, &c_time, &a_time, &m_time)) {
209 errno = smbw_errno(&srv->cli);
214 smbw_setup_stat(st, path, size, mode);
216 st->st_atime = a_time;
217 st->st_ctime = c_time;
218 st->st_mtime = m_time;
219 st->st_dev = srv->dev;