source: branches/samba-3.0/examples/libsmbclient/smbwrapper/smbw_stat.c

Last change on this file was 1, checked in by Paul Smedley, 18 years ago

Initial code import

File size: 3.1 KB
Line 
1/*
2 Unix SMB/Netbios implementation.
3 Version 2.0
4 SMB wrapper stat functions
5 Copyright (C) Andrew Tridgell 1998
6 Copyright (C) Derrell Lipman 2003-2005
7
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.
12
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.
17
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.
21*/
22
23#include "smbw.h"
24
25static void copy_stat(struct SMBW_stat *external, struct stat *internal)
26{
27 external->s_dev = internal->st_dev;
28 external->s_ino = internal->st_ino;
29 external->s_mode = internal->st_mode;
30 external->s_nlink = internal->st_nlink;
31 external->s_uid = internal->st_uid;
32 external->s_gid = internal->st_gid;
33 external->s_rdev = internal->st_rdev;
34 external->s_size = internal->st_size;
35 external->s_blksize = internal->st_blksize;
36 external->s_blocks = internal->st_blocks;
37 external->s_atime = internal->st_atime;
38 external->s_mtime = internal->st_mtime;
39 external->s_ctime = internal->st_ctime;
40}
41
42
43/*****************************************************
44a wrapper for fstat()
45*******************************************************/
46int smbw_fstat(int fd_smbw, struct SMBW_stat *st)
47{
48 int fd_client = smbw_fd_map[fd_smbw];
49 struct stat statbuf;
50
51 if (smbc_fstat(fd_client, &statbuf) < 0) {
52 return -1;
53 }
54
55 copy_stat(st, &statbuf);
56
57 return 0;
58}
59
60
61/*****************************************************
62a wrapper for stat()
63*******************************************************/
64int smbw_stat(const char *fname, struct SMBW_stat *st)
65{
66 int simulate;
67 char *p;
68 char path[PATH_MAX];
69 struct stat statbuf;
70
71 SMBW_INIT();
72
73 smbw_fix_path(fname, path);
74
75 p = path + 6; /* look just past smb:// */
76 simulate = (strchr(p, '/') == NULL);
77
78 /* special case for full-network scan, workgroups, and servers */
79 if (simulate) {
80 statbuf.st_dev = 0;
81 statbuf.st_ino = 0;
82 statbuf.st_mode = 0040777;
83 statbuf.st_nlink = 1;
84 statbuf.st_uid = 0;
85 statbuf.st_gid = 0;
86 statbuf.st_rdev = 0;
87 statbuf.st_size = 0;
88 statbuf.st_blksize = 1024;
89 statbuf.st_blocks = 1;
90 statbuf.st_atime = 0; /* beginning of epoch */
91 statbuf.st_mtime = 0; /* beginning of epoch */
92 statbuf.st_ctime = 0; /* beginning of epoch */
93
94 } else if (smbc_stat(path, &statbuf) < 0) {
95 return -1;
96 }
97
98 copy_stat(st, &statbuf);
99
100 return 0;
101}
Note: See TracBrowser for help on using the repository browser.