Приемы профессиональной работы в UNIX

         

ТЕКСТ ПРОГРАММЫ


1 char id[] = "@(#) c v1.0 Fast clear screen Author: Russ Sage"; Быстрая очистка экрана 3 #define FF "\014" 5 main() 6 { 7 if (write(1, FF, 1) == -1) 8 write(2,"c: write error to stdout\n",25); ошибка записи в стандартный вывод 9 }


1 : 2 # @(#) mntf v1.0 Mount floppies Author: Russ Sage Монтирование гибких дисков 4 CMD="/etc/mount" 5 DIR="/mnt" 6 DRIVE="0" 7 DENSITY="48ds9" 8 SYSTEM="xenix" 10 if [ $# -gt 0 ] 11 then for ARG in $* 12 do 13 case $ARG in 14 -d) CMD="/etc/umount" 15 DIR="";; 16 -h) DENSITY="96ds15";; 17 -1) DRIVE="1" 18 if [ -d /mnt1 ] 19 then DIR="/mnt1" 20 else echo "the directory /mnt1 does not exist" >&2 нет каталога /mnt1 21 echo "using the directory /mnt instead" >&2 используется каталог /mnt 22 fi;; 23 -r) DIR="$DIR -r";; 24 -s) SYSTEM="sysv";; 25 *) echo "mntf: invalid argument $ARG" >&2 26 echo "usage: mntf [-d] [-h] [-1] [-r] [-s]" >&2 27 echo " -d dismount" >&2 28 echo " -h high density" >&2 29 echo " -1 use drive 1" >&2 30 echo " -r read only" >&2 31 echo " -s System V device" >&2 32 echo " default: mount XENIX drive 0 48 tpi to " >&2 33 echo " /mnt as a read/write filesystem" >&2 34 exit 1;; 35 esac 36 done 37 fi 39 case $SYSTEM in 40 sysv) $CMD /dev/fp${DRIVE}21 $DIR;; 41 xenix) $CMD /dev/fd${DRIVE}${DENSITY} $DIR;; 42 esac




1 static char id[] = "@(#) mntlook v1.0 Look for mounts Author: Russ Sage"; Поиск файловых систем

3 #include 4 #include 5 #include 6 #include 7 #include

9 #define BSIZ 512

11 main(argc,argv) 12 int argc; 13 char *argv[]; 14 { 15 struct filsys sb; 16 int d, dev; 17 char buf[BSIZ];

19 for (d = 1; d < argc; d++) 20 { 21 if (argv[d][0] == '-') 22 { 23 printf("mntlook: invalid argument %s\n", argv[d]); 24 printf("usage: mntlook device [device ...]\n"); 25 continue; 26 } 27 if ((dev = open(argv[d],O_RDONLY)) < 0) 28 { 29 sprintf(buf, "cannot open %s",argv[d]); невозможно открыть 30 perror(buf); 31 continue; 32 }

34 /* throw away first block */ обойти первый блок 35 if (read(dev, &sb, sizeof(sb)) == -1) 36 { 37 perror("cannot read block 0"); не читается блок 0 38 continue; 39 }

41 /* block 1 is the superblock */ блок 1 является суперблоком 42 if (read(dev, &sb, sizeof(sb)) == -1) 43 { 44 perror("cannot read block 1"); не читается блок 1 45 continue; 46 }

48 if (sb.s_magic == S_S3MAGIC) 49 { 50 printf("\nDEV: %s --> VALID file system\n",argv[d]); 51 printf("filsys: %s\n",sb.s_fname); 52 printf("pack : %s\n",sb.s_fpack); 53 printf("type : %s byte block\n", 54 (sb.s_type == S_B512) ? "512" : "1024"); 55 printf("magic : %lx\n",sb.s_magic); 56 }

58 close(dev); 59 } 60 }




1 : 2 # @(#)umntsys v1.0 Unmount all file systems Author: Russ Sage Размонтирование всех файловых систем

4 if [ "$#" -gt 0 ] 5 then echo "umntsys: too many arguments" >&2 6 echo "usage: umntsys" >&2 7 exit 1 8 fi

10 /etc/mount | sed -n -e '/^\/ /d' -e 's/^.* on \(.*\) read.*/umount \1/p' | sh -




1 char id[] = "@(#) lrgf v1.0 Create the largest file Author: Russ Sage Создать файл максимального размера

3 #include 4 #include 5 #include 6 #include

8 #define FSIZ 512 9 #define BSIZ 1024

11 long ulimit(); 12 char buf[BSIZ];

14 main() 15 { 16 register int n, fd, bcnt; 17 char file[FSIZ];

19 for (bcnt=0; bcnt



Содержание раздела