更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
vfs_other.c 文件参考

浏览源代码.

函数

int fstat (int fd, struct stat *buf)
 
int fstat64 (int fd, struct stat64 *buf)
 
int lstat (const char *path, struct stat *buffer)
 
int VfsVnodePermissionCheck (const struct Vnode *node, int accMode)
 
int VfsPermissionCheck (uint fuid, uint fgid, uint fileMode, int accMode)
 
static int SetWorkDir (const char *dir, size_t len)
 
int chdir (const char *path)
 
char * getcwd (char *buf, size_t n)
 
int chmod (const char *path, mode_t mode)
 
int chown (const char *pathname, uid_t owner, gid_t group)
 
int access (const char *path, int amode)
 
static struct dirent ** scandir_get_file_list (const char *dir, int *num, int(*filter)(const struct dirent *))
 
int scandir (const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const struct dirent **, const struct dirent **))
 
int alphasort (const struct dirent **a, const struct dirent **b)
 
char * rindex (const char *s, int c)
 locate character in string. 更多...
 
static char * ls_get_fullpath (const char *path, struct dirent *pdirent)
 
static void PrintFileInfo64 (const struct stat64 *stat64Info, const char *name)
 
static void PrintFileInfo (const struct stat *statInfo, const char *name)
 
int LsFile (const char *path)
 
int LsDir (const char *path)
 
void ls (const char *pathname)
 list directory contents. 更多...
 
char * realpath (const char *path, char *resolved_path)
 
void lsfd (void)
 查看FD 更多...
 
mode_t GetUmask (void)
 获取用户创建文件掩码 更多...
 
mode_t SysUmask (mode_t mask)
 给当前进程设置系统创建文件掩码,并返回进程旧掩码 更多...
 

函数说明

◆ access()

int access ( const char *  path,
int  amode 
)

在文件 vfs_other.c293 行定义.

294{
295 int ret;
296 struct stat buf;
297 struct statfs fsBuf;
298
299 ret = statfs(path, &fsBuf);
300 if (ret != 0) {
301 if (get_errno() != ENOSYS) {
302 return VFS_ERROR;
303 }
304 /* dev has no statfs ops, need devfs to handle this in feature */
305 }
306
307 if ((fsBuf.f_flags & MS_RDONLY) && ((unsigned int)amode & W_OK)) {
308 set_errno(EROFS);
309 return VFS_ERROR;
310 }
311
312 ret = stat(path, &buf);
313 if (ret != 0) {
314 return VFS_ERROR;
315 }
316
317 if (VfsPermissionCheck(buf.st_uid, buf.st_gid, buf.st_mode, amode)) {
318 set_errno(EACCES);
319 return VFS_ERROR;
320 }
321
322 return OK;
323}
int VfsPermissionCheck(uint fuid, uint fgid, uint fileMode, int accMode)
Definition: vfs_other.c:87
函数调用图:
这是这个函数的调用关系图:

◆ alphasort()

int alphasort ( const struct dirent **  a,
const struct dirent **  b 
)

在文件 vfs_other.c427 行定义.

428{
429 return strcoll((*a)->d_name, (*b)->d_name);
430}

◆ chdir()

int chdir ( const char *  path)

在文件 vfs_other.c150 行定义.

