OSDN Git Service

Prefix all functions and macros in ntfsprogs/list.h with 'ntfs_/NTFS_'.
authorErik Larsson <mechie@users.sourceforge.net>
Wed, 11 Jan 2012 10:44:09 +0000 (11:44 +0100)
committerErik Larsson <mechie@users.sourceforge.net>
Fri, 13 Jan 2012 12:37:33 +0000 (13:37 +0100)
This avoids name collisions with Mac OS X system headers (specifically
/usr/include/sys/queue.h). It's quite possible that other operating
systems also have similarly named macros in their system headers since
the function/macro names are very generic.

ntfsprogs/list.h
ntfsprogs/ntfsls.c
ntfsprogs/ntfsundelete.c
ntfsprogs/ntfsundelete.h

index e3c7744..4db45d4 100644 (file)
@@ -23,7 +23,7 @@
 #define _NTFS_LIST_H
 
 /**
- * struct list_head - Simple doubly linked list implementation.
+ * struct ntfs_list_head - Simple doubly linked list implementation.
  *
  * Copied from Linux kernel 2.4.2-ac18 into Linux-NTFS (with minor
  * modifications). - AIA
  * generate better code by using them directly rather than
  * using the generic single-entry routines.
  */
-struct list_head {
-       struct list_head *next, *prev;
+struct ntfs_list_head {
+       struct ntfs_list_head *next, *prev;
 };
 
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
+#define NTFS_LIST_HEAD_INIT(name) { &(name), &(name) }
 
-#define LIST_HEAD(name) \
-       struct list_head name = LIST_HEAD_INIT(name)
+#define NTFS_LIST_HEAD(name) \
+       struct ntfs_list_head name = NTFS_LIST_HEAD_INIT(name)
 
-#define INIT_LIST_HEAD(ptr) do { \
+#define NTFS_INIT_LIST_HEAD(ptr) do { \
        (ptr)->next = (ptr); (ptr)->prev = (ptr); \
 } while (0)
 
 /**
- * __list_add - Insert a new entry between two known consecutive entries.
+ * __ntfs_list_add - Insert a new entry between two known consecutive entries.
  * @new:
  * @prev:
  * @next:
@@ -56,8 +56,8 @@ struct list_head {
  * This is only for internal list manipulation where we know the prev/next
  * entries already!
  */
