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 its 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 /* We have to convert from a MM/DD/YY format to the unix ctime format.  We have to
  89    take into account leap years and all of that good stuff.  Unfortunately, the kernel
  90    does not have the information on hand to take into account daylight savings time,
  91    so there will be cases (roughly half the time) where the dates are off by one hour. */
  92 int iso_date(char * p, int flag)
     /* [previous][next][first][last][top][bottom][index][help] */
  93 {
  94         int year, month, day, hour ,minute, second, tz;
  95         int crtime, days, i;
  96 
  97         year = p[0] - 70;
  98         month = p[1];
  99         day = p[2];
 100         hour = p[3];
 101         minute = p[4];
 102         second = p[5];
 103         if (flag == 0) tz = p[6]; /* High sierra has no time zone */
 104         else tz = 0;
 105         
 106         if (year < 0) {
 107                 crtime = 0;
 108         } else {
 109                 int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
 110                 days = year * 365;
 111                 if (year > 2)
 112                         days += (year+1) / 4;
 113                 for (i = 1; i < month; i++)
 114                         days += monlen[i-1];
 115                 if (((year+2) % 4) == 0 && month > 2)
 116                         days++;
 117                 days += day - 1;
 118                 crtime = ((((days * 24) + hour) * 60 + minute) * 60)
 119                         + second;
 120                 
 121                 /* sign extend */
 122                 if (tz & 0x80)
 123                         tz |= (-1 << 8);
 124                 
 125                 /* timezone offset is unreliable on some disks */
 126                 if (-48 <= tz && tz <= 52)
 127                         crtime += tz * 15 * 60;
 128         }
 129         return crtime;
 130 }               
 131         

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