151{
152 int ret;
153 char *fullpath = NULL;
154 char *fullpath_bak = NULL;
155 struct stat statBuff;
156
157
158 if (!path) {
159 set_errno(EFAULT);
160 return -1;
161 }
162
163 if (!strlen(path)) {
164 set_errno(ENOENT);
165 return -1;
166 }
167
168 if (strlen(path) > PATH_MAX) {
169 set_errno(ENAMETOOLONG);
170 return -1;
171 }
172
173 ret = vfs_normalize_path((const char *)NULL, path, &fullpath);
174 if (ret < 0) {
175 set_errno(-ret);
176 return -1; /* build path failed */
177 }
178 fullpath_bak = fullpath;
179 ret = stat(fullpath, &statBuff);
180 if (ret < 0) {
181 free(fullpath_bak);
182 return -1;
183 }
184
185 if (!S_ISDIR(statBuff.st_mode)) {
186 set_errno(ENOTDIR);
187 free(fullpath_bak);
188 return -1;
189 }
190
191 if (VfsPermissionCheck(statBuff.st_uid, statBuff.st_gid, statBuff.st_mode, EXEC_OP)) {
192 set_errno(EACCES);
193 free(fullpath_bak);
194 return -1;
195 }
196
197#ifdef VFS_USING_WORKDIR
198 ret = SetWorkDir(fullpath, strlen(fullpath));
199 if (ret != 0) {
200 PRINT_ERR("chdir path error!\n");
201 ret = -1;
202 }
203#endif
204
205 /* release normalize directory path name */
206
207 free(fullpath_bak);
208
209 return ret;
210}
int vfs_normalize_path(const char *directory, const char *filename, char **pathname)
Definition: fullpath.c:245
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
static int SetWorkDir(const char *dir, size_t len)
Definition: vfs_other.c:132
函数调用图:
这是这个函数的调用关系图:

◆ chmod()

int chmod ( const char *  path,
mode_t  mode 
)

在文件 vfs_other.c256 行定义.

257{
258 struct IATTR attr = {0};
259 attr.attr_chg_mode = mode;
260 attr.attr_chg_valid = CHG_MODE; /* change mode */
261 int ret;
262
263 ret = chattr(path, &attr);
264 if (ret < 0) {
265 return VFS_ERROR;
266 }
267
268 return OK;
269}
int chattr(const char *pathname, struct IATTR *attr)
Definition: vfs_chattr.c:58
此结构用于记录 vnode 的属性
Definition: vnode.h:81
unsigned attr_chg_mode
确定了文件的类型,以及它的所有者、它的group、其它用户访问此文件的权限 (S_IWUSR | ...)
Definition: vnode.h:85
unsigned int attr_chg_valid
节点改变有效性 (CHG_MODE | CHG_UID | ... )
Definition: vnode.h:83
函数调用图:
这是这个函数的调用关系图:

◆ chown()

int chown ( const char *  pathname,
uid_t  owner,
gid_t  group 
)

在文件 vfs_other.c271 行定义.

272{
273 struct IATTR attr = {0};
274 attr.attr_chg_valid = 0;
275 int ret;
276
277 if (owner != (uid_t)-1) {
278 attr.attr_chg_uid = owner;
279 attr.attr_chg_valid |= CHG_UID;
280 }
281 if (group != (gid_t)-1) {
282 attr.attr_chg_gid = group;
283 attr.attr_chg_valid |= CHG_GID;
284 }
285 ret = chattr(pathname, &attr);
286 if (ret < 0) {
287 return VFS_ERROR;
288 }
289
290 return OK;
291}
unsigned attr_chg_uid
用户ID
Definition: vnode.h:86
unsigned attr_chg_gid
组ID
Definition: vnode.h:87
函数调用图:
这是这个函数的调用关系图:

◆ fstat()

int fstat ( int  fd,
struct stat *  buf 
)

在文件 vfs_other.c51 行定义.

52{
53 struct file *filep = NULL;
54
55 int ret = fs_getfilep(fd, &filep);
56 if (ret < 0) {
57 return VFS_ERROR;
58 }
59
60 return stat(filep->f_path, buf);//统计
61}
char * f_path

◆ fstat64()

int fstat64 ( int  fd,
struct stat64 *  buf 
)

在文件 vfs_other.c63 行定义.

64{
65 struct file *filep = NULL;
66
67 int ret = fs_getfilep(fd, &filep);
68 if (ret < 0) {
69 return VFS_ERROR;
70 }
71
72 return stat64(filep->f_path, buf);
73}
这是这个函数的调用关系图:

◆ getcwd()

char * getcwd ( char *  buf,
size_t  n 
)

this function is a POSIX compliant version, which will return current working directory.

参数
bufthe returned current directory.
sizethe buffer size.
返回
the returned current directory.

在文件 vfs_other.c222 行定义.

