Is dfree command implemented?

Ken Weaverling weave at hopi.dtcc.edu
Mon May 10 15:07:33 GMT 1999


On Fri, 7 May 1999, Morgan Hughes wrote:

>   I've run into a situation where I have to use the "dfree command" to 
>   calculate meaningful disk space numbers.  It was pretty simple to hack 
>   together a dfree program, but I couldn't get Samba to use it...  It parsed
>   the option, but wouldn't actually use my program.  After reading the 2.0.3 
>   source, it seems that the "dfree command" isn't ever actually used.

True.

Look at http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=453050513

It was mistakenly dropped out of 2.0.x but should get back in.

Note to Samba developers:  "Pretty please?"  I checked out the latest 
SAMBA_2.0 branch and the change still isn't in there.

I hacked support back in based on code pre 2.0, but I wouldn't consider it
"pretty." It works for us though. (I had some weird problems with ints
being "long long" which gcc supports, but the hardware and scanf didn't on
this box, so I bobbled the ints around. Gotta be a better way...)

You probably should kill the DEBUG(1, ... line I added too...


*** source/param/loadparm.c.orig	Fri Apr 16 01:27:08 1999
--- source/param/loadparm.c	Fri Apr 16 01:27:41 1999
***************
*** 1119,1122 ****
--- 1119,1123 ----
  FN_GLOBAL_STRING(lp_defaultservice,&Globals.szDefaultService)
  FN_GLOBAL_STRING(lp_msg_command,&Globals.szMsgCommand)
+ FN_GLOBAL_STRING(lp_dfree_command,&Globals.szDfree)
  FN_GLOBAL_STRING(lp_hosts_equiv,&Globals.szHostsEquiv)
  FN_GLOBAL_STRING(lp_auto_services,&Globals.szAutoServices)
*** source/smbd/dfree.c.orig	Fri Apr 16 01:18:57 1999
--- source/smbd/dfree.c	Fri Apr 16 03:36:19 1999
***************
*** 196,199 ****
--- 196,200 ----
                                SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize)
  {
+         char *df_command = (char *) lp_dfree_command();
  	int dfree_retval;
  	SMB_BIG_UINT dfree_q = 0;
***************
*** 204,209 ****
  	(*bsize) = 512;
  
! 	fsusage(path, dfree, dsize);
  
  	if (disk_quotas(path, &bsize_q, &dfree_q, &dsize_q)) {
  		(*bsize) = bsize_q;
--- 205,251 ----
  	(*bsize) = 512;
  
! 	/* possibly use system() to get the result */
  
+ 	if (df_command && *df_command)
+ 	  {
+ 	    int ret;
+ 	    pstring syscmd;
+ 	    pstring outfile;
+ 	    
+ 	    slprintf(outfile,sizeof(outfile)-1, "%s/dfree.smb.%d",tmpdir(),(int)getpid());
+ 	    slprintf(syscmd,sizeof(syscmd)-1,"%s %s",df_command,path);
+ 	    standard_sub_basic(syscmd);
+ 	    
+ 	    ret = smbrun(syscmd,outfile,False);
+ 	    DEBUG(1,("Running the command `%s' on %s gave %d\n",syscmd, outfile, ret));
+ 	    
+ 	    {
+ 	      FILE *f = fopen(outfile,"r");
+ 	      *dsize = 0;
+ 	      *dfree = 0;
+ 	      *bsize = 1024;
+ 	      if (f)
+ 		{
+                   int x;
+ 		  int i_dfree, i_dsize, i_bsize;
+ 		  i_bsize = *bsize;
+ 
+ 		  x = fscanf(f,"%d %d %d", &i_dsize, &i_dfree, &i_bsize);
+ 		  DEBUG(3,("disk_free test: dfree = %d dsize = %d bsize = %d\n", i_dfree, i_dsize, i_bsize));
+ 		  *dsize = i_dsize;
+ 		  *dfree = i_dfree;
+ 		  *bsize = i_bsize;
+ 
+ 		  fclose(f);
+ 		}
+ 	      else
+ 		DEBUG(0,("Can't open %s\n",outfile));
+ 	    }
+ 	    
+ 	    unlink(outfile);
+ 	  }
+ 	else {
+ 	  fsusage(path, dfree, dsize);
+ 	}
  	if (disk_quotas(path, &bsize_q, &dfree_q, &dsize_q)) {
  		(*bsize) = bsize_q;



More information about the samba-technical mailing list