fs.c 14.6 KB
Newer Older
L
likailong 已提交
1
/*
M
mamingshuai 已提交
2 3
 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
L
likailong 已提交
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
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
C
chenjing 已提交
31
#include "fs_operations.h"
32
#include "los_config.h"
33
#ifdef LOSCFG_SUPPORT_FATFS
M
mamingshuai 已提交
34
#include "fatfs.h"
35
#endif
M
mamingshuai 已提交
36 37 38 39 40 41 42 43 44 45 46
#include "dirent.h"
#include "errno.h"
#include "fcntl.h"
#include "securec.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "sys/mount.h"
#include "sys/statfs.h"
#include "sys/stat.h"
#include "unistd.h"
L
likailong 已提交
47

C
chenjing 已提交
48 49 50
struct FsMap g_fsmap[MAX_FILESYSTEM_LEN] = {0};
struct FsMap *g_fs = NULL;

51 52
#ifdef LOSCFG_NET_LWIP_SACK
#include "lwip/lwipopts.h"
Y
YOUR_NAME 已提交
53
#include "lwip/sockets.h"
54 55 56 57 58
#define CONFIG_NSOCKET_DESCRIPTORS  LWIP_CONFIG_NUM_SOCKETS
#else
#define CONFIG_NSOCKET_DESCRIPTORS  0
#endif

M
mamingshuai 已提交
59 60 61 62 63
#define CONFIG_NFILE_DESCRIPTORS    FAT_MAX_OPEN_FILES /* only for random currently */

#ifdef LOSCFG_RANDOM_DEV
#include "hks_client.h"
#define RANDOM_DEV_FD  CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS
L
likailong 已提交
64
#define RANDOM_DEV_PATH  "/dev/random"
M
mamingshuai 已提交
65
#endif
L
likailong 已提交
66

67 68 69 70 71
#define FREE_AND_SET_NULL(ptr) do { \
    free(ptr);                      \
    ptr = NULL;                     \
} while (0)

M
mamingshuai 已提交
72
#ifdef LOSCFG_RANDOM_DEV
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
/**
 * @brief Get canonical form of a given path based on cwd(Current working directory).
 *
 * @param cwd Indicates the current working directory.
 * @param path Indicates the path to be canonicalization.
 * @param buf Indicates the pointer to the buffer where the result will be return.
 * @param bufSize Indicates the size of the buffer.
 * @return Returns the length of the canonical path.
 *
 * @attention if path is an absolute path, cwd is ignored. if cwd if not specified, it is assumed to be root('/').
 *            if the buffer is not big enough the result will be truncated, but the return value will always be the
 *            length of the canonical path.
 */
static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, size_t bufSize)
{
M
mamingshuai 已提交
88
    size_t offset;
89 90 91 92 93 94 95 96
    if (!path) {
        path = "";
    }

    if (!cwd || path[0] == '/') {
        cwd = "";
    }

M
mamingshuai 已提交
97 98
    offset = strlen("///") + 1; // three '/' and one '\0'
    size_t tmpLen = strlen(cwd) + strlen(path) + offset;
99 100
    char *tmpBuf = (char *)malloc(tmpLen);
    if (tmpBuf == NULL) {
C
chenjing 已提交
101
        return FS_SUCCESS;
102 103 104 105
    }

    if (-1 == sprintf_s(tmpBuf, tmpLen, "/%s/%s/", cwd, path)) {
        free(tmpBuf);
C
chenjing 已提交
106
        return FS_SUCCESS;
107 108 109 110
    }

    char *p;
    /* replace /./ to / */
M
mamingshuai 已提交
111
    offset = strlen("/./") - 1;
112
    while ((p = strstr(tmpBuf, "/./")) != NULL) {
M
mamingshuai 已提交
113
        if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
114
            free(tmpBuf);
C
chenjing 已提交
115
            return FS_SUCCESS;
116 117 118 119 120 121 122
        }
    }

    /* replace // to / */
    while ((p = strstr(tmpBuf, "//")) != NULL) {
        if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + 1, tmpLen - (p - tmpBuf) - 1)) {
            free(tmpBuf);
C
chenjing 已提交
123
            return FS_SUCCESS;
124 125 126 127
        }
    }

    /* handle /../ (e.g., replace /aa/bb/../ to /aa/) */
M
mamingshuai 已提交
128
    offset = strlen("/../") - 1;
