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(5,("sending qpathinfo\n"));
68 if (cli_qpathinfo(&srv->cli, path, c_time, a_time, m_time,
69 size, mode)) return True;
71 DEBUG(5,("qpathinfo OK\n"));
73 /* if this is NT then don't bother with the getatr */
74 if (srv->cli.capabilities & CAP_NT_SMBS) return False;
76 if (cli_getatr(&srv->cli, path, mode, size, m_time)) {
77 a_time = c_time = m_time;
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 if (!cli_qfileinfo(&file->srv->cli, file->f->cli_fd,
139 &mode, &size, &c_time, &a_time, &m_time) &&
140 !cli_getattrE(&file->srv->cli, file->f->cli_fd,
141 &mode, &size, &c_time, &a_time, &m_time)) {
147 smbw_setup_stat(st, file->f->fname, size, mode);
149 st->st_atime = a_time;
150 st->st_ctime = c_time;
151 st->st_mtime = m_time;
152 st->st_dev = file->srv->dev;
159 /*****************************************************
161 *******************************************************/
162 int smbw_stat(const char *fname, struct stat *st)
164 struct smbw_server *srv;
165 fstring server, share;
167 time_t m_time=0, a_time=0, c_time=0;
180 /* work out what server they are after */
181 smbw_parse_path(fname, server, share, path);
183 /* get a connection to the server */
184 srv = smbw_server(server, share);
186 /* smbw_server sets errno */
190 if (strncmp(srv->cli.dev,"IPC",3) == 0) {
191 mode = aDIR | aRONLY;
192 } else if (strncmp(srv->cli.dev,"LPT",3) == 0) {
193 if (strcmp(path,"\\") == 0) {
194 mode = aDIR | aRONLY;
197 smbw_stat_printjob(srv, path, &size, &m_time);
198 c_time = a_time = m_time;
201 if (!smbw_getatr(srv, path,
202 &mode, &size, &c_time, &a_time, &m_time)) {
203 errno = smbw_errno(&srv->cli);
208 smbw_setup_stat(st, path, size, mode);
210 st->st_atime = a_time;
211 st->st_ctime = c_time;
212 st->st_mtime = m_time;
213 st->st_dev = srv->dev;