• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Revisióne520d036165b36cf5c4cb305f9cec7d183977b61 (tree)
Tiempo2008-11-21 03:38:36
AutorJay Freeman (saurik) <saurik@saur...>
CommiterJay Freeman (saurik)

Log Message

Added support for loop@/path/to/filename to init's mount.

In keeping with the pattern of mtd@partition, I have added loop@path as a way to specify a loopback device. This way you can do things like mount directories in /system using cramfs from a file otherwise on /system (just one example oof how I'm using it). I specifically went with loop@ rather than adding this feature as a flag as the flags system is designed to set bits in the flags argument to mount: using loop@ fit the model in a much simpler manner and actually feels "correct".

This is a better version of the previously submitted 4045 that also refactors the mtd@ case. The reason for this is that I received comments that I should check for errors and return errors rather that do work in the case of success and fall through, but the mtd@ case wasn't doing that either and it became awkward to design the function so that it was half in one style of error handling and half in another. I also made certain to use inequality comparisons for Unix's -1 error returns rather than checking for -1, refactored my large if statement so as not to have danling parentheses, and disassocited the loop device on mount failure.

Cambiar Resumen

Diferencia incremental

--- a/init/builtins.c
+++ b/init/builtins.c
@@ -29,6 +29,7 @@
2929 #include <stdlib.h>
3030 #include <sys/mount.h>
3131 #include <sys/resource.h>
32+#include <linux/loop.h>
3233
3334 #include "init.h"
3435 #include "keywords.h"
@@ -231,7 +232,7 @@ static struct {
231232 int do_mount(int nargs, char **args)
232233 {
233234 char tmp[64];
234- char *source;
235+ char *source, *target, *system;
235236 char *options = NULL;
236237 unsigned flags = 0;
237238 int n, i;
@@ -249,15 +250,70 @@ int do_mount(int nargs, char **args)
249250 options = args[n];
250251 }
251252
253+ system = args[1];
252254 source = args[2];
255+ target = args[3];
256+
253257 if (!strncmp(source, "mtd@", 4)) {
254258 n = mtd_name_to_number(source + 4);
255- if (n >= 0) {
256- sprintf(tmp, "/dev/block/mtdblock%d", n);
257- source = tmp;
259+ if (n < 0) {
260+ return -1;
261+ }
262+
263+ sprintf(tmp, "/dev/block/mtdblock%d", n);
264+
265+ if (mount(tmp, target, system, flags, options) < 0) {
266+ return -1;
267+ }
268+
269+ return 0;
270+ } else if (!strncmp(source, "loop@", 5)) {
271+ int mode, loop, fd;
272+ struct loop_info info;
273+
274+ mode = (flags & MS_RDONLY) ? O_RDONLY : O_RDWR;
275+ fd = open(source + 5, mode);
276+ if (fd < 0) {
277+ return -1;
258278 }
279+
280+ for (n = 0; ; n++) {
281+ sprintf(tmp, "/dev/block/loop%d", n);
282+ loop = open(tmp, mode);
283+ if (loop < 0) {
284+ return -1;
285+ }
286+
287+ /* if it is a blank loop device */
288+ if (ioctl(loop, LOOP_GET_STATUS, &info) < 0 && errno == ENXIO) {
289+ /* if it becomes our loop device */
290+ if (ioctl(loop, LOOP_SET_FD, fd) >= 0) {
291+ close(fd);
292+
293+ if (mount(tmp, target, system, flags, options) < 0) {
294+ ioctl(loop, LOOP_CLR_FD, 0);
295+ close(loop);
296+ return -1;
297+ }
298+
299+ close(loop);
300+ return 0;
301+ }
302+ }
303+
304+ close(loop);
305+ }
306+
307+ close(fd);
308+ ERROR("out of loopback devices");
309+ return -1;
310+ } else {
311+ if (mount(source, target, system, flags, options) < 0) {
312+ return -1;
313+ }
314+
315+ return 0;
259316 }
260- return mount(source, args[3], args[1], flags, options);
261317 }
262318
263319 int do_setkey(int nargs, char **args)