annotate packages/redboot/current/src/fs/fileio.c @ 1598:d177755187d3

Fix configuration check so -f XXX works again.
author gthomas
date Mon, 19 Apr 2004 21:26:52 +0000
parents 183857c0ce4b
children 43a89c18d005
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.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
12 // Copyright (C) 2002, 2003 Gary Thomas
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>
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
72
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
73 static void do_mount(int argc, char *argv[]);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
74 static void do_umount(int argc, char *argv[]);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
75
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
76 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
77 #define FLASHPART "[-f <partition>] "
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
78 #else
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
79 #define FLASHPART
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
80 #endif
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
81
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
82 RedBoot_cmd("mount",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
83 "Mount file system",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
84 FLASHPART "[-d <device>] -t fstype",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
85 do_mount
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
86 );
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
87 RedBoot_cmd("umount",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
88 "Unmount file system",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
89 "",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
90 do_umount
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
91 );
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 int fileio_mounted = 0;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
94
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
95 // Mount disk/filesystem
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
96 static void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
97 do_mount(int argc, char *argv[])
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
98 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
99 char *part_str, *dev_str, *type_str;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
100 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
101 struct option_info opts[3];
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
102 int err, num_opts = 2;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
103
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
104 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
105 (void *)&dev_str, &dev_set, "device");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
106 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
107 (void *)&type_str, &type_set, "fstype");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
108 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
109 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
110 (void *)&part_str, &part_set, "partition");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
111 num_opts++;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
112 #endif
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
113
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
114 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
115 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
116
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
117 if (!type_set) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
118 diag_printf("Must specify file system type\n");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
119 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
120 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
121 if (fileio_mounted) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
122 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
123 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
124 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
125 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
126 if (part_set) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
127 int len;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
128 cyg_io_handle_t h;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
129
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
130 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
131 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
132 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
133 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
134
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
135 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
136 len = strlen(part_str);
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 err = cyg_io_lookup(dev_str, &h);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
139 if (err < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
140 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
141 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
142 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
143 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
144 part_str, &len);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
145 if (err < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
146 diag_printf("FIS partition \"%s\" not found\n",
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
147 part_str);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
148 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
149 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
150 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
151 #endif
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
152 err = mount(dev_str, "/", type_str);
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 if (err) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
155 diag_printf("Mount failed %d\n", err);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
156 } else {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
157 // 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
158 fileio_mounted = 1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
159 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
160 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
161
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
162 static void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
163 do_umount(int argc, char *argv[])
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 if (!fileio_mounted) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
166 return;
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 umount ("/");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
169 fileio_mounted = 0;
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
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
172 static int fd;
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 externC int
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
175 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
176 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
177 char *filename = info->filename;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
178
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
179 if (!fileio_mounted) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
180 diag_printf("No file system mounted\n");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
181 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
182 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
183 fd = open(filename, O_RDONLY);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
184 if (fd < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
185 diag_printf("Open failed, error %d\n", errno);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
186 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
187 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
188 return 0;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
189 }
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 externC int
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
192 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
193 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
194 int nread;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
195
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
196 if ((nread = read(fd, buf, size)) < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
197 *err = errno;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
198 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
199 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
200 return nread;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
201 }
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 externC void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
204 fileio_stream_close(int *err)
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 close(fd);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
207 }
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 externC char *
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
210 fileio_error(int err)
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 static char myerr[10];
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
213
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
214 diag_sprintf(myerr, "error %d\n", err);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
215 return myerr;
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
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
218 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
219 // RedBoot interface
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 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
222 0, fileio_stream_read, fileio_error);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
223 RedBoot_load(file, fileio_io, true, true, 0);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
224