Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 1 | /** |
| 2 | * libf2fs.c |
| 3 | * |
| 4 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com/ |
| 6 | * |
Jaegeuk Kim | 0fbdf6c | 2014-04-07 12:10:59 +0900 | [diff] [blame] | 7 | * Dual licensed under the GPL or LGPL version 2 licenses. |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 8 | */ |
| 9 | #define _LARGEFILE64_SOURCE |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 14 | #include <errno.h> |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 15 | #include <unistd.h> |
| 16 | #include <fcntl.h> |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 17 | #ifdef __linux__ |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 18 | #include <mntent.h> |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 19 | #include <linux/hdreg.h> |
| 20 | #endif |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 21 | #include <time.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <sys/mount.h> |
| 24 | #include <sys/ioctl.h> |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 25 | |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 26 | #include <f2fs_fs.h> |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 27 | |
Greg Wallace | b8f37de | 2016-01-02 17:01:27 -0500 | [diff] [blame^] | 28 | #ifdef __ANDROID__ |
| 29 | char *hasmntopt (const struct mntent *mnt, const char *opt) { |
| 30 | const size_t optlen = strlen (opt); |
| 31 | char *rest = mnt->mnt_opts, *p; |
| 32 | |
| 33 | while ((p = strstr (rest, opt)) != NULL) { |
| 34 | if ((p == rest || p[-1] == ',') |
| 35 | && (p[optlen] == '\0' || p[optlen] == '=' || p[optlen] == ',')) |
| 36 | return p; |
| 37 | |
| 38 | rest = strchr (p, ','); |
| 39 | if (rest == NULL) |
| 40 | break; |
| 41 | ++rest; |
| 42 | } |
| 43 | return NULL; |
| 44 | } |
| 45 | #endif |
| 46 | |
Jaegeuk Kim | 77b8e79 | 2015-12-14 14:29:41 -0800 | [diff] [blame] | 47 | /* |
| 48 | * UTF conversion codes are Copied from exfat tools. |
| 49 | */ |
| 50 | static const char *utf8_to_wchar(const char *input, wchar_t *wc, |
| 51 | size_t insize) |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 52 | { |
Jaegeuk Kim | 77b8e79 | 2015-12-14 14:29:41 -0800 | [diff] [blame] | 53 | if ((input[0] & 0x80) == 0 && insize >= 1) { |
| 54 | *wc = (wchar_t) input[0]; |
| 55 | return input + 1; |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 56 | } |
Jaegeuk Kim | 77b8e79 | 2015-12-14 14:29:41 -0800 | [diff] [blame] | 57 | if ((input[0] & 0xe0) == 0xc0 && insize >= 2) { |
| 58 | *wc = (((wchar_t) input[0] & 0x1f) << 6) | |
| 59 | ((wchar_t) input[1] & 0x3f); |
| 60 | return input + 2; |
| 61 | } |
| 62 | if ((input[0] & 0xf0) == 0xe0 && insize >= 3) { |
| 63 | *wc = (((wchar_t) input[0] & 0x0f) << 12) | |
| 64 | (((wchar_t) input[1] & 0x3f) << 6) | |
| 65 | ((wchar_t) input[2] & 0x3f); |
| 66 | return input + 3; |
| 67 | } |
| 68 | if ((input[0] & 0xf8) == 0xf0 && insize >= 4) { |
| 69 | *wc = (((wchar_t) input[0] & 0x07) << 18) | |
| 70 | (((wchar_t) input[1] & 0x3f) << 12) | |
| 71 | (((wchar_t) input[2] & 0x3f) << 6) | |
| 72 | ((wchar_t) input[3] & 0x3f); |
| 73 | return input + 4; |
| 74 | } |
| 75 | if ((input[0] & 0xfc) == 0xf8 && insize >= 5) { |
| 76 | *wc = (((wchar_t) input[0] & 0x03) << 24) | |
| 77 | (((wchar_t) input[1] & 0x3f) << 18) | |
| 78 | (((wchar_t) input[2] & 0x3f) << 12) | |
| 79 | (((wchar_t) input[3] & 0x3f) << 6) | |
| 80 | ((wchar_t) input[4] & 0x3f); |
| 81 | return input + 5; |
| 82 | } |
| 83 | if ((input[0] & 0xfe) == 0xfc && insize >= 6) { |
| 84 | *wc = (((wchar_t) input[0] & 0x01) << 30) | |
| 85 | (((wchar_t) input[1] & 0x3f) << 24) | |
| 86 | (((wchar_t) input[2] & 0x3f) << 18) | |
| 87 | (((wchar_t) input[3] & 0x3f) << 12) | |
| 88 | (((wchar_t) input[4] & 0x3f) << 6) | |
| 89 | ((wchar_t) input[5] & 0x3f); |
| 90 | return input + 6; |
| 91 | } |
| 92 | return NULL; |
| 93 | } |
| 94 | |
| 95 | static u_int16_t *wchar_to_utf16(u_int16_t *output, wchar_t wc, size_t outsize) |
| 96 | { |
| 97 | if (wc <= 0xffff) { |
| 98 | if (outsize == 0) |
| 99 | return NULL; |
| 100 | output[0] = cpu_to_le16(wc); |
| 101 | return output + 1; |
| 102 | } |
| 103 | if (outsize < 2) |
| 104 | return NULL; |
| 105 | wc -= 0x10000; |
| 106 | output[0] = cpu_to_le16(0xd800 | ((wc >> 10) & 0x3ff)); |
| 107 | output[1] = cpu_to_le16(0xdc00 | (wc & 0x3ff)); |
| 108 | return output + 2; |
| 109 | } |
| 110 | |
| 111 | int utf8_to_utf16(u_int16_t *output, const char *input, size_t outsize, |
| 112 | size_t insize) |
| 113 | { |
| 114 | const char *inp = input; |
| 115 | u_int16_t *outp = output; |
| 116 | wchar_t wc; |
| 117 | |
Jaegeuk Kim | 3aa929b | 2016-01-13 11:51:33 -0800 | [diff] [blame] | 118 | while ((size_t)(inp - input) < insize && *inp) { |
Jaegeuk Kim | 77b8e79 | 2015-12-14 14:29:41 -0800 | [diff] [blame] | 119 | inp = utf8_to_wchar(inp, &wc, insize - (inp - input)); |
| 120 | if (inp == NULL) { |
| 121 | DBG(0, "illegal UTF-8 sequence\n"); |
| 122 | return -EILSEQ; |
| 123 | } |
| 124 | outp = wchar_to_utf16(outp, wc, outsize - (outp - output)); |
| 125 | if (outp == NULL) { |
| 126 | DBG(0, "name is too long\n"); |
| 127 | return -ENAMETOOLONG; |
| 128 | } |
| 129 | } |
| 130 | *outp = cpu_to_le16(0); |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static const u_int16_t *utf16_to_wchar(const u_int16_t *input, wchar_t *wc, |
| 135 | size_t insize) |
| 136 | { |
| 137 | if ((le16_to_cpu(input[0]) & 0xfc00) == 0xd800) { |
| 138 | if (insize < 2 || (le16_to_cpu(input[1]) & 0xfc00) != 0xdc00) |
| 139 | return NULL; |
| 140 | *wc = ((wchar_t) (le16_to_cpu(input[0]) & 0x3ff) << 10); |
| 141 | *wc |= (le16_to_cpu(input[1]) & 0x3ff); |
| 142 | *wc += 0x10000; |
| 143 | return input + 2; |
| 144 | } else { |
| 145 | *wc = le16_to_cpu(*input); |
| 146 | return input + 1; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | static char *wchar_to_utf8(char *output, wchar_t wc, size_t outsize) |
| 151 | { |
| 152 | if (wc <= 0x7f) { |
| 153 | if (outsize < 1) |
| 154 | return NULL; |
| 155 | *output++ = (char) wc; |
| 156 | } else if (wc <= 0x7ff) { |
| 157 | if (outsize < 2) |
| 158 | return NULL; |
| 159 | *output++ = 0xc0 | (wc >> 6); |
| 160 | *output++ = 0x80 | (wc & 0x3f); |
| 161 | } else if (wc <= 0xffff) { |
| 162 | if (outsize < 3) |
| 163 | return NULL; |
| 164 | *output++ = 0xe0 | (wc >> 12); |
| 165 | *output++ = 0x80 | ((wc >> 6) & 0x3f); |
| 166 | *output++ = 0x80 | (wc & 0x3f); |
| 167 | } else if (wc <= 0x1fffff) { |
| 168 | if (outsize < 4) |
| 169 | return NULL; |
| 170 | *output++ = 0xf0 | (wc >> 18); |
| 171 | *output++ = 0x80 | ((wc >> 12) & 0x3f); |
| 172 | *output++ = 0x80 | ((wc >> 6) & 0x3f); |
| 173 | *output++ = 0x80 | (wc & 0x3f); |
| 174 | } else if (wc <= 0x3ffffff) { |
| 175 | if (outsize < 5) |
| 176 | return NULL; |
| 177 | *output++ = 0xf8 | (wc >> 24); |
| 178 | *output++ = 0x80 | ((wc >> 18) & 0x3f); |
| 179 | *output++ = 0x80 | ((wc >> 12) & 0x3f); |
| 180 | *output++ = 0x80 | ((wc >> 6) & 0x3f); |
| 181 | *output++ = 0x80 | (wc & 0x3f); |
| 182 | } else if (wc <= 0x7fffffff) { |
| 183 | if (outsize < 6) |
| 184 | return NULL; |
| 185 | *output++ = 0xfc | (wc >> 30); |
| 186 | *output++ = 0x80 | ((wc >> 24) & 0x3f); |
| 187 | *output++ = 0x80 | ((wc >> 18) & 0x3f); |
| 188 | *output++ = 0x80 | ((wc >> 12) & 0x3f); |
| 189 | *output++ = 0x80 | ((wc >> 6) & 0x3f); |
| 190 | *output++ = 0x80 | (wc & 0x3f); |
| 191 | } else |
| 192 | return NULL; |
| 193 | |
| 194 | return output; |
| 195 | } |
| 196 | |
| 197 | int utf16_to_utf8(char *output, const u_int16_t *input, size_t outsize, |
| 198 | size_t insize) |
| 199 | { |
| 200 | const u_int16_t *inp = input; |
| 201 | char *outp = output; |
| 202 | wchar_t wc; |
| 203 | |
Jaegeuk Kim | 3aa929b | 2016-01-13 11:51:33 -0800 | [diff] [blame] | 204 | while ((size_t)(inp - input) < insize && le16_to_cpu(*inp)) { |
Jaegeuk Kim | 77b8e79 | 2015-12-14 14:29:41 -0800 | [diff] [blame] | 205 | inp = utf16_to_wchar(inp, &wc, insize - (inp - input)); |
| 206 | if (inp == NULL) { |
| 207 | DBG(0, "illegal UTF-16 sequence\n"); |
| 208 | return -EILSEQ; |
| 209 | } |
| 210 | outp = wchar_to_utf8(outp, wc, outsize - (outp - output)); |
| 211 | if (outp == NULL) { |
| 212 | DBG(0, "name is too long\n"); |
| 213 | return -ENAMETOOLONG; |
| 214 | } |
| 215 | } |
| 216 | *outp = '\0'; |
| 217 | return 0; |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | int log_base_2(u_int32_t num) |
| 221 | { |
| 222 | int ret = 0; |
| 223 | if (num <= 0 || (num & (num - 1)) != 0) |
| 224 | return -1; |
| 225 | |
| 226 | while (num >>= 1) |
| 227 | ret++; |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * f2fs bit operations |
| 233 | */ |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 234 | static const int bits_in_byte[256] = { |
| 235 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, |
| 236 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
| 237 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
| 238 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 239 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
| 240 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 241 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 242 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
| 243 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
| 244 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 245 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 246 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
| 247 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 248 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
| 249 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
| 250 | 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, |
| 251 | }; |
| 252 | |
| 253 | int get_bits_in_byte(unsigned char n) |
| 254 | { |
| 255 | return bits_in_byte[n]; |
| 256 | } |
| 257 | |
Jaegeuk Kim | 94a04b1 | 2015-12-15 11:13:25 -0800 | [diff] [blame] | 258 | int test_and_set_bit_le(u32 nr, u8 *addr) |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 259 | { |
Jaegeuk Kim | 0cb56c8 | 2015-12-09 11:44:31 -0800 | [diff] [blame] | 260 | int mask, retval; |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 261 | |
Jaegeuk Kim | 4455742 | 2015-12-15 10:10:15 -0800 | [diff] [blame] | 262 | addr += nr >> 3; |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 263 | mask = 1 << ((nr & 0x07)); |
Jaegeuk Kim | 4455742 | 2015-12-15 10:10:15 -0800 | [diff] [blame] | 264 | retval = mask & *addr; |
| 265 | *addr |= mask; |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 266 | return retval; |
| 267 | } |
| 268 | |
Jaegeuk Kim | 94a04b1 | 2015-12-15 11:13:25 -0800 | [diff] [blame] | 269 | int test_and_clear_bit_le(u32 nr, u8 *addr) |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 270 | { |
Jaegeuk Kim | 0cb56c8 | 2015-12-09 11:44:31 -0800 | [diff] [blame] | 271 | int mask, retval; |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 272 | |
Jaegeuk Kim | 4455742 | 2015-12-15 10:10:15 -0800 | [diff] [blame] | 273 | addr += nr >> 3; |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 274 | mask = 1 << ((nr & 0x07)); |
Jaegeuk Kim | 4455742 | 2015-12-15 10:10:15 -0800 | [diff] [blame] | 275 | retval = mask & *addr; |
| 276 | *addr &= ~mask; |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 277 | return retval; |
| 278 | } |
| 279 | |
Jaegeuk Kim | 94a04b1 | 2015-12-15 11:13:25 -0800 | [diff] [blame] | 280 | int test_bit_le(u32 nr, const u8 *addr) |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 281 | { |
Jaegeuk Kim | 4455742 | 2015-12-15 10:10:15 -0800 | [diff] [blame] | 282 | return ((1 << (nr & 7)) & (addr[nr >> 3])); |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 283 | } |
| 284 | |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 285 | int f2fs_test_bit(unsigned int nr, const char *p) |
| 286 | { |
| 287 | int mask; |
| 288 | char *addr = (char *)p; |
| 289 | |
| 290 | addr += (nr >> 3); |
| 291 | mask = 1 << (7 - (nr & 0x07)); |
| 292 | return (mask & *addr) != 0; |
| 293 | } |
| 294 | |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 295 | int f2fs_set_bit(unsigned int nr, char *addr) |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 296 | { |
| 297 | int mask; |
| 298 | int ret; |
| 299 | |
| 300 | addr += (nr >> 3); |
| 301 | mask = 1 << (7 - (nr & 0x07)); |
| 302 | ret = mask & *addr; |
| 303 | *addr |= mask; |
| 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | int f2fs_clear_bit(unsigned int nr, char *addr) |
| 308 | { |
| 309 | int mask; |
| 310 | int ret; |
| 311 | |
| 312 | addr += (nr >> 3); |
| 313 | mask = 1 << (7 - (nr & 0x07)); |
| 314 | ret = mask & *addr; |
| 315 | *addr &= ~mask; |
| 316 | return ret; |
| 317 | } |
| 318 | |
Jaegeuk Kim | 94a04b1 | 2015-12-15 11:13:25 -0800 | [diff] [blame] | 319 | static inline u64 __ffs(u8 word) |
Changman Lee | 57baa23 | 2013-07-30 16:39:06 +0900 | [diff] [blame] | 320 | { |
| 321 | int num = 0; |
| 322 | |
Changman Lee | 57baa23 | 2013-07-30 16:39:06 +0900 | [diff] [blame] | 323 | if ((word & 0xf) == 0) { |
| 324 | num += 4; |
| 325 | word >>= 4; |
| 326 | } |
| 327 | if ((word & 0x3) == 0) { |
| 328 | num += 2; |
| 329 | word >>= 2; |
| 330 | } |
| 331 | if ((word & 0x1) == 0) |
| 332 | num += 1; |
| 333 | return num; |
| 334 | } |
| 335 | |
Jaegeuk Kim | 0cb56c8 | 2015-12-09 11:44:31 -0800 | [diff] [blame] | 336 | /* Copied from linux/lib/find_bit.c */ |
| 337 | #define BITMAP_FIRST_BYTE_MASK(start) (0xff << ((start) & (BITS_PER_BYTE - 1))) |
| 338 | |
Jaegeuk Kim | 94a04b1 | 2015-12-15 11:13:25 -0800 | [diff] [blame] | 339 | static u64 _find_next_bit_le(const u8 *addr, u64 nbits, u64 start, char invert) |
Changman Lee | 57baa23 | 2013-07-30 16:39:06 +0900 | [diff] [blame] | 340 | { |
Jaegeuk Kim | 94a04b1 | 2015-12-15 11:13:25 -0800 | [diff] [blame] | 341 | u8 tmp; |
Changman Lee | 57baa23 | 2013-07-30 16:39:06 +0900 | [diff] [blame] | 342 | |
Jaegeuk Kim | 0cb56c8 | 2015-12-09 11:44:31 -0800 | [diff] [blame] | 343 | if (!nbits || start >= nbits) |
| 344 | return nbits; |
Changman Lee | 57baa23 | 2013-07-30 16:39:06 +0900 | [diff] [blame] | 345 | |
Jaegeuk Kim | 0cb56c8 | 2015-12-09 11:44:31 -0800 | [diff] [blame] | 346 | tmp = addr[start / BITS_PER_BYTE] ^ invert; |
| 347 | |
| 348 | /* Handle 1st word. */ |
| 349 | tmp &= BITMAP_FIRST_BYTE_MASK(start); |
| 350 | start = round_down(start, BITS_PER_BYTE); |
| 351 | |
| 352 | while (!tmp) { |
| 353 | start += BITS_PER_BYTE; |
| 354 | if (start >= nbits) |
| 355 | return nbits; |
| 356 | |
| 357 | tmp = addr[start / BITS_PER_BYTE] ^ invert; |
| 358 | } |
| 359 | |
| 360 | return min(start + __ffs(tmp), nbits); |
| 361 | } |
| 362 | |
Jaegeuk Kim | 94a04b1 | 2015-12-15 11:13:25 -0800 | [diff] [blame] | 363 | u64 find_next_bit_le(const u8 *addr, u64 size, u64 offset) |
Jaegeuk Kim | 0cb56c8 | 2015-12-09 11:44:31 -0800 | [diff] [blame] | 364 | { |
| 365 | return _find_next_bit_le(addr, size, offset, 0); |
| 366 | } |
| 367 | |
| 368 | |
Jaegeuk Kim | 94a04b1 | 2015-12-15 11:13:25 -0800 | [diff] [blame] | 369 | u64 find_next_zero_bit_le(const u8 *addr, u64 size, u64 offset) |
Jaegeuk Kim | 0cb56c8 | 2015-12-09 11:44:31 -0800 | [diff] [blame] | 370 | { |
| 371 | return _find_next_bit_le(addr, size, offset, 0xff); |
Changman Lee | 57baa23 | 2013-07-30 16:39:06 +0900 | [diff] [blame] | 372 | } |
| 373 | |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 374 | /* |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 375 | * Hashing code adapted from ext3 |
| 376 | */ |
| 377 | #define DELTA 0x9E3779B9 |
| 378 | |
| 379 | static void TEA_transform(unsigned int buf[4], unsigned int const in[]) |
| 380 | { |
| 381 | __u32 sum = 0; |
| 382 | __u32 b0 = buf[0], b1 = buf[1]; |
| 383 | __u32 a = in[0], b = in[1], c = in[2], d = in[3]; |
| 384 | int n = 16; |
| 385 | |
| 386 | do { |
| 387 | sum += DELTA; |
| 388 | b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b); |
| 389 | b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d); |
| 390 | } while (--n); |
| 391 | |
| 392 | buf[0] += b0; |
| 393 | buf[1] += b1; |
| 394 | |
| 395 | } |
| 396 | |
Jaegeuk Kim | 347fe81 | 2014-08-26 16:28:12 -0700 | [diff] [blame] | 397 | static void str2hashbuf(const unsigned char *msg, int len, |
| 398 | unsigned int *buf, int num) |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 399 | { |
| 400 | unsigned pad, val; |
| 401 | int i; |
| 402 | |
| 403 | pad = (__u32)len | ((__u32)len << 8); |
| 404 | pad |= pad << 16; |
| 405 | |
| 406 | val = pad; |
| 407 | if (len > num * 4) |
| 408 | len = num * 4; |
| 409 | for (i = 0; i < len; i++) { |
| 410 | if ((i % 4) == 0) |
| 411 | val = pad; |
| 412 | val = msg[i] + (val << 8); |
| 413 | if ((i % 4) == 3) { |
| 414 | *buf++ = val; |
| 415 | val = pad; |
| 416 | num--; |
| 417 | } |
| 418 | } |
| 419 | if (--num >= 0) |
| 420 | *buf++ = val; |
| 421 | while (--num >= 0) |
| 422 | *buf++ = pad; |
| 423 | |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * Return hash value of directory entry |
| 428 | * @param name dentry name |
| 429 | * @param len name lenth |
| 430 | * @return return on success hash value, errno on failure |
| 431 | */ |
Jaegeuk Kim | 347fe81 | 2014-08-26 16:28:12 -0700 | [diff] [blame] | 432 | f2fs_hash_t f2fs_dentry_hash(const unsigned char *name, int len) |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 433 | { |
| 434 | __u32 hash; |
| 435 | f2fs_hash_t f2fs_hash; |
Jaegeuk Kim | 347fe81 | 2014-08-26 16:28:12 -0700 | [diff] [blame] | 436 | const unsigned char *p; |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 437 | __u32 in[8], buf[4]; |
| 438 | |
| 439 | /* special hash codes for special dentries */ |
Jaegeuk Kim | 347fe81 | 2014-08-26 16:28:12 -0700 | [diff] [blame] | 440 | if ((len <= 2) && (name[0] == '.') && |
| 441 | (name[1] == '.' || name[1] == '\0')) |
| 442 | return 0; |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 443 | |
| 444 | /* Initialize the default seed for the hash checksum functions */ |
| 445 | buf[0] = 0x67452301; |
| 446 | buf[1] = 0xefcdab89; |
| 447 | buf[2] = 0x98badcfe; |
| 448 | buf[3] = 0x10325476; |
| 449 | |
| 450 | p = name; |
Jaegeuk Kim | 347fe81 | 2014-08-26 16:28:12 -0700 | [diff] [blame] | 451 | while (1) { |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 452 | str2hashbuf(p, len, in, 4); |
| 453 | TEA_transform(buf, in); |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 454 | p += 16; |
Jaegeuk Kim | 347fe81 | 2014-08-26 16:28:12 -0700 | [diff] [blame] | 455 | if (len <= 16) |
| 456 | break; |
| 457 | len -= 16; |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 458 | } |
| 459 | hash = buf[0]; |
| 460 | |
Jaegeuk Kim | 347fe81 | 2014-08-26 16:28:12 -0700 | [diff] [blame] | 461 | f2fs_hash = cpu_to_le32(hash & ~F2FS_HASH_COL_BIT); |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 462 | return f2fs_hash; |
| 463 | } |
| 464 | |
Jaegeuk Kim | cd1e470 | 2013-08-20 18:05:56 +0900 | [diff] [blame] | 465 | unsigned int addrs_per_inode(struct f2fs_inode *i) |
| 466 | { |
| 467 | if (i->i_inline & F2FS_INLINE_XATTR) |
| 468 | return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; |
| 469 | return DEF_ADDRS_PER_INODE; |
| 470 | } |
| 471 | |
Changman Lee | 7f35b54 | 2013-07-04 17:11:32 +0900 | [diff] [blame] | 472 | /* |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 473 | * CRC32 |
| 474 | */ |
| 475 | #define CRCPOLY_LE 0xedb88320 |
| 476 | |
| 477 | u_int32_t f2fs_cal_crc32(u_int32_t crc, void *buf, int len) |
| 478 | { |
| 479 | int i; |
| 480 | unsigned char *p = (unsigned char *)buf; |
| 481 | while (len--) { |
| 482 | crc ^= *p++; |
| 483 | for (i = 0; i < 8; i++) |
| 484 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); |
| 485 | } |
| 486 | return crc; |
| 487 | } |
| 488 | |
Jaegeuk Kim | 5043dff | 2013-02-12 11:03:24 +0900 | [diff] [blame] | 489 | int f2fs_crc_valid(u_int32_t blk_crc, void *buf, int len) |
| 490 | { |
| 491 | u_int32_t cal_crc = 0; |
| 492 | |
| 493 | cal_crc = f2fs_cal_crc32(F2FS_SUPER_MAGIC, buf, len); |
| 494 | |
| 495 | if (cal_crc != blk_crc) { |
Changman Lee | fd9816f | 2014-05-12 22:03:46 +0900 | [diff] [blame] | 496 | DBG(0,"CRC validation failed: cal_crc = %u, " |
| 497 | "blk_crc = %u buff_size = 0x%x\n", |
Jaegeuk Kim | 5043dff | 2013-02-12 11:03:24 +0900 | [diff] [blame] | 498 | cal_crc, blk_crc, len); |
| 499 | return -1; |
| 500 | } |
| 501 | return 0; |
| 502 | } |
| 503 | |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 504 | /* |
| 505 | * device information |
| 506 | */ |
| 507 | void f2fs_init_configuration(struct f2fs_configuration *c) |
| 508 | { |
JP Abgrall | 94f9285 | 2014-06-11 21:55:38 -0700 | [diff] [blame] | 509 | c->total_sectors = 0; |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 510 | c->sector_size = DEFAULT_SECTOR_SIZE; |
| 511 | c->sectors_per_blk = DEFAULT_SECTORS_PER_BLOCK; |
| 512 | c->blks_per_seg = DEFAULT_BLOCKS_PER_SEGMENT; |
| 513 | |
| 514 | /* calculated by overprovision ratio */ |
Jaegeuk Kim | 5ddd5f8 | 2015-08-10 15:45:10 -0700 | [diff] [blame] | 515 | c->reserved_segments = 0; |
| 516 | c->overprovision = 0; |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 517 | c->segs_per_sec = 1; |
| 518 | c->secs_per_zone = 1; |
Changman Lee | 060292e | 2014-11-17 14:03:41 +0900 | [diff] [blame] | 519 | c->segs_per_zone = 1; |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 520 | c->heap = 1; |
Mike Fleetwood | 9799d63 | 2013-04-02 23:15:20 +0100 | [diff] [blame] | 521 | c->vol_label = ""; |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 522 | c->device_name = NULL; |
Changman Lee | b155ea8 | 2013-08-31 08:41:31 +0900 | [diff] [blame] | 523 | c->trim = 1; |
qemx13 | bf53b3a | 2015-10-19 13:05:55 -0700 | [diff] [blame] | 524 | c->bytes_reserved = 0; |
Jaegeuk Kim | 378a835 | 2015-11-22 10:53:07 +0800 | [diff] [blame] | 525 | c->ro = 0; |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 526 | } |
| 527 | |
Jaegeuk Kim | 3aa929b | 2016-01-13 11:51:33 -0800 | [diff] [blame] | 528 | static int is_mounted(const char *mpt, const char *device) |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 529 | { |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 530 | #ifdef __linux__ |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 531 | FILE *file = NULL; |
| 532 | struct mntent *mnt = NULL; |
| 533 | |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 534 | file = setmntent(mpt, "r"); |
| 535 | if (file == NULL) |
| 536 | return 0; |
| 537 | |
| 538 | while ((mnt = getmntent(file)) != NULL) { |
Jaegeuk Kim | 378a835 | 2015-11-22 10:53:07 +0800 | [diff] [blame] | 539 | if (!strcmp(device, mnt->mnt_fsname)) { |
Jaegeuk Kim | 3aa929b | 2016-01-13 11:51:33 -0800 | [diff] [blame] | 540 | #ifdef MNTOPT_RO |
Jaegeuk Kim | 378a835 | 2015-11-22 10:53:07 +0800 | [diff] [blame] | 541 | if (hasmntopt(mnt, MNTOPT_RO)) |
Greg Wallace | b8f37de | 2016-01-02 17:01:27 -0500 | [diff] [blame^] | 542 | #else |
| 543 | if (hasmntopt(mnt, "ro")) |
Jaegeuk Kim | 3aa929b | 2016-01-13 11:51:33 -0800 | [diff] [blame] | 544 | #endif |
Greg Wallace | b8f37de | 2016-01-02 17:01:27 -0500 | [diff] [blame^] | 545 | config.ro = 1; |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 546 | break; |
Jaegeuk Kim | 378a835 | 2015-11-22 10:53:07 +0800 | [diff] [blame] | 547 | } |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 548 | } |
| 549 | endmntent(file); |
| 550 | return mnt ? 1 : 0; |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 551 | #else |
| 552 | /* TODO */ |
| 553 | return 0; |
| 554 | #endif |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | int f2fs_dev_is_umounted(struct f2fs_configuration *c) |
| 558 | { |
| 559 | struct stat st_buf; |
| 560 | int ret = 0; |
| 561 | |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 562 | #ifdef __linux__ |
Jaegeuk Kim | 3aa929b | 2016-01-13 11:51:33 -0800 | [diff] [blame] | 563 | ret = is_mounted(MOUNTED, c->device_name); |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 564 | if (ret) { |
Jaegeuk Kim | 378a835 | 2015-11-22 10:53:07 +0800 | [diff] [blame] | 565 | MSG(0, "Info: Mounted device!\n"); |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 566 | return -1; |
Namjae Jeon | 8d3802b | 2013-03-31 11:51:29 +0900 | [diff] [blame] | 567 | } |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 568 | #endif |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 569 | |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 570 | /* |
| 571 | * if failed due to /etc/mtab file not present |
| 572 | * try with /proc/mounts. |
| 573 | */ |
Jaegeuk Kim | 3aa929b | 2016-01-13 11:51:33 -0800 | [diff] [blame] | 574 | ret = is_mounted("/proc/mounts", c->device_name); |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 575 | if (ret) { |
Jaegeuk Kim | 378a835 | 2015-11-22 10:53:07 +0800 | [diff] [blame] | 576 | MSG(0, "Info: Mounted device!\n"); |
Jaegeuk Kim | 2c877a8 | 2013-08-02 17:03:10 +0900 | [diff] [blame] | 577 | return -1; |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * If f2fs is umounted with -l, the process can still use |
| 582 | * the file system. In this case, we should not format. |
| 583 | */ |
| 584 | if (stat(c->device_name, &st_buf) == 0 && S_ISBLK(st_buf.st_mode)) { |
| 585 | int fd = open(c->device_name, O_RDONLY | O_EXCL); |
| 586 | |
| 587 | if (fd >= 0) { |
| 588 | close(fd); |
| 589 | } else if (errno == EBUSY) { |
| 590 | MSG(0, "\tError: In use by the system!\n"); |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 591 | return -1; |
| 592 | } |
| 593 | } |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 594 | return 0; |
| 595 | } |
| 596 | |
Jaegeuk Kim | c07795e | 2014-11-06 19:34:40 -0800 | [diff] [blame] | 597 | void get_kernel_version(__u8 *version) |
| 598 | { |
| 599 | int i; |
| 600 | for (i = 0; i < VERSION_LEN; i++) { |
| 601 | if (version[i] == '\n') |
| 602 | break; |
| 603 | } |
| 604 | memset(version + i, 0, VERSION_LEN + 1 - i); |
| 605 | } |
| 606 | |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 607 | int f2fs_get_device_info(struct f2fs_configuration *c) |
| 608 | { |
| 609 | int32_t fd = 0; |
JP Abgrall | 3c85e73 | 2014-05-13 17:02:55 -0700 | [diff] [blame] | 610 | uint32_t sector_size; |
joerg jungermann | 290d040 | 2014-09-25 22:05:12 -0700 | [diff] [blame] | 611 | #ifndef BLKGETSIZE64 |
| 612 | uint32_t total_sectors; |
| 613 | #endif |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 614 | struct stat stat_buf; |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 615 | #ifdef __linux__ |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 616 | struct hd_geometry geom; |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 617 | #endif |
JP Abgrall | 94f9285 | 2014-06-11 21:55:38 -0700 | [diff] [blame] | 618 | u_int64_t wanted_total_sectors = c->total_sectors; |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 619 | |
| 620 | fd = open(c->device_name, O_RDWR); |
| 621 | if (fd < 0) { |
| 622 | MSG(0, "\tError: Failed to open the device!\n"); |
| 623 | return -1; |
| 624 | } |
| 625 | c->fd = fd; |
| 626 | |
Jaegeuk Kim | c07795e | 2014-11-06 19:34:40 -0800 | [diff] [blame] | 627 | c->kd = open("/proc/version", O_RDONLY); |
| 628 | if (c->kd < 0) |
| 629 | MSG(0, "\tInfo: No support kernel version!\n"); |
| 630 | |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 631 | if (fstat(fd, &stat_buf) < 0 ) { |
| 632 | MSG(0, "\tError: Failed to get the device stat!\n"); |
| 633 | return -1; |
| 634 | } |
| 635 | |
| 636 | if (S_ISREG(stat_buf.st_mode)) { |
qemx13 | bf53b3a | 2015-10-19 13:05:55 -0700 | [diff] [blame] | 637 | if (c->bytes_reserved >= stat_buf.st_size) { |
| 638 | MSG(0, "\n\Error: reserved bytes (%u) is bigger than the device size (%u bytes)\n", |
| 639 | (unsigned int) c->bytes_reserved, |
| 640 | (unsigned int) stat_buf.st_size); |
| 641 | return -1; |
| 642 | } |
| 643 | |
| 644 | c->total_sectors = (stat_buf.st_size - c->bytes_reserved) / c->sector_size; |
| 645 | |
| 646 | if (c->bytes_reserved) { |
| 647 | MSG(0, "Info: Reserved %u bytes ", (unsigned int) c->bytes_reserved); |
| 648 | MSG(0, "from device of size %u sectors\n", |
| 649 | (unsigned int) (stat_buf.st_size / c->sector_size)); |
| 650 | } |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 651 | #ifdef __linux__ |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 652 | } else if (S_ISBLK(stat_buf.st_mode)) { |
| 653 | if (ioctl(fd, BLKSSZGET, §or_size) < 0) { |
| 654 | MSG(0, "\tError: Using the default sector size\n"); |
| 655 | } else { |
| 656 | if (c->sector_size < sector_size) { |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 657 | c->sector_size = sector_size; |
| 658 | c->sectors_per_blk = PAGE_SIZE / sector_size; |
| 659 | } |
| 660 | } |
| 661 | |
joerg jungermann | 290d040 | 2014-09-25 22:05:12 -0700 | [diff] [blame] | 662 | #ifdef BLKGETSIZE64 |
| 663 | if (ioctl(fd, BLKGETSIZE64, &c->total_sectors) < 0) { |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 664 | MSG(0, "\tError: Cannot get the device size\n"); |
| 665 | return -1; |
| 666 | } |
joerg jungermann | 290d040 | 2014-09-25 22:05:12 -0700 | [diff] [blame] | 667 | c->total_sectors /= c->sector_size; |
| 668 | #else |
| 669 | if (ioctl(fd, BLKGETSIZE, &total_sectors) < 0) { |
| 670 | MSG(0, "\tError: Cannot get the device size\n"); |
| 671 | return -1; |
| 672 | } |
| 673 | total_sectors /= c->sector_size; |
| 674 | c->total_sectors = total_sectors; |
| 675 | #endif |
qemx13 | bf53b3a | 2015-10-19 13:05:55 -0700 | [diff] [blame] | 676 | |
| 677 | if (c->bytes_reserved) { |
| 678 | unsigned int reserved_sectors; |
| 679 | |
| 680 | reserved_sectors = c->bytes_reserved / c->sector_size; |
| 681 | if (c->bytes_reserved % c->sector_size) {reserved_sectors++;} |
| 682 | |
| 683 | if(reserved_sectors >= c->total_sectors) { |
| 684 | MSG(0, "\n\Error: reserved bytes (%u sectors) is bigger than the device size (%u sectors)\n", |
| 685 | (unsigned int) reserved_sectors, |
| 686 | (unsigned int) c->total_sectors); |
| 687 | return -1; |
| 688 | } |
| 689 | |
| 690 | MSG(0, "\n"); |
| 691 | MSG(0, "Info: Reserved %u sectors ", (unsigned int) reserved_sectors); |
| 692 | MSG(0, "from device of size %u sectors\n", |
| 693 | (unsigned int) c->total_sectors); |
| 694 | |
| 695 | c->total_sectors -= reserved_sectors; |
| 696 | } |
| 697 | |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 698 | if (ioctl(fd, HDIO_GETGEO, &geom) < 0) |
| 699 | c->start_sector = 0; |
| 700 | else |
| 701 | c->start_sector = geom.start; |
Keith Mok | 45f6df2 | 2015-09-03 11:34:33 -0700 | [diff] [blame] | 702 | #endif |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 703 | } else { |
| 704 | MSG(0, "\tError: Volume type is not supported!!!\n"); |
| 705 | return -1; |
| 706 | } |
JP Abgrall | 94f9285 | 2014-06-11 21:55:38 -0700 | [diff] [blame] | 707 | if (wanted_total_sectors && wanted_total_sectors < c->total_sectors) { |
Chao Yu | 29ab4d8 | 2015-02-05 17:36:39 +0800 | [diff] [blame] | 708 | MSG(0, "Info: total device sectors = %"PRIu64" (in %u bytes)\n", |
| 709 | c->total_sectors, c->sector_size); |
JP Abgrall | 94f9285 | 2014-06-11 21:55:38 -0700 | [diff] [blame] | 710 | c->total_sectors = wanted_total_sectors; |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 711 | |
JP Abgrall | 94f9285 | 2014-06-11 21:55:38 -0700 | [diff] [blame] | 712 | } |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 713 | MSG(0, "Info: sector size = %u\n", c->sector_size); |
Jaegeuk Kim | eb38acb | 2015-03-20 16:41:59 -0700 | [diff] [blame] | 714 | MSG(0, "Info: total sectors = %"PRIu64" (%"PRIu64" MB)\n", |
Jaegeuk Kim | a093b0f | 2015-12-07 15:50:26 -0800 | [diff] [blame] | 715 | c->total_sectors, (c->total_sectors * |
| 716 | (c->sector_size >> 9)) >> 11); |
Jaegeuk Kim | e69e437 | 2013-01-25 17:20:16 +0900 | [diff] [blame] | 717 | return 0; |
| 718 | } |
| 719 | |