• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * SPDX-License-Identifier: GPL-2.0
4  *
5  * Legacy blkg rwstat helpers enabled by CONFIG_BLK_CGROUP_RWSTAT.
6  * Do not use in new code.
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 
15 #include <cstddef>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <cstdint>
19 #include <cstdlib>
20 #include "hccommon.h"
21 
22 namespace OHOS {
HcFuzzTest(const uint8_t * data,const char * pathname,size_t size)23 bool HcFuzzTest(const uint8_t *data, const char *pathname, size_t size)
24 {
25     uint32_t value = 0;
26     uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
27     int ret = access("/mnt/f2fs_mount/", F_OK);
28     if (ret < 0) {
29         system("mkdir -p /mnt/f2fs_mount/");
30         system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
31         system("losetup /dev/block/loop1 /data/image_f2fs");
32         system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
33     }
34 
35     int fd = open(pathname, O_RDWR);
36     if (fd < 0) {
37         return false;
38     }
39 
40     ret = read(fd, &value, sizeof(value));
41     if (ret < 0) {
42         close(fd);
43         return false;
44     }
45 
46     ret = write(fd, data, length);
47     if (ret < 0) {
48         close(fd);
49         return false;
50     }
51     close(fd);
52     return true;
53 }
54 }