⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remount_service.c

📁 Android 一些工具
💻 C
字号:
/* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */#include <stdlib.h>#include <stdio.h>#include <unistd.h>#include <string.h>#include <fcntl.h>#include <sys/mount.h>#include <errno.h>#include "sysdeps.h"#define  TRACE_TAG  TRACE_ADB#include "adb.h"static int system_ro = 1;/* Returns the mount number of the requested partition from /proc/mtd */static int find_mount(const char *findme){    int fd;    int res;    int size;    char *token = NULL;    const char delims[] = "\n";    char buf[1024];    fd = unix_open("/proc/mtd", O_RDONLY);    if (fd < 0)        return -errno;    buf[sizeof(buf) - 1] = '\0';    size = adb_read(fd, buf, sizeof(buf) - 1);    adb_close(fd);    token = strtok(buf, delims);    while (token) {        char mtdname[16];        int mtdnum, mtdsize, mtderasesize;        res = sscanf(token, "mtd%d: %x %x %15s",                     &mtdnum, &mtdsize, &mtderasesize, mtdname);        if (res == 4 && !strcmp(mtdname, findme))            return mtdnum;        token = strtok(NULL, delims);    }    return -1;}/* Init mounts /system as read only, remount to enable writes. */static int remount_system(){    int num;    char source[64];    if (system_ro == 0) {        return 0;    }    if ((num = find_mount("\"system\"")) < 0)        return -1;    snprintf(source, sizeof source, "/dev/block/mtdblock%d", num);    system_ro = mount(source, "/system", "yaffs2", MS_REMOUNT, NULL);    return system_ro;}static void write_string(int fd, const char* str){    writex(fd, str, strlen(str));}void remount_service(int fd, void *cookie){    int ret = remount_system();    if (!ret)       write_string(fd, "remount succeeded\n");    else {        char    buffer[200];        snprintf(buffer, sizeof(buffer), "remount failed: %s\n", strerror(errno));        write_string(fd, buffer);    }    adb_close(fd);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -