annotate packages/redboot/current/src/fs/fileio.c @ 2257:467fd46113f3

* src/fs/fileio.c (do_list): Use getcwd for current directory, rather than "." which may not be implemented in the FS. * src/parse.c (redboot_exec): Conditionalise use of __mem_fault_handler to only be when stubs are included. (error_handler): Ditto for this function. * src/main.c (cyg_start): Conditionalise use of __mem_fault_handler to only be when stubs are included. (do_go): Ditto. (error_handler): Ditto for this function. * src/fs/fileio.c (do_mkdir, do_deldir, do_del, do_write): Added some extra argument checking to these functions. * src/fs/fileio.c (do_mount): Only support -f with "legacy" flash block devices. Clear mount table on failure. (do_move): Silence rename undefined warning. (do_write): Silence warnings. (do_info): Support longer device names. * src/decompress.c (ZLIB_COMPRESSION_OVERHEAD): Increase substantially if jffs2 is present. * src/fs/fileio.c: Fixed some bugs in handling of mounts. The strings used in the mount table must be copied, otherwise the mount table is corrupted by later commands. Also toughened up some error testing. * doc/redboot_cmds.sgml: Added file mode documentation to load command. * doc/redboot_cmds.sgml: Added documentation of filesystem access commands. * src/fs/fileio.c (do_write): Added O_TRUNC to the open call to ensure that the file is resized to fit the new data. * src/fs/fileio.c: Significantly reorganized to present an interface similar to the fis commands. Added a variety of command to manipulate files and directories in a filesystem. * src/parse.c: Added redboot_exec() to provide an internal interface for executing RedBoot commands. Added err_printf() which allows an error message to be printed before longjumping out to an enclosing call to redboot_exec(). Where redboot_exec() is not involved, it just behaves like diag_printf(). * src/main.c: Removed unnecessary delay during startup. Changed diag_printf() in do_go() into err_printf(). * src/load.c: Changed some calls to diag_printf() to err_printf(). * src/net/net_io.c: Changed init priority to RedBoot_INIT_NET. * include/redboot.h: Added some extra initialization priorities. Added prototypes for redboot_exec() and err_printf().
author jlarmour
date Thu, 20 Jul 2006 20:27:47 +0000
parents a0d4c606e72d
children 09f5e65f57b1
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
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
13 // Copyright (C) 2004, 2005, 2006 eCosCentric Limited.
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
14 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
15 // 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
16 // 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
17 // 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
18 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
19 // 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
20 // 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
21 // 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
22 // for more details.
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
23 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
24 // 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
25 // 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
26 // 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
27 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
28 // 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
29 // 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
30 // 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
31 // 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
32 // 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
33 // 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
34 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
35 // 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
36 // 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
37 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
38 // -------------------------------------------
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
39 //####ECOSGPLCOPYRIGHTEND####
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
40 //==========================================================================
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
41 //#####DESCRIPTIONBEGIN####
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
42 //
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
43 // Author(s): nickg
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
44 // Contributors: dwmw2, msalter
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
45 // Date: 2004-11-21
1414
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
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
71 #include <cyg/io/devtab.h>
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
72 #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
73 #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
74
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
75 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
76
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
77 // Define table boundaries
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
78 CYG_HAL_TABLE_BEGIN( __FS_cmds_TAB__, FS_cmds);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
79 CYG_HAL_TABLE_END( __FS_cmds_TAB_END__, FS_cmds);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
80
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
81 extern struct cmd __FS_cmds_TAB__[], __FS_cmds_TAB_END__;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
82
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
83 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
84
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
85 static void
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
86 fs_usage(char *why)
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
87 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
88 diag_printf("*** invalid 'fs' command: %s\n", why);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
89 cmd_usage(__FS_cmds_TAB__, &__FS_cmds_TAB_END__, "fs ");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
90 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
91
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
92
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
93 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
94
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
95 #define MAX_MOUNTS 4
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
96
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
97 static int mount_count = 0;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
98
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
99 static struct
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
100 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
101 char dev_str[PATH_MAX];
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
102 char mp_str[PATH_MAX];
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
103 char type_str[PATH_MAX];
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
104 } mounts[MAX_MOUNTS];
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
105
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
106 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
107
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
108 static void do_mount(int argc, char *argv[]);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
109 static void do_umount(int argc, char *argv[]);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
110
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
111 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
112 #define FLASHPART "[-f <partition>] "
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
113 #else
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
114 #define FLASHPART
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
115 #endif
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
116
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
117 local_cmd_entry("mount",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
118 "Mount file system",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
119 FLASHPART "[-d <device>] -t <fstype> [<mountpoint>]",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
120 do_mount,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
121 FS_cmds
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
122 );
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
123 local_cmd_entry("umount",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
124 "Unmount file system",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
125 "<mountpoint>",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
126 do_umount,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
127 FS_cmds
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
128 );
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
129
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
130 //==========================================================================
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
131
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
132 // Mount disk/filesystem
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
133 static void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
134 do_mount(int argc, char *argv[])
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
135 {
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
136 char *dev_str = "<undefined>", *type_str, *mp_str;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
137 bool dev_set = false, type_set = false;
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
138 struct option_info opts[3];
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
139 int err, num_opts = 2;
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
140 int i,m=0; /* Set to 0 to silence warning */
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
141 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
142 char *part_str;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
143 bool part_set = false;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
144 #endif
1414
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 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
147 (void *)&dev_str, &dev_set, "device");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
148 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
149 (void *)&type_str, &type_set, "fstype");
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
150 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
151 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
152 (void *)&part_str, &part_set, "partition");
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
153 num_opts++;
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
1605
43a89c18d005 Add checking (assert) for size of option arrays. Also fix port for TFTP on little endian systems.
gthomas
parents: 1598
diff changeset
156 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
157
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
158 if (!scan_opts(argc, argv, 1, opts, num_opts, &mp_str, OPTION_ARG_TYPE_STR, "mountpoint"))
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
159 return;
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 if (!type_set) {
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
162 err_printf("fs mount: Must specify file system type\n");
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
163 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
164 }
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
165
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
166 if( mp_str == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
167 mp_str = "/";
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
168
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
169 if( mount_count >= MAX_MOUNTS )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
170 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
171 err_printf("fs mount: Maximum number of mounts exceeded\n");
1414
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 }
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
174
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
175 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
176 if (part_set) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
177 int len;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
178 cyg_io_handle_t h;
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 if (dev_set && strcmp(dev_str, CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1)) {
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
181 err_printf("fs mount: May only set one of <device> or <partition>\n");
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
182 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
183 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
184
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
185 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
186 len = strlen(part_str);
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 err = cyg_io_lookup(dev_str, &h);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
189 if (err < 0) {
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
190 err_printf("fs mount: cyg_io_lookup of \"%s\" returned %d\n", err);
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
191 return;
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 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
194 part_str, &len);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
195 if (err < 0) {
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
196 diag_printf("fs mount: FIS partition \"%s\" not found\n",
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
197 part_str);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
198 return;
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 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
201 #endif
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
202
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
203 for( i = 0; i < MAX_MOUNTS; i++ )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
204 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
205 if( mounts[i].mp_str[0] != '\0' )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
206 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
207 if( strcmp(mounts[i].dev_str, dev_str ) == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
208 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
209 err_printf("fs mount: Device %s already mounted\n",dev_str);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
210 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
211 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
212 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
213 else
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
214 m = i;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
215 }
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
216
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
217 strcpy( mounts[m].mp_str, mp_str );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
218 strcpy( mounts[m].dev_str, dev_str );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
219 strcpy( mounts[m].type_str, type_str );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
220
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
221 err = mount(mounts[m].dev_str, mounts[m].mp_str, mounts[m].type_str);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
222
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
223 if (err)
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
224 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
225 err_printf("fs mount: mount(%s,%s,%s) failed %d\n", dev_str, mp_str, type_str, errno);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
226 mounts[m].mp_str[0] = '\0'; // mount failed so don't let it appear mounted
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
227 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
228 else
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
229 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
230 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
231 chdir( "/" );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
232 mount_count++;
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
233 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
234 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
235
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
236 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
237
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
238 static void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
239 do_umount(int argc, char *argv[])
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
240 {
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
241 char *dir_str;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
242 int err;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
243 int i;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
244
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
245 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
246 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
247 err_printf("fs: No filesystems mounted\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
248 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
249 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
250
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
251 if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "mountpoint"))
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
252 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
253
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
254 if( dir_str == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
255 dir_str = "/";
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
256
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
257 for( i = 0; i < MAX_MOUNTS; i++ )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
258 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
259 if( strcmp(mounts[i].mp_str, dir_str ) == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
260 break;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
261 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
262
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
263 if( i == MAX_MOUNTS )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
264 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
265 err_printf("fs unmount: unknown mountpoint %s\n",dir_str);
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
266 return;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
267 }
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
268
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
269 err = umount (dir_str);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
270
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
271 if (err)
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
272 err_printf("fs umount: unmount failed %d\n", errno);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
273 else
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
274 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
275 mounts[i].mp_str[0] = '\0';
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
276 mount_count--;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
277 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
278 chdir( "/" );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
279 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
280
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
281 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
282
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
283 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
284
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
285 #include <dirent.h>
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
286
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
287 static char rwx[8][4] = { "---", "r--", "-w-", "rw-", "--x", "r-x", "-wx", "rwx" };
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
288
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
289 static void
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
290 do_list(int argc, char * argv[])
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
291 {
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
292 char * dir_str;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
293 DIR *dirp;
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
294 char filename[PATH_MAX];
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
295 char cwd[PATH_MAX];
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
296 struct stat sbuf;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
297 int err;
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
298
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
299 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
300 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
301 err_printf("fs: No filesystems mounted\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
302 return;
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
303 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
304
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
305 if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory"))
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
306 return;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
307
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
308 if( dir_str == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
309 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
310 dir_str = getcwd(cwd, sizeof(cwd));
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
311 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
312
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
313 dirp = opendir(dir_str);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
314 if (dirp==NULL) {
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
315 err_printf("fs list: no such directory %s\n",dir_str);
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
316 return;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
317 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
318
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
319 for (;;) {
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
320 struct dirent *entry = readdir(dirp);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
321
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
322 if( entry == NULL )
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
323 break;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
324
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
325 strcpy(filename, dir_str);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
326 strcat(filename, "/");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
327 strcat(filename, entry->d_name);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
328
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
329 err = stat(filename, &sbuf);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
330 if (err < 0) {
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
331 diag_printf("Unable to stat file %s\n", filename);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
332 continue;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
333 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
334 diag_printf("%4d ", sbuf.st_ino);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
335 if (S_ISDIR(sbuf.st_mode)) diag_printf("d");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
336 if (S_ISCHR(sbuf.st_mode)) diag_printf("c");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
337 if (S_ISBLK(sbuf.st_mode)) diag_printf("b");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
338 if (S_ISREG(sbuf.st_mode)) diag_printf("-");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
339 if (S_ISLNK(sbuf.st_mode)) diag_printf("l");
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
340 diag_printf("%s%s%s", // Ho, humm, have to hard code the shifts
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
341 rwx[(sbuf.st_mode & S_IRWXU) >> 16],
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
342 rwx[(sbuf.st_mode & S_IRWXG) >> 19],
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
343 rwx[(sbuf.st_mode & S_IRWXO) >> 22]);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
344 diag_printf(" %2d size %6d %s\n",
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
345 sbuf.st_nlink,sbuf.st_size,
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
346 entry->d_name);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
347 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
348
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
349 closedir(dirp);
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
350 return;
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
351 }
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
352
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
353 local_cmd_entry("list",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
354 "list directory contents",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
355 "[<directory>]",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
356 do_list,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
357 FS_cmds
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
358 );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
359
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
360
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
361 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
362
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
363
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
364 static void
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
365 do_mkdir(int argc, char * argv[])
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
366 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
367 char *dir_str;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
368 int err;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
369
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
370 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
371 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
372 err_printf("fs: No filesystems mounted\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
373 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
374 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
375
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
376 if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory") ||
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
377 dir_str == NULL)
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
378 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
379 fs_usage("invalid arguments");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
380 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
381 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
382
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
383 err = mkdir( dir_str, 0 );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
384
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
385 if( err != 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
386 err_printf("fs mkdir: failed to create directory %s\n",dir_str);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
387 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
388
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
389 local_cmd_entry("mkdir",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
390 "create directory",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
391 "<directory>",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
392 do_mkdir,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
393 FS_cmds
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
394 );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
395
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
396 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
397
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
398 static void
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
399 do_deldir(int argc, char * argv[])
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
400 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
401 char *dir_str;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
402 int err;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
403
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
404 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
405 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
406 err_printf("fs: No filesystems mounted\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
407 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
408 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
409
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
410 if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory") ||
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
411 dir_str == NULL)
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
412 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
413 fs_usage("invalid arguments");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
414 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
415 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
416
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
417 err = rmdir( dir_str );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
418
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
419 if( err != 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
420 err_printf("fs deldir: failed to remove directory %s\n",dir_str);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
421 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
422
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
423 local_cmd_entry("deldir",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
424 "delete directory",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
425 "<directory>",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
426 do_deldir,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
427 FS_cmds
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
428 );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
429
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
430 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
431
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
432 static void
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
433 do_del(int argc, char * argv[])
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
434 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
435 char *name_str = NULL;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
436 int err;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
437
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
438 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
439 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
440 err_printf("fs: No filesystems mounted\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
441 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
442 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
443
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
444 if (!scan_opts(argc, argv, 1, NULL, 0, &name_str, OPTION_ARG_TYPE_STR, "file") ||
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
445 name_str == NULL)
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
446 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
447 fs_usage("invalid arguments");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
448 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
449 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
450
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
451 err = unlink( name_str );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
452
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
453 if( err != 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
454 err_printf("fs del: failed to delete file %s\n",name_str);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
455 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
456
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
457 local_cmd_entry("del",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
458 "delete file",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
459 "<file>",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
460 do_del,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
461 FS_cmds
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
462 );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
463
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
464 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
465
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
466 static void
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
467 do_move(int argc, char * argv[])
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
468 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
469 int err;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
470 __externC int rename( const char *oldname, const char *newname );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
471 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
472 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
473 err_printf("fs: No filesystems mounted\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
474 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
475 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
476
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
477 if( argc != 3 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
478 fs_usage("bad arguments to move command\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
479
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
480 err = rename( argv[1], argv[2] );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
481
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
482 if( err != 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
483 err_printf("fs move: failed to move file %s to %s\n",argv[1],argv[2]);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
484 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
485
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
486 local_cmd_entry("move",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
487 "move file",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
488 "<from> <to>",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
489 do_move,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
490 FS_cmds
1724
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
491 );
549e69d9a7d0 * cdl/redboot.cdl:
asl
parents: 1605
diff changeset
492
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
493 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
494
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
495 static void
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
496 do_cd(int argc, char * argv[])
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
497 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
498 char *dir_str;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
499 int err;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
500
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
501 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
502 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
503 err_printf("fs: No filesystems mounted\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
504 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
505 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
506
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
507 if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory"))
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
508 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
509
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
510 if( dir_str == NULL )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
511 dir_str = "/";
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
512
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
513 err = chdir( dir_str );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
514
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
515 if( err != 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
516 err_printf("fs cd: failed to change directory %s\n",dir_str);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
517 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
518
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
519 local_cmd_entry("cd",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
520 "change directory",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
521 "[<directory>]",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
522 do_cd,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
523 FS_cmds
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
524 );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
525
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
526 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
527
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
528 static void
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
529 do_write(int argc, char * argv[])
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
530 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
531 char *name_str = NULL;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
532 int err;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
533 struct option_info opts[2];
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
534 CYG_ADDRESS mem_addr = 0;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
535 unsigned long length = 0;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
536 bool mem_addr_set = false;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
537 bool length_set = false;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
538 int fd;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
539
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
540 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
541 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
542 err_printf("fs: No filesystems mounted\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
543 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
544 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
545
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
546 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
547 (void *)&mem_addr, (bool *)&mem_addr_set, "memory base address");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
548 init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
549 (void *)&length, (bool *)&length_set, "image length");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
550
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
551 if (!scan_opts(argc, argv, 1, opts, 2, &name_str, OPTION_ARG_TYPE_STR, "file name") ||
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
552 name_str == NULL)
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
553 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
554 fs_usage("invalid arguments");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
555 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
556 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
557
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
558 // diag_printf("load_address %08x %08x\n",load_address,load_address_end);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
559 // diag_printf("ram %08x %08x\n",ram_start, ram_end);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
560 // diag_printf("file name %08x >%s<\n",name_str,name_str);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
561
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
562 if (!mem_addr_set &&
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
563 (load_address >= (CYG_ADDRESS)ram_start) &&
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
564 ((load_address_end) < (CYG_ADDRESS)ram_end))
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
565 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
566 mem_addr = load_address;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
567 mem_addr_set = true;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
568 if (!length_set)
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
569 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
570 length = load_address_end - load_address;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
571 length_set = true;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
572 // maybe get length from existing file size if no loaded
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
573 // image?
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
574 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
575 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
576
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
577 fd = open( name_str, O_WRONLY|O_CREAT|O_TRUNC );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
578
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
579 if( fd < 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
580 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
581 err_printf("fs write: Cannot open %s\n", name_str );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
582 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
583 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
584
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
585 // diag_printf("write %08x %08x\n",mem_addr, length );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
586
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
587 err = write( fd, (void *)mem_addr, length );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
588
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
589 if( err != length )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
590 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
591 err_printf("fs write: failed to write to file %d(%d) %d\n",err,length,errno);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
592 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
593
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
594 err = close( fd );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
595
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
596 if( err != 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
597 err_printf("fs write: close failed\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
598 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
599
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
600 local_cmd_entry("write",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
601 "write data to file",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
602 "-b <mem_base> -l <image_length> <file_name>",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
603 do_write,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
604 FS_cmds
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
605 );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
606
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
607 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
608
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
609 __externC cyg_fstab_entry cyg_fstab[];
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
610 __externC cyg_fstab_entry cyg_fstab_end;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
611 __externC cyg_mtab_entry cyg_mtab[];
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
612 __externC cyg_mtab_entry cyg_mtab_end;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
613
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
614 static void
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
615 do_info(int argc, char * argv[])
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
616 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
617 cyg_bool found = false;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
618 cyg_fstab_entry *f;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
619 cyg_devtab_entry_t *t;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
620
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
621 for( f = &cyg_fstab[0] ; f != &cyg_fstab_end; f++ )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
622 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
623 if( !found )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
624 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
625 diag_printf("Filesystems available:\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
626 found = true;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
627 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
628 diag_printf("%s\n",f->name);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
629 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
630
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
631 found = false;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
632 for (t = &__DEVTAB__[0]; t != &__DEVTAB_END__; t++)
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
633 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
634 if( (t->status & CYG_DEVTAB_STATUS_BLOCK) == 0 ||
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
635 (t->status & CYG_DEVTAB_STATUS_AVAIL) == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
636 continue;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
637
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
638 if( !found )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
639 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
640 diag_printf("\nDevices available:\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
641 found = true;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
642 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
643 diag_printf("%s\n",t->name);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
644 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
645
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
646 if( mount_count != 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
647 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
648 int i;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
649
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
650 diag_printf("\nMounted filesystems:\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
651 diag_printf(" Device Filesystem Mounted on\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
652
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
653 for( i = 0; i < MAX_MOUNTS; i++ )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
654 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
655 if( mounts[i].mp_str[0] != '\0' )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
656 diag_printf("%32s %10s %s\n", mounts[i].dev_str, mounts[i].type_str, mounts[i].mp_str);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
657 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
658 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
659 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
660
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
661 local_cmd_entry("info",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
662 "filesystem info",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
663 "",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
664 do_info,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
665 FS_cmds
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
666 );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
667
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
668 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
669
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
670 static void
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
671 do_fs(int argc, char *argv[])
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
672 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
673 struct cmd *cmd;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
674
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
675 if (argc < 2) {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
676 fs_usage("too few arguments");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
677 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
678 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
679 if ((cmd = cmd_search(__FS_cmds_TAB__, &__FS_cmds_TAB_END__,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
680 argv[1])) != (struct cmd *)0) {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
681 (cmd->fun)(argc-1, argv+1);
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
682 return;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
683 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
684 fs_usage("unrecognized command");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
685 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
686
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
687 RedBoot_nested_cmd("fs",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
688 "Manage Filesystem files",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
689 "{cmds}",
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
690 do_fs,
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
691 __FS_cmds_TAB__, &__FS_cmds_TAB_END__
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
692 );
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
693
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
694
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
695 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
696
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
697 static int fd;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
698
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
699 externC int
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
700 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
701 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
702 char *filename = info->filename;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
703
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
704 if( mount_count == 0 )
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
705 {
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
706 diag_printf("fs: No filesystems mounted\n");
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
707 return -1;
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
708 }
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
709
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
710 fd = open(filename, O_RDONLY);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
711 if (fd < 0) {
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
712 diag_printf("fs: Open failed, error %d\n", errno);
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
713 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
714 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
715 return 0;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
716 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
717
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
718 externC int
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
719 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
720 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
721 int nread;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
722
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
723 if ((nread = read(fd, buf, size)) < 0) {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
724 *err = errno;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
725 return -1;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
726 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
727 return nread;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
728 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
729
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
730 externC void
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
731 fileio_stream_close(int *err)
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
732 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
733 close(fd);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
734 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
735
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
736 externC char *
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
737 fileio_error(int err)
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
738 {
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
739 static char myerr[10];
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
740
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
741 diag_sprintf(myerr, "error %d", err);
1414
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
742 return myerr;
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
743 }
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
744
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
745 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
746 // RedBoot interface
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
747 //
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
748 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
749 0, fileio_stream_read, fileio_error);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
750 RedBoot_load(file, fileio_io, true, true, 0);
9a2e186be457 Add support for mountable file systems (like JFFS2) - from David Woodhouse
gthomas
parents:
diff changeset
751
2257
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
752 //==========================================================================
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
753 // End of fileio.c
467fd46113f3 * src/fs/fileio.c (do_list): Use getcwd for current directory,
jlarmour
parents: 1867
diff changeset
754