223{
224#ifdef VFS_USING_WORKDIR
225 int ret;
226 unsigned int len;
227 UINTPTR lock_flags;
229#endif
230 if (buf == NULL) {
231 set_errno(EINVAL);
232 return buf;
233 }
234#ifdef VFS_USING_WORKDIR
235 spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
236 len = strlen(curr->files->workdir);
237 if (n <= len) {
238 set_errno(ERANGE);
239 spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
240 return NULL;
241 }
242 ret = memcpy_s(buf, n, curr->files->workdir, len + 1);
243 if (ret != EOK) {
244 set_errno(ENAMETOOLONG);
245 spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
246 return NULL;
247 }
248 spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
249#else
250 PRINT_ERR("NO_WORKING_DIR\n");
251#endif
252
253 return buf;
254}
STATIC INLINE LosProcessCB * OsCurrProcessGet(VOID)
unsigned long UINTPTR
Definition: los_typedef.h:68
struct files_struct * files
spinlock_t workdir_lock
工作区目录自旋锁
Definition: fd_table.h:99
char workdir[PATH_MAX]
工作区路径,最大 256个字符
Definition: fd_table.h:100
函数调用图:
这是这个函数的调用关系图:

◆ GetUmask()

mode_t GetUmask ( void  )

获取用户创建文件掩码

在文件 vfs_other.c715 行定义.

716{
717 return OsCurrProcessGet()->umask;
718}
mode_t umask
umask(user file-creatiopn mode mask)为用户文件创建掩码,是创建文件或文件夹时默认权限的基础。
函数调用图:
这是这个函数的调用关系图:

◆ ls()

void ls ( const char *  pathname)

list directory contents.

Description:
List information about the FILEs (the current directory by default).
注意
  • The total length of parameter pathname must be less than the value defined by PATH_MAX.
参数
pathname[IN] Type #const char* The file pathname.
返回值
<ul>None.</ul>
Dependency:
  • fs.h: the header file that contains the API declaration.
参见
ls

在文件 vfs_other.c600 行定义.

601{
602 struct stat statInfo = { 0 };
603 char *path = NULL;
604 int ret;
605
606 if (pathname == NULL) {
607#ifdef VFS_USING_WORKDIR
608 UINTPTR lock_flags;
610
611 /* open current working directory */
612
613 spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
614 path = strdup(curr->files->workdir);
615 spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
616#else
617 path = strdup("/");
618#endif
619 if (path == NULL) {
620 return;
621 }
622 } else {
623 ret = vfs_normalize_path(NULL, pathname, &path);
624 if (ret < 0) {
625 set_errno(-ret);
626 return;
627 }
628 }
629
630 ret = stat(path, &statInfo);
631 if (ret < 0) {
632 perror("ls error");
633 free(path);
634 return;
635 }
636
637 if (statInfo.st_mode & S_IFDIR) { /* list all directory and file */
638 ret = LsDir((pathname == NULL) ? path : pathname);
639 } else { /* show the file infomation */
640 ret = LsFile(path);
641 }
642 if (ret < 0) {
643 perror("ls error");
644 }
645
646 free(path);
647 return;
648}
int LsFile(const char *path)
Definition: vfs_other.c:537
int LsDir(const char *path)
Definition: vfs_other.c:553
函数调用图:

◆ ls_get_fullpath()

static char * ls_get_fullpath ( const char *  path,
struct dirent *  pdirent 
)
static

在文件 vfs_other.c442 行定义.

