Commit graph

64 commits

Author SHA1 Message Date
Tom Cherry
72a114a3e1 Add android::fs_mgr namespace for new Fstab code
Also add libfstab dependencies where needed.  Previously the
`typedef struct FstabEntry Volume;` line served to both define a
`struct FstabEntry` as well as alias Volume to it.  With the new
namespace for android::fs_mgr::FstabEntry, `struct FstabEntry` isn't
compatible anymore, so we need to alias Volume to the real
android::fs_mgr::FstabEntry.

In doing so, we need to include <fstab/fstab.h> and this requires
libfstab as a library, which a few modules did not have before.

Test: treehugger
Change-Id: I655209a0efb304b3e0568db0748bd5cf7cecbdb7
2019-01-31 09:00:40 -08:00
Tao Bao
c674dfb584 Use dynamically linked f2fs executables.
It also reduces the space cost for devices using f2fs (e.g. crosshatch).
/sbin/mkfs.f2fs   722560 => /system/bin/make_f2fs   49568
/sbin/sload.f2fs 1182456 => /system/bin/sload_f2fs 150032

Test: Build and boot recovery on crosshatch. Factory reset.
Test: Install a non-A/B OTA package that formats a f2fs partition.
Change-Id: Ibe70c8d91a1d07e1c78ff9eac19b1f7955800161
2018-12-20 14:47:11 -08:00
Tao Bao
3d69f0df96 Clean up the arg setup for exec(3).
Test: Build and boot into recovery on marlin. Factory reset.
Test: Build and install a non-A/B OTA that calls format.
Change-Id: I72416e775e237fc15ca5eff1036175a9eef43b76
2018-12-20 10:46:06 -08:00
Yifan Hong
d81b8e3d77 roots.cpp: convert to C++ Fstab
Convert code to use C++ Fstab struct and C++ std::strings.

Bug: 62292478
Bug: 118634720
Test: boots
Change-Id: Ibdc1df5831bc885d7c1574419f41af026e49a137
2018-12-18 15:57:29 -08:00
Yifan Hong
0f339e27bb Move parts of roots.cpp to libfs_mgr
Move some mounting functionalities to libfs_mgr.

Test: run recovery tests

Bug: 118634720
Bug: 113182233

Change-Id: Ie59376664a744992429f0262ec96d13a1aed30f9
2018-12-18 15:57:29 -08:00
Yifan Hong
cbfeb7f6af Merge "SYSTEM_ROOT -> get_system_root" 2018-11-30 22:07:24 +00:00
Tom Cherry
45e505a4e9 Update for long long -> off64_t for fstab.length
Test: boot
Change-Id: I755a5dd48f1d5be2cbd8e494b9c405674b12cebb
2018-11-29 13:33:07 -08:00
Yifan Hong
4932780606 SYSTEM_ROOT -> get_system_root
Add a get_system_root() function in roots.cpp
which returns / or /system based on fstab.
This factors out the 'if' check from recovery.cpp
and fsck_unshare_blocks.cpp.

Test: boot recovery, mount system
Bug: 118634720
Change-Id: If4947cba3a3f08dbe695fd2b50a9354cd302ee03
2018-11-27 15:57:47 -08:00
Jaegeuk Kim
91e631d4dd make_f2fs: use -g android by default
Bug: 119875846
Change-Id: Ibff18ea6f92620852222fff4073379ec8afd0e10
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-11-21 12:53:09 -08:00
David Anderson
2b2f423ef6 recovery: Fix mounting /system with dynamic partitions.
When using dynamic partitions, the blk_device field in fstab_rec must be
translated to a /dev/block/dm-N node with
fs_mgr_update_logical_partition. However, init will not have created
these nodes to begin with since CreateLogicalPartitions is not called in
recovery. This patch addresses both issues.

Note that flashing system through fastbootd will not work while /system is
mounted.

