Programming FSRM quotas


Recently I was evaluating the options I had for implementing disk quotas on a backend system running on a major Internet Service Provider in Brazil.

Windows offers quota management up to some degree since NTFS 5 (Windows 2000) with user/volume quotas. Those were not appropriate for our scenario since we needed to set quotas on a per directory basis and this was not supported natively by Windows until the arrival of Windows Server 2003 R2.

R2 brings us a new feature called File Server Resource Manager a.k.a. FSRM. It is exposed for the system administrator as an MMC 3.0 snap-in.

Unfortunately, as of today Microsoft does not officially support any way for programming against FSRM quotas.  I said “officially support” because if the snap-in can do it, probably we can too! So after some research I found two DLLs called srm.dll and srmlib.dll that happens to do the stuff we want. Srm.dll exposes FSRM functionality through COM and srmlib.dll is a managed code wrapper around srm.dll.

Let’s take a look at some sample code:

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.Storage;

using System.IO;

using System.Runtime.InteropServices;


namespace Fsrm {

    class Program {

        static void Main(string[] args) {

            string directoryName = @"c:FsrmTests";


            // Creates a directory for testing if necessary

            if (!Directory.Exists(directoryName)) {




            ISrmQuotaManager quotaManager = new SrmQuotaManagerClass();

            ISrmQuota quota = null;

            try {

                // Try to get quota info

                quota = quotaManager.GetQuota(directoryName);

                quota.QuotaLimit *= 2;


            catch (COMException ex) {

                unchecked {

                    if (ex.ErrorCode == (int)0x80045301) {

                        // Quota doesn’t exist for this directory. Create it.

                        Console.WriteLine("No quota defined for ‘{0}’. Creating quota.", directoryName);

                        quota = quotaManager.CreateQuota(directoryName);

                        quota.QuotaLimit = 1024 * 1024;


                    else {







            // Update quota info



            // Add new file to the diretory to see QuotaUsed getting updated

            File.WriteAllText(directoryName + @"" + Path.GetRandomFileName() + ".txt", "Testing FSRM directory quotas");

            Console.WriteLine("New file added. Quota doubledrn{0} of {1} used.", quota.QuotaUsed, quota.QuotaLimit);





This sample doubles the size of the directory’s quota and puts a file in it every time it is run.

There are a bunch of other classes and methods available. Have fun!

Happy Old Year / Happy New Year!

I passed two more exams and became:
MCPD Enterprise Applications Developer
MCTS SQL Server 2005
MCSD .NET is the top developer’s certification for .NET 1.x and MCPD EAD is the top developer’s certification for .NET 2.0.
When I started the certification path back in 2003, the plan was to become MCSD, MCDBA and MCSE.
Since then MCDBA has started to fase out in favor of the new MCITP certification.
I already passed two exams in the new path. There’s only one to go.
Then I’ll see if I will still try to pursue MCSE or if I’ll wait for the Longhorn Server exams;
Oh.. By the way… Happy new year!

Certification Update

This week I passed another couple of exams:

70-551 – UPGRADE: MCAD Skills to MCPD Web Developer by Using the Microsoft® .NET Framework

70-300 – Analyzing Requirements and Defining Microsoft .NET Solution Architectures

With 70-551 I became an MCPD Web Developer and as a side effect, an MCTS .NET Framework 2.0 Web Applications



Dependency Hell – Or Compilation-time DLL Hell

For the last couple of months I’ve been working on a project on which the entire Visual Studio solution has 65 projects.

Luckily I’ve been able to work with a smaller solution with only a subset of the projects: The ones that I was working directly with and the ones that I needed for a reason or another.

Unfortunately a couple of weeks ago, the time to start integrating my projects to the main solution arrived and since then I and other team members have been having troubles setting up references between projects.

I ended up detecting that the problems where caused by the references being set by file when for the sake of easy compilation they should been referenced by project.

I then reviewed all the projects setting their reference types to project references and the number of issues fell dramatically.

But occasionally a team member was getting compilation errors during to version number conflicts.

Imagine that project A depends on projects B and C and that B and C depend on different versions of D.

When you try to build the entire solution, although references where set to projects instead of files, Visual Studio 2003 couldn’t compile project A stating that there where conflicting versions of D in the bin folder.

Well, to get the story short, after trying to get rid of the error I searched around and ended up finding an article the explained how to resolve the issue: Error: the dependency ‘file’ in project ‘project’ cannot be copied to the run directory because it would conflict with dependency ‘file’