|
|
1.1 ! root 1: ! 2: ! 3: canon.h Header file canon.h ! 4: ! 5: ! 6: ! 7: ! 8: Portable layout of binary data ! 9: ! 10: #include <canon.h> ! 11: #include <sys/types.h> ! 12: ! 13: The layout of binary data varies among machines. For example, ! 14: the byte order of a 16-bit word on the PDP-11 is low-byte.high- ! 15: byte, whereas on the Z8000 it is high-byte.low-byte. ! 16: ! 17: To ensure that file systems can be ported among machines with ! 18: differing byte orders, COHERENT uses a canonical layout of binary ! 19: data. (The word ``canonical'' in this context means, ``of or ! 20: conforming to a general rule''.) Data not in primary memory ! 21: (e.g., on disk or communications line) must conform to COHERENT's ! 22: canonical layout. ! 23: ! 24: To insulate programs from the details of the difference between ! 25: the `natural' and canonical layouts, the COHERENT system provides ! 26: a set of procedures to convert from one layout to another. They ! 27: are as follows: ! 28: ! 29: ! 30: ccaannsshhoorrtt()Convert a sshhoorrtt ! 31: ccaanniinntt() Convert an iinntt ! 32: ccaannlloonngg() Convert a lloonngg ! 33: ccaannvvaaddddrr()Convert vvaaddddrr_tt ! 34: ccaannssiizzee() Convert ffssiizzee_tt ! 35: ccaannddaaddddrr()Convert ddaaddddrr_tt ! 36: ccaannttiimmee() Convert ttiimmee_tt ! 37: ccaannddeevv() Convert ddeevv_tt ! 38: ccaanniinnoo() Convert iinnoo_tt ! 39: ! 40: ! 41: Each procedure takes an lvalue of the indicated type, converts it ! 42: in place, and returns nothing. The argument should not have ! 43: side-effects. Each procedure is its own inverse. Several proce- ! 44: dures are designed for elements of file systems. ! 45: ! 46: The file formats that contain canonical binary data and the com- ! 47: mands that deal with them are as follows: ! 48: ! 49: ! 50: _F_o_r_m_a_t _C_o_m_m_a_n_d_s ! 51: ! 52: ar.h ar, ld, ranlib ! 53: dir.h ls, tar ! 54: l.out.h as, cc, db, ld, nm, size, strip ! 55: ! 56: ! 57: Any program that manipulates binary data within files must per- ! 58: form canonical conversion immediately upon input and immediately ! 59: before output. The following fragment of the source code to the ! 60: command df should be instructive: ! 61: ! 62: ! 63: ! 64: COHERENT Lexicon Page 1 ! 65: ! 66: ! 67: ! 68: ! 69: canon.h Header file canon.h ! 70: ! 71: ! 72: ! 73: ! 74: #include <stdio.h> ! 75: #include <canon.h> ! 76: #include <filsys.h> ! 77: char superb[BSIZE]; ! 78: ! 79: ! 80: ! 81: . ! 82: . ! 83: . ! 84: ! 85: ! 86: ! 87: df(fs) ! 88: char *fs; ! 89: { ! 90: register struct filsys *sbp = &superb; ! 91: FILE *fp; ! 92: daddr_t nfree; ! 93: ! 94: ! 95: ! 96: if ((fp = fopen(fs, "r")) == NULL) { ! 97: perror(fs); ! 98: return (1); ! 99: } ! 100: ! 101: ! 102: ! 103: fseek(fp, (long)BSIZE, 0); ! 104: if (fread(superb, sizeof superb, 1, fp) != 1) { ! 105: fprintf(stderr, "%s: read error\n", fs); ! 106: return (1); ! 107: } ! 108: ! 109: ! 110: ! 111: candaddr(sbp->s_tfree); ! 112: candaddr(sbp->s_fsize); ! 113: canshort(sbp->s_isize); ! 114: nfree = sbp->s_tfree; ! 115: ! 116: ! 117: ! 118: if (nfree > sbp->s_fsize-sbp->s_isize || nfree < 0) { ! 119: fprintf(stderr, "%s: bad free count\n", fs); ! 120: return (1); ! 121: } ! 122: ! 123: ! 124: ! 125: ! 126: ! 127: ! 128: ! 129: ! 130: COHERENT Lexicon Page 2 ! 131: ! 132: ! 133: ! 134: ! 135: canon.h Header file canon.h ! 136: ! 137: ! 138: ! 139: printf("%s: %ld\n", fs, nfree); ! 140: fclose(fp); ! 141: return (0); ! 142: } ! 143: ! 144: ! 145: ***** Files ***** ! 146: ! 147: <canon.h> ! 148: ! 149: ***** See Also ***** ! 150: ! 151: ar.h, byte ordering, candaddr(), candev(), canino(), canint(), ! 152: canlong(), canshort(), cansize(), cantime(), canvaddr(), dir.h, ! 153: l.out.h, header files ! 154: ! 155: ! 156: ! 157: ! 158: ! 159: ! 160: ! 161: ! 162: ! 163: ! 164: ! 165: ! 166: ! 167: ! 168: ! 169: ! 170: ! 171: ! 172: ! 173: ! 174: ! 175: ! 176: ! 177: ! 178: ! 179: ! 180: ! 181: ! 182: ! 183: ! 184: ! 185: ! 186: ! 187: ! 188: ! 189: ! 190: ! 191: ! 192: ! 193: ! 194: ! 195: ! 196: COHERENT Lexicon Page 3 ! 197: ! 198:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.