root/fs/isofs/util.c

/* [previous][next][first][last][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 (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
  15 {
  16         return (*p & 0xff);
  17 }
  18 
  19 int
  20 isonum_712 (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
  21 {
  22         int val;
  23         
  24         val = *p;
  25         if (val & 0x80)
  26                 val |= 0xffffff00;
  27         return (val);
  28 }
  29 
  30 int
  31 isonum_721 (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
  32 {
  33         return ((p[0] & 0xff) | ((p[1] & 0xff) << 8));
  34 }
  35 
  36 int
  37 isonum_722 (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39         return (((p[0] & 0xff) << 8) | (p[1] & 0xff));
  40 }
  41 
  42 int
  43 isonum_723 (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45 #if 0
  46         if (p[0] != p[3] || p[1] != p[2]) {
  47                 fprintf (stderr, "invalid format 7.2.3 number\n");
  48                 exit (1);
  49         }
  50 #endif
  51         return (isonum_721 (p));
  52 }
  53 
  54 int
  55 isonum_731 (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
  56 {
  57         return ((p[0] & 0xff)
  58                 | ((p[1] & 0xff) << 8)
  59                 | ((p[2] & 0xff) << 16)
  60                 | ((p[3] & 0xff) << 24));
  61 }
  62 
  63 int
  64 isonum_732 (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66         return (((p[0] & 0xff) << 24)
  67                 | ((p[1] & 0xff) << 16)
  68                 | ((p[2] & 0xff) << 8)
  69                 | (p[3] & 0xff));
  70 }
  71 
  72 int
  73 isonum_733 (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
  74 {
  75 #if 0
  76         int i;
  77 
  78         for (i = 0; i < 4; i++) {
  79                 if (p[i] != p[7-i]) {
  80                         fprintf (stderr, "bad format 7.3.3 number\n");
  81                         exit (1);
  82                 }
  83         }
  84 #endif
  85         return (isonum_731 (p));
  86 }
  87 
  88 int iso_date(char * p, int flag)
     /* [previous][next][first][last][top][bottom][index][help] */
  89 {
  90         int year, month, day, hour ,minute, second, tz;
  91         int crtime, days, i;
  92 
  93         year = p[0] - 70;
  94         month = p[1];
  95         day = p[2];
  96         hour = p[3];
  97         minute = p[4];
  98         second = p[5];
  99         if (flag == 0) tz = p[6]; /* High sierra has no time zone */
 100         else tz = 0;
 101         
 102         if (year < 0) {
 103                 crtime = 0;
 104         } else {
 105                 int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
 106                 days = year * 365;
 107                 if (year > 2)
 108                         days += (year+2) / 4;
 109                 for (i = 1; i < month; i++)
 110                         days += monlen[i-1];
 111                 if (((year+2) % 4) == 0 && month > 2)
 112                         days++;
 113                 days += day - 1;
 114                 crtime = ((((days * 24) + hour) * 60 + minute) * 60)
 115                         + second;
 116                 
 117                 /* sign extend */
 118                 if (tz & 0x80)
 119                         tz |= (-1 << 8);
 120                 
 121                 /* timezone offset is unreliable on some disks */
 122                 if (-48 <= tz && tz <= 52)
 123                         crtime += tz * 15 * 60;
 124         }
 125         return crtime;
 126 }               
 127         

/* [previous][next][first][last][top][bottom][index][help] */