root/fs/isofs/util.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. isonum_711
  2. isonum_712
  3. isonum_721
  4. isonum_722
  5. isonum_723
  6. isonum_731
  7. isonum_732
  8. isonum_733
  9. iso_date

   1 /*
   2  *  linux/fs/isofs/util.c
   3  *
   4  *  The special functions in the file are numbered according to the section
   5  *  of the iso 9660 standard in which they are described.  isonum_733 will
   6  *  convert numbers according to section 7.3.3, etc.
   7  *
   8  *  isofs special functions.  This file was lifted in it's entirety from
   9  * the bsd386 iso9660 filesystem, by Pace Williamson.
  10  */
  11 
  12 
  13 int
  14 isonum_711 (p)
     /* [<][>][^][v][top][bottom][index][help] */
  15 char *p;
  16 {
  17         return (*p & 0xff);
  18 }
  19 
  20 int
  21 isonum_712 (p)
     /* [<][>][^][v][top][bottom][index][help] */
  22 char *p;
  23 {
  24         int val;
  25         
  26         val = *p;
  27         if (val & 0x80)
  28                 val |= 0xffffff00;
  29         return (val);
  30 }
  31 
  32 int
  33 isonum_721 (p)
     /* [<][>][^][v][top][bottom][index][help] */
  34 char *p;
  35 {
  36         return ((p[0] & 0xff) | ((p[1] & 0xff) << 8));
  37 }
  38 
  39 int
  40 isonum_722 (p)
     /* [<][>][^][v][top][bottom][index][help] */
  41 char *p;
  42 {
  43         return (((p[0] & 0xff) << 8) | (p[1] & 0xff));
  44 }
  45 
  46 int
  47 isonum_723 (p)
     /* [<][>][^][v][top][bottom][index][help] */
  48 char *p;
  49 {
  50 #if 0
  51         if (p[0] != p[3] || p[1] != p[2]) {
  52                 fprintf (stderr, "invalid format 7.2.3 number\n");
  53                 exit (1);
  54         }
  55 #endif
  56         return (isonum_721 (p));
  57 }
  58 
  59 int
  60 isonum_731 (p)
     /* [<][>][^][v][top][bottom][index][help] */
  61 char *p;
  62 {
  63         return ((p[0] & 0xff)
  64                 | ((p[1] & 0xff) << 8)
  65                 | ((p[2] & 0xff) << 16)
  66                 | ((p[3] & 0xff) << 24));
  67 }
  68 
  69 int
  70 isonum_732 (p)
     /* [<][>][^][v][top][bottom][index][help] */
  71 char *p;
  72 {
  73         return (((p[0] & 0xff) << 24)
  74                 | ((p[1] & 0xff) << 16)
  75                 | ((p[2] & 0xff) << 8)
  76                 | (p[3] & 0xff));
  77 }
  78 
  79 int
  80 isonum_733 (p)
     /* [<][>][^][v][top][bottom][index][help] */
  81 char *p;
  82 {
  83 #if 0
  84         int i;
  85 
  86         for (i = 0; i < 4; i++) {
  87                 if (p[i] != p[7-i]) {
  88                         fprintf (stderr, "bad format 7.3.3 number\n");
  89                         exit (1);
  90                 }
  91         }
  92 #endif
  93         return (isonum_731 (p));
  94 }
  95 
  96 int iso_date(p, flag)
     /* [<][>][^][v][top][bottom][index][help] */
  97 char * p;
  98 int flag;
  99 {
 100         int year, month, day, hour ,minute, second, tz;
 101         int crtime, days, i;
 102 
 103         year = p[0] - 70;
 104         month = p[1];
 105         day = p[2];
 106         hour = p[3];
 107         minute = p[4];
 108         second = p[5];
 109         if (flag == 0) tz = p[6]; /* High sierra has no time zone */
 110         else tz = 0;
 111         
 112         if (year < 0) {
 113                 crtime = 0;
 114         } else {
 115                 int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
 116                 days = year * 365;
 117                 if (year > 2)
 118                         days += (year+2) / 4;
 119                 for (i = 1; i < month; i++)
 120                         days += monlen[i-1];
 121                 if (((year+2) % 4) == 0 && month > 2)
 122                         days++;
 123                 days += day - 1;
 124                 crtime = ((((days * 24) + hour) * 60 + minute) * 60)
 125                         + second;
 126                 
 127                 /* sign extend */
 128                 if (tz & 0x80)
 129                         tz |= (-1 << 8);
 130                 
 131                 /* timezone offset is unreliable on some disks */
 132                 if (-48 <= tz && tz <= 52)
 133                         crtime += tz * 15 * 60;
 134         }
 135         return crtime;
 136 }               
 137         

/* [<][>][^][v][top][bottom][index][help] */