mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2026-06-08 01:54:44 +00:00
tools: acrn-crashlog: file system utils for acrn-crashlog
This file provides file system operations for acrn-crashlog. Signed-off-by: Liu Xinwu <xinwu.liu@intel.com> Reviewed-by: Zhang Yanmin <yanmin.zhang@intel.com> Reviewed-by: Liu Chuansheng <chuansheng.liu@intel.com> Reviewed-by: Zhao Yakui <yakui.zhao@intel.com> Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com> Acked-by: Eddie Dong <Eddie.dong@intel.com>
This commit is contained in:
92
tools/acrn-crashlog/common/include/fsutils.h
Normal file
92
tools/acrn-crashlog/common/include/fsutils.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __FSUTILS_H__
|
||||
#define __FSUTILS_H__
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
|
||||
|
||||
#define KB (1024)
|
||||
#define MB (KB * KB)
|
||||
#define MAXLINESIZE (4 * KB)
|
||||
#define CPBUFFERSIZE (4 * KB)
|
||||
#define PAGE_SIZE (4 * KB)
|
||||
|
||||
struct mm_file_t {
|
||||
char *path;
|
||||
int fd;
|
||||
char *begin;
|
||||
int size;
|
||||
};
|
||||
|
||||
static inline int file_exists(const char *filename)
|
||||
{
|
||||
struct stat info;
|
||||
|
||||
return (stat(filename, &info) == 0);
|
||||
}
|
||||
|
||||
static inline int directory_exists(char *path)
|
||||
{
|
||||
struct stat info;
|
||||
|
||||
return (stat(path, &info) == 0 && S_ISDIR(info.st_mode));
|
||||
}
|
||||
|
||||
static inline int get_file_size(const char *filepath)
|
||||
{
|
||||
struct stat info;
|
||||
|
||||
if (filepath == NULL)
|
||||
return -ENOENT;
|
||||
|
||||
if (stat(filepath, &info) < 0)
|
||||
return -errno;
|
||||
|
||||
return info.st_size;
|
||||
}
|
||||
|
||||
char *mm_get_line(struct mm_file_t *mfile, int line);
|
||||
int mkdir_p(char *path);
|
||||
int mm_count_lines(struct mm_file_t *mfile);
|
||||
struct mm_file_t *mmap_file(const char *path);
|
||||
void unmap_file(struct mm_file_t *mfile);
|
||||
int do_copy_tail(char *src, char *dest, int limit);
|
||||
int do_mv(char *src, char *dest);
|
||||
int append_file(char *filename, char *text);
|
||||
int mm_replace_str_line(struct mm_file_t *mfile, char *replace,
|
||||
int line);
|
||||
int replace_file_head(char *filename, char *text);
|
||||
int overwrite_file(char *filename, char *value);
|
||||
int readline(int fd, char buffer[MAXLINESIZE]);
|
||||
int file_read_string(const char *file, char *string, int size);
|
||||
void file_reset_init(const char *filename);
|
||||
int file_read_int(const char *filename, unsigned int *pcurrent);
|
||||
int file_update_int(const char *filename, unsigned int current,
|
||||
unsigned int max);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user