Bug: 118634720
Test: manual test
Change-Id: I06c83309d09eab6b65245b1ed10c51d05398f23e
2018-10-30 13:47:59 -07:00
Lianjun Huang
5d7be6b4a5 support mounting f2fs in recovery mode
Change-Id: Ic03b3e95c4b5cd49b92cb3ec697e327a59421549
Signed-off-by: Lianjun Huang <huanglianjun@vivo.com>
2018-09-03 15:37:00 +00:00
Jiyong Park
681ae40d41 Merge "e2fsdroid and mke2fs are dynamic executable in recovery partition"
am: 9b5d4ea20f

Change-Id: I017a76c320f29baff3183b0156c1fdf2deed66bf
2018-06-20 15:24:29 -07:00
Jiyong Park
69364fe553 e2fsdroid and mke2fs are dynamic executable in recovery partition
The two utilities are now converted to dynamic executables as shared
libraries are supported in recovery mode.

As part of the conversion, their location has moved from /sbin to
/system/bin. Reflect the change in the program 'recovery'

Bug: 79146551
Test: adb reboot recovery, and select 'Wipe data/factory reset'. The
data partition is formatted and there is no selinux denial.

Change-Id: Ie7cfc4c50ab1e6767e4a5170533ccf826ec7d7f3
2018-06-20 14:24:05 +09:00
android-build-prod (mdb)
1c1737b660 Merge "Merge libmounts into libotautil." am: 686353215f
am: cddf5dbf67

Change-Id: I57bcd1195084d2e60861aa5b410e2eb50c41c3c3
2018-04-28 09:55:49 -07:00
Tao Bao
9a319f01f8 Merge libmounts into libotautil.
Export its header (mounts.h) from there, and drop the dot dot dependency
from libupdater / updater.

Test: mmma bootable/recovery
Test: recovery_component_test
Change-Id: Ic26a6b9b78a34dbe1f178b138f3abaafffbec44c
2018-04-27 21:13:57 -07:00
Jaegeuk Kim
2e5dc84d51 recovery: enable fsverity feature bit
Bug: 74604441
Bug 67380979
Change-Id: Iab1cc9aef356f0ddf6e2491578a2bd53009182ce
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-04-06 10:17:47 -07:00
Jaegeuk Kim
4358262b75 mkfs.f2fs: specify sector size for target image size
The total sectors that we want to format is used in different meanings from
various users. This notifies its size based on 4096 bytes explicitly.

Bug: 76407663
Change-Id: I3392646648264ad1ca78e4b87240edc9385a0cc4
Merged-In: I3392646648264ad1ca78e4b87240edc9385a0cc4
Reported-by: katao@xiaomi.com
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-04-04 14:26:23 -07:00
Jaegeuk Kim
f139bb4c56 mkfs.f2fs: specify sector size for target image size
The total sectors that we want to format is used in different meanings from
various users. This notifies its size based on 4096 bytes explicitly.

Bug: 76407663
Change-Id: I3392646648264ad1ca78e4b87240edc9385a0cc4
Reported-by: katao@xiaomi.com
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-04-04 09:14:14 -07:00
George Burgess IV
1cfb361129 Replace vfork() with fork().
The static analyzer complained about the function calls we were doing
here to vector::data() and vector::operator[]:
bootable/recovery/roots.cpp:193:11: warning: This function call is
prohibited after a successful vfork

Since it's not clear that vfork() is needed here, just use fork()
instead.

Bug: None
Test: Reran the static analyzer with only this patch applied. Bug
disappeared
Change-Id: I580f8243a21899f1e1678c8aee6948dfa7f69a1d
2018-02-22 19:25:22 -08:00
Jaegeuk Kim
c1c7311b8a add sload.f2fs for recovery format
Change-Id: Iddfe54b2b36f2d531925cbe61c98dbfb4903c0d1
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2017-12-04 20:27:49 -08:00
Treehugger Robot
5ce9fe355c Merge "root: Fix an issue when volume length from fs_mgr is negative." 2017-11-20 18:47:56 +00:00
Jin Qian
cc10008887 root: Fix an issue when volume length from fs_mgr is negative.
fs_mgr passes negative length as offset for crypt_footer. We need
to compute the actual device size for this case in addition to
when length is zero.

