• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "proc_fs.h"
33 
34 #include <stdio.h>
35 #include <sys/mount.h>
36 #include <sys/statfs.h>
37 
38 #include "fs/mount.h"
39 #include "internal.h"
40 
ShowType(const char * devPoint,const char * mountPoint,struct statfs * statBuf,void * arg)41 static int ShowType(const char *devPoint, const char *mountPoint, struct statfs *statBuf, void *arg)
42 {
43     struct SeqBuf *seqBuf = (struct SeqBuf *)arg;
44     char *type = NULL;
45 
46     switch (statBuf->f_type) {
47         case PROCFS_MAGIC:
48             type = "proc";
49             break;
50         case JFFS2_SUPER_MAGIC:
51             type = "jffs2";
52             break;
53         case NFS_SUPER_MAGIC:
54             type = "nfs";
55             break;
56         case TMPFS_MAGIC:
57             type = "tmpfs";
58             break;
59         case MSDOS_SUPER_MAGIC:
60             type = "vfat";
61             break;
62         case ZPFS_MAGIC:
63             type = "zpfs";
64             break;
65         default:
66             return 0;
67     }
68 
69     if (strlen(devPoint) == 0) {
70         (void)LosBufPrintf(seqBuf, "%s %s %s %s %d %d\n", type, mountPoint, type, "()", 0, 0);
71     } else {
72         (void)LosBufPrintf(seqBuf, "%s %s %s %s %d %d\n", devPoint, mountPoint, type, "()", 0, 0);
73     }
74 
75     return 0;
76 }
77 
MountsProcFill(struct SeqBuf * m,void * v)78 static int MountsProcFill(struct SeqBuf *m, void *v)
79 {
80     foreach_mountpoint_t handler = ShowType;
81     (void)foreach_mountpoint(handler, (void *)m);
82 
83     return 0;
84 }
85 
86 static const struct ProcFileOperations MOUNTS_PROC_FOPS = {
87     .read = MountsProcFill,
88 };
89 
ProcMountsInit(void)90 void ProcMountsInit(void)
91 {
92     struct ProcDirEntry *pde = CreateProcEntry("mounts", 0, NULL);
93     if (pde == NULL) {
94         PRINT_ERR("create mounts error!\n");
95         return;
96     }
97 
98     pde->procFileOps = &MOUNTS_PROC_FOPS;
99 }
100 
101