Lines 18-23
Link Here
|
18 |
#include <fcntl.h> |
18 |
#include <fcntl.h> |
19 |
|
19 |
|
20 |
#include "nfslib.h" |
20 |
#include "nfslib.h" |
|
|
21 |
#include "misc.h" |
21 |
|
22 |
|
22 |
/* if /proc/net/rpc/... exists, then |
23 |
/* if /proc/net/rpc/... exists, then |
23 |
* write to it, as that interface is more stable. |
24 |
* write to it, as that interface is more stable. |
Lines 32-93
Link Here
|
32 |
static int |
33 |
static int |
33 |
exp_unexp(struct nfsctl_export *exp, int export) |
34 |
exp_unexp(struct nfsctl_export *exp, int export) |
34 |
{ |
35 |
{ |
35 |
FILE *f; |
36 |
char buf[RPC_CHAN_BUF_SIZE], *bp; |
36 |
struct stat stb; |
37 |
struct stat stb; |
37 |
__u32 fsid; |
38 |
__u32 fsid; |
38 |
char fsidstr[8]; |
39 |
char fsidstr[8]; |
39 |
__u16 dev; |
40 |
__u16 dev; |
40 |
__u32 inode; |
41 |
__u32 inode; |
41 |
int err; |
42 |
int err = 0, f, blen; |
42 |
|
43 |
|
|
|
44 |
f = open("/proc/net/rpc/nfsd.export/channel", O_WRONLY); |
45 |
if (f < 0) return -1; |
43 |
|
46 |
|
44 |
f = fopen("/proc/net/rpc/nfsd.export/channel", "w"); |
47 |
bp = buf; blen = sizeof(buf); |
45 |
if (f == NULL) return -1; |
48 |
qword_add(&bp, &blen, exp->ex_client); |
46 |
qword_print(f, exp->ex_client); |
49 |
qword_add(&bp, &blen, exp->ex_path); |
47 |
qword_print(f, exp->ex_path); |
|
|
48 |
if (export) { |
50 |
if (export) { |
49 |
qword_printint(f, 0x7fffffff); |
51 |
qword_addint(&bp, &blen, 0x7fffffff); |
50 |
qword_printint(f, exp->ex_flags); |
52 |
qword_addint(&bp, &blen, exp->ex_flags); |
51 |
qword_printint(f, exp->ex_anon_uid); |
53 |
qword_addint(&bp, &blen, exp->ex_anon_uid); |
52 |
qword_printint(f, exp->ex_anon_gid); |
54 |
qword_addint(&bp, &blen, exp->ex_anon_gid); |
53 |
qword_printint(f, exp->ex_dev); |
55 |
qword_addint(&bp, &blen, exp->ex_dev); |
54 |
} else |
56 |
} else |
55 |
qword_printint(f, 1); |
57 |
qword_addint(&bp, &blen, 1); |
56 |
|
58 |
qword_addeol(&bp, &blen); |
57 |
err = qword_eol(f); |
59 |
if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) |
58 |
fclose(f); |
60 |
err = -1; |
|
|
61 |
close(f); |
59 |
|
62 |
|
60 |
if (stat(exp->ex_path, &stb) != 0) |
63 |
if (stat(exp->ex_path, &stb) != 0) |
61 |
return -1; |
64 |
return -1; |
62 |
f = fopen("/proc/net/rpc/nfsd.fh/channel", "w"); |
65 |
|
63 |
if (f==NULL) return -1; |
66 |
f = open("/proc/net/rpc/nfsd.fh/channel", O_WRONLY); |
|
|
67 |
if (f < 0) return -1; |
64 |
if (exp->ex_flags & NFSEXP_FSID) { |
68 |
if (exp->ex_flags & NFSEXP_FSID) { |
65 |
qword_print(f,exp->ex_client); |
69 |
bp = buf; blen = sizeof(buf); |
66 |
qword_printint(f,1); |
70 |
qword_add(&bp, &blen, exp->ex_client); |
|
|
71 |
qword_addint(&bp, &blen, 1); |
67 |
fsid = exp->ex_dev; |
72 |
fsid = exp->ex_dev; |
68 |
qword_printhex(f, (char*)&fsid, 4); |
73 |
qword_addhex(&bp, &blen, (char*)&fsid, 4); |
69 |
if (export) { |
74 |
if (export) { |
70 |
qword_printint(f, 0x7fffffff); |
75 |
qword_addint(&bp, &blen, 0x7fffffff); |
71 |
qword_print(f, exp->ex_path); |
76 |
qword_add(&bp, &blen, exp->ex_path); |
72 |
} else |
77 |
} else |
73 |
qword_printint(f, 1); |
78 |
qword_addint(&bp, &blen, 1); |
74 |
|
79 |
qword_addeol(&bp, &blen); |
75 |
err = qword_eol(f) || err; |
80 |
if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) |
|
|
81 |
err = -1; |
76 |
} |
82 |
} |
77 |
qword_print(f,exp->ex_client); |
83 |
|
78 |
qword_printint(f,0); |
84 |
bp = buf; blen = sizeof(buf); |
|
|
85 |
qword_add(&bp, &blen, exp->ex_client); |
86 |
qword_addint(&bp, &blen, 0); |
79 |
dev = htons(major(stb.st_dev)); memcpy(fsidstr, &dev, 2); |
87 |
dev = htons(major(stb.st_dev)); memcpy(fsidstr, &dev, 2); |
80 |
dev = htons(minor(stb.st_dev)); memcpy(fsidstr+2, &dev, 2); |
88 |
dev = htons(minor(stb.st_dev)); memcpy(fsidstr+2, &dev, 2); |
81 |
inode = stb.st_ino; memcpy(fsidstr+4, &inode, 4); |
89 |
inode = stb.st_ino; memcpy(fsidstr+4, &inode, 4); |
82 |
|
90 |
|
83 |
qword_printhex(f, fsidstr, 8); |
91 |
qword_addhex(&bp, &blen, fsidstr, 8); |
84 |
if (export) { |
92 |
if (export) { |
85 |
qword_printint(f, 0x7fffffff); |
93 |
qword_addint(&bp, &blen, 0x7fffffff); |
86 |
qword_print(f, exp->ex_path); |
94 |
qword_add(&bp, &blen, exp->ex_path); |
87 |
} else |
95 |
} else |
88 |
qword_printint(f, 1); |
96 |
qword_addint(&bp, &blen, 1); |
89 |
err = qword_eol(f) || err; |
97 |
qword_addeol(&bp, &blen); |
90 |
fclose(f); |
98 |
if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) |
|
|
99 |
err = -1; |
100 |
close(f); |
101 |
|
91 |
return err; |
102 |
return err; |
92 |
} |
103 |
} |
93 |
|
104 |
|
94 |
- |
|
|