OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [isofs/] [util.c] - Blame information for rev 1628

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
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 386bsd iso9660 filesystem, by Pace Willisson <pace@blitz.com>.
10
 */
11
 
12
#include <linux/time.h>
13
 
14
int
15
isonum_711 (char * p)
16
{
17
        return (*p & 0xff);
18
}
19
 
20
int
21
isonum_712 (char * p)
22
{
23
        int val;
24
 
25
        val = *p;
26
        if (val & 0x80)
27
                val |= 0xffffff00;
28
        return (val);
29
}
30
 
31
int
32
isonum_721 (char * p)
33
{
34
        return ((p[0] & 0xff) | ((p[1] & 0xff) << 8));
35
}
36
 
37
int
38
isonum_722 (char * p)
39
{
40
        return (((p[0] & 0xff) << 8) | (p[1] & 0xff));
41
}
42
 
43
int
44
isonum_723 (char * p)
45
{
46
#if 0
47
        if (p[0] != p[3] || p[1] != p[2]) {
48
                fprintf (stderr, "invalid format 7.2.3 number\n");
49
                exit (1);
50
        }
51
#endif
52
        return (isonum_721 (p));
53
}
54
 
55
int
56
isonum_731 (char * p)
57
{
58
        return ((p[0] & 0xff)
59
                | ((p[1] & 0xff) << 8)
60
                | ((p[2] & 0xff) << 16)
61
                | ((p[3] & 0xff) << 24));
62
}
63
 
64
int
65
isonum_732 (char * p)
66
{
67
        return (((p[0] & 0xff) << 24)
68
                | ((p[1] & 0xff) << 16)
69
                | ((p[2] & 0xff) << 8)
70
                | (p[3] & 0xff));
71
}
72
 
73
int
74
isonum_733 (char * p)
75
{
76
#if 0
77
        int i;
78
 
79
        for (i = 0; i < 4; i++) {
80
                if (p[i] != p[7-i]) {
81
                        fprintf (stderr, "bad format 7.3.3 number\n");
82
                        exit (1);
83
                }
84
        }
85
#endif
86
        return (isonum_731 (p));
87
}
88
 
89
/* We have to convert from a MM/DD/YY format to the unix ctime format.
90
 * We have to take into account leap years and all of that good stuff.
91
 */
92
int iso_date(char * p, int flag)
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
                extern struct timezone sys_tz;
111
 
112
                days = year * 365;
113
                if (year > 2)
114
                        days += (year+1) / 4;
115
                for (i = 1; i < month; i++)
116
                        days += monlen[i-1];
117
                if (((year+2) % 4) == 0 && month > 2)
118
                        days++;
119
                days += day - 1;
120
                crtime = ((((days * 24) + hour) * 60 + minute) * 60)
121
                        + second;
122
                if (sys_tz.tz_dsttime)
123
                        crtime -= 3600;
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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.