summaryrefslogtreecommitdiff
path: root/lib/ext2fs/unix_io.c
AgeCommit message (Collapse)AuthorFilesLines
2011-10-06libext2fs: make ext2fs_open_file() always use 3 arguments instead of varargsTheodore Ts'o1-1/+1
Some architectures have narrow mode_t's which can cause some portability warnings with varargs. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-18Shorten compile commands run by the build systemTheodore Ts'o1-0/+1
The DEFS line in MCONFIG had gotten so long that it exceeded 4k, and this was starting to cause some tools heartburn. It also made "make V=1" almost useless, since trying to following the individual commands run by make was lost in the noise of all of the defines. So fix this by putting the configure-generated defines in lib/config.h and the directory pathnames to lib/dirpaths.h. In addition, clean up some vestigal defines in configure.in and in the Makefiles to further shorten the cc command lines. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16e2fsprogs: Fix some error cleanup path bugsEric Sandeen1-1/+1
In inode_open(), if the allocation of &io fails, we go to cleanup and dereference io to test io->name, which is a bug. Similarly in undo_open() if allocation of &data fails, we go to cleanup and dereference data to test data->real. In the test_open() case we explicitly set retval to the only possible error return from ext2fs_get_mem(), so remove that for tidiness. The other changes just make make earlier returns go through the error goto for consistency. In many cases we returned directly from the first error, but "goto cleanup" etc for every subsequent error. In some cases this leads to "impossible" tests such as: if (ptr) ext2fs_free_mem(&ptr) on paths where ptr cannot be null because we would have returned directly earlier, and Coverity flags this. This isn't really indicative of an error in most cases, but I think it can be clearer to always exit through the error goto if it's used later in the function. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15e2fsprogs: Use punch hole as "discard" on regular filesLukas Czerner1-8/+45
If e2fsprogs tools (mke2fs, e2fsck) is run on regular file instead of on block device, we can use punch hole instead of regular discard command which would not work on regular file anyway. This gives us several advantages. First of all when e2fsck is run with '-E discard' parameter it will punch out all ununsed space from the image, hence trimming down the file system image. And secondly, when creating an file system on regular file (with '-E discard' which is default), we can use punch hole to clear the file content, hence we can skip inode table initialization, because reads from sparse area returns zeros. This will result in faster file system creation (without the need to specify lazy_itable_init) and smaller images. This commit also fixes some tests that would fail due to mke2fs showing discard progress, hence the output would differ. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15e2fsprogs: create open() and stat() helpersLukas Czerner1-7/+3
In many places we are using #ifdef HAVE_OPEN64 to determine if we can use open64() but that's ugly. This commit creates two new helpers ext2fs_open_file() for open() and ext2fs_stat() for stat(). Also we need new typedef ext2fs_struct_stat for struct stat. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-07-07libext2fs: Fix gcc -Wall warningsTheodore Ts'o1-2/+4
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-06-11ext2fs: don't use O_DIRECT if not availableAndreas Dilger1-0/+2
O_DIRECT is not defined on OSX. Since direct IO is only a new optimization and not needed for correct functionality, disable it if O_DIRECT is unavailable. Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-06-11misc: clean up compiler warningsAndreas Dilger1-0/+2
Fix several types of compiler warnings (unused variables/labels), uninitialized variables, etc that are hit with gcc -Wall. Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-11-22e2fsprogs: Add CHANNEL_FLAGS_DISCARD_ZEROES flag for io_managerLukas Czerner1-1/+13
When the device have discard support and simultaneously discard zeroes data (and it is properly advertised), then we can take advantage of such behavior in several e2fsprogs tools. Add new flag CHANNEL_FLAGS_DISCARD_ZEROES for struct_io_channel so each io_manager can take advantage of this. The flag is properly set according to BLKDISCARDZEROES ioctl in unix_open. Also remove old mke2fs_discard_zeroes_data() function and substitute it with helper which test this flag. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-11-22e2fsprogs: Add discard function into struct_io_managerLukas Czerner1-0/+31
In order to provide generic "discard" function for all e2fsprogs tools add a discard function prototype into struct_io_manager. Specific function for specific io managers can be crated that way. This commit also creates unix_discard function which uses BLKDISCARD ioctl to discard data blocks on the block device and bind it into unit_io_manager structure to be available for all e2fsprogs tools. Note that BLKDISCARD is still Linux specific ioctl, however other unix systems may provide similar functionality. So far the unix_discard() remains linux specific hence is embedded in #ifdef __linux__ macro. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-09-24ext2fs: Add Direct I/O support to the ext2fs libraryTheodore Ts'o1-83/+137
This adds the basic support for Direct I/O to unix_io.c, and adds a new flag EXT_FLAG_DIRECT_IO which can be passed to ext2fs_open() or ext2fs_open2() to request Direct I/O support. Note that device mapper devices in Linux don't support Direct I/O, and in some circumstances using Direct I/O can actually make performance *worse*! Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-09-23libext2fs: Fix memory leak in the Unix I/O layer when changing block sizeTheodore Ts'o1-0/+2
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-05-17libe2p, libext2fs: Update file copyright permission states to match COPYINGTheodore Ts'o1-2/+2
The top-level COPYING file states that the e2p and ext2fs libraries are available under the LGPLv2. The files were incorrectly labelled. Alex Thomas/Luster has been consulted wrt to the ext3_extents.h file; the rest of the files were primarily authored by Theodore Ts'o. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-10-12unix_io: check for read-only devices when opening R/WEric Sandeen1-0/+25
When we open a device on linux, test whether it is writable right away, rather than trying to proceed and clean up when writes start failing. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2008-08-27Remove trailing whitespace for the entire source treeTheodore Ts'o1-22/+22
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-03-13Add {read,write}_blk64 to unix_io.cJose R. Santos1-7/+25
Add 64-bit block capable routines to Unix IO manager. Signed-off-by: Jose R. Santos <jrs@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-08-03Add I/O statistics to e2fsckTheodore Ts'o1-2/+25
This patch instruments the libext2fs unix I/O manager and adds bytes read/written and data rate to e2fsck -tt pass/overall timing output. Signed-off-by: Jim Garlick <garlick@llnl.gov> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2006-11-12Allow unix_io offsets greater than 2GTheodore Ts'o1-2/+4
Addresses SourceForge Bug: #1547922 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2006-09-12Fix signed vs unsigned printf format strings for block and inode numbersEric Sandeen1-4/+4
There were still some %d's lurking when we print blocks & inodes; also many of the counters in the e2fsck_struct were signed, and probably need to be unsigned to avoid overflows. Signed-off-by: Eric Sandeen <esandeen@redhat.com>
2006-03-18Add IO_FLAG_EXCLUSIVE flag to io_channel abstractionTheodore Ts'o1-0/+2
Add a new io_channel open flag, IO_FLAG_EXCLUSIVE,which requests that the device be opened in exclusive (O_EXCL) mode. Add support to the unix_io implementation for this flag. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2004-11-30Add support for passing options to the io layer using the URL syntax. For Theodore Ts'o1-9/+36
example, /tmp/test.img?offset=1024. Multiple options can separated using the & character, although at the moment the only option implemented is the offset option in the unix_io layer.
2004-03-30unix_io.c, pass1.c:Matthias Andree1-2/+2
int -> unsigned for 1 bit wide bitfields - we cannot have a value and a sign in 1 bit. Fixes some of the Intel C++ 8.0 warnings (-w1 level).
2004-03-30GNU/KFreeBSD portability fixes. (Addresses Debian Bug #239934)Matthias Andree1-1/+3
2003-12-28Re-add FreeBSD support. Matthias Andree1-4/+10
Tested on FreeBSD 5.2-CURRENT as of 2003-12-28. Tested on FreeBSD 4.9-STABLE as of 2003-12-27.
2003-12-07Fix gcc -Wall nitpicksTheodore Ts'o1-15/+11
2003-08-01ext2fs_getmem(), ext2fs_free_mem(), and ext2fs_resize_mem() Theodore Ts'o1-12/+10
all now take a 'void *' instead of a 'void **' in order to avoid pointer aliasing problems with GCC 3.x.
2003-05-13unix_io.c: Add #ifdef NO_IO_CACHE which disables all userspaceTheodore Ts'o1-0/+18
caching by the unix_io layer. Not enabled, only for debugging.
2003-04-18configure.in: Remove CYGWIN definition; we will use theTheodore Ts'o1-3/+3
automatically defined __CYGWIN__ instead.
2003-04-13Add portability enhancements for Cygwin32 environment.Theodore Ts'o1-3/+65
2003-01-22unix_io.c (unix_write_blk): Fix up GCC -Wall nits.Theodore Ts'o1-2/+5
2002-11-09unix_io.c (find_cached_block, reuse_cache, unix_read_blk, Theodore Ts'o1-43/+40
unix_write_blk): Optimize routines so that we don't end up searching the cache twice when a block isn't in the cache. If reads are larger than READ_DIRECT_SIZE, don't let them go through the cache.
2002-11-09unix_io.c (find_cached_block): Fixed bug which caused some cleanTheodore Ts'o1-0/+1
blocks to be erroneously marked as dirty, so they would get written back to the disk before they are evicted from the cache. Harmless, but it slows down e2fsck significantly.
2002-07-14unix_io.c (unix_open): Only attempt the setrlimit workaround ifTheodore Ts'o1-3/+17
the kernel version is 2.4.10 -- 2.4.17, since otherwise an old version of glibc (built against 2.2 headers) will interact badly with the workaround to actually cause more problems. I hate it when the glibc folks think they're being smarter than the kernel....
2002-02-23unix_io.c (unix_open): Fix 2.4 resource limit workaround so thatTheodore Ts'o1-2/+12
it doesn't break things on mis32, sparc32, and alpha platforms.
2002-02-20Add new inode I/O abstraction interface which exports an inode asTheodore Ts'o1-2/+2
an I/O object. Export ext2_file_flush as a public interface. Also minor cleanups to tighten code in other I/O abstractions, and to mark a void * pointer as const in the ext2_file_write interface.
2001-12-03unix_io.c (unix_open): Make sure the ulimit workaround worksTheodore Ts'o1-3/+3
regardless of the version of glibc which is used to compild e2fsprogs.
2001-11-26unix_io.c (unix_open): Work around a bug in 2.4.10+ kernels byTheodore Ts'o1-0/+20
trying to unset the filesize limit if at all possible, if a block device is getting opened. (The filesize limit shouldn't be applied against writes to a block device, but starting in 2.4.10, the kernel is doing this.)
2001-05-14Many files:Theodore Ts'o1-5/+0
alloc.c, alloc_tables.c, badblocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2_fs.h, fileio.c, finddev.c, flushb.c, freefs.c, get_pathname.c, getsize.c, icount.c, imager.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, mkjournal.c, namei.c, native.c, newdir.c, nt_io.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_byteswap.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c, write_bb_file.c, ext2_fs.h: Moved file from include/linux. Adjust all files in this directroy to include this file.
2001-01-11Many files:Theodore Ts'o1-23/+23
alloc.c, bb_inode.c, bitmaps.c, bitops.h, block.c, bmap.c, bmove.c, brel.h, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, expanddir.c, ext2fs.h, ext2fsP.h, fileio.c, finddev.c, get_pathname.c, icount.c, inode.c, irel.h, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, mkjournal.c, namei.c, newdir.c, read_bb_file.c, test_io.c, tst_iscan.c, unix_io.c, unlink.c: Change use of ino_t to ext2_ino_t, to protect applications that attempt to compile -D_FILE_OFFSET_BITS=64, since this inexplicably changes ino_t(!?). So we use ext2_ino_t to avoid an unexpected ABI change.
2000-10-26Many files:Theodore Ts'o1-1/+34
ext2_io.h (io_channel_write_byte): Add new interface to allow callers to write specific byte ranges. This is an optional interface, which not all IO channels may implement. unix_io.c (unix_write_byte): test_io.c (test_write_byte): Add implementation of the write_byte function. closefs.c (write_primary_superblock, ext2fs_flush): Add a new function which writes the primary superblock. If the IO channel supports writing raw bytes directly, only fields which were modified are written to the disk. This makes it safe(r) to use utilities like tune2fs on a mounted filesystem. freefs.c (ext2fs_free): Free the original superblock if it is available. openfs.c (ext2fs_open): Store a copy of the original superblock when opening it. ext2fs.h: Add a field to store the original superblock in the ext2 context structure.
2000-10-18ChangeLog, ext2_io.h, unix_io.c:Theodore Ts'o1-84/+314
unix_io.c: Make massive changes to support a multiple block writethrough cacheing. ext2_io.h: Added flags field to the io_channel structure.
2000-05-25ChangeLog, getsize.c, llseek.c, unix_io.c:Theodore Ts'o1-1/+10
getsize.c (ext2fs_get_device_size): Use open64() instead of open() if it exists. unix_io.c (unix_open): Use open64() instead of open() if it exists. llseek.c: Simplify header includes of unistd.h. If lseek64 is available (and prototypes are defined) use it in preference to llseek.
1998-02-20ChangeLog, getsize.c, ismounted.c, unix_io.c:Theodore Ts'o1-0/+3
getsize.c, ismounted.c, unix_io.c: #include errno.h since it's needed.
1998-01-19Many files:Theodore Ts'o1-0/+4
inode.c (ext2fs_open_inode_scan): Initialize the group variables so that we don't need to call get_next_blockgroup() the first time around. Saves a bit of time, and prevents us from needing to assign -1 to current_group (which is an unsigned value). icount.c (insert_icount_el): Cast the estimated number of inodes from a float to an ino_t. alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c, bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c, check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c, ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c, icount.c, initialize.c, inline.c, inode.c, irel_ma.c, ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c, newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c, rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c, tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c, version.c: If EXT2_FLAT_INCLUDES is defined, then assume all of the ext2-specific header files are in a flat directory. block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast all assignments from void * to be compatible with C++. closefs.c (ext2fs_flush): Add a call to io_channel_flush() to make sure the contents of the disk are flushed to disk. dblist.c (ext2fs_add_dir_block): Change new to be new_entry to avoid C++ namespace clash. bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to avoid C++ namespace clash. ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c, irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c, ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c, unlink.c: Change private to be priv_data (to avoid C++ namespace clash)
1997-12-01Many files:Theodore Ts'o1-3/+2
dblist.c (ext2fs_get_num_dirs): Make ext2fs_get_num_dirs more paranoid about validating the directory counts from the block group information. all files: Don't include stdlib.h anymore; include it in ext2_fs.h, since that file requires stdlib.h ChangeLog, Makefile.in, dirinfo.c: dirinfo.c (e2fsck_add_dir_info): Use ext2fs_get_num_dirs instead of e2fsck_get_num_dirs, which has been removed. Makefile.in (PROGS): Remove @EXTRA_PROGS@, since we don't want to compile and install flushb. ChangeLog, configure.in: Remove @EXTRA_PROGS@, since we aren't using it in 2fsck/Makefile.in anymore ChangeLog, Makefile.in: Install debugfs in /sbin, instead of /usr/sbin. libext2fs.texinfo: Update version string to be 1.12 Makefile.in: Fix bug in find script which made the exclusion list, where a '-' was missing from an -name option.
1997-10-26Many files:Theodore Ts'o1-30/+29
Added definition of ext2fs_get_mem, ext2fs_free_mem, and ext2fs_resize_mem in ext2fs.h, and changed all library routines to use these wrapper functions.
1997-10-25Many files:Theodore Ts'o1-8/+5
alloc.c (ext2fs_alloc_block): New function which allocates a block and updates the filesystem accounting records appropriately. ext2_err.et.in: Added new error codes: EXT2_NO_MEMORY, EXT2_INVALID_ARGUMENT, EXT2_BLOCK_ALLOC_FAIL, EXT2_INODE_ALLOC_FAIL, EXT2_NOT_DIRECTORY Change various library files to use these functions instead of EINVAL, ENOENT, etc. ChangeLog, pass1.c, pass3.c: pass3.c (get_lost_and_found): Check error return of EXT2_FILE_NOT_FOUND instead of ENOTDIR pass1.c (pass1_check_directory): Return EXT2_NO_DIRECTORY instead of ENOTDIR expect.icount: Change expected error string to be "Invalid argument passed to ext2 library" instead of just "Invalid argument"
1997-10-20Many files:Theodore Ts'o1-1/+1
Rename io.h to be ext2_io.h (avoid namespace collisions) ChangeLog, resize2fs.h: Add #ifdef's for HAVE_SYS_TYPES_H and HAVE_SYS_TIME_H.
1997-10-19Many files:Theodore Ts'o1-0/+4
Add #ifdef's for HAVE_SYS_STAT_H and HAVE_SYS_TYPES_H
1997-08-10Many files:Theodore Ts'o1-0/+2
block.c (ext2fs_block_iterate2): Use retval which is a errcode_t type. bitmaps.c (make_bitmap): Use size_t instead of int where appropriate. bb_inode.c (set_bad_block_proc): Add #pragma argsused for Turbo C. alloc.c (ext2fs_new_inode): Use ino_t instead of int for the group number. get_pathname.c: Use ino_t instead of int where appropriate. ext2fs.h: Make the magic structure element be errcode_t instead of int. alloc.c alloc_tables.c badblocks.c bb_compat.c bb_inode.c bitmaps.c block.c bmove.c brel_ma.c check_desc.c closefs.c cmp_bitmaps.c dblist.c dblist_dir.c dir_iterate.c dirblock.c dupfs.c expanddir.c freefs.c get_pathname.c icount.c initialize.c inline.c inode.c irel_ma.c link.c llseek.c lookup.c mkdir.c namei.c newdir.c read_bb.c read_bb_file.c rs_bitmap.c rw_bitmaps.c swapfs.c test_io.c tst_badblocks.c tst_iscan.c unix_io.c unlink.c valid_blk.c version.c: Add an #ifdef for HAVE_UNISTD_H