home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume07 / vol < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  3.2 KB

  1. From decwrl!ucbvax!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!allbery Thu Aug  3 08:51:18 PDT 1989
  2. Article 994 of comp.sources.misc:
  3. Path: decwrl!ucbvax!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v07i102: which volume am i on?
  7. Message-ID: <61717@uunet.UU.NET>
  8. Date: 28 Jul 89 01:20:53 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: jjb@otter.UUCP (John Burns)
  11. Organization: Hewlett-Packard Laboratories, Bristol, UK.
  12. Lines: 134
  13. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  14.  
  15. Posting-number: Volume 7, Issue 102
  16. Submitted-by: jjb@otter.UUCP (John Burns)
  17. Archive-name: vol
  18.  
  19. [For System V.  Maybe this should become part of C news for those of us who
  20.  don't have the most ultra-modern systems?  ++bsa]
  21.  
  22. #! /bin/sh
  23. # This file was wrapped with "dummyshar".  "sh" this file to extract.
  24. # Contents:  vol.c
  25. echo extracting 'vol.c'
  26. if test -f 'vol.c' -a -z "$1"; then echo Not overwriting 'vol.c'; else
  27. sed 's/^X//' << \EOF > 'vol.c'
  28. X/*
  29. X * This is a little program that prints out the volume on which
  30. X * the specified file resides.
  31. X */
  32. X
  33. Xstatic char RCSid[] = "$Header: vol.c,v 1.1 89/07/20 11:50:03 anon Exp $";
  34. X/*
  35. X * $Log:    vol.c,v $
  36. X * Revision 1.1  89/07/20  11:50:03  11:50:03  jjb ()
  37. X * Initial revision
  38. X * 
  39. X
  40. X * vol will print out the name of the file system on which the
  41. X * current or named directory exists.  It will do the same for all
  42. X * the parents of those directories also.
  43. X
  44. X*/
  45. X#include <stdio.h>
  46. X#include <sys/types.h>
  47. X#include <sys/stat.h>
  48. X#include <string.h>
  49. X
  50. X
  51. X
  52. Xstatic struct mnt_entry{
  53. X    char name[64];
  54. X    dev_t devno;
  55. X}mount_table[32];
  56. Xstatic int mtp = 0;
  57. X
  58. Xextern char *getcwd(/*char *,int*/);
  59. Xextern int   stat (/*char *, struct stat * */);
  60. X
  61. Xmain(argc,argv)
  62. Xchar *argv[];
  63. X{
  64. X    char name[64];
  65. X    /*
  66. X     * pick up /etc/mnttab and
  67. X     *  store data locally
  68. X     */
  69. X    build_mount_table();
  70. X
  71. X    if(argc == 1){
  72. X        process(getcwd(name,sizeof(name)));
  73. X    }
  74. X    else
  75. X        while(--argc){
  76. X
  77. X            process(*++argv);
  78. X        }
  79. X}
  80. Xstatic process(name)
  81. X{
  82. X    char cwd[4096];
  83. X    struct stat buf;
  84. X    char *match();
  85. X
  86. X
  87. X    /*
  88. X     * get the device number from
  89. X     * the stat call as a way of identifying
  90. X     * the volume
  91. X     */
  92. X
  93. X    if( stat(name,&buf) == -1 ){
  94. X        perror(cwd);
  95. X    }
  96. X    else {
  97. X        fprintf(stderr,"%s is on %s\n",name,match(buf.st_dev));
  98. X    }
  99. X
  100. X}
  101. Xbuild_mount_table()
  102. X{
  103. X    char line[2048];
  104. X    struct stat buf;
  105. X
  106. X
  107. X    FILE *mount;
  108. X
  109. X    mount = fopen("/etc/mnttab","r");
  110. X    if(mount == NULL){
  111. X        perror("/etc/mnttab");
  112. X        return;
  113. X    }
  114. X
  115. X    while(fgets(line,sizeof(line)-1,mount)){
  116. X
  117. X        register struct mnt_entry *p = &(mount_table[mtp++]);
  118. X        char filsys[64];
  119. X
  120. X        sscanf(line,"%s %s",p->name,filsys);
  121. X
  122. X        strcat(filsys,"/.");
  123. X        if(stat(filsys,&buf) == -1){
  124. X            perror(filsys) ;
  125. X            p->devno = 0 ;
  126. X            continue;
  127. X        }
  128. X        p->devno = buf.st_dev;
  129. X    }
  130. X}
  131. Xchar * match(id)
  132. Xdev_t id;
  133. X{
  134. X    int i;
  135. X    static char q[32];
  136. X
  137. X    for(i = 0 ; i < mtp ; i++){
  138. X        if(id == mount_table[i].devno)return(mount_table[i].name);
  139. X    }
  140. X
  141. X    sprintf(q,"%X",id);
  142. X    return q;
  143. X}
  144. EOF
  145. chars=`wc -c < 'vol.c'`
  146. if test $chars !=     1909; then echo 'vol.c' is $chars characters, should be     1909 characters!; fi
  147. fi
  148. exit 0
  149.  
  150.  
  151.