Linux line-endings
[lwext4.git] / lwext4 / ext4_dir.h
index d185a0b26e5df244034ed9ad5d89648c708d6860..fa45c24dff6aa85a928510ff42c50e33674d453b 100644 (file)
-/*\r
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
- *\r
- *\r
- * HelenOS:\r
- * Copyright (c) 2012 Martin Sucha\r
- * Copyright (c) 2012 Frantisek Princ\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * - Redistributions of source code must retain the above copyright\r
- *   notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- *   notice, this list of conditions and the following disclaimer in the\r
- *   documentation and/or other materials provided with the distribution.\r
- * - The name of the author may not be used to endorse or promote products\r
- *   derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-\r
-/** @addtogroup lwext4\r
- * @{\r
- */\r
-/**\r
- * @file  ext4_dir.h\r
- * @brief Directory handle procedures.\r
- */\r
-\r
-#ifndef EXT4_DIR_H_\r
-#define EXT4_DIR_H_\r
-\r
-#include "ext4_config.h"\r
-#include "ext4_types.h"\r
-#include "ext4_blockdev.h"\r
-#include "ext4_super.h"\r
-\r
-#include <stdint.h>\r
-\r
-/**@brief Get i-node number from directory entry.\r
- * @param de Directory entry\r
- * @return I-node number\r
- */\r
-static inline uint32_t\r
-ext4_dir_entry_ll_get_inode(struct ext4_directory_entry_ll *de)\r
-{\r
-       return to_le32(de->inode);\r
-}\r
-\r
-/**@brief Set i-node number to directory entry.\r
- * @param de Directory entry\r
- * @param inode I-node number\r
- */\r
-static inline void\r
-ext4_dir_entry_ll_set_inode(struct ext4_directory_entry_ll *de, uint32_t inode)\r
-{\r
-       de->inode = to_le32(inode);\r
-}\r
-\r
-/**@brief Get directory entry length.\r
- * @param de Directory entry\r
- * @return Entry length\r
- */\r
-static inline uint16_t\r
-ext4_dir_entry_ll_get_entry_length(struct ext4_directory_entry_ll *de)\r
-{\r
-       return to_le16(de->entry_length);\r
-}\r
-\r
-/**@brief Set directory entry length.\r
- * @param de     Directory entry\r
- * @param length Entry length\r
- */\r
-static inline void\r
-ext4_dir_entry_ll_set_entry_length(struct ext4_directory_entry_ll *de,\r
-                                  uint16_t len)\r
-{\r
-       de->entry_length = to_le16(len);\r
-}\r
-\r
-/**@brief Get directory entry name length.\r
- * @param sb Superblock\r
- * @param de Directory entry\r
- * @return Entry name length\r
- */\r
-static inline uint16_t\r
-ext4_dir_entry_ll_get_name_length(struct ext4_sblock *sb,\r
-                                 struct ext4_directory_entry_ll *de)\r
-{\r
-       uint16_t v = de->name_length;\r
-\r
-       if ((ext4_get32(sb, rev_level) == 0) &&\r
-           (ext4_get32(sb, minor_rev_level) < 5))\r
-               v |= ((uint16_t)de->in.name_length_high) << 8;\r
-\r
-       return v;\r
-}\r
-\r
-/**@brief Set directory entry name length.\r
- * @param sb     Superblock\r
- * @param de     Directory entry\r
- * @param length Entry name length\r
- */\r
-static inline void ext4_dir_entry_ll_set_name_length(\r
-    struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint16_t len)\r
-{\r
-       de->name_length = (len << 8) >> 8;\r
-\r
-       if ((ext4_get32(sb, rev_level) == 0) &&\r
-           (ext4_get32(sb, minor_rev_level) < 5))\r
-               de->in.name_length_high = len >> 8;\r
-}\r
-\r
-/**@brief Get i-node type of directory entry.\r
- * @param sb Superblock\r
- * @param de Directory entry\r
- * @return I-node type (file, dir, etc.)\r
- */\r
-static inline uint8_t\r
-ext4_dir_entry_ll_get_inode_type(struct ext4_sblock *sb,\r
-                                struct ext4_directory_entry_ll *de)\r
-{\r
-       if ((ext4_get32(sb, rev_level) > 0) ||\r
-           (ext4_get32(sb, minor_rev_level) >= 5))\r
-               return de->in.inode_type;\r
-\r
-       return EXT4_DIRECTORY_FILETYPE_UNKNOWN;\r
-}\r
-/**@brief Set i-node type of directory entry.\r
- * @param sb   Superblock\r
- * @param de   Directory entry\r
- * @param type I-node type (file, dir, etc.)\r
- */\r
-\r
-static inline void ext4_dir_entry_ll_set_inode_type(\r
-    struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint8_t type)\r
-{\r
-       if ((ext4_get32(sb, rev_level) > 0) ||\r
-           (ext4_get32(sb, minor_rev_level) >= 5))\r
-               de->in.inode_type = type;\r
-}\r
-\r
-/**@brief Initialize directory iterator.\r
- * Set position to the first valid entry from the required position.\r
- * @param it        Pointer to iterator to be initialized\r
- * @param inode_ref Directory i-node\r
- * @param pos       Position to start reading entries from\r
- * @return Error code\r
- */\r
-int ext4_dir_iterator_init(struct ext4_directory_iterator *it,\r
-                          struct ext4_inode_ref *inode_ref, uint64_t pos);\r
-\r
-/**@brief Jump to the next valid entry\r
- * @param it Initialized iterator\r
- * @return Error code\r
- */\r
-int ext4_dir_iterator_next(struct ext4_directory_iterator *it);\r
-\r
-/**@brief Uninitialize directory iterator.\r
- *        Release all allocated structures.\r
- * @param it Iterator to be finished\r
- * @return Error code\r
- */\r
-int ext4_dir_iterator_fini(struct ext4_directory_iterator *it);\r
-\r
-/**@brief Write directory entry to concrete data block.\r
- * @param sb        Superblock\r
- * @param entry     Pointer to entry to be written\r
- * @param entry_len Length of new entry\r
- * @param child     Child i-node to be written to new entry\r
- * @param name      Name of the new entry\r
- * @param name_len  Length of entry name\r
- */\r
-void ext4_dir_write_entry(struct ext4_sblock *sb,\r
-                         struct ext4_directory_entry_ll *entry,\r
-                         uint16_t entry_len, struct ext4_inode_ref *child,\r
-                         const char *name, size_t name_len);\r
-\r
-/**@brief Add new entry to the directory.\r
- * @param parent Directory i-node\r
- * @param name   Name of new entry\r
- * @param child  I-node to be referenced from new entry\r
- * @return Error code\r
- */\r
-int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,\r
-                      uint32_t name_len, struct ext4_inode_ref *child);\r
-\r
-/**@brief Find directory entry with passed name.\r
- * @param result Result structure to be returned if entry found\r
- * @param parent Directory i-node\r
- * @param name   Name of entry to be found\r
- * @param name_len  Name length\r
- * @return Error code\r
- */\r
-int ext4_dir_find_entry(struct ext4_directory_search_result *result,\r
-                       struct ext4_inode_ref *parent, const char *name,\r
-                       uint32_t name_len);\r
-\r
-/**@brief Remove directory entry.\r
- * @param parent Directory i-node\r
- * @param name   Name of the entry to be removed\r
- * @param name_len  Name length\r
- * @return Error code\r
- */\r
-int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,\r
-                         uint32_t name_len);\r
-\r
-/**@brief Try to insert entry to concrete data block.\r
- * @param sb           Superblock\r
- * @param target_block Block to try to insert entry to\r
- * @param child        Child i-node to be inserted by new entry\r
- * @param name         Name of the new entry\r
- * @param name_len     Length of the new entry name\r
- * @return Error code\r
- */\r
-int ext4_dir_try_insert_entry(struct ext4_sblock *sb,\r
-                             struct ext4_block *target_block,\r
-                             struct ext4_inode_ref *child, const char *name,\r
-                             uint32_t name_len);\r
-\r
-/**@brief Try to find entry in block by name.\r
- * @param block     Block containing entries\r
- * @param sb        Superblock\r
- * @param name_len  Length of entry name\r
- * @param name      Name of entry to be found\r
- * @param res_entry Output pointer to found entry, NULL if not found\r
- * @return Error code\r
- */\r
-int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,\r
-                          size_t name_len, const char *name,\r
-                          struct ext4_directory_entry_ll **res_entry);\r
-\r
-/**@brief Simple function to release allocated data from result.\r
- * @param parent Parent inode\r
- * @param result Search result to destroy\r
- * @return Error code\r
- *\r
- */\r
-int ext4_dir_destroy_result(struct ext4_inode_ref *parent,\r
-                           struct ext4_directory_search_result *result);\r
-\r
-#endif /* EXT4_DIR_H_ */\r
-\r
-/**\r
- * @}\r
- */\r
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ *
+ *
+ * HelenOS:
+ * Copyright (c) 2012 Martin Sucha
+ * Copyright (c) 2012 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup lwext4
+ * @{
+ */
+/**
+ * @file  ext4_dir.h
+ * @brief Directory handle procedures.
+ */
+
+#ifndef EXT4_DIR_H_
+#define EXT4_DIR_H_
+
+#include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_blockdev.h"
+#include "ext4_super.h"
+
+#include <stdint.h>
+
+/**@brief Get i-node number from directory entry.
+ * @param de Directory entry
+ * @return I-node number
+ */
+static inline uint32_t
+ext4_dir_entry_ll_get_inode(struct ext4_directory_entry_ll *de)
+{
+       return to_le32(de->inode);
+}
+
+/**@brief Set i-node number to directory entry.
+ * @param de Directory entry
+ * @param inode I-node number
+ */
+static inline void
+ext4_dir_entry_ll_set_inode(struct ext4_directory_entry_ll *de, uint32_t inode)
+{
+       de->inode = to_le32(inode);
+}
+
+/**@brief Get directory entry length.
+ * @param de Directory entry
+ * @return Entry length
+ */
+static inline uint16_t
+ext4_dir_entry_ll_get_entry_length(struct ext4_directory_entry_ll *de)
+{
+       return to_le16(de->entry_length);
+}
+
+/**@brief Set directory entry length.
+ * @param de     Directory entry
+ * @param length Entry length
+ */
+static inline void
+ext4_dir_entry_ll_set_entry_length(struct ext4_directory_entry_ll *de,
+                                  uint16_t len)
+{
+       de->entry_length = to_le16(len);
+}
+
+/**@brief Get directory entry name length.
+ * @param sb Superblock
+ * @param de Directory entry
+ * @return Entry name length
+ */
+static inline uint16_t
+ext4_dir_entry_ll_get_name_length(struct ext4_sblock *sb,
+                                 struct ext4_directory_entry_ll *de)
+{
+       uint16_t v = de->name_length;
+
+       if ((ext4_get32(sb, rev_level) == 0) &&
+           (ext4_get32(sb, minor_rev_level) < 5))
+               v |= ((uint16_t)de->in.name_length_high) << 8;
+
+       return v;
+}
+
+/**@brief Set directory entry name length.
+ * @param sb     Superblock
+ * @param de     Directory entry
+ * @param length Entry name length
+ */
+static inline void ext4_dir_entry_ll_set_name_length(
+    struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint16_t len)
+{
+       de->name_length = (len << 8) >> 8;
+
+       if ((ext4_get32(sb, rev_level) == 0) &&
+           (ext4_get32(sb, minor_rev_level) < 5))
+               de->in.name_length_high = len >> 8;
+}
+
+/**@brief Get i-node type of directory entry.
+ * @param sb Superblock
+ * @param de Directory entry
+ * @return I-node type (file, dir, etc.)
+ */
+static inline uint8_t
+ext4_dir_entry_ll_get_inode_type(struct ext4_sblock *sb,
+                                struct ext4_directory_entry_ll *de)
+{
+       if ((ext4_get32(sb, rev_level) > 0) ||
+           (ext4_get32(sb, minor_rev_level) >= 5))
+               return de->in.inode_type;
+
+       return EXT4_DIRECTORY_FILETYPE_UNKNOWN;
+}
+/**@brief Set i-node type of directory entry.
+ * @param sb   Superblock
+ * @param de   Directory entry
+ * @param type I-node type (file, dir, etc.)
+ */
+
+static inline void ext4_dir_entry_ll_set_inode_type(
+    struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint8_t type)
+{
+       if ((ext4_get32(sb, rev_level) > 0) ||
+           (ext4_get32(sb, minor_rev_level) >= 5))
+               de->in.inode_type = type;
+}
+
+/**@brief Initialize directory iterator.
+ * Set position to the first valid entry from the required position.
+ * @param it        Pointer to iterator to be initialized
+ * @param inode_ref Directory i-node
+ * @param pos       Position to start reading entries from
+ * @return Error code
+ */
+int ext4_dir_iterator_init(struct ext4_directory_iterator *it,
+                          struct ext4_inode_ref *inode_ref, uint64_t pos);
+
+/**@brief Jump to the next valid entry
+ * @param it Initialized iterator
+ * @return Error code
+ */
+int ext4_dir_iterator_next(struct ext4_directory_iterator *it);
+
+/**@brief Uninitialize directory iterator.
+ *        Release all allocated structures.
+ * @param it Iterator to be finished
+ * @return Error code
+ */
+int ext4_dir_iterator_fini(struct ext4_directory_iterator *it);
+
+/**@brief Write directory entry to concrete data block.
+ * @param sb        Superblock
+ * @param entry     Pointer to entry to be written
+ * @param entry_len Length of new entry
+ * @param child     Child i-node to be written to new entry
+ * @param name      Name of the new entry
+ * @param name_len  Length of entry name
+ */
+void ext4_dir_write_entry(struct ext4_sblock *sb,
+                         struct ext4_directory_entry_ll *entry,
+                         uint16_t entry_len, struct ext4_inode_ref *child,
+                         const char *name, size_t name_len);
+
+/**@brief Add new entry to the directory.
+ * @param parent Directory i-node
+ * @param name   Name of new entry
+ * @param child  I-node to be referenced from new entry
+ * @return Error code
+ */
+int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
+                      uint32_t name_len, struct ext4_inode_ref *child);
+
+/**@brief Find directory entry with passed name.
+ * @param result Result structure to be returned if entry found
+ * @param parent Directory i-node
+ * @param name   Name of entry to be found
+ * @param name_len  Name length
+ * @return Error code
+ */
+int ext4_dir_find_entry(struct ext4_directory_search_result *result,
+                       struct ext4_inode_ref *parent, const char *name,
+                       uint32_t name_len);
+
+/**@brief Remove directory entry.
+ * @param parent Directory i-node
+ * @param name   Name of the entry to be removed
+ * @param name_len  Name length
+ * @return Error code
+ */
+int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
+                         uint32_t name_len);
+
+/**@brief Try to insert entry to concrete data block.
+ * @param sb           Superblock
+ * @param target_block Block to try to insert entry to
+ * @param child        Child i-node to be inserted by new entry
+ * @param name         Name of the new entry
+ * @param name_len     Length of the new entry name
+ * @return Error code
+ */
+int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
+                             struct ext4_block *target_block,
+                             struct ext4_inode_ref *child, const char *name,
+                             uint32_t name_len);
+
+/**@brief Try to find entry in block by name.
+ * @param block     Block containing entries
+ * @param sb        Superblock
+ * @param name_len  Length of entry name
+ * @param name      Name of entry to be found
+ * @param res_entry Output pointer to found entry, NULL if not found
+ * @return Error code
+ */
+int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,
+                          size_t name_len, const char *name,
+                          struct ext4_directory_entry_ll **res_entry);
+
+/**@brief Simple function to release allocated data from result.
+ * @param parent Parent inode
+ * @param result Search result to destroy
+ * @return Error code
+ *
+ */
+int ext4_dir_destroy_result(struct ext4_inode_ref *parent,
+                           struct ext4_directory_search_result *result);
+
+#endif /* EXT4_DIR_H_ */
+
+/**
+ * @}
+ */