1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/**
* libf2fs.c
*
* Copyright (c) 2013 Samsung Electronics Co., Ltd.
* http://www.samsung.com/
*
* Dual licensed under the GPL or LGPL version 2 licenses.
*/
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <mntent.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/ioctl.h>
#include <linux/hdreg.h>
#include <f2fs_fs.h>
struct f2fs_configuration config;
/*
* IO interfaces
*/
int dev_read(void *buf, __u64 offset, size_t len)
{
if (lseek64(config.fd, (off64_t)offset, SEEK_SET) < 0)
return -1;
if (read(config.fd, buf, len) < 0)
return -1;
return 0;
}
int dev_write(void *buf, __u64 offset, size_t len)
{
if (lseek64(config.fd, (off64_t)offset, SEEK_SET) < 0)
return -1;
if (write(config.fd, buf, len) < 0)
return -1;
return 0;
}
int dev_fill(void *buf, __u64 offset, size_t len)
{
/* Only allow fill to zero */
if (*((__u8*)buf))
return -1;
if (lseek64(config.fd, (off64_t)offset, SEEK_SET) < 0)
return -1;
if (write(config.fd, buf, len) < 0)
return -1;
return 0;
}
int dev_read_block(void *buf, __u64 blk_addr)
{
return dev_read(buf, blk_addr * F2FS_BLKSIZE, F2FS_BLKSIZE);
}
int dev_read_blocks(void *buf, __u64 addr, __u32 nr_blks)
{
return dev_read(buf, addr * F2FS_BLKSIZE, nr_blks * F2FS_BLKSIZE);
}
|