129 130
    while ((p = strstr(tmpBuf, "/../")) != NULL) {
        char *start = p;
M
mamingshuai 已提交
131 132
        while (start > tmpBuf && *(start - 1) != '/') {
            --start;
133
        }
M
mamingshuai 已提交
134
        if (EOK != memmove_s(start, tmpLen - (start - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
135
            free(tmpBuf);
C
chenjing 已提交
136
            return FS_SUCCESS;
137 138 139 140 141 142 143 144 145 146 147 148 149 150
        }
    }

    size_t totalLen = strlen(tmpBuf);
    /* strip the last / */
    if (totalLen > 1 && tmpBuf[totalLen - 1] == '/') {
        tmpBuf[--totalLen] = 0;
    }

    if (!buf || bufSize == 0) {
        free(tmpBuf);
        return totalLen;
    }

M
mamingshuai 已提交
151
    if (EOK != memcpy_s(buf, bufSize, tmpBuf, (((totalLen + 1) > bufSize) ? bufSize : (totalLen + 1)))) {
152
        free(tmpBuf);
C
chenjing 已提交
153
        return FS_SUCCESS;
154 155 156 157 158 159
    }

    buf[bufSize - 1] = 0;
    free(tmpBuf);
    return totalLen;
}
M
mamingshuai 已提交
160 161
#endif

C
chenjing 已提交
162 163
static void InitMountInfo(void)
{
164
#if (LOSCFG_SUPPORT_FATFS == 1)
C
chenjing 已提交
165 166 167 168 169
    extern struct MountOps g_fatfsMnt;
    extern struct FileOps g_fatfsFops;
    g_fsmap[0].fileSystemtype = strdup("fat");
    g_fsmap[0].fsMops = &g_fatfsMnt;
    g_fsmap[0].fsFops = &g_fatfsFops;
170 171
#endif
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
C
chenjing 已提交
172 173 174 175 176
    extern struct MountOps g_lfsMnt;
    extern struct FileOps g_lfsFops;
    g_fsmap[1].fileSystemtype = strdup("littlefs");
    g_fsmap[1].fsMops = &g_lfsMnt;
    g_fsmap[1].fsFops = &g_lfsFops;
177
#endif
C
chenjing 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
}

static struct FsMap *MountFindfs(const char *fileSystemtype)
{
    struct FsMap *m = NULL;

    for (int i = 0; i < MAX_FILESYSTEM_LEN; i++) {
        m = &(g_fsmap[i]);
        if (m->fileSystemtype && strcmp(fileSystemtype, m->fileSystemtype) == 0) {
            return m;
        }
    }

    return NULL;
}

M
mamingshuai 已提交
194 195 196 197
int mount(const char *source, const char *target,
          const char *filesystemtype, unsigned long mountflags,
          const void *data)
{
C
chenjing 已提交
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
    static int initFlag = 0;

    if (initFlag == 0) {
        InitMountInfo();
        initFlag = 1;
    }

    g_fs = MountFindfs(filesystemtype);
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }

    if (g_fs->fsMops == NULL || g_fs->fsMops->Mount == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }

    return g_fs->fsMops->Mount(source, target, filesystemtype, mountflags, data);
M
mamingshuai 已提交
217 218 219 220
}

int umount(const char *target)
{
C
chenjing 已提交
221 222 223 224 225 226 227 228 229
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsMops == NULL || g_fs->fsMops->Umount == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsMops->Umount(target);
M
mamingshuai 已提交
230 231 232 233
}

int umount2(const char *target, int flag)
{
C
chenjing 已提交
234 235 236 237 238 239 240 241 242
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsMops == NULL || g_fs->fsMops->Umount2 == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsMops->Umount2(target, flag);
M
mamingshuai 已提交
243
}
244

