2007-09-21 15:51:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Greg White
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-09-21 15:51:53 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
2010-05-06 22:13:54 +00:00
|
|
|
#include <stdio.h>
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
#include <errno.h>
|
2014-08-08 06:28:11 +00:00
|
|
|
#include "../kernel-internal.h"
|
2010-08-12 13:38:25 +00:00
|
|
|
#include "gcc_extensions.h"
|
2008-05-07 07:14:39 +00:00
|
|
|
#include "string.h"
|
2008-05-10 18:00:11 +00:00
|
|
|
#include "adc.h"
|
|
|
|
#include "powermgmt.h"
|
2008-11-01 16:14:28 +00:00
|
|
|
#include "storage.h"
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
#include "file_internal.h"
|
2007-11-27 15:40:29 +00:00
|
|
|
#include "dir.h"
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
#include "file.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "disk.h"
|
|
|
|
#include "common.h"
|
2012-03-04 14:34:29 +00:00
|
|
|
#include "rb-loader.h"
|
|
|
|
#include "loader_strerror.h"
|
2011-01-21 07:05:51 +00:00
|
|
|
#include "power.h"
|
2008-05-10 18:00:11 +00:00
|
|
|
#include "backlight.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "usb.h"
|
2008-05-10 18:00:11 +00:00
|
|
|
#include "button.h"
|
2008-05-07 07:14:39 +00:00
|
|
|
#include "font.h"
|
|
|
|
#include "lcd.h"
|
2010-05-27 09:41:46 +00:00
|
|
|
#include "version.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2011-01-21 07:05:51 +00:00
|
|
|
/* Show the Rockbox logo - in show_logo.c */
|
2011-09-08 18:31:15 +00:00
|
|
|
extern void show_logo(void);
|
2011-01-21 07:05:51 +00:00
|
|
|
|
2008-02-17 23:17:08 +00:00
|
|
|
#define TAR_CHUNK 512
|
|
|
|
#define TAR_HEADER_SIZE 157
|
|
|
|
|
2008-05-07 07:14:39 +00:00
|
|
|
/* Where files sent via MTP are stored */
|
|
|
|
static const char basedir[] = "/Content/0b00/00/";
|
|
|
|
/* Can use memory after vector table up to 0x01f00000 */
|
|
|
|
static char * const tarbuf = (char *)0x00000040;
|
|
|
|
static const size_t tarbuf_size = 0x01f00000 - 0x00000040;
|
2008-05-10 18:00:11 +00:00
|
|
|
/* Firmware data */
|
|
|
|
static void * const load_buf = 0x00000000;
|
|
|
|
static const size_t load_buf_size = 0x20000000 - 0x100000;
|
|
|
|
static const void * const start_addr = 0x00000000;
|
2008-02-08 02:20:05 +00:00
|
|
|
|
2011-01-21 07:05:51 +00:00
|
|
|
/* Show a message + "Shutting down...", then power off the device */
|
|
|
|
static void display_message_and_power_off(int timeout, const char *msg)
|
2008-04-18 16:42:50 +00:00
|
|
|
{
|
2011-01-21 07:05:51 +00:00
|
|
|
verbose = true;
|
|
|
|
printf(msg);
|
|
|
|
printf("Shutting down...");
|
2008-04-18 16:42:50 +00:00
|
|
|
sleep(timeout);
|
2011-01-21 07:05:51 +00:00
|
|
|
power_off();
|
2008-04-18 16:42:50 +00:00
|
|
|
}
|
|
|
|
|
2011-01-21 07:05:51 +00:00
|
|
|
static void check_battery_safe(void)
|
2008-05-10 18:00:11 +00:00
|
|
|
{
|
2011-01-21 07:05:51 +00:00
|
|
|
if (battery_level_safe())
|
|
|
|
return;
|
2008-05-10 18:00:11 +00:00
|
|
|
|
2011-01-21 07:05:51 +00:00
|
|
|
display_message_and_power_off(HZ, "Battery low");
|
2008-05-10 18:00:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Handle charging while connected */
|
2011-01-21 07:05:51 +00:00
|
|
|
static void handle_usb(int connect_timeout)
|
2008-05-10 18:00:11 +00:00
|
|
|
{
|
2011-01-21 07:05:51 +00:00
|
|
|
long end_tick = 0;
|
2008-05-10 18:00:11 +00:00
|
|
|
int button;
|
|
|
|
|
|
|
|
/* We need full button and backlight handling now */
|
|
|
|
backlight_init();
|
|
|
|
button_init();
|
2011-01-21 07:05:51 +00:00
|
|
|
backlight_on();
|
2008-05-10 18:00:11 +00:00
|
|
|
|
|
|
|
/* Start the USB driver */
|
|
|
|
usb_init();
|
|
|
|
usb_start_monitoring();
|
|
|
|
|
|
|
|
/* Wait for threads to connect or cable is pulled */
|
2011-01-21 07:05:51 +00:00
|
|
|
printf("USB: Connecting");
|
|
|
|
|
|
|
|
if (connect_timeout != TIMEOUT_BLOCK)
|
|
|
|
end_tick = current_tick + connect_timeout;
|
2008-05-10 18:00:11 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
button = button_get_w_tmo(HZ/2);
|
|
|
|
|
|
|
|
if (button == SYS_USB_CONNECTED)
|
|
|
|
break; /* Hit */
|
|
|
|
|
2011-01-21 07:05:51 +00:00
|
|
|
if (connect_timeout != TIMEOUT_BLOCK &&
|
|
|
|
TIME_AFTER(current_tick, end_tick))
|
|
|
|
{
|
|
|
|
/* Timed out waiting for the connect - will happen when connected
|
|
|
|
* to a charger through the USB port */
|
|
|
|
printf("USB: Timed out");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-01 03:19:52 +00:00
|
|
|
if (usb_plugged() == USB_EXTRACTED)
|
2008-05-10 18:00:11 +00:00
|
|
|
break; /* Cable pulled */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (button == SYS_USB_CONNECTED)
|
|
|
|
{
|
2011-01-21 07:05:51 +00:00
|
|
|
/* Switch to verbose mode if not in it so that the status updates
|
|
|
|
* are shown */
|
|
|
|
verbose = true;
|
2008-05-10 18:00:11 +00:00
|
|
|
/* Got the message - wait for disconnect */
|
2011-01-21 07:05:51 +00:00
|
|
|
printf("Bootloader USB mode");
|
2008-05-10 18:00:11 +00:00
|
|
|
|
|
|
|
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2011-01-21 07:05:51 +00:00
|
|
|
button = button_get_w_tmo(HZ/2);
|
2008-05-10 18:00:11 +00:00
|
|
|
if (button == SYS_USB_DISCONNECTED)
|
|
|
|
break;
|
2011-01-21 07:05:51 +00:00
|
|
|
|
|
|
|
check_battery_safe();
|
2008-05-10 18:00:11 +00:00
|
|
|
}
|
2011-01-21 07:05:51 +00:00
|
|
|
|
|
|
|
backlight_on();
|
|
|
|
/* Sleep a little to let the backlight ramp up */
|
|
|
|
sleep(HZ*5/4);
|
2008-05-10 18:00:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Put drivers initialized for USB connection into a known state */
|
|
|
|
usb_close();
|
|
|
|
button_close();
|
|
|
|
backlight_close();
|
|
|
|
}
|
|
|
|
|
2008-05-07 07:14:39 +00:00
|
|
|
static void untar(int tar_fd)
|
2008-02-17 23:17:08 +00:00
|
|
|
{
|
|
|
|
char header[TAR_HEADER_SIZE];
|
2008-04-16 00:38:06 +00:00
|
|
|
char *ptr;
|
2008-02-17 23:17:08 +00:00
|
|
|
char path[102];
|
2008-05-07 07:14:39 +00:00
|
|
|
int fd, i;
|
2008-04-16 00:38:06 +00:00
|
|
|
int ret;
|
2008-05-07 07:14:39 +00:00
|
|
|
size_t size = filesize(tar_fd);
|
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
if (size > tarbuf_size)
|
|
|
|
{
|
2008-05-07 07:14:39 +00:00
|
|
|
printf("tar file too large"); /* Paranoid but proper */
|
|
|
|
return;
|
|
|
|
}
|
2008-04-16 00:38:06 +00:00
|
|
|
|
|
|
|
ret = read(tar_fd, tarbuf, filesize(tar_fd));
|
2008-05-10 18:00:11 +00:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2008-04-16 00:38:06 +00:00
|
|
|
printf("couldn't read tar file (%d)", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ptr = tarbuf;
|
2008-02-17 23:17:08 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2008-04-16 00:38:06 +00:00
|
|
|
memcpy(header, ptr, TAR_HEADER_SIZE);
|
2008-02-17 23:17:08 +00:00
|
|
|
|
|
|
|
if (*header == '\0') /* Check for EOF */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Parse the size field */
|
|
|
|
size = 0;
|
|
|
|
for (i = 124 ; i < 124 + 11 ; i++) {
|
|
|
|
size = (8 * size) + header[i] - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip rest of header */
|
2008-04-16 00:38:06 +00:00
|
|
|
ptr += TAR_CHUNK;
|
2008-02-17 23:17:08 +00:00
|
|
|
|
|
|
|
/* Make the path absolute */
|
|
|
|
strcpy(path, "/");
|
|
|
|
strcat(path, header);
|
|
|
|
|
|
|
|
if (header[156] == '0') /* file */
|
|
|
|
{
|
2008-04-16 00:38:06 +00:00
|
|
|
int wc;
|
2008-02-17 23:17:08 +00:00
|
|
|
|
2010-05-06 17:35:04 +00:00
|
|
|
fd = creat(path, 0666);
|
2008-02-17 23:17:08 +00:00
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
printf("failed to create file (%d)", fd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-16 00:38:06 +00:00
|
|
|
wc = write(fd, ptr, size);
|
|
|
|
if (wc < 0)
|
2008-02-17 23:17:08 +00:00
|
|
|
{
|
2008-04-16 00:38:06 +00:00
|
|
|
printf("write failed (%d)", wc);
|
|
|
|
break;
|
2008-02-17 23:17:08 +00:00
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
2008-04-16 00:38:06 +00:00
|
|
|
ptr += (size + TAR_CHUNK-1) & (~(TAR_CHUNK-1));
|
2008-02-17 23:17:08 +00:00
|
|
|
}
|
|
|
|
else if (header[156] == '5') /* directory */
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Remove the trailing slash */
|
|
|
|
if (path[strlen(path) - 1] == '/')
|
|
|
|
path[strlen(path) - 1] = '\0';
|
|
|
|
|
|
|
|
/* Create the dir */
|
|
|
|
ret = mkdir(path);
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
if (ret < 0 && errno != EEXIST)
|
2008-02-17 23:17:08 +00:00
|
|
|
{
|
|
|
|
printf("failed to create dir (%d)", ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
/* Look for a tar file or rockbox binary in the MTP directory */
|
|
|
|
static void handle_untar(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-02-17 23:17:08 +00:00
|
|
|
char buf[MAX_PATH];
|
|
|
|
char tarstring[6];
|
2008-04-15 23:17:03 +00:00
|
|
|
char model[5];
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
struct dirent* entry;
|
|
|
|
DIR* dir;
|
2008-05-10 18:00:11 +00:00
|
|
|
int fd;
|
2007-09-21 15:51:53 +00:00
|
|
|
int rc;
|
|
|
|
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
dir = opendir(basedir);
|
2008-02-08 02:20:05 +00:00
|
|
|
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
while ((entry = readdir(dir)))
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-05-10 18:00:11 +00:00
|
|
|
if (*entry->d_name == '.')
|
|
|
|
continue;
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s%s", basedir, entry->d_name);
|
|
|
|
fd = open(buf, O_RDONLY);
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
if (fd < 0)
|
|
|
|
continue;
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
/* Check whether the file is a rockbox binary. */
|
|
|
|
lseek(fd, 4, SEEK_SET);
|
|
|
|
rc = read(fd, model, 4);
|
|
|
|
if (rc == 4)
|
2007-11-27 15:40:29 +00:00
|
|
|
{
|
2008-05-10 18:00:11 +00:00
|
|
|
model[4] = 0;
|
|
|
|
if (strcmp(model, "gigs") == 0)
|
2007-11-27 15:40:29 +00:00
|
|
|
{
|
2011-01-21 07:05:51 +00:00
|
|
|
verbose = true;
|
2008-05-10 18:00:11 +00:00
|
|
|
printf("Found rockbox binary. Moving...");
|
2008-02-17 23:17:08 +00:00
|
|
|
close(fd);
|
2008-11-23 22:07:48 +00:00
|
|
|
int ret = rename(buf, BOOTDIR "/" BOOTFILE);
|
2008-05-10 18:00:11 +00:00
|
|
|
printf("returned %d", ret);
|
|
|
|
sleep(HZ);
|
|
|
|
break;
|
2007-11-27 15:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-18 16:42:50 +00:00
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
/* Check whether the file is a tar file. */
|
|
|
|
lseek(fd, 257, SEEK_SET);
|
|
|
|
rc = read(fd, tarstring, 5);
|
|
|
|
if (rc == 5)
|
2008-04-18 16:42:50 +00:00
|
|
|
{
|
2008-05-10 18:00:11 +00:00
|
|
|
tarstring[5] = 0;
|
|
|
|
if (strcmp(tarstring, "ustar") == 0)
|
|
|
|
{
|
2011-01-21 07:05:51 +00:00
|
|
|
verbose = true;
|
2008-05-10 18:00:11 +00:00
|
|
|
printf("Found tar file. Unarchiving...");
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
untar(fd);
|
|
|
|
close(fd);
|
|
|
|
printf("Removing tar file");
|
|
|
|
remove(buf);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-18 16:42:50 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
close(fd);
|
2008-04-20 03:30:57 +00:00
|
|
|
}
|
2008-05-10 18:00:11 +00:00
|
|
|
}
|
2008-04-18 16:42:50 +00:00
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
/* Try to load the firmware and run it */
|
2010-08-12 13:38:25 +00:00
|
|
|
static void NORETURN_ATTR handle_firmware_load(void)
|
2008-05-10 18:00:11 +00:00
|
|
|
{
|
2011-01-21 07:05:51 +00:00
|
|
|
int rc = load_firmware(load_buf, BOOTFILE, load_buf_size);
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2012-03-04 14:34:29 +00:00
|
|
|
if(rc <= EFILE_EMPTY)
|
2010-06-23 05:08:36 +00:00
|
|
|
error(EBOOTFILE, rc, true);
|
2008-02-08 02:20:05 +00:00
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
/* Pause to look at messages */
|
2011-01-21 07:05:51 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int button = button_read_device();
|
|
|
|
|
|
|
|
/* Ignore settings reset */
|
|
|
|
if (button == BUTTON_NONE || button == BUTTON_MENU)
|
|
|
|
break;
|
|
|
|
|
|
|
|
sleep(HZ/5);
|
|
|
|
|
|
|
|
check_battery_safe();
|
|
|
|
|
|
|
|
/* If the disk powers off, the firmware will lock at startup */
|
|
|
|
storage_spin();
|
|
|
|
}
|
2008-05-10 18:00:11 +00:00
|
|
|
|
|
|
|
/* Put drivers into a known state */
|
|
|
|
button_close_device();
|
2008-11-01 16:14:28 +00:00
|
|
|
storage_close();
|
2008-02-08 02:20:05 +00:00
|
|
|
system_prepare_fw_start();
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2012-03-04 14:34:29 +00:00
|
|
|
commit_discard_idcache();
|
|
|
|
asm volatile ("bx %0": : "r"(start_addr));
|
2007-11-27 15:40:29 +00:00
|
|
|
|
2008-04-18 16:42:50 +00:00
|
|
|
/* Halt */
|
|
|
|
while (1)
|
|
|
|
core_idle();
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
int rc;
|
2011-01-21 07:05:51 +00:00
|
|
|
int batt;
|
2008-05-10 18:00:11 +00:00
|
|
|
|
|
|
|
system_init();
|
|
|
|
kernel_init();
|
|
|
|
|
2011-01-21 07:05:51 +00:00
|
|
|
/* Keep button_device_init early to delay calls to button_read_device */
|
|
|
|
button_init_device();
|
|
|
|
|
|
|
|
lcd_init();
|
|
|
|
font_init();
|
|
|
|
show_logo();
|
2009-02-07 10:09:13 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
|
2011-01-21 07:05:51 +00:00
|
|
|
if (button_hold())
|
|
|
|
display_message_and_power_off(HZ, "Hold switch on");
|
|
|
|
|
|
|
|
if (button_read_device() != BUTTON_NONE)
|
|
|
|
verbose = true;
|
|
|
|
|
2009-02-07 10:09:13 +00:00
|
|
|
printf("Gigabeat S Rockbox Bootloader");
|
2014-08-28 14:26:45 +00:00
|
|
|
printf("Version %s", rbversion);
|
2009-02-07 10:09:13 +00:00
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
adc_init();
|
2012-01-03 23:44:38 +00:00
|
|
|
batt = _battery_voltage();
|
2011-01-21 07:05:51 +00:00
|
|
|
printf("Battery: %d.%03d V", batt / 1000, batt % 1000);
|
|
|
|
check_battery_safe();
|
2008-05-10 18:00:11 +00:00
|
|
|
|
2008-11-01 16:14:28 +00:00
|
|
|
rc = storage_init();
|
2008-05-10 18:00:11 +00:00
|
|
|
if(rc)
|
2010-06-23 05:08:36 +00:00
|
|
|
error(EATA, rc, true);
|
2008-05-10 18:00:11 +00:00
|
|
|
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
filesystem_init();
|
2008-05-10 18:00:11 +00:00
|
|
|
|
|
|
|
rc = disk_mount_all();
|
2011-01-21 07:05:51 +00:00
|
|
|
if (rc <= 0)
|
2010-06-23 05:08:36 +00:00
|
|
|
error(EDISK, rc, true);
|
2008-05-10 18:00:11 +00:00
|
|
|
|
|
|
|
printf("Init complete");
|
|
|
|
|
|
|
|
/* Do USB first since a tar or binary could be added to the MTP directory
|
|
|
|
* at the time and we can untar or move after unplugging. */
|
2012-01-01 03:19:52 +00:00
|
|
|
if (usb_plugged() == USB_INSERTED)
|
2011-01-21 07:05:51 +00:00
|
|
|
handle_usb(HZ*2);
|
|
|
|
|
2008-05-10 18:00:11 +00:00
|
|
|
handle_untar();
|
|
|
|
handle_firmware_load(); /* No return */
|
|
|
|
}
|