File:  [MW Coherent from dump] / coherent / a / usr / man / MULTI / canon.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



canon.h                    Header file                    canon.h




Portable layout of binary data

#include <canon.h>
#include <sys/types.h>

The layout  of binary data  varies among machines.   For example,
the byte  order of a 16-bit word on  the PDP-11 is low-byte.high-
byte, whereas on the Z8000 it is high-byte.low-byte.

To ensure  that file  systems can  be ported among  machines with
differing byte orders, COHERENT uses a canonical layout of binary
data.   (The word  ``canonical'' in this  context means,  ``of or
conforming  to a  general  rule''.) Data  not  in primary  memory
(e.g., on disk or communications line) must conform to COHERENT's
canonical layout.

To insulate  programs from the details  of the difference between
the `natural' and canonical layouts, the COHERENT system provides
a set of procedures to  convert from one layout to another.  They
are as follows:


          ccaannsshhoorrtt()Convert a sshhoorrtt
          ccaanniinntt()  Convert an iinntt
          ccaannlloonngg() Convert a lloonngg
          ccaannvvaaddddrr()Convert vvaaddddrr_tt
          ccaannssiizzee() Convert ffssiizzee_tt
          ccaannddaaddddrr()Convert ddaaddddrr_tt
          ccaannttiimmee() Convert ttiimmee_tt
          ccaannddeevv()  Convert ddeevv_tt
          ccaanniinnoo()  Convert iinnoo_tt


Each procedure takes an lvalue of the indicated type, converts it
in  place, and  returns nothing.   The  argument should  not have
side-effects.  Each procedure is its own inverse.  Several proce-
dures are designed for elements of file systems.

The file formats that  contain canonical binary data and the com-
mands that deal with them are as follows:


          _F_o_r_m_a_t    _C_o_m_m_a_n_d_s

          ar.h      ar, ld, ranlib
          dir.h     ls, tar
          l.out.h   as, cc, db, ld, nm, size, strip


Any program  that manipulates binary data  within files must per-
form canonical conversion  immediately upon input and immediately
before output.  The following  fragment of the source code to the
command df should be instructive:



COHERENT Lexicon                                           Page 1




canon.h                    Header file                    canon.h




#include <stdio.h>
#include <canon.h>
#include <filsys.h>
char    superb[BSIZE];



        .
        .
        .



df(fs)
char *fs;
{
        register struct filsys *sbp = &superb;
        FILE *fp;
        daddr_t nfree;



        if ((fp = fopen(fs, "r")) == NULL) {
                perror(fs);
                return (1);
        }



        fseek(fp, (long)BSIZE, 0);
        if (fread(superb, sizeof superb, 1, fp) != 1) {
                fprintf(stderr, "%s: read error\n", fs);
                return (1);
        }



        candaddr(sbp->s_tfree);
        candaddr(sbp->s_fsize);
        canshort(sbp->s_isize);
        nfree = sbp->s_tfree;



        if (nfree > sbp->s_fsize-sbp->s_isize  ||  nfree < 0) {
                fprintf(stderr, "%s: bad free count\n", fs);
                return (1);
        }








COHERENT Lexicon                                           Page 2




canon.h                    Header file                    canon.h



        printf("%s: %ld\n", fs, nfree);
        fclose(fp);
        return (0);
}


***** Files *****

<canon.h>

***** See Also *****

ar.h,  byte ordering,  candaddr(), candev(),  canino(), canint(),
canlong(), canshort(),  cansize(), cantime(),  canvaddr(), dir.h,
l.out.h, header files










































COHERENT Lexicon                                           Page 3



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.