M
mamingshuai 已提交
245
int open(const char *path, int oflag, ...)
L
likailong 已提交
246
{
M
mamingshuai 已提交
247
#ifdef LOSCFG_RANDOM_DEV
248 249 250
    unsigned flags = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE | O_TRUNC | O_EXCL | O_DIRECTORY;
    if ((unsigned)oflag & ~flags) {
        errno = EINVAL;
C
chenjing 已提交
251
        return FS_FAILURE;
252
    }
M
mamingshuai 已提交
253 254

    size_t pathLen = strlen(path) + 1;
255 256 257
    char *canonicalPath = (char *)malloc(pathLen);
    if (!canonicalPath) {
        errno = ENOMEM;
C
chenjing 已提交
258
        return FS_FAILURE;
259
    }
M
mamingshuai 已提交
260
    if (GetCanonicalPath(NULL, path, canonicalPath, pathLen) == 0) {
261 262
        FREE_AND_SET_NULL(canonicalPath);
        errno = ENOMEM;
C
chenjing 已提交
263
        return FS_FAILURE;
264
    }
M
mamingshuai 已提交
265

266 267 268 269
    if (strcmp(canonicalPath, RANDOM_DEV_PATH) == 0) {
        FREE_AND_SET_NULL(canonicalPath);
        if ((O_ACCMODE & (unsigned)oflag) != O_RDONLY) {
            errno = EPERM;
C
chenjing 已提交
270
            return FS_FAILURE;
271 272 273
        }
        if ((unsigned)oflag & O_DIRECTORY) {
            errno = ENOTDIR;
C
chenjing 已提交
274
            return FS_FAILURE;
L
likailong 已提交
275 276 277
        }
        return RANDOM_DEV_FD;
    }
278 279 280 281
    if (strcmp(canonicalPath, "/") == 0 || strcmp(canonicalPath, "/dev") == 0) {
        FREE_AND_SET_NULL(canonicalPath);
        if ((unsigned)oflag & O_DIRECTORY) {
            errno = EPERM;
C
chenjing 已提交
282
            return FS_FAILURE;
283 284
        }
        errno = EISDIR;
C
chenjing 已提交
285
        return FS_FAILURE;
286 287
    }
    FREE_AND_SET_NULL(canonicalPath);
M
mamingshuai 已提交
288
#endif
C
chenjing 已提交
289 290 291 292 293 294 295 296 297
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Open == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Open(path, oflag);
L
likailong 已提交
298 299 300 301
}

int close(int fd)
{
M
mamingshuai 已提交
302
#ifdef LOSCFG_RANDOM_DEV
L
likailong 已提交
303
    if (fd == RANDOM_DEV_FD) {
C
chenjing 已提交
304
        return FS_SUCCESS;
L
likailong 已提交
305
    }
M
mamingshuai 已提交
306
#endif
307 308 309 310 311
#ifdef LOSCFG_NET_LWIP_SACK
    if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
        return closesocket(fd);
    }
#endif
C
chenjing 已提交
312 313 314 315 316 317 318 319 320
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Close == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Close(fd);
L
likailong 已提交
321 322
}

M
mamingshuai 已提交
323
ssize_t read(int fd, void *buf, size_t nbyte)
L
likailong 已提交
324
{
M
mamingshuai 已提交
325
#ifdef LOSCFG_RANDOM_DEV
L
likailong 已提交
326
    if (fd == RANDOM_DEV_FD) {
M
mamingshuai 已提交
327
        if (nbyte == 0) {
C
chenjing 已提交
328
            return FS_SUCCESS;
L
likailong 已提交
329 330 331
        }
        if (buf == NULL) {
            errno = EINVAL;
C
chenjing 已提交
332
            return FS_FAILURE;
L
likailong 已提交
333
        }
W
wangchen 已提交
334
        if (nbyte > 1024) { /* 1024, max random_size */
M
mamingshuai 已提交
335
            nbyte = 1024; /* hks_generate_random: random_size must <= 1024 */
L
likailong 已提交
336
        }
M
mamingshuai 已提交
337
        struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbyte};
L
likailong 已提交
338 339
        if (hks_generate_random(&key) != 0) {
            errno = EIO;
C
chenjing 已提交
340
            return FS_FAILURE;
L
likailong 已提交
341
        }
M
mamingshuai 已提交
342
        return (ssize_t)nbyte;
L
likailong 已提交
343
    }
M
mamingshuai 已提交
344
#endif
345 346
#ifdef LOSCFG_NET_LWIP_SACK
    if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
M
mamingshuai 已提交
347
        return recv(fd, buf, nbyte, 0);
348 349
    }
#endif
C
chenjing 已提交
350 351 352 353 354 355 356 357 358
    if (g_fs->fsFops == NULL || g_fs->fsFops->Read == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Read(fd, buf, nbyte);
L
likailong 已提交
359 360
}