443{
444 char *fullpath = NULL;
445 int ret;
446
447 if (path[1] != '\0') {
448 /* 2, The position of the path character: / and the end character '/0' */
449 fullpath = (char *)malloc(strlen(path) + strlen(pdirent->d_name) + 2);
450 if (fullpath == NULL) {
451 goto exit_with_nomem;
452 }
453
454 /* 2, The position of the path character: / and the end character '/0' */
455 ret = snprintf_s(fullpath, strlen(path) + strlen(pdirent->d_name) + 2,
456 strlen(path) + strlen(pdirent->d_name) + 1, "%s/%s", path, pdirent->d_name);
457 if (ret < 0) {
458 free(fullpath);
459 set_errno(ENAMETOOLONG);
460 return NULL;
461 }
462 } else {
463 /* 2, The position of the path character: / and the end character '/0' */
464 fullpath = (char *)malloc(strlen(pdirent->d_name) + 2);
465 if (fullpath == NULL) {
466 goto exit_with_nomem;
467 }
468
469 /* 2, The position of the path character: / and the end character '/0' */
470 ret = snprintf_s(fullpath, strlen(pdirent->d_name) + 2, strlen(pdirent->d_name) + 1,
471 "/%s", pdirent->d_name);
472 if (ret < 0) {
473 free(fullpath);
474 set_errno(ENAMETOOLONG);
475 return NULL;
476 }
477 }
478 return fullpath;
479
480exit_with_nomem:
481 set_errno(ENOSPC);
482 return (char *)NULL;
483}
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
函数调用图:
这是这个函数的调用关系图:

◆ LsDir()

int LsDir ( const char *  path)

在文件 vfs_other.c553 行定义.

554{
555 struct stat statInfo = { 0 };
556 struct stat64 stat64Info = { 0 };
557 DIR *d = NULL;
558 char *fullpath = NULL;
559 char *fullpath_bak = NULL;
560 struct dirent *pdirent = NULL;
561
562 d = opendir(path);
563 if (d == NULL) {
564 return -1;
565 }
566
567 PRINTK("Directory %s:\n", path);
568 do {
569 pdirent = readdir(d);
570 if (pdirent == NULL) {
571 break;
572 } else {
573 if (!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, "..")) {
574 continue;
575 }
576 (void)memset_s(&statInfo, sizeof(struct stat), 0, sizeof(struct stat));
577 (void)memset_s(&stat64Info, sizeof(struct stat), 0, sizeof(struct stat));
578 fullpath = ls_get_fullpath(path, pdirent);
579 if (fullpath == NULL) {
580 (void)closedir(d);
581 return -1;
582 }
583
584 fullpath_bak = fullpath;
585 if (stat64(fullpath, &stat64Info) == 0) {
586 PrintFileInfo64(&stat64Info, pdirent->d_name);
587 } else if (stat(fullpath, &statInfo) == 0) {
588 PrintFileInfo(&statInfo, pdirent->d_name);
589 } else {
590 PRINTK("BAD file: %s\n", pdirent->d_name);
591 }
592 free(fullpath_bak);
593 }
594 } while (1);
595 (void)closedir(d);
596
597 return 0;
598}
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
static char * ls_get_fullpath(const char *path, struct dirent *pdirent)
Definition: vfs_other.c:442
static void PrintFileInfo64(const struct stat64 *stat64Info, const char *name)
Definition: vfs_other.c:485
static void PrintFileInfo(const struct stat *statInfo, const char *name)
Definition: vfs_other.c:511
函数调用图:
这是这个函数的调用关系图:

◆ lsfd()

void lsfd ( void  )

查看FD

在文件 vfs_other.c689 行定义.

690{
691 struct filelist *f_list = NULL;
692 unsigned int i = 3; /* file start fd */
693 int ret;
694 struct Vnode *node = NULL;
695
696 f_list = &tg_filelist;
697
698 PRINTK(" fd filename\n");
699 ret = sem_wait(&f_list->fl_sem);
700 if (ret < 0) {
701 PRINTK("sem_wait error, ret=%d\n", ret);
702 return;
703 }
704
705 while (i < CONFIG_NFILE_DESCRIPTORS) {
706 node = files_get_openfile(i);//bitmap对应位 为 1的
707 if (node) {
708 PRINTK("%5d %s\n", i, f_list->fl_files[i].f_path);//打印fd 和 路径
709 }
710 i++;
711 }
712 (void)sem_post(&f_list->fl_sem);
713}
int sem_post(sem_t *sem)
增加信号量计数
Definition: semaphore.c:139
int sem_wait(sem_t *sem)
获取信号量
Definition: semaphore.c:77
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
函数调用图:
这是这个函数的调用关系图:

