• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <stdio.h>
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <errno.h>
21 #include <string.h>
22 
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 
26 #define LOG_TAG "Vold"
27 
28 #include <cutils/log.h>
29 
30 #include "Xwarp.h"
31 const char *Xwarp::XWARP_BACKINGFILE = "/mnt/secure/asec/xwarp.img";
32 const char *Xwarp::XWARP_CFG = "/sys/fs/yaffs/mtd3/xwarp-backing-store";
33 const char *Xwarp::XWARP_READY = "/sys/fs/yaffs/mtd3/xwarp-ready";
34 const char *Xwarp::XWARP_MIRROR_STATUS = "/sys/fs/yaffs/mtd3/xwarp-mirror";
35 
enable()36 int Xwarp::enable() {
37     return doEnableDisable(true);
38 }
39 
disable()40 int Xwarp::disable() {
41     return doEnableDisable(false);
42 }
43 
status(bool * ready,unsigned * mirrorPos,unsigned * maxSize)44 int Xwarp::status(bool *ready, unsigned *mirrorPos, unsigned *maxSize) {
45     FILE *fp;
46 
47     *ready = false;
48     *mirrorPos = 0;
49     *maxSize = 0;
50     if (!(fp = fopen(XWARP_READY, "r"))) {
51         return -1;
52     }
53 
54     fscanf(fp, "%d", (int *) ready);
55     fclose(fp);
56 
57     if (!(fp = fopen(XWARP_MIRROR_STATUS, "r"))) {
58         return -1;
59     }
60 
61     fscanf(fp, "%u %u", mirrorPos, maxSize);
62     fclose(fp);
63     return 0;
64 }
65 
doEnableDisable(bool enable)66 int Xwarp::doEnableDisable(bool enable) {
67     const char *tmp;
68     int fd = open(XWARP_CFG, O_WRONLY);
69 
70     if (fd < 0)
71         return -1;
72 
73     tmp = (enable ? XWARP_BACKINGFILE : "");
74 
75     if (write(fd, tmp, strlen(tmp)+1) < 0) {
76         SLOGE("Failed to write xwarp cfg (%s)", strerror(errno));
77         close(fd);
78         return -1;
79     }
80 
81     close(fd);
82     return 0;
83 }
84