M
mamingshuai 已提交
361
ssize_t write(int fd, const void *buf, size_t nbyte)
L
likailong 已提交
362
{
M
mamingshuai 已提交
363
#ifdef LOSCFG_RANDOM_DEV
L
likailong 已提交
364 365
    if (fd == RANDOM_DEV_FD) {
        errno = EBADF; /* "/dev/random" is readonly */
C
chenjing 已提交
366
        return FS_FAILURE;
L
likailong 已提交
367
    }
M
mamingshuai 已提交
368
#endif
369 370
#ifdef LOSCFG_NET_LWIP_SACK
    if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
M
mamingshuai 已提交
371
        return send(fd, buf, nbyte, 0);
372 373
    }
#endif
C
chenjing 已提交
374 375 376 377 378 379 380 381 382
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Write == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Write(fd, buf, nbyte);
M
mamingshuai 已提交
383 384 385 386
}

off_t lseek(int fd, off_t offset, int whence)
{
C
chenjing 已提交
387 388 389 390 391 392 393 394 395
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Seek == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Seek(fd, offset, whence);
M
mamingshuai 已提交
396 397 398 399
}

int unlink(const char *path)
{
C
chenjing 已提交
400 401 402 403 404 405 406 407 408
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Unlink == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Unlink(path);
M
mamingshuai 已提交
409 410 411 412
}

int fstat(int fd, struct stat *buf)
{
C
chenjing 已提交
413 414 415 416 417 418 419 420 421
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Fstat == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Fstat(fd, buf);
M
mamingshuai 已提交
422 423 424 425
}

int stat(const char *path, struct stat *buf)
{
C
chenjing 已提交
426 427 428 429
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
430
    if (g_fs->fsFops == NULL || g_fs->fsFops->Getattr == NULL) {
C
chenjing 已提交
431 432 433
        errno = ENOSYS;
        return FS_FAILURE;
    }
434
    return g_fs->fsFops->Getattr(path, buf);
M
mamingshuai 已提交
435 436 437 438
}

int fsync(int fd)
{
C
chenjing 已提交
439 440 441 442 443 444 445 446 447
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Fsync == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Fsync(fd);
M
mamingshuai 已提交
448 449 450 451
}

int mkdir(const char *path, mode_t mode)
{
C
chenjing 已提交
452 453 454 455 456 457 458 459 460
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Mkdir == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Mkdir(path, mode);
M
mamingshuai 已提交
461 462 463 464
}

DIR *opendir(const char *dirName)
{
C
chenjing 已提交
465 466 467 468 469 470 471 472 473
    if (g_fs == NULL) {
        errno = ENODEV;
        return NULL;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Opendir == NULL) {
        errno = ENOSYS;
        return NULL;
    }
    return g_fs->fsFops->Opendir(dirName);
M
mamingshuai 已提交
474 475 476 477
}

struct dirent *readdir(DIR *dir)
{
C
chenjing 已提交
478 479 480 481 482 483 484 485 486
    if (g_fs == NULL) {
        errno = ENODEV;
        return NULL;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Readdir == NULL) {
        errno = ENOSYS;
        return NULL;
    }
    return g_fs->fsFops->Readdir(dir);
M
mamingshuai 已提交
487 488 489 490
}

int closedir(DIR *dir)
{
C
chenjing 已提交
491 492 493 494 495 496 497 498 499
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Closedir == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Closedir(dir);
M
mamingshuai 已提交
500 501 502 503
}

int rmdir(const char *path)
{
C
chenjing 已提交
504 505 506 507 508 509 510 511 512
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Rmdir == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Rmdir(path);
M
mamingshuai 已提交
513 514 515 516
}

int rename(const char *oldName, const char *newName)
{
C
chenjing 已提交
517 518 519 520 521 522 523 524 525
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Rename == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Rename(oldName, newName);
M
mamingshuai 已提交
526 527 528 529
}

int statfs(const char *path, struct statfs *buf)
{
C
chenjing 已提交
530 531 532 533 534 535 536 537 538
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsMops == NULL || g_fs->fsMops->Statfs == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsMops->Statfs(path, buf);
M
mamingshuai 已提交
539 540 541 542
}

int ftruncate(int fd, off_t length)
{
C
chenjing 已提交
543 544 545 546 547 548 549 550 551
    if (g_fs == NULL) {
        errno = ENODEV;
        return FS_FAILURE;
    }
    if (g_fs->fsFops == NULL || g_fs->fsFops->Ftruncate == NULL) {
        errno = ENOSYS;
        return FS_FAILURE;
    }
    return g_fs->fsFops->Ftruncate(fd, length);
L
likailong 已提交
552
}