Home | History | Annotate | Download | only in arch-mips
      1 /*
      2  * Copyright 2012, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <portability.h>
     18 #include <unistd.h>
     19 #include <fcntl.h>
     20 
     21 #include <asm/unistd.h>
     22 #include <asm/unistd-portable.h>
     23 
     24 #include <fcntl_portable.h>
     25 #include <inotify_portable.h>
     26 
     27 #include <filefd_portable.h>
     28 
     29 
     30 #define PORTABLE_TAG "inotify_portable"
     31 #include <log_portable.h>
     32 
     33 extern int syscall(int, ...);
     34 
     35 
     36 /*
     37  * NOTE: LTP defaults to using O_CLOEXEC for IN_CLOEXEC,
     38  *       and 02000000 if O_CLOEXEC isn't defined.
     39  */
     40 
     41 
     42 /*
     43  * Portable to Native event flags mapper.
     44  */
     45 static inline int in_flags_pton(int portable_flags)
     46 {
     47     int native_flags = 0;
     48 
     49     ALOGV("%s(portable_flags:0x%x) {", __func__, portable_flags);
     50 
     51     if (portable_flags & IN_NONBLOCK_PORTABLE) {
     52         native_flags |= IN_NONBLOCK;
     53     }
     54 
     55     if (portable_flags & IN_CLOEXEC_PORTABLE) {
     56         native_flags |= IN_CLOEXEC;
     57     }
     58 
     59     ALOGV("%s: return(native_flags:%d); }", __func__, native_flags);
     60     return native_flags;
     61 }
     62 
     63 
     64 int WRAP(inotify_init1)(int portable_flags) {
     65     int rv;
     66     int native_flags;
     67 
     68     ALOGV(" ");
     69     ALOGV("%s(portable_flags:%d) {", __func__,
     70               portable_flags);
     71 
     72     native_flags = in_flags_pton(portable_flags);
     73 
     74     rv = syscall(__NR_inotify_init1, native_flags);
     75     if (rv >= 0) {
     76         if (native_flags & IN_CLOEXEC) {
     77             filefd_CLOEXEC_enabled(rv);
     78         }
     79         filefd_opened(rv, INOTIFY_FD_TYPE);
     80     }
     81 
     82     ALOGV("%s: return(rv:%d); }", __func__, rv);
     83     return rv;
     84 }
     85 
     86