#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:
* 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;
}
/**
- * 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:
*
* 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;
}
/**
- * 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)
* @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;
* character array name in struct dir.
*/
struct path_component {
- struct list_head list;
+ struct ntfs_list_head list;
const char *name;
};
* 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
/**
* 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);
{
/* 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
};
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);
}
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)
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
break;
tofree = subdir;
- list_del(dir_walker);
+ ntfs_list_del(dir_walker);
}
- list_del(&comp.list);
+ ntfs_list_del(&comp.list);
}
if (tofree)
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);
*/
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)
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)
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++;
}
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++;
}
}
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++;
}
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);
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;
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;
static void dump_record(struct ufile *file)
{
char buffer[20];
- struct list_head *item;
+ struct ntfs_list_head *item;
int i;
if (!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: ");
}
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");
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;
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)
*/
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;
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;
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)
};
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) */
};
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 */
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 */