nxt_fs.c (1580:f1aefdf995d4) nxt_fs.c (1673:883f2f79c2f6)
1/*
2 * Copyright (C) NGINX, Inc.
3 */
4
5#include <nxt_main.h>
6
7#if (NXT_HAVE_FREEBSD_NMOUNT)
8#include <sys/param.h>

--- 4 unchanged lines hidden (view full) ---

13static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode);
14
15
16#if (NXT_HAVE_LINUX_MOUNT)
17
18nxt_int_t
19nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt)
20{
1/*
2 * Copyright (C) NGINX, Inc.
3 */
4
5#include <nxt_main.h>
6
7#if (NXT_HAVE_FREEBSD_NMOUNT)
8#include <sys/param.h>

--- 4 unchanged lines hidden (view full) ---

13static nxt_int_t nxt_fs_mkdir(const u_char *dir, mode_t mode);
14
15
16#if (NXT_HAVE_LINUX_MOUNT)
17
18nxt_int_t
19nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt)
20{
21 int rc;
21 int rc;
22 const char *fsname;
23 unsigned long flags;
22
24
23 rc = mount((const char *) mnt->src, (const char *) mnt->dst,
24 (const char *) mnt->fstype, mnt->flags, mnt->data);
25 flags = 0;
25
26
27 switch (mnt->type) {
28 case NXT_FS_BIND:
29 if (nxt_slow_path(mnt->flags != 0)) {
30 nxt_log(task, NXT_LOG_WARN,
31 "bind mount ignores additional flags");
32 }
33
34 fsname = "bind";
35 flags = MS_BIND | MS_REC;
36 break;
37
38 case NXT_FS_PROC:
39 fsname = "proc";
40 goto getflags;
41
42 case NXT_FS_TMP:
43 fsname = "tmpfs";
44 goto getflags;
45
46 default:
47 fsname = (const char *) mnt->name;
48
49 getflags:
50
51 if (mnt->flags & NXT_FS_FLAGS_NODEV) {
52 flags |= MS_NODEV;
53 }
54
55 if (mnt->flags & NXT_FS_FLAGS_NOEXEC) {
56 flags |= MS_NOEXEC;
57 }
58
59 if (mnt->flags & NXT_FS_FLAGS_NOSUID) {
60 flags |= MS_NOSUID;
61 }
62
63 if (!(mnt->flags & NXT_FS_FLAGS_NOTIME)) {
64 flags |= MS_RELATIME;
65 }
66 }
67
68 rc = mount((const char *) mnt->src, (const char *) mnt->dst, fsname, flags,
69 mnt->data);
70
26 if (nxt_slow_path(rc < 0)) {
71 if (nxt_slow_path(rc < 0)) {
27 nxt_alert(task, "mount(\"%s\", \"%s\", \"%s\", %d, \"%s\") %E",
28 mnt->src, mnt->dst, mnt->fstype, mnt->flags, mnt->data,
29 nxt_errno);
72 nxt_alert(task, "mount(\"%s\", \"%s\", \"%s\", %ul, \"%s\") %E",
73 mnt->src, mnt->dst, fsname, flags, mnt->data, nxt_errno);
30
31 return NXT_ERROR;
32 }
33
34 return NXT_OK;
35}
36
74
75 return NXT_ERROR;
76 }
77
78 return NXT_OK;
79}
80
37
38#elif (NXT_HAVE_FREEBSD_NMOUNT)
39
40nxt_int_t
41nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt)
42{
81#elif (NXT_HAVE_FREEBSD_NMOUNT)
82
83nxt_int_t
84nxt_fs_mount(nxt_task_t *task, nxt_fs_mount_t *mnt)
85{
86 int flags;
43 u_char *data, *p, *end;
44 size_t iovlen;
45 nxt_int_t ret;
87 u_char *data, *p, *end;
88 size_t iovlen;
89 nxt_int_t ret;
46 const char *fstype;
90 const char *fsname;
47 struct iovec iov[128];
48 char errmsg[256];
49
91 struct iovec iov[128];
92 char errmsg[256];
93
50 if (nxt_strncmp(mnt->fstype, "bind", 4) == 0) {
51 fstype = "nullfs";
94 if (nxt_slow_path((mnt->flags & NXT_FS_FLAGS_NODEV) && !mnt->builtin)) {
95 nxt_alert(task, "nmount(2) doesn't support \"nodev\" option");
52
96
53 } else if (nxt_strncmp(mnt->fstype, "proc", 4) == 0) {
54 fstype = "procfs";
97 return NXT_ERROR;
98 }
55
99
56 } else if (nxt_strncmp(mnt->fstype, "tmpfs", 5) == 0) {
57 fstype = "tmpfs";
100 flags = 0;
58
101
59 } else {
60 nxt_alert(task, "mount type \"%s\" not implemented.", mnt->fstype);
61 return NXT_ERROR;
102 switch (mnt->type) {
103 case NXT_FS_BIND:
104 fsname = "nullfs";
105 break;
106
107 case NXT_FS_PROC:
108 fsname = "procfs";
109 goto getflags;
110
111 case NXT_FS_TMP:
112 fsname = "tmpfs";
113 goto getflags;
114
115 default:
116 fsname = (const char *) mnt->name;
117
118 getflags:
119
120 if (mnt->flags & NXT_FS_FLAGS_NOEXEC) {
121 flags |= MNT_NOEXEC;
122 }
123
124 if (mnt->flags & NXT_FS_FLAGS_NOSUID) {
125 flags |= MNT_NOSUID;
126 }
127
128 if (mnt->flags & NXT_FS_FLAGS_NOTIME) {
129 flags |= MNT_NOATIME;
130 }
131
132 if (mnt->flags & NXT_FS_FLAGS_RDONLY) {
133 flags |= MNT_RDONLY;
134 }
62 }
63
64 iov[0].iov_base = (void *) "fstype";
65 iov[0].iov_len = 7;
135 }
136
137 iov[0].iov_base = (void *) "fstype";
138 iov[0].iov_len = 7;
66 iov[1].iov_base = (void *) fstype;
67 iov[1].iov_len = nxt_strlen(fstype) + 1;
139 iov[1].iov_base = (void *) fsname;
140 iov[1].iov_len = nxt_strlen(fsname) + 1;
68 iov[2].iov_base = (void *) "fspath";
69 iov[2].iov_len = 7;
70 iov[3].iov_base = (void *) mnt->dst;
71 iov[3].iov_len = nxt_strlen(mnt->dst) + 1;
72 iov[4].iov_base = (void *) "target";
73 iov[4].iov_len = 7;
74 iov[5].iov_base = (void *) mnt->src;
75 iov[5].iov_len = nxt_strlen(mnt->src) + 1;

--- 36 unchanged lines hidden (view full) ---

112 iov[iovlen++].iov_base = (void *) p;
113 iov[iovlen++].iov_len = nxt_strlen(p) + 1;
114
115 } while (end != NULL && nxt_nitems(iov) > (iovlen + 2));
116 }
117
118 ret = NXT_OK;
119
141 iov[2].iov_base = (void *) "fspath";
142 iov[2].iov_len = 7;
143 iov[3].iov_base = (void *) mnt->dst;
144 iov[3].iov_len = nxt_strlen(mnt->dst) + 1;
145 iov[4].iov_base = (void *) "target";
146 iov[4].iov_len = 7;
147 iov[5].iov_base = (void *) mnt->src;
148 iov[5].iov_len = nxt_strlen(mnt->src) + 1;

--- 36 unchanged lines hidden (view full) ---

185 iov[iovlen++].iov_base = (void *) p;
186 iov[iovlen++].iov_len = nxt_strlen(p) + 1;
187
188 } while (end != NULL && nxt_nitems(iov) > (iovlen + 2));
189 }
190
191 ret = NXT_OK;
192
120 if (nxt_slow_path(nmount(iov, iovlen, 0) < 0)) {
193 if (nxt_slow_path(nmount(iov, iovlen, flags) < 0)) {
121 nxt_alert(task, "nmount(%p, %d, 0) %s", iov, iovlen, errmsg);
122 ret = NXT_ERROR;
123 }
124
125 if (data != NULL) {
126 free(data);
127 }
128

--- 79 unchanged lines hidden ---
194 nxt_alert(task, "nmount(%p, %d, 0) %s", iov, iovlen, errmsg);
195 ret = NXT_ERROR;
196 }
197
198 if (data != NULL) {
199 free(data);
200 }
201

--- 79 unchanged lines hidden ---