Thursday, March 26, 2009

Windows Vista Defragmentation Tools

Windows Vista by default uses NTFS file system. Sooner or later files on it will start to fragment.

Fragmentation can lead to significant disk I/O performance decrease. Common way how to handle this problem is a process called defragmentation

It turns out that Vista's defragmentation tools is little bit oversimplified

As you can see, user interface lacks volume fragmentation information. So it is hard to say whether my volume needs defragmentation.

Be afraid not as Vista has command-line based tool - defrag.exe.

Windows Disk Defragmenter
Copyright (c) 2006 Microsoft Corp.
Description: Locates and consolidates fragmented files on local volumes to
improve system performance.

Syntax: defrag -a [-v]
defrag [{-r | -w}] [-f] [-v]
defrag -c [{-r | -w}] [-f] [-v]


Value Description

Specifies the drive letter or mount point path of the volume to
be defragmented or analyzed.

-c Defragments all volumes on this computer.

-a Performs fragmentation analysis only.

-r Performs partial defragmentation (default). Attempts to
consolidate only fragments smaller than 64 megabytes (MB).

-w Performs full defragmentation. Attempts to consolidate all file
fragments, regardless of their size.

-f Forces defragmentation of the volume when free space is low.

-v Specifies verbose mode. The defragmentation and analysis output
is more detailed.

-? Displays this help information.


defrag d:
defrag d:\vol\mountpoint -w -f
defrag d: -a -v
defrag -c -v

Here's sample output on my system volume (C:),
defrag c: -a
Windows Disk Defragmenter
Copyright (c) 2006 Microsoft Corp.

Analysis report for volume C: VISTA

Volume size = 70.00 GB
Free space = 21.84 GB
Largest free space extent = 6.20 GB
Percent file fragmentation = 4 %

Note: On NTFS volumes, file fragments larger than 64MB are not included in the fragmentation statistics

You do not need to defragment this volume.

It is also possible to increase the amount of information returned by the tool, just specify -v switch.

Now we have some information about disk fragmentation and hence can decide when to start defragmentation process.

P.S. I had a strange filling when writing this post. In an operating system like Windows Vista with redesigned user interface it is awkward too use command-line tools to perform common task like disk defragmentation.

Sunday, March 15, 2009

Image Watermarking

We all know that when image is posted on the internet it no longer belongs to you.

It can be arguable, but nevertheless, any user with browser can simply save it on HDD and you can do nothing about it.

One of the ways how to control image distribution is Digital watermarking.

In my case I had ~100 images that had to be watermarked. There are two ways how to do this: manually (e.g using Photoshop) or write some code to do the job automatically.

In case of simple watermarks: horizontal/vertical text everything is simple, but things become harder when watermark text should be positioned diagonally.

After poking around the web I found this brilliant article. The code did it job well, so I wired it into small console app, and voilà - 105 files watermaked in less then 20 seconds.