◆ LsFile()

int LsFile ( const char *  path)

在文件 vfs_other.c537 行定义.

538{
539 struct stat64 stat64Info;
540 struct stat statInfo;
541
542 if (stat64(path, &stat64Info) == 0) {
543 PrintFileInfo64(&stat64Info, path);
544 } else if (stat(path, &statInfo) == 0) {
545 PrintFileInfo(&statInfo, path);
546 } else {
547 return -1;
548 }
549
550 return 0;
551}
函数调用图:
这是这个函数的调用关系图:

◆ lstat()

int lstat ( const char *  path,
struct stat *  buffer 
)

在文件 vfs_other.c75 行定义.

76{
77 return stat(path, buffer);
78}

◆ PrintFileInfo()

static void PrintFileInfo ( const struct stat *  statInfo,
const char *  name 
)
static

在文件 vfs_other.c511 行定义.

512{
513 mode_t mode;
514 char str[UGO_NUMS][UGO_NUMS + 1] = {0};
515 char dirFlag;
516 int i;
517
518 for (i = 0; i < UGO_NUMS; i++) {
519 mode = statInfo->st_mode >> (uint)(USER_MODE_SHIFT - i * UGO_NUMS);
520 str[i][0] = (mode & READ_OP) ? 'r' : '-';
521 str[i][1] = (mode & WRITE_OP) ? 'w' : '-';
522 str[i][UGO_NUMS - 1] = (mode & EXEC_OP) ? 'x' : '-';
523 }
524
525 if (S_ISDIR(statInfo->st_mode)) {
526 dirFlag = 'd';
527 } else if (S_ISLNK(statInfo->st_mode)) {
528 dirFlag = 'l';
529 } else {
530 dirFlag = '-';
531 }
532
533 PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
534 str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size, statInfo->st_uid, statInfo->st_gid, name);
535}
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 mode_t
这是这个函数的调用关系图:

◆ PrintFileInfo64()

static void PrintFileInfo64 ( const struct stat64 *  stat64Info,
const char *  name 
)
static

在文件 vfs_other.c485 行定义.

486{
487 mode_t mode;
488 char str[UGO_NUMS][UGO_NUMS + 1] = {0};
489 char dirFlag;
490 int i;
491
492 for (i = 0; i < UGO_NUMS; i++) {
493 mode = stat64Info->st_mode >> (uint)(USER_MODE_SHIFT - i * UGO_NUMS);
494 str[i][0] = (mode & READ_OP) ? 'r' : '-';
495 str[i][1] = (mode & WRITE_OP) ? 'w' : '-';
496 str[i][UGO_NUMS - 1] = (mode & EXEC_OP) ? 'x' : '-';
497 }
498
499 if (S_ISDIR(stat64Info->st_mode)) {
500 dirFlag = 'd';
501 } else if (S_ISLNK(stat64Info->st_mode)) {
502 dirFlag = 'l';
503 } else {
504 dirFlag = '-';
505 }
506
507 PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
508 str[0], str[1], str[UGO_NUMS - 1], stat64Info->st_size, stat64Info->st_uid, stat64Info->st_gid, name);
509}
这是这个函数的调用关系图:

◆ realpath()

char * realpath ( const char *  path,
char *  resolved_path 
)

在文件 vfs_other.c651 行定义.

652{
653 int ret, result;
654 char *new_path = NULL;
655 struct stat buf;
656
657 ret = vfs_normalize_path(NULL, path, &new_path);
658 if (ret < 0) {
659 ret = -ret;
660 set_errno(ret);
661 return NULL;
662 }
663
664 result = stat(new_path, &buf);//获取统计信息,即属性信息
665
666 if (resolved_path == NULL) {
667 if (result != ENOERR) {
668 free(new_path);
669 return NULL;
670 }
671 return new_path;
672 }
673
674 ret = strcpy_s(resolved_path, PATH_MAX, new_path);
675 if (ret != EOK) {
676 ret = -ret;
677 set_errno(ret);
678 free(new_path);
679 return NULL;
680 }
681
682 free(new_path);
683 if (result != ENOERR) {
684 return NULL;
685 }
686 return resolved_path;
687}
函数调用图:
这是这个函数的调用关系图:

