Przeglądaj źródła

split dfs flags

shaojinchun 4 lat temu
rodzic
commit
216d87de49

+ 3 - 3
components/dfs/filesystems/cromfs/dfs_cromfs.c

@@ -929,7 +929,7 @@ static int dfs_cromfs_open(struct dfs_fd *file)
     int is_dir = 0;
     rt_err_t result = RT_EOK;
 
-    if (file->fnode->flags & (O_CREAT | O_WRONLY | O_APPEND | O_TRUNC | O_RDWR))
+    if (file->flags & (O_CREAT | O_WRONLY | O_APPEND | O_TRUNC | O_RDWR))
     {
         return -EINVAL;
     }
@@ -954,7 +954,7 @@ static int dfs_cromfs_open(struct dfs_fd *file)
     /* entry is a directory file type */
     if (is_dir)
     {
-        if (!(file->fnode->flags & O_DIRECTORY))
+        if (!(file->flags & O_DIRECTORY))
         {
             ret = -ENOENT;
             goto end;
@@ -963,7 +963,7 @@ static int dfs_cromfs_open(struct dfs_fd *file)
     else
     {
         /* entry is a file, but open it as a directory */
-        if (file->fnode->flags & O_DIRECTORY)
+        if (file->flags & O_DIRECTORY)
         {
             ret = -ENOENT;
             goto end;

+ 1 - 1
components/dfs/filesystems/devfs/devfs.c

@@ -127,7 +127,7 @@ int dfs_device_fs_open(struct dfs_fd *file)
 
     /* open root directory */
     if ((file->fnode->path[0] == '/') && (file->fnode->path[1] == '\0') &&
-        (file->fnode->flags & O_DIRECTORY))
+        (file->flags & O_DIRECTORY))
     {
         struct rt_object *object;
         struct rt_list_node *node;

+ 8 - 8
components/dfs/filesystems/elmfat/dfs_elm.c

@@ -351,11 +351,11 @@ int dfs_elm_open(struct dfs_fd *file)
     drivers_fn = file->fnode->path;
 #endif
 
-    if (file->fnode->flags & O_DIRECTORY)
+    if (file->flags & O_DIRECTORY)
     {
         DIR *dir;
 
-        if (file->fnode->flags & O_CREAT)
+        if (file->flags & O_CREAT)
         {
             result = f_mkdir(drivers_fn);
             if (result != FR_OK)
@@ -394,26 +394,26 @@ int dfs_elm_open(struct dfs_fd *file)
     {
         mode = FA_READ;
 
-        if (file->fnode->flags & O_WRONLY)
+        if (file->flags & O_WRONLY)
         {
             mode |= FA_WRITE;
         }
-        if ((file->fnode->flags & O_ACCMODE) & O_RDWR)
+        if ((file->flags & O_ACCMODE) & O_RDWR)
         {
             mode |= FA_WRITE;
         }
         /* Opens the file, if it is existing. If not, a new file is created. */
-        if (file->fnode->flags & O_CREAT)
+        if (file->flags & O_CREAT)
         {
             mode |= FA_OPEN_ALWAYS;
         }
         /* Creates a new file. If the file is existing, it is truncated and overwritten. */
-        if (file->fnode->flags & O_TRUNC)
+        if (file->flags & O_TRUNC)
         {
             mode |= FA_CREATE_ALWAYS;
         }
         /* Creates a new file. The function fails if the file is already existing. */
-        if (file->fnode->flags & O_EXCL)
+        if (file->flags & O_EXCL)
         {
             mode |= FA_CREATE_NEW;
         }
@@ -438,7 +438,7 @@ int dfs_elm_open(struct dfs_fd *file)
             file->fnode->size = f_size(fd);
             file->data = fd;
 
-            if (file->fnode->flags & O_APPEND)
+            if (file->flags & O_APPEND)
             {
                 /* seek to the end of file */
                 f_lseek(fd, f_size(fd));

+ 2 - 2
components/dfs/filesystems/jffs2/dfs_jffs2.c

@@ -223,7 +223,7 @@ static int dfs_jffs2_open(struct dfs_fd* file)
     struct dfs_filesystem *fs;
     struct cyg_mtab_entry * mte;
 
-    oflag = file->fnode->flags;
+    oflag = file->flags;
     fs = file->fnode->fs;
     RT_ASSERT(fs != RT_NULL);
 
@@ -330,7 +330,7 @@ static int dfs_jffs2_close(struct dfs_fd* file)
     RT_ASSERT(file->fnode->data != NULL);
     jffs2_file = (cyg_file *)(file->fnode->data);
 
-    if (file->fnode->flags & O_DIRECTORY) /* operations about dir */
+    if (file->flags & O_DIRECTORY) /* operations about dir */
     {
         rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
         result = jffs2_dir_colse(jffs2_file);

+ 13 - 5
components/dfs/filesystems/nfs/dfs_nfs.c

@@ -747,19 +747,25 @@ int nfs_open(struct dfs_fd *file)
     nfs = (struct nfs_filesystem *)(dfs_nfs->data);
     RT_ASSERT(nfs != NULL);
 
-    if (file->fnode->flags & O_DIRECTORY)
+    if (file->flags & O_DIRECTORY)
     {
         nfs_dir *dir;
 
-        if (file->fnode->flags & O_CREAT)
+        if (file->flags & O_CREAT)
         {
             if (nfs_mkdir(nfs, file->fnode->path, 0755) < 0)
+            {
                 return -EAGAIN;
+            }
         }
 
         /* open directory */
         dir = nfs_opendir(nfs, file->fnode->path);
-        if (dir == NULL) return -ENOENT;
+        if (dir == NULL)
+        {
+            return -ENOENT;
+        }
+        file->fnode->type = FT_DIRECTORY;
         nfs->data = dir;
     }
     else
@@ -768,10 +774,12 @@ int nfs_open(struct dfs_fd *file)
         nfs_fh3 *handle;
 
         /* create file */
-        if (file->fnode->flags & O_CREAT)
+        if (file->flags & O_CREAT)
         {
             if (nfs_create(nfs, file->fnode->path, 0664) < 0)
+            {
                 return -EAGAIN;
+            }
         }
 
         /* open file (get file handle ) */
@@ -796,7 +804,7 @@ int nfs_open(struct dfs_fd *file)
         xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle);
         rt_free(handle);
 
-        if (file->fnode->flags & O_APPEND)
+        if (file->flags & O_APPEND)
         {
             fp->offset = fp->size;
         }

+ 12 - 6
components/dfs/filesystems/ramfs/dfs_ramfs.c

@@ -182,9 +182,9 @@ int dfs_ramfs_open(struct dfs_fd *file)
     ramfs = (struct dfs_ramfs *)fs->data;
     RT_ASSERT(ramfs != NULL);
 
-    if (file->fnode->flags & O_DIRECTORY)
+    if (file->flags & O_DIRECTORY)
     {
-        if (file->fnode->flags & O_CREAT)
+        if (file->flags & O_CREAT)
         {
             return -ENOSPC;
         }
@@ -195,7 +195,7 @@ int dfs_ramfs_open(struct dfs_fd *file)
             return -ENOENT;
         if (dirent == &(ramfs->root)) /* it's root directory */
         {
-            if (!(file->fnode->flags & O_DIRECTORY))
+            if (!(file->flags & O_DIRECTORY))
             {
                 return -ENOENT;
             }
@@ -211,7 +211,7 @@ int dfs_ramfs_open(struct dfs_fd *file)
 
         if (dirent == NULL)
         {
-            if (file->fnode->flags & O_CREAT || file->fnode->flags & O_WRONLY)
+            if (file->flags & O_CREAT || file->flags & O_WRONLY)
             {
                 char *name_ptr;
 
@@ -227,7 +227,9 @@ int dfs_ramfs_open(struct dfs_fd *file)
                 /* remove '/' separator */
                 name_ptr = file->fnode->path;
                 while (*name_ptr == '/' && *name_ptr)
+                {
                     name_ptr++;
+                }
                 strncpy(dirent->name, name_ptr, RAMFS_NAME_MAX);
 
                 rt_list_init(&(dirent->list));
@@ -245,7 +247,7 @@ int dfs_ramfs_open(struct dfs_fd *file)
         /* Creates a new file.
          * If the file is existing, it is truncated and overwritten.
          */
-        if (file->fnode->flags & O_TRUNC)
+        if (file->flags & O_TRUNC)
         {
             dirent->size = 0;
             if (dirent->data != NULL)
@@ -258,10 +260,14 @@ int dfs_ramfs_open(struct dfs_fd *file)
 
     file->fnode->data = dirent;
     file->fnode->size = dirent->size;
-    if (file->fnode->flags & O_APPEND)
+    if (file->flags & O_APPEND)
+    {
         file->pos = file->fnode->size;
+    }
     else
+    {
         file->pos = 0;
+    }
 
     return 0;
 }

+ 27 - 3
components/dfs/filesystems/romfs/dfs_romfs.c

@@ -165,6 +165,10 @@ int dfs_romfs_lseek(struct dfs_fd *file, off_t offset)
 
 int dfs_romfs_close(struct dfs_fd *file)
 {
+    if (file->fnode->ref_count > 1)
+    {
+        return RT_EOK;
+    }
     file->fnode->data = NULL;
     return RT_EOK;
 }
@@ -176,30 +180,44 @@ int dfs_romfs_open(struct dfs_fd *file)
     struct romfs_dirent *root_dirent;
     struct dfs_filesystem *fs;
 
+    if (file->fnode->ref_count > 1)
+    {
+        return RT_EOK;
+    }
     fs = file->fnode->fs;
     root_dirent = (struct romfs_dirent *)fs->data;
 
     if (check_dirent(root_dirent) != 0)
+    {
         return -EIO;
+    }
 
-    if (file->fnode->flags & (O_CREAT | O_WRONLY | O_APPEND | O_TRUNC | O_RDWR))
+    if (file->flags & (O_CREAT | O_WRONLY | O_APPEND | O_TRUNC | O_RDWR))
+    {
         return -EINVAL;
+    }
 
     dirent = dfs_romfs_lookup(root_dirent, file->fnode->path, &size);
     if (dirent == NULL)
+    {
         return -ENOENT;
+    }
 
     /* entry is a directory file type */
     if (dirent->type == ROMFS_DIRENT_DIR)
     {
-        if (!(file->fnode->flags & O_DIRECTORY))
+        if (!(file->flags & O_DIRECTORY))
+        {
             return -ENOENT;
+        }
     }
     else
     {
         /* entry is a file, but open it as a directory */
-        if (file->fnode->flags & O_DIRECTORY)
+        if (file->flags & O_DIRECTORY)
+        {
             return -ENOENT;
+        }
     }
 
     file->fnode->data = dirent;
@@ -219,7 +237,9 @@ int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
     dirent = dfs_romfs_lookup(root_dirent, path, &size);
 
     if (dirent == NULL)
+    {
         return -ENOENT;
+    }
 
     st->st_dev = 0;
     st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH |
@@ -246,7 +266,9 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
 
     dirent = (struct romfs_dirent *)file->fnode->data;
     if (check_dirent(dirent) != 0)
+    {
         return -EIO;
+    }
     RT_ASSERT(dirent->type == ROMFS_DIRENT_DIR);
 
     /* enter directory */
@@ -255,7 +277,9 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
     /* make integer count */
     count = (count / sizeof(struct dirent));
     if (count == 0)
+    {
         return -EINVAL;
+    }
 
     index = 0;
     for (index = 0; index < count && file->pos < file->fnode->size; index++)

+ 2 - 2
components/dfs/filesystems/uffs/dfs_uffs.c

@@ -281,7 +281,7 @@ static int dfs_uffs_open(struct dfs_fd *file)
     int oflag, mode;
     char *file_path;
 
-    oflag = file->fnode->flags;
+    oflag = file->flags;
     if (oflag & O_DIRECTORY)   /* operations about dir */
     {
         uffs_DIR *dir;
@@ -356,7 +356,7 @@ static int dfs_uffs_close(struct dfs_fd *file)
     int oflag;
     int fd;
 
-    oflag = file->fnode->flags;
+    oflag = file->flags;
     if (oflag & O_DIRECTORY)
     {
         /* operations about dir */

+ 2 - 1
components/dfs/include/dfs_file.h

@@ -48,8 +48,8 @@ struct dfs_fnode
 
     struct dfs_filesystem *fs;
     const struct dfs_file_ops *fops;
+    uint32_t flags;              /* self flags, is dir etc.. */
 
-    uint32_t flags;              /* Descriptor flags */
     size_t   size;               /* Size in bytes */
     void *data;                  /* Specific file system data */
 };
@@ -57,6 +57,7 @@ struct dfs_fnode
 struct dfs_fd
 {
     uint16_t magic;              /* file descriptor magic number */
+    uint32_t flags;              /* Descriptor flags */
     int ref_count;               /* Descriptor reference count */
     off_t    pos;                /* Current file position */
     struct dfs_fnode *fnode;     /* file node struct */

+ 10 - 8
components/dfs/src/dfs_file.c

@@ -186,7 +186,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
 
         /* initialize the fd item */
         fnode->type  = FT_REGULAR;
-        fnode->flags = flags;
+        fnode->flags = 0;
 
         if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
         {
@@ -224,6 +224,8 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
         rt_list_insert_after(hash_head, &fnode->list);
     }
 
+    fd->flags = flags;
+
     if ((result = fnode->fops->open(fd)) < 0)
     {
         fnode->ref_count--;
@@ -247,11 +249,11 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
         return result;
     }
 
-    fnode->flags |= DFS_F_OPEN;
+    fd->flags |= DFS_F_OPEN;
     if (flags & O_DIRECTORY)
     {
-        fnode->type = FT_DIRECTORY;
-        fnode->flags |= DFS_F_DIRECTORY;
+        fd->fnode->type = FT_DIRECTORY;
+        fd->flags |= DFS_F_DIRECTORY;
     }
     dfs_fm_unlock();
 
@@ -340,15 +342,15 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
         switch (cmd)
         {
         case F_GETFL:
-            return fd->fnode->flags; /* return flags */
+            return fd->flags; /* return flags */
         case F_SETFL:
             {
                 int flags = (int)(rt_base_t)args;
                 int mask  = O_NONBLOCK | O_APPEND;
 
                 flags &= mask;
-                fd->fnode->flags &= ~mask;
-                fd->fnode->flags |= flags;
+                fd->flags &= ~mask;
+                fd->flags |= flags;
             }
             return 0;
         }
@@ -388,7 +390,7 @@ int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len)
 
     if ((result = fd->fnode->fops->read(fd, buf, len)) < 0)
     {
-        fd->fnode->flags |= DFS_F_EOF;
+        fd->flags |= DFS_F_EOF;
     }
 
     return result;

+ 0 - 3
components/drivers/include/ipc/pipe.h

@@ -30,9 +30,6 @@ struct rt_pipe_device
     struct rt_ringbuffer *fifo;
     rt_uint16_t bufsz;
 
-    rt_uint8_t readers;
-    rt_uint8_t writers;
-
     rt_wqueue_t reader_queue;
     rt_wqueue_t writer_queue;
 

+ 11 - 6
components/drivers/serial/serial.c

@@ -68,7 +68,7 @@ static int serial_fops_open(struct dfs_fd *fd)
     device = (rt_device_t)fd->fnode->data;
     RT_ASSERT(device != RT_NULL);
 
-    switch (fd->fnode->flags & O_ACCMODE)
+    switch (fd->flags & O_ACCMODE)
     {
     case O_RDONLY:
         LOG_D("fops open: O_RDONLY!");
@@ -83,14 +83,19 @@ static int serial_fops_open(struct dfs_fd *fd)
         flags = RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_RDWR;
         break;
     default:
-        LOG_E("fops open: unknown mode - %d!", fd->fnode->flags & O_ACCMODE);
+        LOG_E("fops open: unknown mode - %d!", fd->flags & O_ACCMODE);
         break;
     }
 
-    if ((fd->fnode->flags & O_ACCMODE) != O_WRONLY)
+    if ((fd->flags & O_ACCMODE) != O_WRONLY)
+    {
         rt_device_set_rx_indicate(device, serial_fops_rx_ind);
+    }
     ret = rt_device_open(device, flags);
-    if (ret == RT_EOK) return 0;
+    if (ret == RT_EOK)
+    {
+        return 0;
+    }
 
     return ret;
 }
@@ -136,7 +141,7 @@ static int serial_fops_read(struct dfs_fd *fd, void *buf, size_t count)
         size = rt_device_read(device, -1,  buf, count);
         if (size <= 0)
         {
-            if (fd->fnode->flags & O_NONBLOCK)
+            if (fd->flags & O_NONBLOCK)
             {
                 break;
             }
@@ -177,7 +182,7 @@ static int serial_fops_poll(struct dfs_fd *fd, struct rt_pollreq *req)
     serial = (struct rt_serial_device *)device;
 
     /* only support POLLIN */
-    flags = fd->fnode->flags & O_ACCMODE;
+    flags = fd->flags & O_ACCMODE;
     if (flags == O_RDONLY || flags == O_RDWR)
     {
         rt_base_t level;

+ 65 - 120
components/drivers/src/pipe.c

@@ -20,16 +20,17 @@
 static int pipe_fops_open(struct dfs_fd *fd)
 {
     int rc = 0;
-    rt_device_t device;
     rt_pipe_t *pipe;
 
     pipe = (rt_pipe_t *)fd->fnode->data;
-    if (!pipe) return -1;
+    if (!pipe)
+    {
+        return -1;
+    }
 
-    device = &(pipe->parent);
-    rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
+    rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
 
-    if (device->ref_count == 0)
+    if (fd->fnode->ref_count == 1)
     {
         pipe->fifo = rt_ringbuffer_create(pipe->bufsz);
         if (pipe->fifo == RT_NULL)
@@ -39,23 +40,8 @@ static int pipe_fops_open(struct dfs_fd *fd)
         }
     }
 
-    switch (fd->fnode->flags & O_ACCMODE)
-    {
-    case O_RDONLY:
-        pipe->readers++;
-        break;
-    case O_WRONLY:
-        pipe->writers++;
-        break;
-    case O_RDWR:
-        pipe->readers++;
-        pipe->writers++;
-        break;
-    }
-    device->ref_count++;
-
 __exit:
-    rt_mutex_release(&(pipe->lock));
+    rt_mutex_release(&pipe->lock);
 
     return rc;
 }
@@ -66,46 +52,26 @@ static int pipe_fops_close(struct dfs_fd *fd)
     rt_pipe_t *pipe;
 
     pipe = (rt_pipe_t *)fd->fnode->data;
-    if (!pipe) return -1;
-
-    device = &(pipe->parent);
-    rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
-
-    switch (fd->fnode->flags & O_ACCMODE)
+    if (!pipe)
     {
-    case O_RDONLY:
-        pipe->readers--;
-        break;
-    case O_WRONLY:
-        pipe->writers--;
-        break;
-    case O_RDWR:
-        pipe->readers--;
-        pipe->writers--;
-        break;
-    }
-
-    if (pipe->writers == 0)
-    {
-        rt_wqueue_wakeup(&(pipe->reader_queue), (void*)(POLLIN | POLLERR | POLLHUP));
+        return -1;
     }
 
-    if (pipe->readers == 0)
-    {
-        rt_wqueue_wakeup(&(pipe->writer_queue), (void*)(POLLOUT | POLLERR | POLLHUP));
-    }
+    device = &pipe->parent;
+    rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
 
-    if (device->ref_count == 1)
+    if (fd->fnode->ref_count == 1)
     {
         if (pipe->fifo != RT_NULL)
+        {
             rt_ringbuffer_destroy(pipe->fifo);
+        }
         pipe->fifo = RT_NULL;
     }
-    device->ref_count--;
 
-    rt_mutex_release(&(pipe->lock));
+    rt_mutex_release(&pipe->lock);
 
-    if (device->ref_count == 0 && pipe->is_named == RT_FALSE)
+    if (fd->fnode->ref_count == 1 && pipe->is_named == RT_FALSE)
     {
         /* delete the unamed pipe */
         rt_pipe_delete(device->parent.name);
@@ -145,18 +111,10 @@ static int pipe_fops_read(struct dfs_fd *fd, void *buf, size_t count)
     pipe = (rt_pipe_t *)fd->fnode->data;
 
     /* no process has the pipe open for writing, return end-of-file */
-    if (pipe->writers == 0)
-        return 0;
-
-    rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
+    rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
 
     while (1)
     {
-        if (pipe->writers == 0)
-        {
-            goto out;
-        }
-
         len = rt_ringbuffer_get(pipe->fifo, buf, count);
 
         if (len > 0)
@@ -165,21 +123,21 @@ static int pipe_fops_read(struct dfs_fd *fd, void *buf, size_t count)
         }
         else
         {
-            if (fd->fnode->flags & O_NONBLOCK)
+            if (fd->flags & O_NONBLOCK)
             {
                 len = -EAGAIN;
                 goto out;
             }
 
             rt_mutex_release(&pipe->lock);
-            rt_wqueue_wakeup(&(pipe->writer_queue), (void*)POLLOUT);
-            rt_wqueue_wait(&(pipe->reader_queue), 0, -1);
-            rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
+            rt_wqueue_wakeup(&pipe->writer_queue, (void*)POLLOUT);
+            rt_wqueue_wait(&pipe->reader_queue, 0, -1);
+            rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
         }
     }
 
     /* wakeup writer */
-    rt_wqueue_wakeup(&(pipe->writer_queue), (void*)POLLOUT);
+    rt_wqueue_wakeup(&pipe->writer_queue, (void*)POLLOUT);
 
 out:
     rt_mutex_release(&pipe->lock);
@@ -196,27 +154,16 @@ static int pipe_fops_write(struct dfs_fd *fd, const void *buf, size_t count)
 
     pipe = (rt_pipe_t *)fd->fnode->data;
 
-    if (pipe->readers == 0)
-    {
-        ret = -EPIPE;
-        goto out;
-    }
-
     if (count == 0)
+    {
         return 0;
+    }
 
     pbuf = (uint8_t*)buf;
     rt_mutex_take(&pipe->lock, -1);
 
     while (1)
     {
-        if (pipe->readers == 0)
-        {
-            if (ret == 0)
-                ret = -EPIPE;
-            break;
-        }
-
         len = rt_ringbuffer_put(pipe->fifo, pbuf, count - ret);
         ret +=  len;
         pbuf += len;
@@ -228,7 +175,7 @@ static int pipe_fops_write(struct dfs_fd *fd, const void *buf, size_t count)
         }
         else
         {
-            if (fd->fnode->flags & O_NONBLOCK)
+            if (fd->flags & O_NONBLOCK)
             {
                 if (ret == 0)
                 {
@@ -240,19 +187,18 @@ static int pipe_fops_write(struct dfs_fd *fd, const void *buf, size_t count)
         }
 
         rt_mutex_release(&pipe->lock);
-        rt_wqueue_wakeup(&(pipe->reader_queue), (void*)POLLIN);
+        rt_wqueue_wakeup(&pipe->reader_queue, (void*)POLLIN);
         /* pipe full, waiting on suspended write list */
-        rt_wqueue_wait(&(pipe->writer_queue), 0, -1);
+        rt_wqueue_wait(&pipe->writer_queue, 0, -1);
         rt_mutex_take(&pipe->lock, -1);
     }
     rt_mutex_release(&pipe->lock);
 
     if (wakeup)
     {
-        rt_wqueue_wakeup(&(pipe->reader_queue), (void*)POLLIN);
+        rt_wqueue_wakeup(&pipe->reader_queue, (void*)POLLIN);
     }
 
-out:
     return ret;
 }
 
@@ -263,10 +209,10 @@ static int pipe_fops_poll(struct dfs_fd *fd, rt_pollreq_t *req)
     int mode = 0;
     pipe = (rt_pipe_t *)fd->fnode->data;
 
-    rt_poll_add(&(pipe->reader_queue), req);
-    rt_poll_add(&(pipe->writer_queue), req);
+    rt_poll_add(&pipe->reader_queue, req);
+    rt_poll_add(&pipe->writer_queue, req);
 
-    switch (fd->fnode->flags & O_ACCMODE)
+    switch (fd->flags & O_ACCMODE)
     {
     case O_RDONLY:
         mode = 1;
@@ -285,10 +231,6 @@ static int pipe_fops_poll(struct dfs_fd *fd, rt_pollreq_t *req)
         {
             mask |= POLLIN;
         }
-        if (pipe->writers == 0)
-        {
-            mask |= POLLHUP;
-        }
     }
 
     if (mode & 2)
@@ -297,10 +239,6 @@ static int pipe_fops_poll(struct dfs_fd *fd, rt_pollreq_t *req)
         {
             mask |= POLLOUT;
         }
-        if (pipe->readers == 0)
-        {
-            mask |= POLLERR;
-        }
     }
 
     return mask;
@@ -330,8 +268,8 @@ rt_err_t  rt_pipe_open (rt_device_t device, rt_uint16_t oflag)
         ret = -RT_EINVAL;
         goto __exit;
     }
-    
-    rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
+
+    rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
 
     if (pipe->fifo == RT_NULL)
     {
@@ -342,7 +280,7 @@ rt_err_t  rt_pipe_open (rt_device_t device, rt_uint16_t oflag)
         }
     }
 
-    rt_mutex_release(&(pipe->lock));
+    rt_mutex_release(&pipe->lock);
 
 __exit:
     return ret;
@@ -352,16 +290,16 @@ rt_err_t  rt_pipe_close  (rt_device_t device)
 {
     rt_pipe_t *pipe = (rt_pipe_t *)device;
 
-    if (device == RT_NULL) return -RT_EINVAL;
-    rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
-
-    if (device->ref_count == 1)
+    if (device == RT_NULL)
     {
-        rt_ringbuffer_destroy(pipe->fifo);
-        pipe->fifo = RT_NULL;
+        return -RT_EINVAL;
     }
+    rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
 
-    rt_mutex_release(&(pipe->lock));
+    rt_ringbuffer_destroy(pipe->fifo);
+    pipe->fifo = RT_NULL;
+
+    rt_mutex_release(&pipe->lock);
 
     return RT_EOK;
 }
@@ -377,15 +315,21 @@ rt_size_t rt_pipe_read   (rt_device_t device, rt_off_t pos, void *buffer, rt_siz
         rt_set_errno(-EINVAL);
         return 0;
     }
-    if (count == 0) return 0;
+    if (count == 0)
+    {
+        return 0;
+    }
 
     pbuf = (uint8_t*)buffer;
-    rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
+    rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
 
     while (read_bytes < count)
     {
         int len = rt_ringbuffer_get(pipe->fifo, &pbuf[read_bytes], count - read_bytes);
-        if (len <= 0) break;
+        if (len <= 0)
+        {
+            break;
+        }
 
         read_bytes += len;
     }
@@ -405,7 +349,10 @@ rt_size_t rt_pipe_write  (rt_device_t device, rt_off_t pos, const void *buffer,
         rt_set_errno(-EINVAL);
         return 0;
     }
-    if (count == 0) return 0;
+    if (count == 0)
+    {
+        return 0;
+    }
 
     pbuf = (uint8_t*)buffer;
     rt_mutex_take(&pipe->lock, -1);
@@ -413,7 +360,10 @@ rt_size_t rt_pipe_write  (rt_device_t device, rt_off_t pos, const void *buffer,
     while (write_bytes < count)
     {
         int len = rt_ringbuffer_put(pipe->fifo, &pbuf[write_bytes], count - write_bytes);
-        if (len <= 0) break;
+        if (len <= 0)
+        {
+            break;
+        }
 
         write_bytes += len;
     }
@@ -449,14 +399,14 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
 
     rt_memset(pipe, 0, sizeof(rt_pipe_t));
     pipe->is_named = RT_TRUE; /* initialize as a named pipe */
-    rt_mutex_init(&(pipe->lock), name, RT_IPC_FLAG_FIFO);
-    rt_wqueue_init(&(pipe->reader_queue));
-    rt_wqueue_init(&(pipe->writer_queue));
+    rt_mutex_init(&pipe->lock, name, RT_IPC_FLAG_FIFO);
+    rt_wqueue_init(&pipe->reader_queue);
+    rt_wqueue_init(&pipe->writer_queue);
 
     RT_ASSERT(bufsz < 0xFFFF);
     pipe->bufsz = bufsz;
 
-    dev = &(pipe->parent);
+    dev = &pipe->parent;
     dev->type = RT_Device_Class_Pipe;
 #ifdef RT_USING_DEVICE_OPS
     dev->ops         = &pipe_ops;
@@ -472,7 +422,7 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
     dev->rx_indicate = RT_NULL;
     dev->tx_complete = RT_NULL;
 
-    if (rt_device_register(&(pipe->parent), name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE) != 0)
+    if (rt_device_register(&pipe->parent, name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE) != 0)
     {
         rt_free(pipe);
         return RT_NULL;
@@ -496,18 +446,13 @@ int rt_pipe_delete(const char *name)
         {
             rt_pipe_t *pipe;
 
-            if (device->ref_count != 0)
-            {
-                return -RT_EBUSY;
-            }
-
             pipe = (rt_pipe_t *)device;
 
-            rt_mutex_detach(&(pipe->lock));
+            rt_mutex_detach(&pipe->lock);
             rt_device_unregister(device);
 
             /* close fifo ringbuffer */
-            if (pipe->fifo) 
+            if (pipe->fifo)
             {
                 rt_ringbuffer_destroy(pipe->fifo);
                 pipe->fifo = RT_NULL;

+ 2 - 2
components/lwp/lwp_console.c

@@ -219,7 +219,7 @@ static int console_fops_open(struct dfs_fd *fd)
 
     if (fd->fnode->ref_count == 1)
     {
-        ret = rt_device_open(device, fd->fnode->flags);
+        ret = rt_device_open(device, fd->flags);
     }
     return ret;
 }
@@ -264,7 +264,7 @@ static int console_fops_read(struct dfs_fd *fd, void *buf, size_t count)
         {
             break;
         }
-        if (fd->fnode->flags & O_NONBLOCK)
+        if (fd->flags & O_NONBLOCK)
         {
             break;
         }

+ 1 - 1
components/lwp/lwp_ipc.c

@@ -926,7 +926,7 @@ int lwp_channel_open(int fdt_type, const char *name, int flags)
 
         d->fnode->fops = &channel_fops;
 
-        d->fnode->flags = O_RDWR; /* set flags as read and write */
+        d->flags = O_RDWR; /* set flags as read and write */
         d->fnode->size = 0;
         d->pos = 0;
         d->fnode->ref_count = 1;

+ 2 - 2
components/net/sal_socket/socket/net_sockets.c

@@ -57,7 +57,7 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
             d->fnode->fullpath = NULL;
             d->fnode->ref_count = 1;
             d->fnode->fops = dfs_net_get_fops();
-            d->fnode->flags = O_RDWR; /* set flags as read and write */
+            d->flags = O_RDWR; /* set flags as read and write */
             d->fnode->size = 0;
             d->pos = 0;
 
@@ -238,7 +238,7 @@ int socket(int domain, int type, int protocol)
         d->fnode->ref_count = 1;
         d->fnode->fops = dfs_net_get_fops();
 
-        d->fnode->flags = O_RDWR; /* set flags as read and write */
+        d->flags = O_RDWR; /* set flags as read and write */
         d->fnode->size = 0;
         d->pos = 0;