fb: Add a prototype for board_video_skip()
[platform/kernel/u-boot.git] / fs / fdos / fdos.c
1 /*
2  * (C) Copyright 2002
3  * Stäubli Faverges - <www.staubli.com>
4  * Pierre AUBERT  p.aubert@staubli.com
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <common.h>
10 #include <config.h>
11 #include <malloc.h>
12
13 #include "dos.h"
14 #include "fdos.h"
15
16
17 const char *month [] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
18
19 Fs_t    fs;
20 File_t  file;
21
22 /*-----------------------------------------------------------------------------
23  * dos_open --
24  *-----------------------------------------------------------------------------
25  */
26 int dos_open(char *name)
27 {
28     int lg;
29     int entry;
30     char *fname;
31
32     /* We need to suppress the " char around the name                        */
33     if (name [0] == '"') {
34         name ++;
35     }
36     lg = strlen (name);
37     if (name [lg - 1] == '"') {
38         name [lg - 1] = '\0';
39     }
40
41     /* Open file system                                                      */
42     if (fs_init (&fs) < 0) {
43         return -1;
44     }
45
46     /* Init the file descriptor                                              */
47     file.name = name;
48     file.fs = &fs;
49
50     /* find the subdirectory containing the file                             */
51     if (open_subdir (&file) < 0) {
52         return (-1);
53     }
54
55     fname = basename (name);
56
57     /* if we try to open root directory                                      */
58     if (*fname == '\0') {
59         file.file = file.subdir;
60         return (0);
61     }
62
63     /* find the file in the subdir                                           */
64     entry = 0;
65     if (vfat_lookup (&file.subdir,
66                      file.fs,
67                      &file.file.dir,
68                      &entry,
69                      0,
70                      fname,
71                      ACCEPT_DIR | ACCEPT_PLAIN | SINGLE | DO_OPEN,
72                      0,
73                      &file.file) != 0) {
74         /* File not found                                                    */
75         printf ("File not found\n");
76         return (-1);
77     }
78
79     return 0;
80 }
81
82 /*-----------------------------------------------------------------------------
83  * dos_read --
84  *-----------------------------------------------------------------------------
85  */
86 int dos_read (ulong addr)
87 {
88     int read = 0, nb;
89
90     /* Try to boot a directory ?                                             */
91     if (file.file.dir.attr & (ATTR_DIRECTORY | ATTR_VOLUME)) {
92         printf ("Unable to boot %s !!\n", file.name);
93         return (-1);
94     }
95     while (read < file.file.FileSize) {
96         PRINTF ("read_file (%ld)\n", (file.file.FileSize - read));
97         nb = read_file (&fs,
98                         &file.file,
99                         (char *)addr + read,
100                         read,
101                         (file.file.FileSize - read));
102         PRINTF ("read_file -> %d\n", nb);
103         if (nb < 0) {
104             printf ("read error\n");
105             return (-1);
106         }
107         read += nb;
108     }
109     return (read);
110 }
111 /*-----------------------------------------------------------------------------
112  * dos_dir --
113  *-----------------------------------------------------------------------------
114  */
115 int dos_dir (void)
116 {
117     int entry;
118     Directory_t dir;
119     char *name;
120
121
122     if ((file.file.dir.attr & ATTR_DIRECTORY) == 0) {
123         printf ("%s: not a directory !!\n", file.name);
124         return (1);
125     }
126     entry = 0;
127     if ((name = malloc (MAX_VNAMELEN + 1)) == NULL) {
128         PRINTF ("Allcation error\n");
129         return (1);
130     }
131
132     while (vfat_lookup (&file.file,
133                         file.fs,
134                         &dir,
135                         &entry,
136                         0,
137                         NULL,
138                         ACCEPT_DIR | ACCEPT_PLAIN | MATCH_ANY,
139                         name,
140                         NULL) == 0) {
141         /* Display file info                                                 */
142         printf ("%3.3s %9d %s %02d %04d %02d:%02d:%02d %s\n",
143                 (dir.attr & ATTR_DIRECTORY) ? "dir" : "   ",
144                 __le32_to_cpu (dir.size),
145                 month [DOS_MONTH (&dir) - 1],
146                 DOS_DAY (&dir),
147                 DOS_YEAR (&dir),
148                 DOS_HOUR (&dir),
149                 DOS_MINUTE (&dir),
150                 DOS_SEC (&dir),
151                 name);
152
153     }
154     free (name);
155     return (0);
156 }