ext4: add ext4_inode_exist method
authorgkostka <kostka.grzegorz@gmail.com>
Wed, 19 Apr 2017 18:47:14 +0000 (20:47 +0200)
committergkostka <kostka.grzegorz@gmail.com>
Wed, 19 Apr 2017 18:47:14 +0000 (20:47 +0200)
include/ext4.h
src/ext4.c

index 3e068778e8793f3ab35097a3c587b442208440a5..3b88771dec35f8a3b71eea504b0fc3faf4a0d31e 100644 (file)
@@ -395,6 +395,22 @@ uint64_t ext4_fsize(ext4_file *file);
 int ext4_raw_inode_fill(const char *path, uint32_t *ret_ino,
                        struct ext4_inode *inode);
 
+/**@brief Check if inode exists.
+ *
+ * @param path    Parh to file/dir/link.
+ * @param type    Inode type.
+ *                @ref EXT4_DIRENTRY_UNKNOWN
+ *                @ref EXT4_DE_REG_FILE
+ *                @ref EXT4_DE_DIR
+ *                @ref EXT4_DE_CHRDEV
+ *                @ref EXT4_DE_BLKDEV
+ *                @ref EXT4_DE_FIFO
+ *                @ref EXT4_DE_SOCK
+ *                @ref EXT4_DE_SYMLINK
+ *
+ * @return  Standard error code.*/
+int ext4_inode_exist(const char *path, int type);
+
 /**@brief Change file/directory/link mode bits.
  *
  * @param path Path to file/dir/link.
index 6a8fa107b262cae6821ae0709ae8a5dd12f5465e..98f3e090e650f1b3f6408e1a7441e1e72d423283 100644 (file)
@@ -2110,6 +2110,22 @@ int ext4_raw_inode_fill(const char *path, uint32_t *ret_ino,
        return r;
 }
 
+int ext4_inode_exist(const char *path, int type)
+{
+       int r;
+       ext4_file f;
+       struct ext4_mountpoint *mp = ext4_get_mount(path);
+
+       if (!mp)
+               return ENOENT;
+
+       EXT4_MP_LOCK(mp);
+       r = ext4_generic_open2(&f, path, O_RDONLY, type, NULL, NULL);
+       EXT4_MP_UNLOCK(mp);
+
+       return r;
+}
+
 int ext4_mode_set(const char *path, uint32_t mode)
 {
        int r;