Thread: Windows permissions? help

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Yes the Toshiba DVDs will restore your hard disk all the way back to factory condition. (Useful if returnin it).

    I've always liked Toshiba notebooks, they're rugged, well thought out and very reliable. The only weakness seems to be that on some models it's possible to push the charger's power connector back into the case without much effort... and, of course, like all lappies, the hinges do sometimes break if you handle it roughly.

    What I don't like about Toshiba is all the CRAP software they put in them at the factory... Norton? Really??? And what the heck is this Toshiba BulletinBoard thing... except spyware and advertising? Gees guys...

    But when you rip one down to a bare hard disk and restart it with a clean windows install, Toshiba Rocks!

  2. #17
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Elysia View Post
    Windows 7 does not require 20 GB. It needs around 7 GB to install, and consumes less than that.
    Ok, Rucy, 'splain this one...

    Windows permissions? help-systemsize-png

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The Windows directory grows in size over time as you install and use software and updates (to maintain backward compatibility).
    The user directory typically does not eat much space unless you have a lot of user data (such as video, or application data).
    I have installed Windows on a partition with a little over 7 GB of free space with no trouble.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    No swap file, no system restore, no hyberfile, no automatic updates, user folders on a different drive... 15gb. Drive cleanup and defrag *might* get that down to 14gb.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Not after a clean install. But it will grow in time.
    But I thought we agreed that automatic updates are useless, didn't we? They break more than they fix.
    Also, system restore is close to useless. It eats up a ton of space with only a few restore points. You're better off using a real backup software.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by CommonTater View Post
    Ok, Rucy, 'splain this one...

    Windows permissions? help-systemsize-png
    The Old New Thing - Site Home - MSDN Blogs
    Windows Setup takes advantage of hard links. A large percentage of the files installed by Windows are hard-linked to copies in the C:\Windows\WinSxS directory for reasons I do not understand, but the phrase "component store" may be part of it. (This is why asking Explorer for the size of the C:\Windows directory gives a misleading view of the actual amount of disk space occupied by Windows, because Explorer uses a naive algorithm which counts each hard link as a separate file.) Oh, and in Windows 7, the two copies of Notepad are now hard links to each other.
    Hardlinks. This'll calculate the actual size of a directory tree. Insert an freopen and use PsExec to run it as a service to dodge most of the permission errors.
    Code:
    #define WIN32_LEAN_AND_MEAN
    #define _WIN32_WINNT 0x0600
    #include <windows.h>
    #include <shlwapi.h>
    #include <winioctl.h>
    #include <cstdio>
    #include <cstring>
    #include <map>
    #include <string>
    
    struct FileSizeInfo
    {
        ULONGLONG fileSize;
        std::wstring name;
    };
    
    struct ObjId
    {
        BYTE id[16];
        ObjId(BYTE theId[16])
        {
            memcpy(id, theId, ARRAYSIZE(id));
        }
    
        bool operator<(const ObjId& other) const
        {
            int ret = memcmp(id, other.id, ARRAYSIZE(id));
            return ret < 0;
        }
    };
    
    typedef std::map<ObjId, FileSizeInfo> FileSizeInfos;
    
    SRWLOCK g_srwLock;
    LONG g_outstandingRequests = 0;
    DWORD g_totalFiles = 0;
    
    struct ThreadParams
    {
        std::wstring dir;
        FileSizeInfos& fileSizes;
        ThreadParams(const std::wstring& dir, FileSizeInfos& fileSizes)
            : dir(dir),
            fileSizes(fileSizes)
        {}
    };
    
    DWORD WINAPI UserCallback(PVOID pParams);
    
    void IterateDir(const std::wstring& root, FileSizeInfos& fileSizes)
    {
        FileSizeInfos localSizeVec;
        std::wstring fileSpec = root + L'*';
        WIN32_FIND_DATA wfd = {0};
        DWORD dirFiles = 0;
        HANDLE hDirEntry = FindFirstFile(fileSpec.c_str(), &wfd);
    
        if(hDirEntry == INVALID_HANDLE_VALUE)
        {
            wprintf(L"Failed to start iterating %s because of error %lu\n", fileSpec.c_str(), GetLastError());
            return;
        }
        do
        {
            if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                if(wfd.cFileName[0] == L'.' && (wfd.cFileName[1] == 0 || (wfd.cFileName[1] == L'.' && wfd.cFileName[2] == 0)))
                {
                    continue;
                }
                std::wstring nextRoot = root + wfd.cFileName;
                nextRoot += L'\\';
                ThreadParams* pTp = new(std::nothrow) ThreadParams(nextRoot, fileSizes);
                if(pTp)
                {
                    _InterlockedIncrement(&g_outstandingRequests);
                    QueueUserWorkItem(&UserCallback, pTp, WT_EXECUTEDEFAULT);
                }
                else
                {
                    wprintf(L"Failed to allocate memory for threadparams for root %s\n", nextRoot.c_str());
                }
            }
            else
            {
                ++dirFiles;
                ULONGLONG fileSize = wfd.nFileSizeHigh;
                fileSize <<= 32;
                fileSize |= wfd.nFileSizeLow;
                std::wstring fullName = root + wfd.cFileName;
                FileSizeInfo sizeInfo = {fileSize, fullName};
                HANDLE hFile = CreateFile(
                    fullName.c_str(),
                    0,
                    FILE_SHARE_READ,
                    NULL,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL
                );
                if(hFile == INVALID_HANDLE_VALUE)
                {
                    wprintf(L"Couldn't open handle for %s (%lu)\n", fullName.c_str(), GetLastError());
                    continue;
                }
                DWORD dummy = 0;
                FILE_OBJECTID_BUFFER idBuffer = {0};
                if(DeviceIoControl(hFile, FSCTL_CREATE_OR_GET_OBJECT_ID, NULL, 0, &idBuffer, sizeof(idBuffer), &dummy, NULL))
                {
                    localSizeVec.insert(std::make_pair(ObjId(idBuffer.ObjectId), sizeInfo));
                }
                CloseHandle(hFile);
            }
        }
        while(FindNextFile(hDirEntry, &wfd));
        DWORD err = GetLastError();
        FindClose(hDirEntry);
        bool ret = (err == ERROR_NO_MORE_FILES);
        if(!ret)
        {
            wprintf(L"Failed to enumerate all files with pattern %s because of error %lu\n", fileSpec.c_str(), err);
        }
        AcquireSRWLockExclusive(&g_srwLock);
        fileSizes.insert(localSizeVec.begin(), localSizeVec.end());
        g_totalFiles += dirFiles;
        ReleaseSRWLockExclusive(&g_srwLock);
    }
    
    DWORD WINAPI UserCallback(PVOID pParams)
    {
        ThreadParams* pTp = static_cast<ThreadParams*>(pParams);
        IterateDir(pTp->dir, pTp->fileSizes);
        _InterlockedDecrement(&g_outstandingRequests);
        delete pTp;
        return 0;
    }
    
    int __cdecl wmain(int argc, wchar_t** argv)
    {
        if(argc < 2)
        {
            puts("Usage: FileSizeStats <root>");
            return 0;
        }
        
        InitializeSRWLock(&g_srwLock);
        FileSizeInfos fileSizes;
        std::wstring rootDir = argv[1];
        rootDir += L'\\';
        IterateDir(rootDir, fileSizes);
        while(_InterlockedCompareExchange(&g_outstandingRequests, 0, 0) != 0)
        {
            Sleep(1000);
        }
    
        ULONGLONG totalSize = 0, biggestFile = 0, smallestFile = UINT64_MAX;
        const std::wstring* pBigFile = NULL, *pSmallFile = NULL;
        for(FileSizeInfos::const_iterator iter = fileSizes.begin(), end = fileSizes.end();
            iter != end;
            ++iter
        )
        {
            const FileSizeInfo& fi = iter->second;
            const ULONGLONG& size = fi.fileSize;
            totalSize += size;
            if(size < smallestFile)
            {
                smallestFile = size;
                pSmallFile = &fi.name;
            }
            if(size > biggestFile)
            {
                biggestFile = size;
                pBigFile = &fi.name;
            }
        }
        WCHAR sizeBuf[25] = {0};
        StrFormatByteSizeW((LONGLONG)totalSize, sizeBuf, ARRAYSIZE(sizeBuf));
        wprintf(L"Total size of %s: %s (%I64u)\n", argv[1], sizeBuf, totalSize);
    
        StrFormatByteSizeW((LONGLONG)biggestFile, sizeBuf, ARRAYSIZE(sizeBuf));
        wprintf(L"Biggest file: %s (%s)\n", pBigFile->c_str(), sizeBuf);
    
        StrFormatByteSizeW((LONGLONG)smallestFile, sizeBuf, ARRAYSIZE(sizeBuf));
        wprintf(L"Smallest file: %s (%s)\n", pSmallFile->c_str(), sizeBuf);
    
        wprintf(L"Total files %lu\nunique files: %Iu\n", g_totalFiles, fileSizes.size());
        return 0;
    }
    Last edited by adeyblue; 11-25-2011 at 01:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. file permissions
    By witek25 in forum Windows Programming
    Replies: 6
    Last Post: 06-30-2007, 09:36 PM
  2. File permissions
    By Nephiroth in forum Windows Programming
    Replies: 2
    Last Post: 02-05-2006, 05:47 AM
  3. File Permissions
    By KPY79 in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2005, 03:45 PM
  4. C File permissions
    By vipers in forum C Programming
    Replies: 1
    Last Post: 04-24-2004, 12:00 PM