Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv10128/libntfs
Modified Files:
attrib.c
Log Message:
Add new API ntfs_attr_{get,put}.
Index: attrib.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/attrib.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -U2 -r1.33 -r1.34
--- attrib.c 24 Apr 2002 01:37:37 -0000 1.33
+++ attrib.c 24 Apr 2002 19:02:07 -0000 1.34
@@ -372,7 +372,74 @@
/* Already cleaned up code below, but still look for FIXME:... */
-/* Temporary helper functions -- might become macros */
+/*
+ * Internal function:
+ *
+ * ntfs_attr_init - initialize an ntfs attribute structure
+ * @na: ntfs attribute to initialize
+ * @ni: ntfs inode with which to initialize the ntfs attribute
+ * @type: attribute type
+ * @name: attribute name in little endian Unicode or NULL
+ * @name_len: length of attribute @name in Unicode characters (if @name given)
+ * @state: initial ntfs attribute flags to set in the state of @na
+ *
+ * Initialize the ntfs attribute @na with @ni, @type, @name, @name_len, and
+ * @state.
+ */
+static __inline__ void ntfs_attr_init(ntfs_attr *na, ntfs_inode *ni,
+ const ATTR_TYPES type, uchar_t *name,
+ const __u32 name_len, const unsigned long state)
+{
+ na->rl = NULL;
+ na->ni = ni;
+ na->type = type;
+ na->name = name;
+ na->name_len = name ? name_len : 0;
+ na->state = state;
+}
+
+/**
+ * ntfs_attr_get - allocate/initialize a new ntfs attribute structure
+ * @ni: ntfs inode in which the ntfs attribute resides
+ * @type: attribute type
+ * @name: attribute name in little endian Unicode or NULL
+ * @name_len: length of attribute @name in Unicode characters (if @name given)
+ * @state: initial ntfs attribute flags to set in the state of @na
+ *
+ * Allocate a new ntfs attribute structure, initialize it with @ni, @type,
+ * @name, @name_len, and @state, then return it. Return NULL on error with
+ * errno set to ENOMEM.
+ *
+ * If looking for an unnamed attribute set @name to NULL. @name_len is not used
+ * at all in that case.
+ */
+ntfs_attr *ntfs_attr_get(ntfs_inode *ni, const ATTR_TYPES type,
+ uchar_t *name, const __u32 name_len, const unsigned long state)
+{
+ ntfs_attr *na = malloc(sizeof(ntfs_attr));
+ if (na)
+ ntfs_attr_init(na, ni, type, name, name_len, state);
+ return na;
+}
/**
+ * ntfs_attr_put - free an ntfs attribute structure
+ * @na: ntfs attribute structure to free
+ *
+ * Release all memory associated with the ntfs attribute @na and then release
+ * @na itself.
+ */
+void ntfs_attr_put(ntfs_attr *na)
+{
+ if (NAttrNonResident(na) && na->rl)
+ free(na->rl);
+ if (na->name)
+ free(na->name);
+ free(na);
+ return;
+}
+
+/*
+ * Internal function:
+ *
* ntfs_rl_mm - run_list memmove
*/
@@ -384,5 +451,7 @@
}
-/**
+/*
+ * Internal function:
+ *
* rl_mc - run_list memory copy
*/
@@ -394,5 +463,7 @@
}
-/**
+/*
+ * Internal function:
+ *
* ntfs_rl_realloc - Reallocate memory for run_lists
* @rl: original run list
@@ -420,5 +491,7 @@
}
-/**
+/*
+ * Internal function:
+ *
* ntfs_are_rl_mergeable - test if two run_lists can be joined together
* @one: original run_list
@@ -450,5 +523,7 @@
}
-/**
+/*
+ * Internal function:
+ *
* __ntfs_rl_merge - merge two run lists without testing if they can be merged
* @dst: original, destination run list
@@ -465,5 +540,7 @@
}
-/**
+/*
+ * Internal function:
+ *
* ntfs_rl_merge - test if two run lists can be joined together and merge them
* @dst: original, destination run list
@@ -488,5 +565,7 @@
}
-/**
+/*
+ * Internal function:
+ *
* ntfs_rl_append - append a run list after a given element
* @dst: original run list to be worked on
@@ -553,5 +632,7 @@
}
-/**
+/*
+ * Internal function:
+ *
* ntfs_rl_insert - insert a run list into another
* @dst: original run list to be worked on
@@ -660,5 +741,7 @@
}
-/**
+/*
+ * Internal function:
+ *
* ntfs_rl_replace - overwrite a run_list element with another run list
* @dst: original run list to be worked on
@@ -724,5 +807,7 @@
}
-/**
+/*
+ * Internal function:
+ *
* ntfs_rl_split - insert a run list into the centre of a hole
* @dst: original run list to be worked on
@@ -932,10 +1017,9 @@
drl = ntfs_rl_split(drl, ds, srl + sstart, ss, dins);
}
- if (drl) {
- free (srl);
- } else {
- Dperror("Merge failed, returning error code");
+ if (!drl) {
+ Dperror(__FUNCTION__ "(): Merge failed");
return drl;
}
+ free(srl);
if (marker) {
Dputs("Triggering marker code.");
|