◆ rindex()

char * rindex ( const char *  s,
int  c 
)

locate character in string.

Description:
The API function returns a pointer to the last occurrence of the character c in the string s.
注意
  • The parameter s must point a valid string, which end with the terminating null byte.
参数
s[IN] Type #const char* A pointer to string.
c[IN] Type int The character.
返回值
#char*a pointer to the matched character or NULL if the character is not found.
Dependency:
  • fs.h: the header file that contains the API declaration.
参见
rindex

在文件 vfs_other.c432 行定义.

433{
434 if (s == NULL) {
435 return NULL;
436 }
437
438 /* Don't bother tracing - strrchr can do that */
439 return (char *)strrchr(s, c);
440}

◆ scandir()

int scandir ( const char *  dir,
struct dirent ***  namelist,
int(*)(const struct dirent *)  filter,
int(*)(const struct dirent **, const struct dirent **)  compar 
)

在文件 vfs_other.c391 行定义.

394{
395 int n = 0;
396 struct dirent **list = NULL;
397
398 if ((dir == NULL) || (namelist == NULL)) {
399 return -1;
400 }
401
402 list = scandir_get_file_list(dir, &n, filter);
403 if (list == NULL) {
404 return -1;
405 }
406
407 /* Change to return to the array size */
408 *namelist = (struct dirent **)malloc(n * sizeof(struct dirent *));
409 if (*namelist == NULL && n > 0) {
410 *namelist = list;
411 } else if (*namelist != NULL) {
412 (void)memcpy_s(*namelist, n * sizeof(struct dirent *), list, n * sizeof(struct dirent *));
413 free(list);
414 } else {
415 free(list);
416 }
417
418 /* Sort array */
419
420 if (compar && *namelist) {
421 qsort((void *)*namelist, (size_t)n, sizeof(struct dirent *), (int (*)(const void *, const void *))*compar);
422 }
423
424 return n;
425}
static struct dirent ** scandir_get_file_list(const char *dir, int *num, int(*filter)(const struct dirent *))
Definition: vfs_other.c:325
函数调用图:

◆ scandir_get_file_list()

static struct dirent ** scandir_get_file_list ( const char *  dir,
int num,
int(*)(const struct dirent *)  filter 
)
static

在文件 vfs_other.c325 行定义.

326{
327 DIR *od = NULL;
328 int listSize = MAX_DIR_ENT;
329 int n = 0;
330 struct dirent **list = NULL;
331 struct dirent **newList = NULL;
332 struct dirent *ent = NULL;
333 struct dirent *p = NULL;
334 int err;
335
336 od = opendir(dir);
337 if (od == NULL) {
338 return NULL;
339 }
340
341 list = (struct dirent **)malloc(listSize * sizeof(struct dirent *));
342 if (list == NULL) {
343 (void)closedir(od);
344 return NULL;
345 }
346
347 for (ent = readdir(od); ent != NULL; ent = readdir(od)) {
348 if (filter && !filter(ent)) {
349 continue;
350 }
351
352 if (n == listSize) {
353 listSize += MAX_DIR_ENT;
354 newList = (struct dirent **)malloc(listSize * sizeof(struct dirent *));
355 if (newList == NULL) {
356 break;
357 }
358
359 err = memcpy_s(newList, listSize * sizeof(struct dirent *), list, n * sizeof(struct dirent *));
360 if (err != EOK) {
361 free(newList);
362 break;
363 }
364 free(list);
365 list = newList;
366 }
367
368 p = (struct dirent *)malloc(sizeof(struct dirent));
369 if (p == NULL) {
370 break;
371 }
372
373 (void)memcpy_s((void *)p, sizeof(struct dirent), (void *)ent, sizeof(struct dirent));
374 list[n] = p;
375
376 n++;
377 }
378
379 if (closedir(od) < 0) {
380 while (n--) {
381 free(list[n]);
382 }
383 free(list);
384 return NULL;
385 }
386
387 *num = n;
388 return list;
389}
函数调用图:
这是这个函数的调用关系图:

