Commit 7cdebc3289b05b355dcd718688cf3c0cc83ddb25

Authored by Tim Harvey
Committed by Tom Rini
1 parent 643aae1406

cmd_ubifs: normalize 'file not found' errors

Signed-off-by: Tim Harvey <tharvey@gateworks.com>

Showing 1 changed file with 8 additions and 4 deletions Inline Diff

1 /* 1 /*
2 * (C) Copyright 2008 2 * (C) Copyright 2008
3 * Stefan Roese, DENX Software Engineering, sr@denx.de. 3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 * 4 *
5 * SPDX-License-Identifier: GPL-2.0+ 5 * SPDX-License-Identifier: GPL-2.0+
6 */ 6 */
7 7
8 8
9 /* 9 /*
10 * UBIFS command support 10 * UBIFS command support
11 */ 11 */
12 12
13 #undef DEBUG 13 #undef DEBUG
14 14
15 #include <common.h> 15 #include <common.h>
16 #include <config.h> 16 #include <config.h>
17 #include <command.h> 17 #include <command.h>
18 18
19 #include "../fs/ubifs/ubifs.h" 19 #include "../fs/ubifs/ubifs.h"
20 20
21 static int ubifs_initialized; 21 static int ubifs_initialized;
22 static int ubifs_mounted; 22 static int ubifs_mounted;
23 23
24 extern struct super_block *ubifs_sb; 24 extern struct super_block *ubifs_sb;
25 25
26 /* Prototypes */ 26 /* Prototypes */
27 int ubifs_init(void); 27 int ubifs_init(void);
28 int ubifs_mount(char *vol_name); 28 int ubifs_mount(char *vol_name);
29 void ubifs_umount(struct ubifs_info *c); 29 void ubifs_umount(struct ubifs_info *c);
30 int ubifs_ls(char *dir_name); 30 int ubifs_ls(char *dir_name);
31 int ubifs_load(char *filename, u32 addr, u32 size); 31 int ubifs_load(char *filename, u32 addr, u32 size);
32 32
33 int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 33 int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
34 { 34 {
35 char *vol_name; 35 char *vol_name;
36 int ret; 36 int ret;
37 37
38 if (argc != 2) 38 if (argc != 2)
39 return CMD_RET_USAGE; 39 return CMD_RET_USAGE;
40 40
41 vol_name = argv[1]; 41 vol_name = argv[1];
42 debug("Using volume %s\n", vol_name); 42 debug("Using volume %s\n", vol_name);
43 43
44 if (ubifs_initialized == 0) { 44 if (ubifs_initialized == 0) {
45 ubifs_init(); 45 ubifs_init();
46 ubifs_initialized = 1; 46 ubifs_initialized = 1;
47 } 47 }
48 48
49 ret = ubifs_mount(vol_name); 49 ret = ubifs_mount(vol_name);
50 if (ret) 50 if (ret)
51 return -1; 51 return -1;
52 52
53 ubifs_mounted = 1; 53 ubifs_mounted = 1;
54 54
55 return 0; 55 return 0;
56 } 56 }
57 57
58 int ubifs_is_mounted(void) 58 int ubifs_is_mounted(void)
59 { 59 {
60 return ubifs_mounted; 60 return ubifs_mounted;
61 } 61 }
62 62
63 void cmd_ubifs_umount(void) 63 void cmd_ubifs_umount(void)
64 { 64 {
65 65
66 if (ubifs_sb) { 66 if (ubifs_sb) {
67 printf("Unmounting UBIFS volume %s!\n", 67 printf("Unmounting UBIFS volume %s!\n",
68 ((struct ubifs_info *)(ubifs_sb->s_fs_info))->vi.name); 68 ((struct ubifs_info *)(ubifs_sb->s_fs_info))->vi.name);
69 ubifs_umount(ubifs_sb->s_fs_info); 69 ubifs_umount(ubifs_sb->s_fs_info);
70 } 70 }
71 71
72 ubifs_sb = NULL; 72 ubifs_sb = NULL;
73 ubifs_mounted = 0; 73 ubifs_mounted = 0;
74 ubifs_initialized = 0; 74 ubifs_initialized = 0;
75 } 75 }
76 76
77 int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 77 int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
78 { 78 {
79 if (argc != 1) 79 if (argc != 1)
80 return CMD_RET_USAGE; 80 return CMD_RET_USAGE;
81 81
82 if (ubifs_initialized == 0) { 82 if (ubifs_initialized == 0) {
83 printf("No UBIFS volume mounted!\n"); 83 printf("No UBIFS volume mounted!\n");
84 return -1; 84 return -1;
85 } 85 }
86 86
87 cmd_ubifs_umount(); 87 cmd_ubifs_umount();
88 88
89 return 0; 89 return 0;
90 } 90 }
91 91
92 int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 92 int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
93 { 93 {
94 char *filename = "/"; 94 char *filename = "/";
95 int ret; 95 int ret;
96 96
97 if (!ubifs_mounted) { 97 if (!ubifs_mounted) {
98 printf("UBIFS not mounted, use ubifsmount to mount volume first!\n"); 98 printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
99 return -1; 99 return -1;
100 } 100 }
101 101
102 if (argc == 2) 102 if (argc == 2)
103 filename = argv[1]; 103 filename = argv[1];
104 debug("Using filename %s\n", filename); 104 debug("Using filename %s\n", filename);
105 105
106 ret = ubifs_ls(filename); 106 ret = ubifs_ls(filename);
107 if (ret) 107 if (ret) {
108 printf("%s not found!\n", filename); 108 printf("** File not found %s **\n", filename);
109 ret = CMD_RET_FAILURE;
110 }
109 111
110 return ret; 112 return ret;
111 } 113 }
112 114
113 int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 115 int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
114 { 116 {
115 char *filename; 117 char *filename;
116 char *endp; 118 char *endp;
117 int ret; 119 int ret;
118 u32 addr; 120 u32 addr;
119 u32 size = 0; 121 u32 size = 0;
120 122
121 if (!ubifs_mounted) { 123 if (!ubifs_mounted) {
122 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n"); 124 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
123 return -1; 125 return -1;
124 } 126 }
125 127
126 if (argc < 3) 128 if (argc < 3)
127 return CMD_RET_USAGE; 129 return CMD_RET_USAGE;
128 130
129 addr = simple_strtoul(argv[1], &endp, 16); 131 addr = simple_strtoul(argv[1], &endp, 16);
130 if (endp == argv[1]) 132 if (endp == argv[1])
131 return CMD_RET_USAGE; 133 return CMD_RET_USAGE;
132 134
133 filename = argv[2]; 135 filename = argv[2];
134 136
135 if (argc == 4) { 137 if (argc == 4) {
136 size = simple_strtoul(argv[3], &endp, 16); 138 size = simple_strtoul(argv[3], &endp, 16);
137 if (endp == argv[3]) 139 if (endp == argv[3])
138 return CMD_RET_USAGE; 140 return CMD_RET_USAGE;
139 } 141 }
140 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size); 142 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
141 143
142 ret = ubifs_load(filename, addr, size); 144 ret = ubifs_load(filename, addr, size);
143 if (ret) 145 if (ret) {
144 printf("%s not found!\n", filename); 146 printf("** File not found %s **\n", filename);
147 ret = CMD_RET_FAILURE;
148 }
145 149
146 return ret; 150 return ret;
147 } 151 }
148 152
149 U_BOOT_CMD( 153 U_BOOT_CMD(
150 ubifsmount, 2, 0, do_ubifs_mount, 154 ubifsmount, 2, 0, do_ubifs_mount,
151 "mount UBIFS volume", 155 "mount UBIFS volume",
152 "<volume-name>\n" 156 "<volume-name>\n"
153 " - mount 'volume-name' volume" 157 " - mount 'volume-name' volume"
154 ); 158 );
155 159
156 U_BOOT_CMD( 160 U_BOOT_CMD(
157 ubifsumount, 1, 0, do_ubifs_umount, 161 ubifsumount, 1, 0, do_ubifs_umount,
158 "unmount UBIFS volume", 162 "unmount UBIFS volume",
159 " - unmount current volume" 163 " - unmount current volume"
160 ); 164 );
161 165
162 U_BOOT_CMD( 166 U_BOOT_CMD(
163 ubifsls, 2, 0, do_ubifs_ls, 167 ubifsls, 2, 0, do_ubifs_ls,
164 "list files in a directory", 168 "list files in a directory",
165 "[directory]\n" 169 "[directory]\n"
166 " - list files in a 'directory' (default '/')" 170 " - list files in a 'directory' (default '/')"
167 ); 171 );
168 172
169 U_BOOT_CMD( 173 U_BOOT_CMD(
170 ubifsload, 4, 0, do_ubifs_load, 174 ubifsload, 4, 0, do_ubifs_load,
171 "load file from an UBIFS filesystem", 175 "load file from an UBIFS filesystem",
172 "<addr> <filename> [bytes]\n" 176 "<addr> <filename> [bytes]\n"
173 " - load file 'filename' to address 'addr'" 177 " - load file 'filename' to address 'addr'"
174 ); 178 );
175 179