Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Finding files

Finding files

Scheduled Pinned Locked Moved C / C++ / MFC
jsonquestion
29 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David Crow

    WalderMort wrote:

    Try running your test again but manualy open "C:\$MFT" and "C:\$MFTMirr" and account for the sizes

    c:\$mft = 125.5MB c:\$mftmirr = 4KB


    "A good athlete is the result of a good and worthy opponent." - David Crow

    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

    W Offline
    W Offline
    Waldermort
    wrote on last edited by
    #15

    Well that accounts for some 5%... That's got me thinking now, what does windows need all that space for? Just out of curiousity, how does your test work?

    Waldermort

    D 1 Reply Last reply
    0
    • W Waldermort

      Well that accounts for some 5%... That's got me thinking now, what does windows need all that space for? Just out of curiousity, how does your test work?

      Waldermort

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #16

      WalderMort wrote:

      Just out of curiousity, how does your test work?

      Nothing special. I just used a CFileFind object to round up the sizes of all the files on the C: drive.


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      W 1 Reply Last reply
      0
      • D David Crow

        WalderMort wrote:

        Just out of curiousity, how does your test work?

        Nothing special. I just used a CFileFind object to round up the sizes of all the files on the C: drive.


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        W Offline
        W Offline
        Waldermort
        wrote on last edited by
        #17

        ahh, did you take into account that file size on disk is usually higher than that CFileFind reports? Also many of the smaller files are stored inside the MFT rather than waste cluster space. Through tests, I have found some 30% of my C: volume contains files that CFileFind cannot find. I think the only way to find out what those files are is to read the MFT directly and compare to the results of CFileFind.

        Waldermort

        D 1 Reply Last reply
        0
        • W Waldermort

          ahh, did you take into account that file size on disk is usually higher than that CFileFind reports? Also many of the smaller files are stored inside the MFT rather than waste cluster space. Through tests, I have found some 30% of my C: volume contains files that CFileFind cannot find. I think the only way to find out what those files are is to read the MFT directly and compare to the results of CFileFind.

          Waldermort

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #18

          WalderMort wrote:

          did you take into account that file size on disk is usually higher than that CFileFind reports?

          Yes, I accounted for slack space.

          WalderMort wrote:

          Also many of the smaller files are stored inside the MFT rather than waste cluster space.

          I thought of that, but I've got files that are a few bytes in length, and they are found by CFileFind.


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          W 1 Reply Last reply
          0
          • D David Crow

            WalderMort wrote:

            did you take into account that file size on disk is usually higher than that CFileFind reports?

            Yes, I accounted for slack space.

            WalderMort wrote:

            Also many of the smaller files are stored inside the MFT rather than waste cluster space.

            I thought of that, but I've got files that are a few bytes in length, and they are found by CFileFind.


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            W Offline
            W Offline
            Waldermort
            wrote on last edited by
            #19

            DavidCrow wrote:

            I thought of that, but I've got files that are a few bytes in length, and they are found by CFileFind.

            CfileFind will return the size regardless of which part of the disk it is stored. A more realistic method would be to pass each file into DeviceIoControl and count the cluster/fragment usage. 0 fragments indicates that it is stored in the MFT. Also, I have just accounted for a further 4GB by giving myself access rights to the "System Volume Information". If you know of a way to do this programaticaly I would be glad to hear. My next step is to call CreateFile for every file/folder found, if it fails then I should attempt to adjust the access rights. This is where CFindFile fails the most, it gives no indication of where it skipped a file/directory simply because it had no rights.

            Waldermort

            D 3 Replies Last reply
            0
            • W Waldermort

              DavidCrow wrote:

              I thought of that, but I've got files that are a few bytes in length, and they are found by CFileFind.

              CfileFind will return the size regardless of which part of the disk it is stored. A more realistic method would be to pass each file into DeviceIoControl and count the cluster/fragment usage. 0 fragments indicates that it is stored in the MFT. Also, I have just accounted for a further 4GB by giving myself access rights to the "System Volume Information". If you know of a way to do this programaticaly I would be glad to hear. My next step is to call CreateFile for every file/folder found, if it fails then I should attempt to adjust the access rights. This is where CFindFile fails the most, it gives no indication of where it skipped a file/directory simply because it had no rights.

              Waldermort

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #20

              WalderMort wrote:

              ...giving myself access rights to the "System Volume Information".

              How?

              WalderMort wrote:

              My next step is to call CreateFile for every file/folder found, if it fails then I should attempt to adjust the access rights.

              Going back to your "...for each file I then perform a few tasks." comment, do you need to perform said tasks on those files for which you have insufficient access?


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              W 1 Reply Last reply
              0
              • D David Crow

                WalderMort wrote:

                ...giving myself access rights to the "System Volume Information".

                How?

                WalderMort wrote:

                My next step is to call CreateFile for every file/folder found, if it fails then I should attempt to adjust the access rights.

                Going back to your "...for each file I then perform a few tasks." comment, do you need to perform said tasks on those files for which you have insufficient access?


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                W Offline
                W Offline
                Waldermort
                wrote on last edited by
                #21

                DavidCrow wrote:

                How?

                A simple command prompt[^] But this method is not temporary.

                DavidCrow wrote:

                comment, do you need to perform said tasks on those files for which you have insufficient access?

                I'm creating a defragger, so I would prefer to have access to as many files as possible, especially those on the windows install volume.

                Waldermort

                D 1 Reply Last reply
                0
                • W Waldermort

                  DavidCrow wrote:

                  How?

                  A simple command prompt[^] But this method is not temporary.

                  DavidCrow wrote:

                  comment, do you need to perform said tasks on those files for which you have insufficient access?

                  I'm creating a defragger, so I would prefer to have access to as many files as possible, especially those on the windows install volume.

                  Waldermort

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #22

                  WalderMort wrote:

                  I'm creating a defragger,

                  There might be something here you can use.


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  W 1 Reply Last reply
                  0
                  • D David Crow

                    WalderMort wrote:

                    I'm creating a defragger,

                    There might be something here you can use.


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    W Offline
                    W Offline
                    Waldermort
                    wrote on last edited by
                    #23

                    Thanks, that may come in handy. At a glance it works similar to my method, but I have also built in a DiskMap viewer.

                    Waldermort

                    1 Reply Last reply
                    0
                    • W Waldermort

                      DavidCrow wrote:

                      I thought of that, but I've got files that are a few bytes in length, and they are found by CFileFind.

                      CfileFind will return the size regardless of which part of the disk it is stored. A more realistic method would be to pass each file into DeviceIoControl and count the cluster/fragment usage. 0 fragments indicates that it is stored in the MFT. Also, I have just accounted for a further 4GB by giving myself access rights to the "System Volume Information". If you know of a way to do this programaticaly I would be glad to hear. My next step is to call CreateFile for every file/folder found, if it fails then I should attempt to adjust the access rights. This is where CFindFile fails the most, it gives no indication of where it skipped a file/directory simply because it had no rights.

                      Waldermort

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #24

                      WalderMort wrote:

                      Also, I have just accounted for a further 4GB by giving myself access rights to the "System Volume Information".

                      Same here. It now seems that my numbers have gone the other way. GetDiskFreeSpaceEx() reports 28GB used bytes, but I am counting 30.3GB bytes used by files, a difference of 231.4MB. Hmmm...


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      W 1 Reply Last reply
                      0
                      • D David Crow

                        WalderMort wrote:

                        Also, I have just accounted for a further 4GB by giving myself access rights to the "System Volume Information".

                        Same here. It now seems that my numbers have gone the other way. GetDiskFreeSpaceEx() reports 28GB used bytes, but I am counting 30.3GB bytes used by files, a difference of 231.4MB. Hmmm...


                        "A good athlete is the result of a good and worthy opponent." - David Crow

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        W Offline
                        W Offline
                        Waldermort
                        wrote on last edited by
                        #25

                        Haha, sounds like your loop could do with a little refining. Try the DeviceIoApproach as I mentioned earlier, you should get some more realistic values.

                        Waldermort

                        D 1 Reply Last reply
                        0
                        • W Waldermort

                          Haha, sounds like your loop could do with a little refining. Try the DeviceIoApproach as I mentioned earlier, you should get some more realistic values.

                          Waldermort

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #26

                          WalderMort wrote:

                          Try the DeviceIoApproach as I mentioned earlier...

                          Which control code did you have in mind?


                          "A good athlete is the result of a good and worthy opponent." - David Crow

                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                          W 1 Reply Last reply
                          0
                          • D David Crow

                            WalderMort wrote:

                            Try the DeviceIoApproach as I mentioned earlier...

                            Which control code did you have in mind?


                            "A good athlete is the result of a good and worthy opponent." - David Crow

                            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                            W Offline
                            W Offline
                            Waldermort
                            wrote on last edited by
                            #27

                            you would need to use the FSCTL_GET_EXTENT_BUFFERS. The trouble is with this operation is that you don't know how large the buffer should be. I wrapped the call up in a class with the buffer as a static member. Each time the buffer is too small, I double the size and keep calling until successful. The Extent count indicates how many fragments the file has, 0 indicates that it is located in the MFT. Each extent returned will then tell you how many clusters each fragment has. By adding these and multiplying by your drives 'bytes per cluster' you will find out exactly how much space a particular file/folder is taking. Also be aware of NT's compressed runs which is indicated by a startLCN of -1. I still haven't managed to get my head around what this actualy means.

                            Waldermort

                            1 Reply Last reply
                            0
                            • W Waldermort

                              DavidCrow wrote:

                              I thought of that, but I've got files that are a few bytes in length, and they are found by CFileFind.

                              CfileFind will return the size regardless of which part of the disk it is stored. A more realistic method would be to pass each file into DeviceIoControl and count the cluster/fragment usage. 0 fragments indicates that it is stored in the MFT. Also, I have just accounted for a further 4GB by giving myself access rights to the "System Volume Information". If you know of a way to do this programaticaly I would be glad to hear. My next step is to call CreateFile for every file/folder found, if it fails then I should attempt to adjust the access rights. This is where CFindFile fails the most, it gives no indication of where it skipped a file/directory simply because it had no rights.

                              Waldermort

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #28

                              WalderMort wrote:

                              If you know of a way to do this programaticaly I would be glad to hear.

                              I can 'get' the access rights, but haven't quite got the 'set' part down yet.


                              "A good athlete is the result of a good and worthy opponent." - David Crow

                              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                              W 1 Reply Last reply
                              0
                              • D David Crow

                                WalderMort wrote:

                                If you know of a way to do this programaticaly I would be glad to hear.

                                I can 'get' the access rights, but haven't quite got the 'set' part down yet.


                                "A good athlete is the result of a good and worthy opponent." - David Crow

                                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                W Offline
                                W Offline
                                Waldermort
                                wrote on last edited by
                                #29

                                You still working on that, lol. To be honest, I didn't touch that part of my code yet, I'm still working on my class hierarchy. I was thinking to use ShellExec() with the "runas" flag, change the security settings and store them into a file, which I believe cacls is able to do. This should, in theory, allow the origional settings to be replaced once complete. But like I said, I didn't try this yet and probably won't for another week or so. If you manage to do it using another method, I would be interested to see how.

                                Waldermort

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups