You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/07/14 16:31:05 UTC

[GitHub] [incubator-nuttx] acassis commented on a change in pull request #4153: fs: Add fchstat and chstat callback into mountpt_operations

acassis commented on a change in pull request #4153:
URL: https://github.com/apache/incubator-nuttx/pull/4153#discussion_r669756455



##########
File path: fs/vfs/fs_fchstat.c
##########
@@ -0,0 +1,286 @@
+/****************************************************************************
+ * fs/vfs/fs_fchstat.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <nuttx/fs/fs.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: fchstat
+ ****************************************************************************/
+
+static int fchstat(int fd, FAR struct stat *buf, int flags)
+{
+  FAR struct file *filep;
+  int ret;
+
+  /* First, get the file structure.  Note that on failure,
+   * fs_getfilep() will return the errno.

Review comment:
       It is not returning the "errno", but setting the errno and returning ERROR (-1). Please find this comment.

##########
File path: fs/vfs/fs_fchstat.c
##########
@@ -0,0 +1,286 @@
+/****************************************************************************
+ * fs/vfs/fs_fchstat.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <nuttx/fs/fs.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: fchstat
+ ****************************************************************************/
+
+static int fchstat(int fd, FAR struct stat *buf, int flags)
+{
+  FAR struct file *filep;
+  int ret;
+
+  /* First, get the file structure.  Note that on failure,
+   * fs_getfilep() will return the errno.
+   */
+
+  ret = fs_getfilep(fd, &filep);
+  if (ret < 0)
+    {
+      goto errout;
+    }
+
+  /* Perform the fchstat operation */
+
+  ret = file_fchstat(filep, buf, flags);
+
+  /* Check if the fchstat operation was successful */
+

Review comment:
       Remove remove this comment (it is not necessary here), just:
     ret = file_fchstat(filep, buf, flags);
     if (ret >= 0)
       {
         /* Successfully fchstat'ed the file */
   
         return OK;
       }

##########
File path: fs/vfs/fs_fchstat.c
##########
@@ -0,0 +1,286 @@
+/****************************************************************************
+ * fs/vfs/fs_fchstat.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <nuttx/fs/fs.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: fchstat
+ ****************************************************************************/
+
+static int fchstat(int fd, FAR struct stat *buf, int flags)
+{
+  FAR struct file *filep;
+  int ret;
+
+  /* First, get the file structure.  Note that on failure,
+   * fs_getfilep() will return the errno.
+   */
+
+  ret = fs_getfilep(fd, &filep);
+  if (ret < 0)
+    {
+      goto errout;
+    }
+
+  /* Perform the fchstat operation */
+
+  ret = file_fchstat(filep, buf, flags);
+
+  /* Check if the fchstat operation was successful */
+
+  if (ret >= 0)
+    {
+      /* Successfully fchstat'ed the file */
+
+      return OK;
+    }
+
+errout:
+  set_errno(-ret);
+  return ERROR;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: file_fchstat
+ *
+ * Description:
+ *   file_fchstat() is an internal OS interface. It is functionally similar
+ *   to the combination of fchmod/fchown/futimens standard interface except:
+ *
+ *    - It does not modify the errno variable,
+ *    - It is not a cancellation point,
+ *    - It does not handle socket descriptors, and
+ *    - It accepts a file structure instance instead of file descriptor.
+ *
+ * Input Parameters:
+ *   filep  - File structure instance
+ *   buf    - The stat to be modified
+ *   flags  - The vaild field in buf
+ *
+ * Returned Value:
+ *   Upon successful completion, 0 shall be returned. Otherwise, the
+ *   negative errno shall be returned to indicate the error.
+ *
+ ****************************************************************************/
+
+int file_fchstat(FAR struct file *filep, FAR struct stat *buf, int flags)
+{
+  FAR struct inode *inode;
+  int ret;
+
+  DEBUGASSERT(filep != NULL);
+
+  /* Get the inode from the file structure */
+
+  inode = filep->f_inode;
+  DEBUGASSERT(inode != NULL);
+
+  /* Adjust and check buf and flags */
+
+  if ((flags & CH_STAT_MODE) && (buf->st_mode & ~07777))

Review comment:
       I think this test could always return true: (buf->st_mode & ~07777)
   st_mode is of type mode_t that is 16-bit, but 07777 octal value is only 12-bit long, so if the upper 4 bits from st_mode are 0 the resulting value will be different of zero. Did you check it?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org