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

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