Adapting Operating System Requirements

Android Debug Bridge, commonly known as adb, is the central Android development tool, both for application and operating system development. adb remount command is used for remounting Android system partition from read-only to writable. This is very important for operating system development, since it enables modifying and updating only one library until the issue is resolved, instead of flashing the whole partition, which lasts significantly longer and slows down the development. When Android Nougat was brought up using UBIFS for the first time, it has been noticed that adb remount was not functional. Investigation determined that the origin of the issue came from a security update provided by Google [3]. The update fixed a security breach where files under read-only file system could have been altered by writing raw bytes to block devices. As a final result, hacker wouldbe obtaining Android root access, which provides the highest possible access and modification permissions [4]. Google resolved this issue by using BLKROSET ioctl(). Each time a read-only file system is mounted, its corresponding block device also is being set to read-only state and vice versa. This ioctl() behaves as a simple lock which forbids writing. However, Google’s solution assumed that the file system is mounted on a block device. BLKROSET is only intended for block devices and supported by those. This ioctl() would fail when used on a MTD based file system, like UBIFS. And the failure would result with adb remount command failing. BLKROSET is even being called during the initial file system mounting, but the failure does not stop or alter the boot sequence. Further investigation showed that this double lock mechanism is completely unnecessary for UBIFS. Regardless of whether a partition has been mounted as read-only or not, MTD and UBI devices could not be modified by a simple write operation. The results of the access test are shown in Table 1. First column specifies the file system device. Column named “BLKROSET” shows if this ioctl() has been enabled or not. Columns “write” shows if the corresponding file operation was available under the specified device. Last column specifies if the file system associated to the device has been mounted as read-only or not. Symbol “X” is used if the value is not important or if it does not make sense.

Linux provides an fallocate() system call, which provides a more efficient way of ensuring that the necessary space is allocated, and that glibc posix_fallocate() implementation makes use of this system call when it is available [7]. Kernel side of fallocate() did not only implement the POSIX version of fallocate(). It expanded fallocate()capabilities by requiring its mode to be set when issuing the system call. Upon testing Android Nougat with UBIFS file system, it has been detected that installation of new applications is not functional. It has been determined that the root cause was the fact that fallocate() system call was not supported for UBIFS. Android source code inspection showed that there were several ways of using fallocate() mode throughout the entire operating system. The main issue here is that fallocate() system call has to be implemented for each of the file systems separately. Not even EXT4 and F2FS file systems support all possible fallocate() modes. But Google has decided to make mandatory some of those which are supported. Mandatory modes are: default (0) mode, keepsize mode and keep size punch hole mode. In order to provide Android UBIFS support, this missing functionality has been implemented. Code Shoppy


 Adapting Operating System Requirements

which contains 14 characters. Each of the orange rectangles represents one of the previously written characters. This figure will be used as a base file for modifications achieved by using fallocate() system call. allocate default mode corresponds to its traditional POSIX implementation. It increases the file size to the specified length. The newly added space will be filled with zeroes, which are represented by blue rectangles on Fig. 2. In this example there are 7 newly allocated characters, which brings the total size to 21. If the proposed size is less or equal than the current size of the file, no changes will be made. Implementing fallocate default mode for UBIFS has been achieved by using UBIFS internal truncate mechanism, which is able to achieve the desired result [8], [9]. Fallocate keep size mode also ensures that there is enough space for the file. The main difference is that it does not alter the file and populate zeroes. After specifying the allocation of 7 additional characters, the result filThe keep size mode implementation has been achieved by modifying UBIFS resource allocator. For small size increases, like in this example, the necessary resources are usually already available. But in cases where more resources are required, the pessimistic approach is used for allocation. UBIFS uses data compression and at the time of allocation there is no way to be certain how much physical space the file will need, so the maximal space is always assumed. First the available resources are examined and total available space is observed without taking in the unusable space reserved for file system specific data. If there is enough space, the allocation is approved and UBIFS available resources are reduced by the required amount. If allocated space or a part of that allocated space remains unused upon the closing of the file, it will be released at that point [10]. Fallocate keep size punch hole mode enables turning the specified range of characters into zeroes, without affecting the file size. shows green rectangles on positions where 6 previous characters have been replaced with zeroes. https://codeshoppy.com/android-app-ideas-for-students-college-project.html