#define _LARGEFILE64_SOURCE
#endif
-#define _XOPEN_SOURCE 500
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
+
#include <ctype.h>
#include <dirent.h>
#include <endian.h>
* @len: area length.
* @advise: process flag.
*/
-int fadvise(int fd, loff_t offset, size_t len, int advise)
+static int fadvise(int fd, loff_t offset, size_t len, int advise)
{
return syscall(__NR_fadvise64, fd, offset, len, advise);
}
* @offset: file offset.
* @len: file size.
*/
-int fallocate(int fd, int mode, loff_t offset, loff_t len)
+static int fallocate(int fd, int mode, loff_t offset, loff_t len)
{
return syscall(__NR_fallocate, fd, mode, offset, len);
}
* @mount_point: the mount point.
* @dir_path_len: the length of directory.
*/
-int get_mount_point(const char *devname, char *mount_point, int dir_path_len)
+static int get_mount_point(const char *devname, char *mount_point,
+ int dir_path_len)
{
/* Refer to /etc/mtab */
- char *mtab = MOUNTED;
+ const char *mtab = MOUNTED;
FILE *fp = NULL;
struct mntent *mnt = NULL;
*
* @file: the file's name.
*/
-int is_ext4(const char *file)
+static int is_ext4(const char *file)
{
int maxlen = 0;
int len, ret;
FILE *fp = NULL;
char *mnt_type = NULL;
/* Refer to /etc/mtab */
- char *mtab = MOUNTED;
+ const char *mtab = MOUNTED;
char file_path[PATH_MAX + 1];
struct mntent *mnt = NULL;
struct statfs64 fsbuf;
* @flag: file type.
* @ftwbuf: the pointer of a struct FTW.
*/
-int calc_entry_counts(const char *file EXT2FS_ATTR((unused)),
+static int calc_entry_counts(const char *file EXT2FS_ATTR((unused)),
const struct stat64 *buf, int flag EXT2FS_ATTR((unused)),
struct FTW *ftwbuf EXT2FS_ATTR((unused)))
{
* @vec: page state array.
* @page_num: page number.
*/
-int page_in_core(int fd, struct move_extent defrag_data,
+static int page_in_core(int fd, struct move_extent defrag_data,
unsigned char **vec, unsigned int *page_num)
{
long pagesize = sysconf(_SC_PAGESIZE);
* @vec: page state array.
* @page_num: page number.
*/
-int defrag_fadvise(int fd, struct move_extent defrag_data,
+static int defrag_fadvise(int fd, struct move_extent defrag_data,
unsigned char *vec, unsigned int page_num)
{
int flag = 1;
* @file: file name.
* @buf: the pointer of the struct stat64.
*/
-int check_free_size(int fd, const char *file, const struct stat64 *buf)
+static int check_free_size(int fd, const char *file, const struct stat64 *buf)
{
ext4_fsblk_t blk_count;
ext4_fsblk_t free_blk_count;
*
* @fd: defrag target file's descriptor.
*/
-int file_frag_count(int fd)
+static int file_frag_count(int fd)
{
int ret;
struct fiemap fiemap_buf;
* @file: the file's name.
* @extents: the file's extents.
*/
-int file_check(int fd, const struct stat64 *buf, const char *file,
+static int file_check(int fd, const struct stat64 *buf, const char *file,
int extents)
{
int ret;
* @ext_list_head: the head of logical extent list.
* @ext: the extent element which will be inserted.
*/
-int insert_extent_by_logical(struct fiemap_extent_list **ext_list_head,
+static int insert_extent_by_logical(struct fiemap_extent_list **ext_list_head,
struct fiemap_extent_list *ext)
{
struct fiemap_extent_list *ext_list_tmp = *ext_list_head;
* @ext_list_head: the head of physical extent list.
* @ext: the extent element which will be inserted.
*/
-int insert_extent_by_physical(struct fiemap_extent_list **ext_list_head,
+static int insert_extent_by_physical(struct fiemap_extent_list **ext_list_head,
struct fiemap_extent_list *ext)
{
struct fiemap_extent_list *ext_list_tmp = *ext_list_head;
* @ext_group_head: the head of a exts_group list.
* @exts_group: the exts_group element which will be inserted.
*/
-int insert_exts_group(struct fiemap_extent_group **ext_group_head,
+static int insert_exts_group(struct fiemap_extent_group **ext_group_head,
struct fiemap_extent_group *exts_group)
{
struct fiemap_extent_group *ext_group_tmp = NULL;
* @ext_list_head: the head of the extent list.
* @ext_group_head: the head of the target exts_group list.
*/
-int join_extents(struct fiemap_extent_list *ext_list_head,
+static int join_extents(struct fiemap_extent_list *ext_list_head,
struct fiemap_extent_group **ext_group_head)
{
__u64 len = ext_list_head->data.len;
* @fd: defrag target file's descriptor.
* @ext_list_head: the head of the extent list.
*/
-int get_file_extents(int fd, struct fiemap_extent_list **ext_list_head)
+static int get_file_extents(int fd, struct fiemap_extent_list **ext_list_head)
{
__u32 i;
int ret;
*
* @logical_list_head: the head of the logical extent list.
*/
-int get_logical_count(struct fiemap_extent_list *logical_list_head)
+static int get_logical_count(struct fiemap_extent_list *logical_list_head)
{
int ret = 0;
struct fiemap_extent_list *ext_list_tmp = logical_list_head;
*
* @physical_list_head: the head of the physical extent list.
*/
-int get_physical_count(struct fiemap_extent_list *physical_list_head)
+static int get_physical_count(struct fiemap_extent_list *physical_list_head)
{
int ret = 0;
struct fiemap_extent_list *ext_list_tmp = physical_list_head;
* @physical_list_head: the head of physical extent list.
* @logical_list_head: the head of logical extent list.
*/
-int change_physical_to_logical(struct fiemap_extent_list **physical_list_head,
- struct fiemap_extent_list **logical_list_head)
+static int change_physical_to_logical(
+ struct fiemap_extent_list **physical_list_head,
+ struct fiemap_extent_list **logical_list_head)
{
int ret;
struct fiemap_extent_list *ext_list_tmp = *physical_list_head;
*
* @ext_list_head: the extent list head of which will be free.
*/
-void free_ext(struct fiemap_extent_list *ext_list_head)
+static void free_ext(struct fiemap_extent_list *ext_list_head)
{
struct fiemap_extent_list *ext_list_tmp = NULL;
*
* @*ext_group_head: the exts_group list head which will be free.
*/
- void free_exts_group(struct fiemap_extent_group *ext_group_head)
+static void free_exts_group(struct fiemap_extent_group *ext_group_head)
{
struct fiemap_extent_group *ext_group_tmp = NULL;
* @file: the file's name.
* @sb: the pointer of the struct ext4_super_block.
*/
-int get_superblock_info(const char *file, struct ext4_super_block *sb)
+static int get_superblock_info(const char *file, struct ext4_super_block *sb)
{
/* Refer to /etc/mtab */
- char *mtab = MOUNTED;
+ const char *mtab = MOUNTED;
FILE *fp = NULL;
int fd = -1;
*
* @block_count: the file's physical block count.
*/
-int get_best_count(ext4_fsblk_t block_count)
+static int get_best_count(ext4_fsblk_t block_count)
{
int ret;
unsigned int flex_bg_num;
* @flag: file type.
* @ftwbuf: the pointer of a struct FTW.
*/
-int file_statistic(const char *file, const struct stat64 *buf,
+static int file_statistic(const char *file, const struct stat64 *buf,
int flag EXT2FS_ATTR((unused)),
struct FTW *ftwbuf EXT2FS_ATTR((unused)))
{
int fd;
int ret;
- int now_ext_count, best_ext_count, physical_ext_count;
+ int now_ext_count, best_ext_count = 0, physical_ext_count;
int i, j;
float ratio = 0.0;
ext4_fsblk_t blk_count = 0;
* @start: logical offset for defrag target file
* @file_size: defrag target filesize
*/
-void print_progress(const char *file, loff_t start, loff_t file_size)
+static void print_progress(const char *file, loff_t start, loff_t file_size)
{
int percent = (start * 100) / file_size;
printf("\033[79;0H\033[K[%u/%u]%s:\t%3d%%",
* @buf: pointer of the struct stat64.
* @ext_list_head: head of the extent list.
*/
-int call_defrag(int fd, int donor_fd, const char *file,
+static int call_defrag(int fd, int donor_fd, const char *file,
const struct stat64 *buf, struct fiemap_extent_list *ext_list_head)
{
loff_t start = 0;
* @flag: file type.
* @ftwbuf: the pointer of a struct FTW.
*/
-int file_defrag(const char *file, const struct stat64 *buf,
+static int file_defrag(const char *file, const struct stat64 *buf,
int flag EXT2FS_ATTR((unused)),
struct FTW *ftwbuf EXT2FS_ATTR((unused)))
{
int ret;
int best;
int file_frags_start, file_frags_end;
- int orig_physical_cnt, donor_physical_cnt;
+ int orig_physical_cnt, donor_physical_cnt = 0;
char tmp_inode_name[PATH_MAX + 8];
struct fiemap_extent_list *orig_list_physical = NULL;
struct fiemap_extent_list *orig_list_logical = NULL;
/* Create donor inode */
memset(tmp_inode_name, 0, PATH_MAX + 8);
- sprintf(tmp_inode_name, "%.*s.defrag", strnlen(file, PATH_MAX), file);
+ sprintf(tmp_inode_name, "%.*s.defrag",
+ (int)strnlen(file, PATH_MAX), file);
donor_fd = open64(tmp_inode_name, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR);
if (donor_fd < 0) {
if (mode_flag & DETAIL) {