ntfsls.c revision 1
1N/A * ntfsls - Part of the Linux-NTFS project. 1N/A * Copyright (c) 2003 Lode Leroy 1N/A * Copyright (c) 2003-2005 Anton Altaparmakov 1N/A * Copyright (c) 2003 Richard Russon 1N/A * Copyright (c) 2004 Carmelo Kintana 1N/A * Copyright (c) 2004 Giang Nguyen 1N/A * This utility will list a directory's files. 1N/A * This program is free software; you can redistribute it and/or modify 1N/A * it under the terms of the GNU General Public License as published by 1N/A * the Free Software Foundation; either version 2 of the License, or 1N/A * (at your option) any later version. 1N/A * This program is distributed in the hope that it will be useful, 1N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of 1N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1N/A * GNU General Public License for more details. 1N/A * You should have received a copy of the GNU General Public License 1N/A * along with this program (in the main directory of the Linux-NTFS 1N/A * distribution in the file COPYING); if not, write to the Free Software 1N/A * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1N/A * To hold sub-directory information for recursive listing. 1N/A * @depth: the level of this dir relative to opts.path 1N/A * path_component - to store path component strings 1N/A * @name: string pointer 1N/A * NOTE: @name is not directly allocated memory. It simply points to the 1N/A * character array name in struct dir. 1N/A/* The list of sub-dirs is like a "horizontal" tree. The root of 1N/A * the tree is opts.path, but it is not part of the list because 1N/A * that's not necessary. The rules of the list are (in order of 1N/A * 1. directories immediately follow their parent. 1N/A * 2. siblings are next to one another. 1N/A * 2. / has 2 sub-dirs: dir1 and dir2 1N/A * 3. dir1 has 2 sub-dirs: dir11 and dir12 1N/A * 4. dir2 has 0 sub-dirs 1N/A * then the list will be: 1N/A * dummy head -> dir1 -> dir11 -> dir12 -> dir2 1N/A * dir_list_insert_pos keeps track of where to insert a sub-dir 1N/A/* The global depth relative to opts.path. 1N/A * ie: opts.path has depth 0, a sub-dir of opts.path has depth 1 1N/A * version - Print version information about the program 1N/A * Print a copyright statement and a brief description of the program. 1N/A printf(
"\n%s v%s (libntfs %s) - Display information about an NTFS " 1N/A printf(
"Copyright (c) 2003-2005 Anton Altaparmakov\n");
1N/A printf(
"Copyright (c) 2003 Richard Russon\n");
1N/A printf(
"Copyright (c) 2004 Carmelo Kintana\n");
1N/A * usage - Print a list of the parameters to the program 1N/A * Print a list of the parameters and options for the program. 1N/A " -a, --all Display all files\n" 1N/A " -F, --classify Display classification\n" 1N/A " -f, --force Use less caution\n" 1N/A " -h, --help Display this help\n" 1N/A " -i, --inode Display inode numbers\n" 1N/A " -l, --long Display long info\n" 1N/A " -p, --path PATH Directory whose contents to list\n" 1N/A " -q, --quiet Less output\n" 1N/A " -R, --recursive Recursively list subdirectories\n" 1N/A " -s, --system Display system files\n" 1N/A " -V, --version Display version information\n" 1N/A " -v, --verbose More output\n" 1N/A " -x, --dos Use short (DOS 8.3) names\n" 1N/A printf(
"NOTE: If neither -a nor -s is specified, the program defaults to -a.\n\n");
1N/A * parse_options - Read and validate the programs command line 1N/A * Read the command line, verify the syntax and parse the options. 1N/A * This function is very long, but quite simple. 1N/A * 0 Error, one or more problems 1N/A static const char *
sopt =
"-aFfh?ilp:qRsVvx";
1N/A opterr = 0;
/* We'll handle the errors, thank you. */ 1N/A /* Make sure we're in sync with the log levels */ 1N/A /* defaults to -a if -s is not specified */ 1N/A * free_dir - free one dir 1N/A * @tofree: the dir to free 1N/A * Close the inode and then free the dir 1N/A * free_dirs - walk the list of dir's and free each of them 1N/A * @dir_list: the list_head of any entry in the list 1N/A * Iterate over @dir_list, calling free_dir on each entry 1N/A * readdir_recursive - list a directory and sub-directories encountered 1N/A * @ni: ntfs inode of the directory to list 1N/A * @pos: current position in directory 1N/A * @dirent: context for filldir callback supplied by the caller 1N/A * For each directory, print its path relative to opts.path. List a directory, 1N/A * then list each of its sub-directories. 1N/A * Returns 0 on success or -1 on error. 1N/A * NOTE: Assumes recursive option. Currently no limit on the depths of 1N/A /* list of dirs to "ls" recursively */ 1N/A /* for each of ni's sub-dirs: list in this iteration, then 1N/A free at the top of the next iteration or outside of loop */ 1N/A /* subdir is not a subdir of ni */ 1N/A (
"ntfsls::readdir_recursive(): cannot get inode from pathname.\n");
1N/A /* print relative path header */ 1N/A /* if at the outer-most readdir_recursive, then clean up */ 1N/A * FIXME: Should we print errors as we go along? (AIA) 1N/A ni =
NULL;
/* so release does not close inode */ 1N/A /* Release attribute search context and close the inode. */ 1N/A * Return: 0 Success, the program worked 1N/A * 1 Error, parsing mount options failed 1N/A * 2 Error, mount attempt failed 1N/A * 3 Error, failed to open root directory 1N/A * 4 Error, failed to open directory in search path 1N/A // FIXME: Print error... (AIA) 1N/A // FIXME: Print error... (AIA) 1N/A // FIXME: Print error... (AIA) 1N/A * We now are at the final path component. If it is a file just 1N/A * list it. If it is a directory, list its contents. 1N/A // FIXME: error checking... (AIA) 1N/A /* We know this will always be resident. */ 1N/A // FIXME: error checking... (AIA) 1N/A /* Finished with the inode; release it. */