| /** |
| * Copyright (C) 2018 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. |
| */ |
| #define _GNU_SOURCE |
| #include <cutils/log.h> |
| #include <errno.h> |
| #include <fcntl.h> |
| #include <linux/falloc.h> |
| #include <linux/magic.h> |
| #include <stdint.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <sys/types.h> |
| #include <sys/utsname.h> |
| #include <sys/vfs.h> |
| #include <unistd.h> |
| |
| int main(void) { |
| int fd = -1, result = -1; |
| char tmpFile[32]; |
| struct statfs sfs; |
| |
| memset(tmpFile, 0, sizeof(tmpFile)); |
| strncpy(tmpFile, "/data/local/tmp/tmpFile", 24); |
| |
| fd = open(tmpFile, O_WRONLY | O_APPEND | O_CREAT, 0644); |
| if (fd < 0) { |
| ALOGE("Creation of tmp file is failed [%s]", strerror(errno)); |
| return -1; |
| } |
| |
| fstatfs(fd, &sfs); |
| if (sfs.f_type == EXT4_SUPER_MAGIC) { |
| result = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 1); |
| if (result < 0 && errno == EOPNOTSUPP) { |
| ALOGD("fallocate result [%s] errno [%d]", strerror(errno), errno); |
| ALOGE("fallocate result EOPNOTSUPP"); |
| } |
| } |
| |
| if (fd) { |
| close(fd); |
| } |
| |
| return 0; |
| } |