% more flatex #!/bin/sh if test -r $1 then rm -rf $1.tex fi Ftex <$1 >$1.tex /usr/local/bin/latex $1.tex /bin/rm -rf $1.tex
% more interdir #! /bin/sh # Packages operation (JJL--nov 89) # d1 := d2 & d3 # copy in d1 files common between d2 and d3. d1=`cd $1; pwd` diff -s -r $2 $3 |\ grep 'Files .* are identical$' |\ awk '{print $2}'| sed -e "s,^$2/,," |\ (cd $2; cpio -pdma $d1)
for
#! /bin/sh DEST="ma@src.dec.com georges" # DEST=levy set -xv # ------------------------------------------- # # le texte # for i in standard.tex standard.bib do mail -s "$i" ${DEST} <$i done # ------------------------------------------- pour envoyer le postscript aptex -Psec -of standard.ps standard.dvi /bin/rm -f standard.ps.Z compress standard.ps uuencode standard.ps.Z standard.ps.Z > standard.ps.Z.uu /bin/rm -f x?? split -1500 standard.ps.Z.uu ll x?? mail -s "TODO PostScript" ${DEST} << ---LA-FIN--- # To get the PostScript # Let xaa, xab, xac, xad ... be the parts. Then catenate without # blank lines in any x??, decode, uncompress and print as follows. cat x?? >standard.ps.Z.uu uudecode standard.ps.Z.uu uncompress standard.ps.Z lpr standard.ps rm x?? ---LA-FIN--- for i in x?? do mail -s "standard.ps-$ï ${DEST} <$i done
# ------------------------------------------- # Pour envoyer les dessins tar cf standard.tex-dessins.tar dessins /bin/rm -f standard.tex-dessins.tar.Z compress standard.tex-dessins.tar uuencode standard.tex-dessins.tar.Z standard.tex-dessins.tar.Z > standard.tex-dessins.tar.Z.uu /bin/rm -f x?? split -1500 standard.tex-dessins.tar.Z.uu ll x?? mail -s "TODO drawings" ${DEST} << ---LA-FIN--- # To get the drawings # Let xaa, xab, xac, xad ... be the parts. Then catenate without # blank lines in any x??, decode, uncompress and print as follows. cat x?? >standard.ps.Z.uu uudecode standard.ps.Z.uu uncompress standard.ps.Z lpr standard.ps rm x?? ---LA-FIN--- for i in x?? do mail -s "standard.tex-dessins-$ï ${DEST} <$i done /bin/rm -f *.uu
/lib/cpp
. Ne pas oublier de mettre des
parenthèses pour les précédences. Ne pas faire d'effet de bord dans
un paramètre dupliqué. Pour voir les effect du préprocesseur, faire
cc -E toto.c
.#define Max(x, y) ((x) < (y) ? (y) : (x))
enum
autant que possibleenum boolean {NO, YES}au lieu de
#define NO 0 #define YES 1
int f (x, y) int x; int y; { ... }au lieu de
int f (int x, int y) { ... }Comme le compilateur est 1 passe, les prototypes peuvent maintenant s'écrire
int i, j; int f (int, int); struct toto x;
archive
dit
librairie comme /lib/libc.a
. Il y a d'autres librairies comme la
librairie mathématique /lib/libm.a
, la librairie X-windows
/usr/lib/libX11.a
. cc
prend comme arguments des sources
xxx.c
, mais aussi des binaires relogeables yyy.o
résultats d'une compilation précédente ou des librairies
/lib/libm.a
. Pour obtenir yyy.o
, faire
cc -c yyy.c
. Pour ne pas taper le nom de la librairie, on
fait simplement cc xxx.c -lm
.
open, read, write, close, seek
marchent avec un petit
entier file descriptor. L'entrée standard a, par convention, 0
pour file descriptor; la sortie standard 1; la sortie erreur
standard 2.fopen, fread, fwrite, ...
fonctionnent avec des file
pointers. Tout est décrit dans man fread
ou dans
/usr/include/stdio.h
. extern struct _iobuf { int _cnt; /* characters left */ char *_ptr; /* next character position */ char *_base; /* location of buffer */ int _bufsiz; /* buffer size */ short _flag; /* mode of file access */ char _file; /* file descriptor */ } _iob[_N_STATIC_IOBS]; #define stdin (&_iob[0]) #define stdout (&_iob[1]) #define stderr (&_iob[2]) #define getc(p) (--(p)->_cnt>=0? *(p)->_ptr++&0377:_filbuf(p)) #define getchar() getc(stdin) #define putc(x,p) \ (--(p)->_cnt>=0? \ ((int)(*(unsigned char *)(p)->_ptr++=(x))):\ _flsbuf((unsigned char)(x),p)) #define putchar(x) putc(x,stdout) #define _IOFBF 00000 #define _IOREAD 00001 #define _IOWRT 00002 #define _IONBF 00004 #define _IOMYBUF 00010 #define _IOEOF 00020 #define _IOERR 00040 #define _IOSTRG 00100 #define _IOLBF 00200 #define _IORW 00400 #define _IOAPPEND 01000
#include <stdio.h> #include <ctype.h> main() { int c; while ((c = getchar()) != EOF) putchar (tolower(c)); return 0; }
#include <stdio.h> /* cat: concatenate files */ main (int argc, char *argv[]) { FILE *fp; void filecopy (FILE *, FILE *); if (argc == 1) filecopy (stdin, stdout) else while (--argc > )) if ((fp = fopen (*++argv, "r")) == NULL) { printf ("cat: can't open %s\n", *argv); return 1; } else { filecopy (fp, stdout); fclose (fp); } return 0; } void filecopy (FILE *ifp, FILE *ofp) { int c; while ((c = getc (ifp)) != EOF) putc (c, ofp); }
#include <stdio.h> /* cat: concatenate files */ main (int argc, char *argv[]) { FILE *fp; void filecopy (FILE *, FILE *); char *prog = argv[0]; if (argc == 1) filecopy (stdin, stdout) else while (--argc > )) if ((fp = fopen (*++argv, "r")) == NULL) { fprintf (stderr, "%s: can't open %s\n", prog, *argv); exit (1); } else { filecopy (fp, stdout); fclose (fp); } if (ferror (stdout)) { fprint (stderr, "%s: error writing stdout\n", prog); exit (2); } exit (0); } void filecopy (FILE *ifp, FILE *ofp) { int c; while ((c = getc (ifp)) != EOF) putc (c, ofp); }
TIT .Computer architecture : a quantitative approach SLA .David A. Patterson, John L. Hennessy ; with a contribution .by David Goldberg. - San Mateo, CA : Morgan Kaufmann, 1990. .- XXVIII-594 p. + annexes ; 25 cm.
/dev
contient les périphériques. ls -l
donnent crw------- 1 root 56, 0 Nov 21 1990 /dev/rrz0a crw------- 1 root 56, 1 Sep 23 18:34 /dev/rrz0b crw------- 1 root 56, 2 Nov 21 1990 /dev/rrz0c brw------- 1 root 21, 0 Sep 23 18:18 /dev/rz0a brw------- 1 root 21, 1 Nov 21 1990 /dev/rz0b brw------- 1 root 21, 2 Nov 21 1990 /dev/rz0cLes 2 chiffres devant la date sont les nombres majeur et mineur de ce périphérique. Le 1er indexe une table des drivers qui gèrent ce device, le 2ème est un sous numéro pour distinguer ce périphérique parmi ceux qui sont gérés par un même driver.
/et{c
/mount} ou regarder la table
/etc/fstab
. Certains noms peuvent être montés sur des
devices distants par NFS (cf. plus tard).
struct dinode { unsigned short di_mode;/* mode and type of file */ short di_nlink; /* number of links to file */ short di_uid; /* owner's user id */ short di_gid; /* owner's group id */ off_t di_size; /* number of bytes in file */ char di_addr[40]; /* disk block addresses */ time_t di_atime; /* time last accessed */ time_t di_mtime; /* time last modified */ time_t di_ctime; /* time created */ }; #define INOPB 8 /* 8 inodes per block */ /* * the 40 address bytes: * 39 used; 13 addresses * of 3 bytes each. */
#define DIRSIZ 14 struct direct { ino_t d_ino; char d_name[DIRSIZ]; };
TIT .The Design of the UNIX operating system SLA .Maurice J. Bach. - Englewood Cliffs, NJ : .Prentice-Hall, 1986. - XIV-471 p. ; 23 cm.Accès au fichier:
/unix
)
df -i
.mkfs
. On précise
l'entrelacement optimal pour laisser le temps de rotation nécessaire
entre 2 accès moyens à des blocs de donnée successifs.
Remarque: beaucoup des commandes Unix prennent les arguments en ordre
canonique (souvent alphabétique) à cause de la convention *
des shells. Or créer des fichiers et les supprimer dans ces
conditions avec une stratégie LIFO aboutit à l'éparpillement!
/usr/include/ufs/fs.h
avec les macros
correspondantes pour donner les adresses disques.
#define itod(fs, x) \ ((daddr_t)(cgimin(fs, itog(fs, x))) + \ (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs)))))) #define itog(fs, x) ((x) / (fs)->fs_ipg) #define cgbase(fs, c) ((daddr_t)((fs)->fs_fpg * (c))) #define cgstart(fs, c) \ (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask))) #define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode blk */ #define blkstofrags(fs, blks) /* calculates (blks * fs->fs_frag) */ \ ((blks) << (fs)->fs_fragshift) #define INOPB(fs) ((fs)->fs_inopb)Autrement dit, on a:
itod (x) == cgimin (x / 1920) + blkstofrags ((x % 1920) / 64) == cgstart(x/1920) + 32 + frag << 3 == (4320 * cg) + 24 * (cg & 0xf) + 32 + frag * 8
/root
sur /dev/rrz1a
Dec Station 3100)
fs_link = 0x0, /* linked list of file systems */ fs_rlink = 0x0, /* used for incore super blocks */ fs_sblkno = 16, /* addr of super-block in filesys */ fs_cblkno = 24, /* offset of cyl-block in filesys */ fs_iblkno = 32, /* offset of inode-blocks in filesys */ fs_dblkno = 272, /* offset of first data after cg */ fs_cgoffset = 24, /* cylinder group offset in cylinder */ fs_cgmask = -16, /* used to calc mod fs_ntrak */ fs_time = 696960299, /* last time written */ fs_size = 16384, /* number of blocks in fs */ fs_dsize = 15343, /* number of data blocks in fs */ fs_ncg = 4, /* number of cylinder groups */ fs_bsize = 8192, /* size of basic blocks in fs */ fs_fsize = 1024, /* size of frag blocks in fs */ fs_frag = 8, /* number of frags in a block in fs */ /* these are configuration parameters */ fs_minfree = 10, /* minimum percentage of free blocks */ fs_rotdelay = 0, /* num of ms for optimal next block */ fs_rps = 60, /* disk revolutions per second */ /* these fields can be computed from the others */ fs_bmask = -8192, /* ``blkoff'' calc of blk offsets */ fs_fmask = -1024, /* ``fragoff'' calc of frag offsets */ fs_bshift = 13, /* ``lblkno'' calc of logical blkno */ fs_fshift = 10, /* ``numfrags'' calc number of frags */ /* these are configuration parameters */ fs_maxcontig = 1, /* max number of contiguous blks */ fs_maxbpg = 256, /* max number of blks per cyl group */ /* these fields can be computed from the others */ fs_fragshift = 3, /* block to frag shift */ fs_fsbtodb = 1, /* fsbtodb and dbtofsb shift constant */ fs_sbsize = 8192, /* actual size of super block */ fs_csmask = -512, /* csum block offset */ fs_csshift = 9, /* csum block number */ fs_nindir = 2048, /* value of NINDIR */ fs_inopb = 64, /* value of INOPB */ fs_nspf = 2, /* value of NSPF */ fs_optim = 0, /* optimization preference, see below */ fs_sparecon = {0, 0, 0, 0, 0}, /* reserved for future constants */ /* sizes determined by number of cylinder groups and their sizes */ fs_csaddr = 272, /* blk addr of cyl grp summary area */ fs_cssize = 1024, /* size of cyl grp summary area */ fs_cgsize = 2048, /* cylinder group size */ /* these fields should be derived from the hardware */ fs_ntrak = 15, /* tracks per cylinder */ fs_nsect = 36, /* sectors per track */ fs_spc = 540, /* sectors per cylinder */ /* this comes from the disk driver partitioning */ fs_ncyl = 61, /* cylinders in file system */ /* these fields can be computed from the others */ fs_cpg = 16, /* cylinders per group */ fs_ipg = 1920, /* inodes per group */ fs_fpg = 4320, /* blocks per group * fs_frag */ /* this data must be re-computed after crashes */ fs_cstotal = {cs_ndir = 84, cs_nbfree = 710, cs_nifree = 7146, cs_nffree = 122}, /* these fields are cleared at mount time */ fs_fmod = 0 '\000', /* super block modified flag */ fs_clean = 1 '\001', /* file system is clean flag */ fs_ronly = 0 '\000', /* mounted read-only flag */ fs_flags = 0 '\000', /* currently unused flags */ #define fs_cleantimer fs_flags/* Clean byte timeout factor */ fs_fsmnt = {"/\000nt\000ufs_mount",/* name mounted on */ '\000'Groupe de cylindres (même exemple, \ldots)}, /* these fields retain the current block allocation info */ fs_cgrotor = 3, /* last cg searched */ fs_csp = {0xc3644000, /* list of fs_cs info buffers */ 0x0 }, fs_cpc = 4, /* cyl per cycle in postbl */ fs_postbl = {{0, 5, 3, 1, 8, 6, 4, 2}, /* head of blocks for each rotation */ {34, 41, 39, 37, 35, 42, 40, 38}, {70, 68, 75, 73, 71, 69, 76, 74}, {106, 104 102, 109, 107, 105, 103, 110}, {-1, -1, -1, -1, -1, -1, -1, -1} }, fs_magic = 72020, /* magic number */ fs_rotbl = ...
cg_link = 0x0, /* linked list of cyl groups */ cg_rlink = 0x0, /* used for incore cyl groups */ cg_time = 696960289, /* time last written */ cg_cgx = 0, /* we are the cgx'th cylinder group */ cg_ncyl = 16, /* number of cyl's this cg */ cg_niblk = 1920, /* number of inode blocks this cg */ cg_ndblk = 4320, /* number of data blocks this cg */ cg_cs = {cs_ndir = 28, /* cylinder summary information */ cs_nbfree = 119, cs_nifree = 1862, cs_nffree = 10}, cg_rotor = 2400, /* position of last used block */ cg_frotor = 2688, /* position of last used frag */ cg_irotor = 54, /* position of last used inode */ cg_frsum = {0, 0, 0, 1, 0, 1 0}, /* counts of available frags */ cg_btot = {0, 0, 0, 0, 0, 0, 0, 8, 17, 31, 16 32, 0, 15, 0}, /* block totals per cylinder */ cg_b = {{0, 0, 0, 0, 0, 0, 0, 0}, /* positions of free blocks */ {0, 0, 0, 0, 0, 0, 0, 0}, {0 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 1}, {5, 1, 1, 2, 3, 1, 2, 2}, {6, 4, 3, 4, 3, 4, 3, 4}, {5, 2, 0, 2, 3, 2, 1, 1}, {7, 3, 4, 4, 3, 3, 4, 4}, {0, 0, 0, 0, 0, 0, 0, 0}, {4, 2, 2, 2, 1, 0, 2, 2}, {0, 0, 0, 0, 0, 0, 0, 0} }, cg_iused = {"\377\377\377\377\377\377\177\000p", /* used inode map */ '\000' }, cg_magic = 590421, /* magic number */ cg_free = {"\000"}} /* free block map */
/usr/include/ufs/ufs\_inode.h
,/usr/include/sys/gnode\_common.h
.
2 drwxr-xr-x 15 root 1024 Feb 1 17:04 / di_gcom = {gn_gc = {gc_mode = 0x41ed, /* 0: mode and type of file */ gc_nlink = 15, /* 2: number of links to file */ gc_uid = 0, /* 4: owner's user id */ gc_gid = 0, /* 6: owner's group id */ gc_size = {val = {1024, 0}}, /* 8: number of bytes in file */ gc_atime = {tv_sec = 669396747, tv_usec = 90158}, gc_mtime = {tv_sec = 696960289, tv_usec = 1198}, gc_ctime = {tv_sec = 696960289, tv_usec = 1198}}, dg_db = {288, 0}, dg_ib = {0, 0, 0}, dg_blocks = 2,/* 104: blocks actually held */ 3 drwxr-xr-x 2 root 8192 Jan 13 1989 /lost+found di_gcom = {gn_gc = {gc_mode = 0x41ed, /* 0: mode and type of file */ gc_nlink = 2, /* 2: number of links to file */ gc_uid = 0, /* 4: owner's user id */ gc_gid = 0, /* 6: owner's group id */ gc_size = {val = {8192, 0}}, /* 8: number of bytes in file */ gc_atime = {tv_sec = 621008968, tv_usec = 686698}, gc_mtime = {tv_sec = 600669697, tv_usec = 288278}, gc_ctime = {tv_sec = 600669697, tv_usec = 288278}}, dg_db = {280, 0 }, dg_ib = {0, 0, 0}, dg_blocks = 16,/* 104: blocks actually held */ 4 -rwxr-xr-x 1 root 2113004 Mar 7 1990 /vmunix di_gcom = {gn_gc = {gc_mode = 0x81ed, gc_nlink = 1, gc_uid = 0, gc_gid = 0, gc_size = {val = {2113004, 0}}, gc_atime = {tv_sec = 696619351, tv_usec = 290190}, gc_mtime = {tv_sec = 636832739, tv_usec = 389864}, gc_ctime = {tv_sec = 660850797, tv_usec = 662236}}, dg_db = {296, /* 40: disk block addresses */ 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384}, dg_ib = {392, 0, 0}, /* 88: indirect blocks */ dg_blocks = 4144, /* 104: blocks actually held */
#define MAXNAMLEN 255 struct gen_dir { u_long gd_ino; /* not meaningful for all sfs types */ u_short gd_reclen; /* how large this structure really is */ u_short gd_namelen; /* how long the named component is */ char gd_name[MAXNAMLEN + 1]; /* what the name is */ };
Il y a des ordres spéciaux en BSD pour lire les directories readdir
, \ldots.
TIT .The Design and implementation of the 4.3BSD UNIX operating .system SLA .Samuel J. Leffler, Marshall Kirk McKusick, Michael J. .Karels, John S. Quarterman. - Reprint. with corrections. - .Reading, MA ; Don Mills, Ontario ; Wokingham, GB : .Addison-Wesley, 1989. - XXII-471 p. ; 24 cm.
sur
est ouverte en lecture à tous pour au moins une semaine. Lire les superblocs du fichier spécial
/dev/et imprimer son état d'allocation. Si vous avez le temps, lire le contenu d'un fichier (sans passer par l'ordre
read
normal du
système de fichier. Indication: se servir des fichiers include
décrivant les formats d'un système de fichier (superbloc, groupe de
cylindres, inode).
ls
?).
cat
et exercices du chapitre 1.