Bug: 68949069
Change-Id: I803955dd9591ad7752cee0dea9b683be8f4fd4ba
2017-11-18 21:54:44 -08:00
Jaegeuk Kim
1a8bb0f542 recovery: format f2fs with encrypt/quota
Change-Id: Ia393b7b78b45f09964449ec0e255aa26bb3b8ddf
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2017-11-13 14:05:00 -08:00
Tao Bao
3e18f2bf40 roots: Fix an issue with volume_for_path().
The earlier commit in 2dfc1a3898
unintentionally changed the behavior. It gives a different result when
looking up non-existent mount points (e.g. /cache on marlin).

The logic behind volume_for_path("/xyz") is unclear:
- It's fine to return non-null value if it's called by
  ensure_path_mounted() before accessing that file "/xyz". (Just based
  on the function name, we're not actually having this case.)
- It should return nullptr if the caller is interested in the existence
  of that particular mount point "/xyz".

This CL renames the function to volume_for_mount_point(), which does an
exact match by querying the given mount point from libfs_mgr. The former
volume_for_path() has been moved down to function scope for serving
ensure_path_mounted() only.

Test: Build and boot into recovery on bullhead and marlin respectively.
      'View recovery logs'.
Test: 'Mount /system'
Test: 'Apply update from ADB'
Change-Id: I1a16390f57540cae08a2b8f3d439d17886975217
2017-10-02 11:18:13 -07:00
Tao Bao
ad774b2970 roots: Remove #include "common.h".
And add the missing include of <string.h> (e.g. for strcmp(3)).

Minor update to the arg of fs_mgr_get_entry_for_mount_point(), which now
accepts std::string.

Test: mmma bootable/recovery
Change-Id: I9cb8c31fe71b5a053f4d84bf1aba00e96c02ed03
2017-09-29 11:03:08 -07:00
Treehugger Robot
846f307c6f Merge "Integer overflow observed while formatting volume" 2017-09-29 05:09:23 +00:00
Tao Bao
2dfc1a3898 roots: volume_for_path() parses and tries prefixes.
Commit cc323958f99e40fea06c511656c69c0b2e2d47f7 in system/core has
changed fs_mgr_get_entry_for_mount_point() to do an exact match only,
which breaks the behavior in volume_for_path().

This CL changes the volume_for_path() implementation to parse and pass
prefixes locally. For a given path like "/cache/recovery/last_log", it
will in turn attempt the prefixes of "/cache/recovery/last_log",
"/cache/recovery", "/cache", "/" and return the first hit.

Bug: 63912287
Test: Build and boot into recovery image on bullhead. 'View recovery
      logs' works.
Change-Id: Ic8635b0939649dd5cc9ca501ebc3a2d1fbf5849d
2017-09-27 13:22:17 -07:00
Abhishek Arpure
4fec8e9e9a Integer overflow observed while formatting volume
While calculating volume size, get_block_device_size() returns
u64 value but the returned value is assigned in ssize_t variable.
This may cause integer overflow if the volume size is beyond
ssize_t limit.

Use int64_t instead of ssize_t in get_file_size() and explicitly check
for overflow to fix the issue.

Bug: 65001754
Test: mmma bootable/recovery
Change-Id: I91eb30bff0bf7dcc48678efc2f414d2b79af6d0d
2017-09-11 17:13:15 -07:00
Tao Bao
3c00facb3d roots.cpp: Clean up format_volume().
Test: m -j bootable/recovery
Test: Wipe data/cache in recovery
Change-Id: I11a4bf34015e903992ae2fb100d0b59a9fb75e03
2017-07-25 15:26:32 -07:00
Jin Qian
f3ccad58dd recovery: handle security footer before passing size to mke2fs
mke2fs doesn't take negative size as reserved size. If footer is
specified, compute fs size to be
(max partition size - reserved footer size) / block_size

Bug: 23686092
Bug: 63968011
Change-Id: Iac4e143bd26a70cfc81eb52a399d687e19b1049c
2017-07-25 09:11:09 -07:00
Tao Bao
bb10e58eb1 roots.cpp: Reformatting the file.
Mostly cosmetic changes. Removed the use of errno, and added constness
to a few pointers.

format_volume() and exec_cmd() will be cleaned up in a separate CL.

Test: mmma -j bootable/recovery
Change-Id: Ia12ce25a91c0bdd0e319f6da02ce1dc8377f265d
2017-07-24 17:15:41 -07:00
Tao Bao
338be53ed3 Remove the obsolete reference to /file_contexts.
This file no longer exists:
- /file_contexts has been split into plat_file_contexts and
  nonplat_file_contexts since commit
  b236eb6ca204cefcb926e19bd5682f9dcad4021d (system/sepolicy).
- It was named /file_contexts.bin prior to the split.

'-S file_contexts' is also no longer required by e2fsdroid, since commit
2fff6fb036cbbb6dedd7da3d208b312a9038a5ce (external/e2fsprogs). It will
load the file contexts via libselinux.

Test: Trigger the path by performing a data wipe for converting to FBE.
Change-Id: I179939da409e5c0415ae0ea0bf5ddb23f9e6331e
(cherry picked from commit 7af933b6a6)
2017-07-22 16:16:21 -07:00
Jin Qian
ded2dac082 recovery: replace make_ext4 with e2fsprogs
Execute mke2fs to create empty ext4 filesystem.
Execute e2fsdroid to add files to filesystem.

Test: enter recovery mode and wipe data
Bug: 35219933
Change-Id: I10a9f4c1f4754ad864b2df45b1f879180ab33876
(cherry picked from commit ac31808cd3)
2017-07-20 11:42:17 -07:00
Tao Bao
57130c45f8 recovery: Skip "/" in setup_install_mounts().
We don't want to do anything for "/" when preparing for an install.

Bug: 36686818
Test: adb sideload on angler/marlin respectively.
Change-Id: Id854dd0a743a0e163a8f13baf2514105091ddc67
2017-05-10 12:11:21 -07:00
Jin Qian
adeb41a8c0 recovery: update mkfs.f2fs args to match f2fs-tools 1.8.0
mkfs.f2fs in 1.8.0 returns error if number of sectors is 0. Skip
this argument to let mkfs detect device size. 0 sector is also not
necessary for 1.4.1.

Test: format userdata to f2fs and boot
Bug: 37758867
Change-Id: If120988dfb678596c973d183572f870eb0b72a27
2017-05-05 11:07:46 -07:00
Bowgo Tsai
84a06485a9 recovery: switch to fs_mgr_read_fstab_default()
fs_mgr_read_fstab_default() is now aware of recovery mode so it's ok to
switch to this new API.

Bug: 35811655
Test: recovery boot sailfish
Change-Id: I1025b606fd96e74a893ae99cefc1da01e4b27a23
2017-03-29 16:31:29 +08:00
Bowgo Tsai
d13b6cf29c recovery: replacing fs_mgr_read_fstab() with new fs_mgr APIs
The fstab settings of early-mounted partitions (e.g., /vendor) will be in
kernel device tree. Switch to the new API to get the whole settings with
those in device tree:

    fs_mgr_read_fstab_with_dt("/etc/recovery.fstab")

The original default /fstab.{ro.hardware} might be moved to
/vendor/etc/. or /odm/etc/. Use another new API to get the default fstab
instead of using the hard-coded /fstab.{ro.hardware}. This API also
includes the settings from device tree:

    fs_mgr_read_fstab_default()

Bug: 35811655
Test: boot sailfish recovery
Change-Id: Iaa56ac7f7b4c4dfc7180c65f03e9a37b94f1de09
2017-03-10 17:27:31 +08:00
Tao Bao
3da880156b Replace _exit(-1) with _exit(EXIT_FAILURE).
-1 is not a valid exit status.

Also replace a few exit(1) with exit(EXIT_FAILURE).

Test: mmma bootable/recovery
Change-Id: I4596c8328b770bf95acccc06a4401bd5cabd4bfd
2017-02-03 14:11:11 -08:00
Connor O'Brien
98a658bb54 Use flash erase & logical block size for userdata wipe
If flash erase and logical block size are available, then pass them
to libext4_utils when rebuilding userdata.

Test: Factory reset marlin in recovery, confirmed params passed correctly
Bug: 33243520
Change-Id: I6bed976a73e7a64a80eaac50f48fbacb6d812517
Signed-off-by: Connor O'Brien <connoro@google.com>
2017-01-24 18:04:02 -08:00
Tao Bao
de40ba59c8 Update the header path for ext4_utils.
Test: `mmma bootable/recovery`
Change-Id: I70ccddb3ddf46bb012fdc5f632afc46ebdd5473e
2016-10-09 14:02:10 -07:00
Tianjie Xu
7b0ad9c638 Switch recovery to libbase logging
Clean up the recovery image and switch to libbase logging.

Bug: 28191554
Change-Id: Icd999c3cc832f0639f204b5c36cea8afe303ad35
Merged-In: Icd999c3cc832f0639f204b5c36cea8afe303ad35
2016-09-01 18:33:25 +00:00
Johan Harvyl
2f5cfdbb9d Merge "Format formattable partitions if mount fails"
am: cb76857147

Change-Id: I50c2045f56693e445922d30af72867e7ac55b61f
2016-08-15 18:03:37 +00:00
Johan Harvyl
29dd6b6c01 Format formattable partitions if mount fails
If mount fails and the partition has the formattable flag set in fstab
it is formatted and another attempt at the mount is made.

Change-Id: I44edafac7d7ff663489072c66b7e210466316b14
2016-08-12 16:13:50 +02:00
Elliott Hughes
274d17dc0f resolve merge conflicts of 179c0d8 to stage-aosp-master
Change-Id: Iba5aec266444cabf83f600f2bdb45a3c027e5995
2016-06-15 15:22:17 -07:00
Elliott Hughes
63a319201f Remove obsolete MTD support.
Bug: http://b/29250988
Change-Id: Ia97ba9082a165c37f74d6e1c3f71a367adc59945
2016-06-10 13:45:35 -07:00
Paul Lawrence
d0db337d72 Create convert_fbe breadcrumb file to support conversion to FBE
Change-Id: I38b29e1e34ea793e4b87cd27a1d39fa905fddf7a
2015-11-13 07:49:31 -08:00
Tao Bao
abb8f7785e recovery: Allow "Mount /system" for system_root_image.
When system images contain the root directory, there is no entry of
"/system" in the fstab. Change it to look for "/" instead if
ro.build.system_root_image is true. We actually mount the partition
to /system_root instead, and create a symlink to /system_root/system
for /system. This allows "adb shell" to work properly.

Bug: 22855115
Change-Id: Ibac493a5a9320c98ee3b60bd2cc635b925f5454a
2015-07-30 17:22:29 -07:00
Tao Bao
ba9a42aa7e recovery: Switch applypatch/ and updater/ to cpp.
Mostly trivial changes to make cpp compiler happy.

Change-Id: I69bd1d96fcccf506007f6144faf37e11cfba1270
2015-07-13 17:21:31 -07:00
Mohamad Ayyash
522ea72116 Allow mounting squashfs partitions
Change-Id: Ifb8f84063a406db7aad3f9ef12c349ea09a54e07
Signed-off-by: Mohamad Ayyash <mkayyash@google.com>

(cherry picked from commit 0ddfa329ac)
2015-07-06 22:01:25 +00:00
Tao Bao
6896f9d47d Merge "always use volume mount option when mounting a partition" 2015-03-31 23:56:02 +00:00