-static __inline__ void __list_add(struct list_head * new,
-               struct list_head * prev, struct list_head * next)
+static __inline__ void __ntfs_list_add(struct ntfs_list_head * new,
+               struct ntfs_list_head * prev, struct ntfs_list_head * next)
 {
        next->prev = new;
        new->next = next;
@@ -66,33 +66,35 @@ static __inline__ void __list_add(struct list_head * new,
 }
 
 /**
- * list_add - add a new entry
+ * ntfs_list_add - add a new entry
  * @new:       new entry to be added
  * @head:      list head to add it after
  *
  * Insert a new entry after the specified head.
  * This is good for implementing stacks.
  */
-static __inline__ void list_add(struct list_head *new, struct list_head *head)
+static __inline__ void ntfs_list_add(struct ntfs_list_head *new,
+               struct ntfs_list_head *head)
 {
-       __list_add(new, head, head->next);
+       __ntfs_list_add(new, head, head->next);
 }
 
 /**
- * list_add_tail - add a new entry
+ * ntfs_list_add_tail - add a new entry
  * @new:       new entry to be added
  * @head:      list head to add it before
  *
  * Insert a new entry before the specified head.
  * This is useful for implementing queues.
  */
-static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
+static __inline__ void ntfs_list_add_tail(struct ntfs_list_head *new,
+               struct ntfs_list_head *head)
 {
-       __list_add(new, head->prev, head);
+       __ntfs_list_add(new, head->prev, head);
 }
 
 /**
- * __list_del -
+ * __ntfs_list_del -
  * @prev:
  * @next:
  *
@@ -101,57 +103,57 @@ static __inline__ void list_add_tail(struct list_head *new, struct list_head *he
  * This is only for internal list manipulation where we know the prev/next
  * entries already!
  */
-static __inline__ void __list_del(struct list_head * prev,
-               struct list_head * next)
+static __inline__ void __ntfs_list_del(struct ntfs_list_head * prev,
+               struct ntfs_list_head * next)
 {
        next->prev = prev;
        prev->next = next;
 }
 
 /**
- * list_del - deletes entry from list.
+ * ntfs_list_del - deletes entry from list.
  * @entry:     the element to delete from the list.
  *
- * Note: list_empty on entry does not return true after this, the entry is in
- * an undefined state.
+ * Note: ntfs_list_empty on entry does not return true after this, the entry is
+ * in an undefined state.
  */
-static __inline__ void list_del(struct list_head *entry)
+static __inline__ void ntfs_list_del(struct ntfs_list_head *entry)
 {
-       __list_del(entry->prev, entry->next);
+       __ntfs_list_del(entry->prev, entry->next);
 }
 
 /**
- * list_del_init - deletes entry from list and reinitialize it.
+ * ntfs_list_del_init - deletes entry from list and reinitialize it.
  * @entry:     the element to delete from the list.
  */
-static __inline__ void list_del_init(struct list_head *entry)
+static __inline__ void ntfs_list_del_init(struct ntfs_list_head *entry)
 {
-       __list_del(entry->prev, entry->next);
-       INIT_LIST_HEAD(entry);
+       __ntfs_list_del(entry->prev, entry->next);
+       NTFS_INIT_LIST_HEAD(entry);
 }
 
 /**
- * list_empty - tests whether a list is empty
+ * ntfs_list_empty - tests whether a list is empty
  * @head:      the list to test.
  */
-static __inline__ int list_empty(struct list_head *head)
+static __inline__ int ntfs_list_empty(struct ntfs_list_head *head)
 {
        return head->next == head;
 }
 
 /**
- * list_splice - join two lists
+ * ntfs_list_splice - join two lists
  * @list:      the new list to add.
  * @head:      the place to add it in the first list.
  */
-static __inline__ void list_splice(struct list_head *list,
-               struct list_head *head)
+static __inline__ void ntfs_list_splice(struct ntfs_list_head *list,
+               struct ntfs_list_head *head)
 {
-       struct list_head *first = list->next;
+       struct ntfs_list_head *first = list->next;
 
        if (first != list) {
-               struct list_head *last = list->prev;
-               struct list_head *at = head->next;
+               struct ntfs_list_head *last = list->prev;
+               struct ntfs_list_head *at = head->next;
 
                first->prev = head;
                head->next = first;
@@ -162,29 +164,29 @@ static __inline__ void list_splice(struct list_head *list,
 }
 
 /**
- * list_entry - get the struct for this entry
- * @ptr:       the &struct list_head pointer.
+ * ntfs_list_entry - get the struct for this entry
+ * @ptr:       the &struct ntfs_list_head pointer.
  * @type:      the type of the struct this is embedded in.
  * @member:    the name of the list_struct within the struct.
  */
-#define list_entry(ptr, type, member) \
+#define ntfs_list_entry(ptr, type, member) \
        ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
 
 /**
- * list_for_each - iterate over a list
- * @pos:       the &struct list_head to use as a loop counter.
+ * ntfs_list_for_each - iterate over a list
+ * @pos:       the &struct ntfs_list_head to use as a loop counter.
  * @head:      the head for your list.
  */
-#define list_for_each(pos, head) \
+#define ntfs_list_for_each(pos, head) \
        for (pos = (head)->next; pos != (head); pos = pos->next)
 
 /**
- * list_for_each_safe  -       iterate over a list safe against removal of list entry
- * @pos:       the &struct list_head to use as a loop counter.
- * @n:         another &struct list_head to use as temporary storage
+ * ntfs_list_for_each_safe     -       iterate over a list safe against removal of list entry
+ * @pos:       the &struct ntfs_list_head to use as a loop counter.
+ * @n:         another &struct ntfs_list_head to use as temporary storage
  * @head:      the head for your list.
  */
-#define list_for_each_safe(pos, n, head) \
+#define ntfs_list_for_each_safe(pos, n, head) \
        for (pos = (head)->next, n = pos->next; pos != (head); \
                pos = n, n = pos->next)
 
index e8a006b..fde3e5b 100644 (file)
@@ -61,7 +61,7 @@ static const char *EXEC_NAME = "ntfsls";
  * @depth:     the level of this dir relative to opts.path
  */
 struct dir {
-       struct list_head list;
+       struct ntfs_list_head list;
        ntfs_inode *ni;
        char name[MAX_PATH];
        int depth;
@@ -76,7 +76,7 @@ struct dir {
  * character array name in struct dir.
  */
 struct path_component {
-       struct list_head list;
+       struct ntfs_list_head list;
        const char *name;
 };
 
@@ -98,7 +98,7 @@ struct path_component {
  * dir_list_insert_pos keeps track of where to insert a sub-dir
  * into the list.
  */
-static struct list_head *dir_list_insert_pos = NULL;
+static struct ntfs_list_head *dir_list_insert_pos = NULL;
 
 /* The global depth relative to opts.path.
  * ie: opts.path has depth 0, a sub-dir of opts.path has depth 1
@@ -338,19 +338,19 @@ static void free_dir(struct dir *tofree)
 
 /**
  * free_dirs - walk the list of dir's and free each of them
- * @dir_list:    the list_head of any entry in the list
+ * @dir_list:    the ntfs_list_head of any entry in the list
  *
  * Iterate over @dir_list, calling free_dir on each entry
  */
-static void free_dirs(struct list_head *dir_list)
+static void free_dirs(struct ntfs_list_head *dir_list)
 {
        struct dir *tofree = NULL;
-       struct list_head *walker = NULL;
+       struct ntfs_list_head *walker = NULL;
 
        if (dir_list) {
-               list_for_each(walker, dir_list) {
+               ntfs_list_for_each(walker, dir_list) {
                        free_dir(tofree);
-                       tofree = list_entry(walker, struct dir, list);
+                       tofree = ntfs_list_entry(walker, struct dir, list);
                }
 
                free_dir(tofree);
@@ -375,14 +375,14 @@ static int readdir_recursive(ntfs_inode * ni, s64 * pos, ntfsls_dirent * dirent)
 {
        /* list of dirs to "ls" recursively */
        static struct dir dirs = {
-               .list = LIST_HEAD_INIT(dirs.list),
+               .list = NTFS_LIST_HEAD_INIT(dirs.list),
                .ni = NULL,
                .name = {0},
                .depth = 0
        };
 
        static struct path_component paths = {
-               .list = LIST_HEAD_INIT(paths.list),
+               .list = NTFS_LIST_HEAD_INIT(paths.list),
                .name = NULL
        };
 
@@ -392,15 +392,15 @@ static int readdir_recursive(ntfs_inode * ni, s64 * pos, ntfsls_dirent * dirent)
        struct dir *tofree = NULL;
        struct path_component comp;
        struct path_component *tempcomp = NULL;
-       struct list_head *dir_walker = NULL;
-       struct list_head *comp_walker = NULL;
+       struct ntfs_list_head *dir_walker = NULL;
+       struct ntfs_list_head *comp_walker = NULL;
        s64 pos2 = 0;
        int ni_depth = depth;
        int result = 0;
 
-       if (list_empty(&dirs.list)) {
+       if (ntfs_list_empty(&dirs.list)) {
                base_comp.name = opts.path;
-               list_add(&base_comp.list, &paths.list);
+               ntfs_list_add(&base_comp.list, &paths.list);
                dir_list_insert_pos = &dirs.list;
                printf("%s:\n", opts.path);
        }
@@ -410,16 +410,16 @@ static int readdir_recursive(ntfs_inode * ni, s64 * pos, ntfsls_dirent * dirent)
        result = ntfs_readdir(ni, pos, dirent, (ntfs_filldir_t) list_dir_entry);
 
        if (result == 0) {
-               list_add_tail(&comp.list, &paths.list);
+               ntfs_list_add_tail(&comp.list, &paths.list);
 
                /* for each of ni's sub-dirs: list in this iteration, then
                   free at the top of the next iteration or outside of loop */
-               list_for_each(dir_walker, &dirs.list) {
+               ntfs_list_for_each(dir_walker, &dirs.list) {
                        if (tofree) {
                                free_dir(tofree);
                                tofree = NULL;
                        }
-                       subdir = list_entry(dir_walker, struct dir, list);
+                       subdir = ntfs_list_entry(dir_walker, struct dir, list);
 
                        /* subdir is not a subdir of ni */
                        if (subdir->depth != ni_depth + 1)
@@ -444,9 +444,9 @@ static int readdir_recursive(ntfs_inode * ni, s64 * pos, ntfsls_dirent * dirent)
                        comp.name = subdir->name;
 
                        /* print relative path header */
-                       list_for_each(comp_walker, &paths.list) {
+                       ntfs_list_for_each(comp_walker, &paths.list) {
                                tempcomp =
-                                   list_entry(comp_walker,
+                                   ntfs_list_entry(comp_walker,
                                               struct path_component, list);
                                printf("%s", tempcomp->name);
                                if (tempcomp != &comp
@@ -463,10 +463,10 @@ static int readdir_recursive(ntfs_inode * ni, s64 * pos, ntfsls_dirent * dirent)
                                break;
 
                        tofree = subdir;
-                       list_del(dir_walker);
+                       ntfs_list_del(dir_walker);
                }
 
-               list_del(&comp.list);
+               ntfs_list_del(&comp.list);
        }
 
        if (tofree)
@@ -610,7 +610,7 @@ release:
 
        if (dir) {
                if (result == 0) {
-                       list_add(&dir->list, dir_list_insert_pos);
+                       ntfs_list_add(&dir->list, dir_list_insert_pos);
                        dir_list_insert_pos = &dir->list;
                } else {
                        free(dir);
index b5c4c84..8cbfd92 100644 (file)
@@ -719,13 +719,14 @@ static int parse_options(int argc, char *argv[])
  */
 static void free_file(struct ufile *file)
 {
-       struct list_head *item, *tmp;
+       struct ntfs_list_head *item, *tmp;
 
        if (!file)
                return;
 
-       list_for_each_safe(item, tmp, &file->name) { /* List of filenames */
-               struct filename *f = list_entry(item, struct filename, list);
+       ntfs_list_for_each_safe(item, tmp, &file->name) {
+               /* List of filenames */
+               struct filename *f = ntfs_list_entry(item, struct filename, list);
                ntfs_log_debug("freeing filename '%s'", f->name ? f->name :
                                NONE);
                if (f->name)
@@ -739,8 +740,9 @@ static void free_file(struct ufile *file)
                free(f);
        }
 
-       list_for_each_safe(item, tmp, &file->data) { /* List of data streams */
-               struct data *d = list_entry(item, struct data, list);
+       ntfs_list_for_each_safe(item, tmp, &file->data) {
+               /* List of data streams */
+               struct data *d = ntfs_list_entry(item, struct data, list);
                ntfs_log_debug("Freeing data stream '%s'.\n", d->name ?
                                d->name : UNNAMED);
                if (d->name)
@@ -1023,7 +1025,7 @@ static int get_filenames(struct ufile *file, ntfs_volume* vol)
                file->max_size = max(file->max_size, name->size_alloc);
                file->max_size = max(file->max_size, name->size_data);
 
-               list_add_tail(&name->list, &file->name);
+               ntfs_list_add_tail(&name->list, &file->name);
                count++;
        }
 
@@ -1051,7 +1053,7 @@ static int get_filenames(struct ufile *file, ntfs_volume* vol)
                                name->size_alloc = sle64_to_cpu(attr->allocated_size);
                                name->size_data  = sle64_to_cpu(attr->data_size);
                        }
-               list_add_tail(&name->list, &file->name);
+               ntfs_list_add_tail(&name->list, &file->name);
                count++;
                }
        }
@@ -1133,7 +1135,7 @@ static int get_data(struct ufile *file, ntfs_volume *vol)
                file->max_size = max(file->max_size, data->size_data);
                file->max_size = max(file->max_size, data->size_init);
 
-               list_add_tail(&data->list, &file->data);
+               ntfs_list_add_tail(&data->list, &file->data);
                count++;
        }
 
@@ -1168,8 +1170,8 @@ static struct ufile * read_record(ntfs_volume *vol, long long record)
                return NULL;
        }
 
-       INIT_LIST_HEAD(&file->name);
-       INIT_LIST_HEAD(&file->data);
+       NTFS_INIT_LIST_HEAD(&file->name);
+       NTFS_INIT_LIST_HEAD(&file->data);
        file->inode = record;
 
        file->mft = malloc(vol->mft_record_size);
@@ -1249,7 +1251,7 @@ static struct ufile * read_record(ntfs_volume *vol, long long record)
 static int calc_percentage(struct ufile *file, ntfs_volume *vol)
 {
        runlist_element *rl = NULL;
-       struct list_head *pos;
+       struct ntfs_list_head *pos;
        struct data *data;
        long long i, j;
        long long start, end;
@@ -1264,13 +1266,13 @@ static int calc_percentage(struct ufile *file, ntfs_volume *vol)
                return 0;
        }
 
-       if (list_empty(&file->data)) {
+       if (ntfs_list_empty(&file->data)) {
                ntfs_log_verbose("File has no data streams.\n");
                return 0;
        }
 
-       list_for_each(pos, &file->data) {
-               data  = list_entry(pos, struct data, list);
+       ntfs_list_for_each(pos, &file->data) {
+               data  = ntfs_list_entry(pos, struct data, list);
                clusters_inuse = 0;
                clusters_free  = 0;
 
@@ -1374,7 +1376,7 @@ static int calc_percentage(struct ufile *file, ntfs_volume *vol)
 static void dump_record(struct ufile *file)
 {
        char buffer[20];
-       struct list_head *item;
+       struct ntfs_list_head *item;
        int i;
 
        if (!file)
@@ -1388,8 +1390,9 @@ static void dump_record(struct ufile *file)
        if (file->attr_list)
                ntfs_log_quiet("Metadata may span more than one MFT record\n");
 
-       list_for_each(item, &file->name) {
-               struct filename *f = list_entry(item, struct filename, list);
+       ntfs_list_for_each(item, &file->name) {
+               struct filename *f =
+                       ntfs_list_entry(item, struct filename, list);
 
                ntfs_log_quiet("Filename: (%d) %s\n", f->name_space, f->name);
                ntfs_log_quiet("File Flags: ");
@@ -1436,8 +1439,8 @@ static void dump_record(struct ufile *file)
        }
 
        ntfs_log_quiet("Data Streams:\n");
-       list_for_each(item, &file->data) {
-               struct data *d = list_entry(item, struct data, list);
+       ntfs_list_for_each(item, &file->data) {
+               struct data *d = ntfs_list_entry(item, struct data, list);
                ntfs_log_quiet("Name: %s\n", (d->name) ? d->name : UNNAMED);
                ntfs_log_quiet("Flags: ");
                if (d->resident)   ntfs_log_quiet("Resident\n");
@@ -1497,7 +1500,7 @@ static void dump_record(struct ufile *file)
 static void list_record(struct ufile *file)
 {
        char buffer[20];
-       struct list_head *item;
+       struct ntfs_list_head *item;
        const char *name = NULL;
        long long size = 0;
        int percent = 0;
@@ -1514,8 +1517,8 @@ static void list_record(struct ufile *file)
        else
                flagd = 'F';
 
-       list_for_each(item, &file->data) {
-               struct data *d = list_entry(item, struct data, list);
+       ntfs_list_for_each(item, &file->data) {
+               struct data *d = ntfs_list_entry(item, struct data, list);
 
                if (!d->name) {
                        if (d->resident)
@@ -1558,14 +1561,15 @@ static void list_record(struct ufile *file)
  */
 static int name_match(regex_t *re, struct ufile *file)
 {
-       struct list_head *item;
+       struct ntfs_list_head *item;
        int result;
 
        if (!re || !file)
                return 0;
 
-       list_for_each(item, &file->name) {
-               struct filename *f = list_entry(item, struct filename, list);
+       ntfs_list_for_each(item, &file->name) {
+               struct filename *f =
+                       ntfs_list_entry(item, struct filename, list);
 
                if (!f->name)
                        continue;
@@ -1744,7 +1748,7 @@ static int undelete_file(ntfs_volume *vol, long long inode)
        int i, j;
        long long start, end;
        runlist_element *rl;
-       struct list_head *item;
+       struct ntfs_list_head *item;
        int fd = -1;
        long long k;
        int result = 0;
@@ -1795,13 +1799,13 @@ static int undelete_file(ntfs_volume *vol, long long inode)
                goto free;
        }
 
-       if (list_empty(&file->data)) {
+       if (ntfs_list_empty(&file->data)) {
                ntfs_log_quiet("File has no data.  There is nothing to recover.\n");
                goto free;
        }
 
-       list_for_each(item, &file->data) {
-               struct data *d = list_entry(item, struct data, list);
+       ntfs_list_for_each(item, &file->data) {
+               struct data *d = ntfs_list_entry(item, struct data, list);
                char defname[sizeof(UNKNOWN) + 25];
 
                if (opts.output)
index 15a22dd..dd462f2 100644 (file)
@@ -62,7 +62,7 @@ struct options {
 };
 
 struct filename {
-       struct list_head list;          /* Previous/Next links */
+       struct ntfs_list_head list;     /* Previous/Next links */
        ntfschar        *uname;         /* Filename in unicode */
        int              uname_len;     /* and its length */
        long long        size_alloc;    /* Allocated size (multiple of cluster size) */
@@ -79,7 +79,7 @@ struct filename {
 };
 
 struct data {
-       struct list_head list;          /* Previous/Next links */
+       struct ntfs_list_head list;     /* Previous/Next links */
        char            *name;          /* Stream name in current locale */
        ntfschar        *uname;         /* Unicode stream name */
        int              uname_len;     /* and its length */
@@ -98,8 +98,8 @@ struct data {
 struct ufile {
        long long        inode;         /* MFT record number */
        time_t           date;          /* Last modification date/time */
-       struct list_head name;          /* A list of filenames */
-       struct list_head data;          /* A list of data streams */
+       struct ntfs_list_head name;     /* A list of filenames */
+       struct ntfs_list_head data;     /* A list of data streams */
        char            *pref_name;     /* Preferred filename */
        char            *pref_pname;    /*           parent filename */
        long long        max_size;      /* Largest size we find */