source: TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_statfs.c @ 1395

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_statfs.c
Revision 1395, 5.4 KB checked in by spascoe, 14 years ago (diff)

Eliminated all "implicit declaration" warnings from "python setup.py
build"

Line 
1/*
2 * bbftpd/bbftpd_statfs.c
3 * Copyright (C) 1999, 2000, 2001, 2002 IN2P3, CNRS
4 * bbftp@in2p3.fr
5 * http://doc.in2p3.fr/bbftp
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or any later version.
11 *
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.
16 *
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */ 
21
22/****************************************************************************
23
24 
25 RETURN:
26        0  Keep the connection open (does not mean that the file has been
27           successfully created)
28        -1 Tell the calling program to close the connection
29 
30 *****************************************************************************/
31#include <bbftpd.h>
32#ifdef DARWIN
33#define HAVE_STRUCT_STATFS 1
34#endif
35
36#include <stdio.h>
37#include <stdlib.h>
38#include <bbftpd_private_log.h>
39#include <utime.h>
40#include <errno.h>
41#ifdef HAVE_SYS_STATVFS_H
42# include <sys/types.h>
43# include <sys/statvfs.h>
44#elif defined(HAVE_SYS_VFS_H)
45# include <sys/vfs.h>
46#endif
47#ifdef DARWIN
48#include <sys/mount.h>
49#endif
50
51#if HAVE_STRING_H
52# include <string.h>
53#endif
54#include <netinet/in.h>
55#include <common.h>
56#include <daemon.h>
57#include <daemon_proto.h>
58#include <structures.h>
59
60#ifdef NDG_AUTH
61# include "ndg.h"
62#endif
63
64extern int transferoption ;
65extern  int     recvcontrolto ;
66
67int bbftpd_statfs(int sock,int msglen) 
68{
69#if defined(HAVE_STATVFS64) || defined(HAVE_STATVFS) || defined(HAVE_STATFS)
70    char    *buffer ;
71    char    *logmessage ;
72    struct  mess_dir *msg_file ;
73    char    *dirname ;
74    int     recursif ;
75    int     retcode ;
76
77# ifdef HAVE_STRUCT_STATVFS64
78    struct statvfs64 statfsbuf;
79# elif defined(HAVE_STRUCT_STATVFS)
80    struct statvfs statfsbuf;
81# elif defined(HAVE_STRUCT_STATFS)
82    struct statfs statfsbuf;
83# endif
84#ifdef _SX
85    int statlen, fstyp=0;
86# endif
87
88    if ( (buffer = (char *) malloc (msglen+1) ) == NULL ) {
89        bbftpd_log(BBFTPD_ERR,"Unable to malloc space for dir name (%d)",msglen) ;
90        reply(MSG_BAD,"Unable to malloc space for file name") ;
91        return 0 ;
92    }
93    if ( (logmessage = (char *) malloc (msglen+1024) ) == NULL ) {
94        bbftpd_log(BBFTPD_ERR,"Unable to malloc space for logmessage ") ;
95        reply(MSG_BAD,"Unable to malloc space for logmessage") ;
96        FREE(buffer) ;
97        return 0 ;
98    }
99    /*
100    ** Read the characteristics of the file
101    */
102    if ( readmessage(sock,buffer,msglen,recvcontrolto) < 0 ) {
103        /*
104        ** Error ...
105        */
106        bbftpd_log(BBFTPD_ERR,"Error reading dir name") ;
107        FREE(buffer) ;
108        FREE(logmessage) ;
109        return -1 ;
110    }
111    buffer[msglen] = '\0' ;
112    msg_file = (struct mess_dir *) buffer ;
113#ifdef NDG_AUTH
114    if (bbftpd_private_authz_control(MSG_DF, msg_file->transferoption, msg_file->dirname,
115                                     logmessage) != 0) {
116      bbftpd_log(BBFTPD_ERR, logmessage);
117      reply(MSG_BAD, logmessage);
118      FREE(buffer);
119      FREE(logmessage);
120      return 0;
121    }
122#endif // NDG_AUTH
123    transferoption  = msg_file->transferoption ;
124    dirname = msg_file->dirname ;
125   
126    if ( (transferoption & TROPT_RFIO) == TROPT_RFIO ) {
127#if defined(WITH_RFIO) || defined(WITH_RFIO64)
128        sprintf(logmessage,"df is not supported by RFIO") ;
129#else
130        sprintf(logmessage,"RFIO is not supported by the server") ;
131#endif
132        reply(MSG_BAD_NO_RETRY,logmessage) ;
133        FREE(buffer) ;
134        FREE(logmessage) ;
135        return 0 ;
136    }
137
138#ifdef HAVE_STATVFS64
139    if (statvfs64(dirname,&statfsbuf) < 0) {
140#elif defined(HAVE_STATVFS)
141    if (statvfs(dirname,&statfsbuf) < 0) {
142#elif _SX
143    if (statfs(dirname,&statfsbuf, statlen, fstyp) < 0) {
144#else
145    if (statfs(dirname,&statfsbuf) < 0) {
146#endif
147        sprintf(logmessage,"Unable to df %s: %s",dirname,strerror(errno)) ;
148        reply(MSG_BAD_NO_RETRY,logmessage) ;
149        FREE(buffer) ;
150        FREE(logmessage) ;
151        return 0 ;
152    } else {
153#ifdef HAVE_STATVFS64
154        sprintf(logmessage,"%" LONG_LONG_FORMAT " %" LONG_LONG_FORMAT " %lu %" LONG_LONG_FORMAT " %" LONG_LONG_FORMAT " %lu", statfsbuf.f_blocks, statfsbuf.f_bavail, statfsbuf.f_frsize, statfsbuf.f_files, statfsbuf.f_ffree, statfsbuf.f_namemax) ;
155#elif defined(HAVE_STATVFS)
156        sprintf(logmessage,"%ld %ld %lu %ld %ld %lu", statfsbuf.f_blocks, statfsbuf.f_bavail, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree, statfsbuf.f_namemax) ;
157#elif _SX
158        sprintf(logmessage,"%ld %ld %ld %ld %ld %ld", statfsbuf.f_blocks, statfsbuf.f_bfree, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree, 0) ;
159#else
160#ifdef DARWIN
161                sprintf(logmessage,"%ld %ld %ld %ld", statfsbuf.f_blocks, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree) ;
162#else
163        sprintf(logmessage,"%ld %ld %ld %ld %ld %ld", statfsbuf.f_blocks, statfsbuf.f_b_avail, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree, statfsbuf.f_namelen) ;
164#endif
165#endif
166        reply(MSG_OK,logmessage) ;
167        FREE(buffer) ;
168        FREE(logmessage) ;
169        return 0 ;
170    }
171#else
172    reply(MSG_BAD_NO_RETRY,"operation not supported by the server") ;
173    return 0 ;
174#endif
175}
Note: See TracBrowser for help on using the repository browser.