annotate packages/redboot/current/src/fs/fileio.c @ 1724:549e69d9a7d0

* cdl/redboot.cdl: * src/net/net_io.c: added CDL to allow the default server to be configured. Also respect the CYGSEM_REDBOOT_DEFAULT_NO_BOOTP setting. * cdl/redboot.cdl: * src/load.c: Added cdl to control the size of the buffer used by getc. The size can have significant affect on load speed when loading from a filesystem. * cdl/redboot.cdl * src/load.c (load_elf_image): Added a CDL option to configure if the physical or virtual address in the headers should be used when loading the image. * cdl/redboot.cdl * src/fs/fileio.c (do_ls) Added an ls command so we can see what is inside the mounted filesystem.
author asl
date Sat, 21 Aug 2004 12:43:31 +0000
parents 43a89c18d005
children a0d4c606e72d
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;
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
162 #ifdef CYGBLD_REDBOOT_FILEIO_WITH_LS
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
163 chdir("/");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
164 #endif
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
165 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
166 }
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 static void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
169 do_umount(int argc, char *argv[])
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 if (!fileio_mounted) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
172 return;
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 umount ("/");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
175 fileio_mounted = 0;
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
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
178 #ifdef CYGBLD_REDBOOT_FILEIO_WITH_LS
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
179 #include <dirent.h>
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
180
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
181 static char rwx[8][4] = { "---", "r--", "-w-", "rw-", "--x", "r-x", "-wx", "rwx" };
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
182
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
183 static void
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
184 do_ls(int argc, char * argv[])
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
185 {
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
186 char * dir_str;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
187 struct option_info opts[1];
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
188 bool dir_set = false;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
189 DIR *dirp;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
190 char cwd[PATH_MAX];
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
191 char filename[PATH_MAX];
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
192 struct stat sbuf;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
193 int err;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
194
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
195 init_opts(&opts[0], 'd', true, OPTION_ARG_TYPE_STR,
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
196 (void *)&dir_str, &dir_set, "directory");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
197
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
198 if (!fileio_mounted) {
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
199 diag_printf("No filesystem mounted\n");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
200 return;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
201 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
202
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
203 if (!scan_opts(argc, argv, 1, opts, 1, NULL, 0, NULL))
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
204 return;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
205
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
206 if (!dir_set) {
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
207 diag_printf("getcwd\n");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
208
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
209 getcwd(cwd,sizeof(cwd));
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
210 dir_str = cwd;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
211 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
212
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
213 diag_printf("directory %s\n",dir_str);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
214 dirp = opendir(dir_str);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
215 if (dirp==NULL) {
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
216 diag_printf("no such directory %s\n",dir_str);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
217 return;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
218 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
219
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
220 for (;;) {
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
221 struct dirent *entry = readdir(dirp);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
222
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
223 if( entry == NULL )
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
224 break;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
225
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
226 strcpy(filename, dir_str);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
227 strcat(filename, "/");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
228 strcat(filename, entry->d_name);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
229
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
230 err = stat(filename, &sbuf);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
231 if (err < 0) {
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
232 diag_printf("Unable to stat file %s\n", filename);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
233 continue;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
234 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
235 diag_printf("%4d ", sbuf.st_ino);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
236 if (S_ISDIR(sbuf.st_mode)) diag_printf("d");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
237 if (S_ISCHR(sbuf.st_mode)) diag_printf("c");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
238 if (S_ISBLK(sbuf.st_mode)) diag_printf("b");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
239 if (S_ISREG(sbuf.st_mode)) diag_printf("-");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
240 if (S_ISLNK(sbuf.st_mode)) diag_printf("l");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
241 diag_printf("%s%s%s", // Ho, humm, have to hard code the shifts
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
242 rwx[(sbuf.st_mode & S_IRWXU) >> 16],
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
243 rwx[(sbuf.st_mode & S_IRWXG) >> 19],
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
244 rwx[(sbuf.st_mode & S_IRWXO) >> 22]);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
245 diag_printf(" %2d size %6d %s\n",
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
246 sbuf.st_nlink,sbuf.st_size,
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
247 entry->d_name);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
248 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
249
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
250 closedir(dirp);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
251 return;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
252 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
253
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
254 RedBoot_cmd("ls",
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
255 "list directory contents",
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
256 "[-d directory]",
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
257 do_ls
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
258 );
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
259
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
260 #endif // CYGBLD_REDBOOT_FILEIO_WITH_LS
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
261 static int fd;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
262
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
263 externC int
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
264 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
265 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
266 char *filename = info->filename;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
267
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
268 if (!fileio_mounted) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
269 diag_printf("No file system mounted\n");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
270 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
271 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
272 fd = open(filename, O_RDONLY);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
273 if (fd < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
274 diag_printf("Open failed, error %d\n", errno);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
275 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
276 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
277 return 0;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
278 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
279
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
280 externC int
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
281 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
282 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
283 int nread;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
284
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
285 if ((nread = read(fd, buf, size)) < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
286 *err = errno;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
287 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
288 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
289 return nread;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
290 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
291
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
292 externC void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
293 fileio_stream_close(int *err)
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
294 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
295 close(fd);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
296 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
297
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
298 externC char *
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
299 fileio_error(int err)
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
300 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
301 static char myerr[10];
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
302
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
303 diag_sprintf(myerr, "error %d\n", err);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
304 return myerr;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
305 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
306
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
307 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
308 // RedBoot interface
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
309 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
310 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
311 0, fileio_stream_read, fileio_error);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
312 RedBoot_load(file, fileio_io, true, true, 0);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
313