OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "nacl_io/kernel_proxy.h" | 5 #include "nacl_io/kernel_proxy.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <limits.h> | 10 #include <limits.h> |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 errno = error; | 202 errno = error; |
203 return -1; | 203 return -1; |
204 } | 204 } |
205 | 205 |
206 return AllocateFD(handle, path); | 206 return AllocateFD(handle, path); |
207 } | 207 } |
208 | 208 |
209 int KernelProxy::open(const char* path, int open_flags, mode_t mode) { | 209 int KernelProxy::open(const char* path, int open_flags, mode_t mode) { |
210 ScopedFilesystem fs; | 210 ScopedFilesystem fs; |
211 ScopedNode node; | 211 ScopedNode node; |
212 mode_t mask = ~GetUmask(); | 212 mode_t mask = ~GetUmask() & 0777; |
213 | 213 |
214 Error error = AcquireFsAndNode(path, open_flags, mode & mask, &fs, &node); | 214 Error error = AcquireFsAndNode(path, open_flags, mode & mask, &fs, &node); |
215 if (error) { | 215 if (error) { |
216 errno = error; | 216 errno = error; |
217 return -1; | 217 return -1; |
218 } | 218 } |
219 | 219 |
220 ScopedKernelHandle handle(new KernelHandle(fs, node)); | 220 ScopedKernelHandle handle(new KernelHandle(fs, node)); |
221 error = handle->Init(open_flags); | 221 error = handle->Init(open_flags); |
222 if (error) { | 222 if (error) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 int KernelProxy::mkdir(const char* path, mode_t mode) { | 365 int KernelProxy::mkdir(const char* path, mode_t mode) { |
366 ScopedFilesystem fs; | 366 ScopedFilesystem fs; |
367 Path rel; | 367 Path rel; |
368 | 368 |
369 Error error = AcquireFsAndRelPath(path, &fs, &rel); | 369 Error error = AcquireFsAndRelPath(path, &fs, &rel); |
370 if (error) { | 370 if (error) { |
371 errno = error; | 371 errno = error; |
372 return -1; | 372 return -1; |
373 } | 373 } |
374 | 374 |
375 error = fs->Mkdir(rel, mode & ~GetUmask()); | 375 mode_t mask = ~GetUmask() & 0777; |
| 376 error = fs->Mkdir(rel, mode & mask); |
376 if (error) { | 377 if (error) { |
377 errno = error; | 378 errno = error; |
378 return -1; | 379 return -1; |
379 } | 380 } |
380 | 381 |
381 return 0; | 382 return 0; |
382 } | 383 } |
383 | 384 |
384 int KernelProxy::rmdir(const char* path) { | 385 int KernelProxy::rmdir(const char* path) { |
385 ScopedFilesystem fs; | 386 ScopedFilesystem fs; |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 int KernelProxy::truncate(const char* path, off_t len) { | 786 int KernelProxy::truncate(const char* path, off_t len) { |
786 ScopedFilesystem fs; | 787 ScopedFilesystem fs; |
787 ScopedNode node; | 788 ScopedNode node; |
788 | 789 |
789 Error error = AcquireFsAndNode(path, O_WRONLY, 0, &fs, &node); | 790 Error error = AcquireFsAndNode(path, O_WRONLY, 0, &fs, &node); |
790 if (error) { | 791 if (error) { |
791 errno = error; | 792 errno = error; |
792 return -1; | 793 return -1; |
793 } | 794 } |
794 | 795 |
| 796 // Directories cannot be truncated. |
| 797 if (node->IsaDir()) { |
| 798 return EISDIR; |
| 799 } |
| 800 |
795 if (!node->CanOpen(O_WRONLY)) { | 801 if (!node->CanOpen(O_WRONLY)) { |
796 errno = EACCES; | 802 errno = EACCES; |
797 return -1; | 803 return -1; |
798 } | 804 } |
799 | 805 |
800 error = node->FTruncate(len); | 806 error = node->FTruncate(len); |
801 if (error) { | 807 if (error) { |
802 errno = error; | 808 errno = error; |
803 return -1; | 809 return -1; |
804 } | 810 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 } | 872 } |
867 | 873 |
868 int KernelProxy::fchmod(int fd, mode_t mode) { | 874 int KernelProxy::fchmod(int fd, mode_t mode) { |
869 ScopedKernelHandle handle; | 875 ScopedKernelHandle handle; |
870 Error error = AcquireHandle(fd, &handle); | 876 Error error = AcquireHandle(fd, &handle); |
871 if (error) { | 877 if (error) { |
872 errno = error; | 878 errno = error; |
873 return -1; | 879 return -1; |
874 } | 880 } |
875 | 881 |
876 error = handle->node()->Fchmod(mode); | 882 error = handle->node()->Fchmod(mode & 0777); |
877 if (error) { | 883 if (error) { |
878 errno = error; | 884 errno = error; |
879 return -1; | 885 return -1; |
880 } | 886 } |
881 | 887 |
882 return 0; | 888 return 0; |
883 } | 889 } |
884 | 890 |
885 int KernelProxy::fcntl(int fd, int request, va_list args) { | 891 int KernelProxy::fcntl(int fd, int request, va_list args) { |
886 Error error = 0; | 892 Error error = 0; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 errno = EINVAL; | 1183 errno = EINVAL; |
1178 return -1; | 1184 return -1; |
1179 } | 1185 } |
1180 | 1186 |
1181 // Unknown signum | 1187 // Unknown signum |
1182 errno = EINVAL; | 1188 errno = EINVAL; |
1183 return -1; | 1189 return -1; |
1184 } | 1190 } |
1185 | 1191 |
1186 mode_t KernelProxy::umask(mode_t mask) { | 1192 mode_t KernelProxy::umask(mode_t mask) { |
1187 return SetUmask(mask); | 1193 return SetUmask(mask & 0777); |
1188 } | 1194 } |
1189 | 1195 |
1190 #ifdef PROVIDES_SOCKET_API | 1196 #ifdef PROVIDES_SOCKET_API |
1191 | 1197 |
1192 int KernelProxy::select(int nfds, | 1198 int KernelProxy::select(int nfds, |
1193 fd_set* readfds, | 1199 fd_set* readfds, |
1194 fd_set* writefds, | 1200 fd_set* writefds, |
1195 fd_set* exceptfds, | 1201 fd_set* exceptfds, |
1196 struct timeval* timeout) { | 1202 struct timeval* timeout) { |
1197 std::vector<pollfd> pollfds; | 1203 std::vector<pollfd> pollfds; |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1812 errno = ENOTSOCK; | 1818 errno = ENOTSOCK; |
1813 return -1; | 1819 return -1; |
1814 } | 1820 } |
1815 | 1821 |
1816 return 0; | 1822 return 0; |
1817 } | 1823 } |
1818 | 1824 |
1819 #endif // PROVIDES_SOCKET_API | 1825 #endif // PROVIDES_SOCKET_API |
1820 | 1826 |
1821 } // namespace_nacl_io | 1827 } // namespace_nacl_io |
OLD | NEW |