LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-06-2005, 10:07 PM   #1
eugenewg
LQ Newbie
 
Registered: Sep 2003
Posts: 10

Rep: Reputation: 0
implementing a call to output disk space for sftp


Hi all,
Note, this is regarding OpenBSD.
I've been trying to figure out how to output to a client sftp user the current disk space and total disk space (other other useful information for that matter) each time a user uploads/deletes/creates file/folders etc. I've made numerous posts on different forums/mailing lists and no one seemed to be able to answer my question. So, I decided to e-mail Theo which e-mailed me back suprisingly in 2 mins flat, and wrote the following:

'There is nothing to do what you want. You'll have to do it by hand.'

So, now, I'm here. I have absolutely no idea where to start with this, learning a new language is not a problem. I already know a decent amount of C++, but it seems that all the books that are listed on the OpenBSD website are all regarding C.
Thank you for your help in advance.

Eugene
 
Old 01-07-2005, 01:46 PM   #2
jwstric2
Member
 
Registered: Jan 2004
Posts: 105

Rep: Reputation: 15
considering if you have the sftp source code you will need to insert some code to send a message displaying the disk space. THe disk space code is pretty simple.

first :

man statfs , this is a good start place


Code:
/*Find mount point for a particular directory*/
static char *
find_mount_point (const char *file)
{
  char saved_cwd[MAXFILEPATH];
  static char mp[MAXFILEPATH];
  struct stat last_stat;

  getcwd (saved_cwd, MAXFILEPATH);

  if (chdir (file) < 0){
    return NULL;
  }
  
  if (stat (".", &last_stat) < 0){
    goto done;
  }

  /* Now walk up FILE's parents until we find another filesystem or /,
     chdiring as we go.  LAST_STAT holds stat information for the last place
     we visited.  */
  for (;;)
    {
      struct stat st;
      if (stat ("..", &st) < 0)
  goto done;
      if (st.st_dev != last_stat.st_dev || st.st_ino == last_stat.st_ino)
  /* cwd is the mount point.  */
  break;
      if (chdir ("..") < 0)
  goto done;
      last_stat = st;
    }

  /* Finally reached a mount point, see what it's called.  */
  getcwd (mp, MAXFILEPATH);

done:
  /* Restore the original cwd.  */
  {
    int save_errno = errno;
    chdir(saved_cwd);
    errno = save_errno;
  }

  return mp;
}
Code:
/*Find statitics of mount*/
static void refreshMount(char *mount){
  struct statfs s;
  long long usedSize;
  long long freeSize;

  if (statfs(mount, &s) != 0) {    
    return;
  }
   
  usedSize = (long long)((((long long)s.f_blocks) - s.f_bfree)* s.f_bsize);
  freeSize = (long long)(((long long)s.f_bavail) * s.f_bsize);      
  
}
I had to rip some of my code out but this should work for you. Give it a whirl.
 
Old 01-09-2005, 08:38 PM   #3
eugenewg
LQ Newbie
 
Registered: Sep 2003
Posts: 10

Original Poster
Rep: Reputation: 0
Thank you so much for you help jwstric2. I was wondering which books would you suggest to read in order to learn C, and integrate it with the operating system?
Thank you,

Eugene
 
Old 01-09-2005, 09:10 PM   #4
jwstric2
Member
 
Registered: Jan 2004
Posts: 105

Rep: Reputation: 15
Well I never really read a book but one of the bests I've been told is one of the oldest, The C Programming Language by Brian W Kernighan. So some googling searching though and get a grasp of how memory is laid out, how memory allocation works, ect.. I think once I understood most of the underlying concepts of the system, it make programming in any language much more simple.

Good luck
 
Old 01-09-2005, 09:13 PM   #5
eugenewg
LQ Newbie
 
Registered: Sep 2003
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks again, I have already ordered that book from previous googling.

Eugene
 
Old 01-10-2005, 04:44 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
This is the book you need... (ask anyone)

http://www.amazon.com/gp/reader/0201...21#reader-link
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
poll system call in kernel space xatzipol Programming 0 10-16-2005 07:03 AM
3Gb of disk space lost! Disk space problem or mother board conflicts with HDD Mistreated Linux - Hardware 4 12-06-2004 03:58 PM
Need help on implementing disk quotas Red Hat 8.0 goldenradium Linux - General 1 12-22-2002 08:47 AM
can interrupt handler call user space function? pot_po Programming 0 11-07-2002 09:32 PM
Disk space wastage 73 GB Hard disk rajgopalhg Linux - Hardware 2 10-18-2002 03:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration