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

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