annotate packages/redboot/current/src/fs/fileio.c @ 1605:43a89c18d005

Add checking (assert) for size of option arrays. Also fix port for TFTP on little endian systems.
author gthomas
date Fri, 23 Apr 2004 20:38:17 +0000
parents d177755187d3
children 549e69d9a7d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
1 //==========================================================================
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
2 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
3 // fileio.c
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
4 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
5 // RedBoot fileio support
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
6 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
7 //==========================================================================
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
8 //####ECOSGPLCOPYRIGHTBEGIN####
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
9 // -------------------------------------------
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
1605
43a89c18d005 Add checking (assert) for size of option arrays. Also fix port for TFTP on little endian systems.
gthomas
parents: 1598
diff changeset
12 // Copyright (C) 2002, 2003, 2004 Gary Thomas
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
13 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
14 // eCos is free software; you can redistribute it and/or modify it under
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
15 // the terms of the GNU General Public License as published by the Free
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
16 // Software Foundation; either version 2 or (at your option) any later version.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
17 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
21 // for more details.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
22 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
23 // You should have received a copy of the GNU General Public License along
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
26 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
27 // As a special exception, if other files instantiate templates or use macros
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
28 // or inline functions from this file, or you compile this file and link it
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
29 // with other works to produce a work based on this file, this file does not
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
30 // by itself cause the resulting work to be covered by the GNU General Public
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
31 // License. However the source code for this file must still be made available
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
32 // in accordance with section (3) of the GNU General Public License.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
33 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
34 // This exception does not invalidate any other reasons why a work based on
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
35 // this file might be covered by the GNU General Public License.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
36 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
38 // at http://sources.redhat.com/ecos/ecos-license/
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
39 // -------------------------------------------
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
40 //####ECOSGPLCOPYRIGHTEND####
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
41 //==========================================================================
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
42 //#####DESCRIPTIONBEGIN####
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
43 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
44 // Author(s): dwmw2, msalter
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
45 // Date: 2003-11-27
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
46 // Purpose:
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
47 // Description:
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
48 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
49 // This code is part of RedBoot (tm).
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
50 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
51 //####DESCRIPTIONEND####
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
52 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
53 //==========================================================================
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
54
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
55 // Shoot me. But I don't want struct timeval because redboot provides it.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
56 #define _POSIX_SOURCE
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
57 #include <time.h>
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
58 #undef _POSIX_SOURCE
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
59
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
60 #include <redboot.h>
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
61 #include <errno.h>
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
62 #include <stdio.h>
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
63 #include <fcntl.h>
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
64 #include <unistd.h>
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
65 #include <string.h>
1598
d177755187d3 Fix configuration check so -f XXX works again.
gthomas
parents: 1552
diff changeset
66 #ifdef CYGPKG_IO_FLASH
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
67 #include <cyg/io/io.h>
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
68 #include <cyg/io/flash.h>
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
69 #include <cyg/io/config_keys.h>
1552
183857c0ce4b * src/fs/fileio.c: Only include IO package headers if required.
asl
parents: 1414
diff changeset
70 #endif
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
71 #include <cyg/fileio/fileio.h>
1605
43a89c18d005 Add checking (assert) for size of option arrays. Also fix port for TFTP on little endian systems.
gthomas
parents: 1598
diff changeset
72 #include <cyg/infra/cyg_ass.h> // assertion macros
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
73
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
74 static void do_mount(int argc, char *argv[]);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
75 static void do_umount(int argc, char *argv[]);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
76
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
77 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
78 #define FLASHPART "[-f <partition>] "
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
79 #else
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
80 #define FLASHPART
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
81 #endif
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
82
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
83 RedBoot_cmd("mount",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
84 "Mount file system",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
85 FLASHPART "[-d <device>] -t fstype",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
86 do_mount
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
87 );
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
88 RedBoot_cmd("umount",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
89 "Unmount file system",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
90 "",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
91 do_umount
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
92 );
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
93
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
94 int fileio_mounted = 0;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
95
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
96 // Mount disk/filesystem
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
97 static void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
98 do_mount(int argc, char *argv[])
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
99 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
100 char *part_str, *dev_str, *type_str;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
101 bool part_set = false, dev_set = false, type_set = false;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
102 struct option_info opts[3];
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
103 int err, num_opts = 2;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
104
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
105 init_opts(&opts[0], 'd', true, OPTION_ARG_TYPE_STR,
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
106 (void *)&dev_str, &dev_set, "device");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
107 init_opts(&opts[1], 't', true, OPTION_ARG_TYPE_STR,
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
108 (void *)&type_str, &type_set, "fstype");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
109 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
110 init_opts(&opts[2], 'f', true, OPTION_ARG_TYPE_STR,
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
111 (void *)&part_str, &part_set, "partition");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
112 num_opts++;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
113 #endif
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
114
1605
43a89c18d005 Add checking (assert) for size of option arrays. Also fix port for TFTP on little endian systems.
gthomas
parents: 1598
diff changeset
115 CYG_ASSERT(num_opts <= NUM_ELEMS(opts), "Too many options");
43a89c18d005 Add checking (assert) for size of option arrays. Also fix port for TFTP on little endian systems.
gthomas
parents: 1598
diff changeset
116
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
117 if (!scan_opts(argc, argv, 1, opts, num_opts, NULL, 0, NULL))
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
118 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
119
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
120 if (!type_set) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
121 diag_printf("Must specify file system type\n");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
122 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
123 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
124 if (fileio_mounted) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
125 diag_printf("A file system is already mounted\n");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
126 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
127 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
128 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
129 if (part_set) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
130 int len;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
131 cyg_io_handle_t h;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
132
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
133 if (dev_set && strcmp(dev_str, CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1)) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
134 diag_printf("May only set one of <device> or <partition>\n");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
135 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
136 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
137
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
138 dev_str = CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
139 len = strlen(part_str);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
140
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
141 err = cyg_io_lookup(dev_str, &h);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
142 if (err < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
143 diag_printf("cyg_io_lookup of \"%s\" returned %d\n", err);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
144 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
145 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
146 err = cyg_io_set_config(h, CYG_IO_SET_CONFIG_FLASH_FIS_NAME,
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
147 part_str, &len);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
148 if (err < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
149 diag_printf("FIS partition \"%s\" not found\n",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
150 part_str);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
151 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
152 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
153 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
154 #endif
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
155 err = mount(dev_str, "/", type_str);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
156
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
157 if (err) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
158 diag_printf("Mount failed %d\n", err);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
159 } else {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
160 // diag_printf("Mount %s file system succeeded\n", type_str);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
161 fileio_mounted = 1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
162 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
163 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
164
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
165 static void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
166 do_umount(int argc, char *argv[])
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
167 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
168 if (!fileio_mounted) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
169 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
170 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
171 umount ("/");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
172 fileio_mounted = 0;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
173 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
174
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
175 static int fd;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
176
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
177 externC int
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
178 fileio_stream_open(connection_info_t *info, int *err)
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
179 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
180 char *filename = info->filename;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
181
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
182 if (!fileio_mounted) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
183 diag_printf("No file system mounted\n");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
184 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
185 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
186 fd = open(filename, O_RDONLY);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
187 if (fd < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
188 diag_printf("Open failed, error %d\n", errno);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
189 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
190 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
191 return 0;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
192 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
193
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
194 externC int
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
195 fileio_stream_read(char *buf, int size, int *err)
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
196 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
197 int nread;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
198
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
199 if ((nread = read(fd, buf, size)) < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
200 *err = errno;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
201 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
202 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
203 return nread;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
204 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
205
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
206 externC void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
207 fileio_stream_close(int *err)
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
208 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
209 close(fd);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
210 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
211
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
212 externC char *
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
213 fileio_error(int err)
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
214 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
215 static char myerr[10];
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
216
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
217 diag_sprintf(myerr, "error %d\n", err);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
218 return myerr;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
219 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
220
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
221 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
222 // RedBoot interface
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
223 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
224 GETC_IO_FUNCS(fileio_io, fileio_stream_open, fileio_stream_close,
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
225 0, fileio_stream_read, fileio_error);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
226 RedBoot_load(file, fileio_io, true, true, 0);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
227