◆ SetWorkDir()

static int SetWorkDir ( const char *  dir,
size_t  len 
)
static

在文件 vfs_other.c132 行定义.

133{
134 errno_t ret;
135 uint lock_flags;
137
138 spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
139 ret = strncpy_s(curr->files->workdir, PATH_MAX, dir, len);
140 curr->files->workdir[PATH_MAX - 1] = '\0';
141 spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
142 if (ret != EOK) {
143 return -1;
144 }
145
146 return 0;
147}
函数调用图:
这是这个函数的调用关系图:

◆ SysUmask()

mode_t SysUmask ( mode_t  mask)

给当前进程设置系统创建文件掩码,并返回进程旧掩码

在文件 vfs_other.c720 行定义.

721{
722 UINT32 intSave;
723 mode_t umask;
724 mode_t oldUmask;
725 umask = mask & UMASK_FULL;
726 SCHEDULER_LOCK(intSave);
727 oldUmask = OsCurrProcessGet()->umask;
728 OsCurrProcessGet()->umask = umask;
729 SCHEDULER_UNLOCK(intSave);
730 return oldUmask;
731}
unsigned int UINT32
Definition: los_typedef.h:57
函数调用图:

◆ VfsPermissionCheck()

int VfsPermissionCheck ( uint  fuid,
uint  fgid,
uint  fileMode,
int  accMode 
)

在文件 vfs_other.c87 行定义.

88{
89 uint uid = OsCurrUserGet()->effUserID;
90 mode_t tmpMode = fileMode;
91
92 if (uid == fuid) {
93 tmpMode >>= USER_MODE_SHIFT;
94 } else if (LOS_CheckInGroups(fgid)) {
95 tmpMode >>= GROUP_MODE_SHIFT;
96 }
97
98 tmpMode &= (READ_OP | WRITE_OP | EXEC_OP);
99
100 if (((uint)accMode & tmpMode) == accMode) {
101 return 0;
102 }
103
104 tmpMode = 0;
105 if (S_ISDIR(fileMode)) {
106 if (IsCapPermit(CAP_DAC_EXECUTE)
107 || (!((uint)accMode & WRITE_OP) && IsCapPermit(CAP_DAC_READ_SEARCH))) {
108 tmpMode |= EXEC_OP;
109 }
110 } else {
111 if (IsCapPermit(CAP_DAC_EXECUTE) && (fileMode & MODE_IXUGO)) {
112 tmpMode |= EXEC_OP;
113 }
114 }
115
116 if (IsCapPermit(CAP_DAC_WRITE)) {
117 tmpMode |= WRITE_OP;
118 }
119
120 if (IsCapPermit(CAP_DAC_READ_SEARCH)) {
121 tmpMode |= READ_OP;
122 }
123
124 if (((uint)accMode & tmpMode) == accMode) {
125 return 0;
126 }
127
128 return 1;
129}
BOOL IsCapPermit(UINT32 capIndex)
Definition: capability.c:43
LITE_OS_SEC_TEXT BOOL LOS_CheckInGroups(UINT32 gid)
Definition: los_process.c:805
STATIC INLINE User * OsCurrUserGet(VOID)
UINT32 effUserID
函数调用图:
这是这个函数的调用关系图:

◆ VfsVnodePermissionCheck()

int VfsVnodePermissionCheck ( const struct Vnode node,
int  accMode 
)

在文件 vfs_other.c80 行定义.

81{
82 uint fuid = node->uid;
83 uint fgid = node->gid;
84 uint fileMode = node->mode;
85 return VfsPermissionCheck(fuid, fgid, fileMode, accMode);
86}
uint gid
Definition: vnode.h:169
mode_t mode
Definition: vnode.h:170
uint uid
Definition: vnode.h:168
函数调用图:
这是这个函数的调用关系图: