Skip to content

Commit

Permalink
Version 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rasa committed Feb 18, 2015
1 parent b75bcc4 commit 7dc3e4f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
lsdsk changelog

Version 1.4 - 04 Apr 07:

Better error reporting

Version 1.3 - 12 Jul 06:

Standardized version information across all programs
Expand Down
54 changes: 40 additions & 14 deletions lsdsk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$Id$
Copyright (c) 2005-2006 Ross Smith II (http://smithii.com). All rights reserved.
Copyright (c) 2005-2007 Ross Smith II (http://smithii.com). All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public License
Expand Down Expand Up @@ -203,6 +203,24 @@ static void usage() {
);
}

char *last_error() {
int last_error = GetLastError();
static char buf[2048];
if (FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
last_error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &buf,
sizeof(buf),
NULL
) == 0) {
_snprintf(buf, sizeof(buf), "Unknown Windows error %d", last_error);
}
return buf;
}

/* @todo move to shared lib */
/* per http://www.scit.wlv.ac.uk/cgi-bin/mansec?3C+basename */
static char* basename(char* s) {
Expand Down Expand Up @@ -817,13 +835,6 @@ int main(int argc, char **argv) {

printf("\n");

// USE_INFO_2 ui2[26];

unsigned char *BufPtr = NULL;
DWORD EntriesRead = 0;
DWORD TotalEntries = 0;
DWORD ResumeHandle = NULL;

for (int i = 0; i < 26; ++i) {
char c = 'A' + i;
drive[i].letter = c;
Expand All @@ -842,16 +853,27 @@ int main(int argc, char **argv) {
StringList freelist;

while (1) {
// USE_INFO_2 ui2[26];

unsigned char *BufPtr = NULL;
DWORD EntriesRead = 0;
DWORD TotalEntries = 0;
DWORD ResumeHandle = NULL;

NET_API_STATUS rv3 = NetUseEnum(
NULL, // LMSTR UncServerName,
2, // DWORD Level,
NULL, // LMSTR UncServerName,
2, // DWORD Level,
&BufPtr,
MAX_PREFERRED_LENGTH, // DWORD PreferedMaximumSize,
&EntriesRead,
&TotalEntries,
&ResumeHandle
);
if (rv3 != NERR_Success) {
fprintf(stderr, "%s\n", last_error());
if (BufPtr) {
NetApiBufferFree(BufPtr);
}
break;
}

Expand Down Expand Up @@ -891,6 +913,10 @@ int main(int argc, char **argv) {
p += sizeof(USE_INFO_2);
}

if (BufPtr) {
NetApiBufferFree(BufPtr);
}

if (!ResumeHandle)
break;
}
Expand All @@ -909,11 +935,11 @@ int main(int argc, char **argv) {
case DRIVE_UNKNOWN: // The drive type cannot be determined.
case DRIVE_NO_ROOT_DIR: // The root path is invalid, for example, no volume is mounted at the path.
case DRIVE_REMOVABLE: // The drive is a type that has removable media, for example, a floppy drive or removable hard disk.
case DRIVE_REMOTE: // The drive is a remote (network) drive.
case DRIVE_CDROM: // The drive is a CD-ROM drive.
case DRIVE_RAMDISK: // The drive is a RAM disk.
drive[i].type = types[rv];
break;
case DRIVE_REMOTE: // The drive is a remote (network) drive.
case DRIVE_FIXED: // The drive is a type that cannot be removed, for example, a fixed hard drive.
drive[i].type = types[rv];

Expand All @@ -922,14 +948,14 @@ int main(int argc, char **argv) {
if (strstr(buf, "RAM")) {
drive[i].type = types[DRIVE_RAMDISK];
}
if (strchr(buf, ':')) {
drive[i].type = types[DRIVE_SUBST];
}
if (drive[i].name.length() == 0) {
drive[i].name = buf;
if (drive[i].name.substr(0, 3) == "\\??")
drive[i].name = drive[i].name.substr(4);
}
if (strcspn(drive[i].name.c_str(), ":") == 1) {
drive[i].type = types[DRIVE_SUBST];
}
}
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lsdsk - Version 1.3 - Jul 19 2006
Copyright (c) 2005-2006 Ross Smith II (http://smithii.com) All Rights Reserved
lsdsk - Version 1.4 - Apr 04 2007
Copyright (c) 2005-2007 Ross Smith II (http://smithii.com) All Rights Reserved

------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ General Public License for more details.
#define VER_INTERNAL_NAME "lsdsk"
#define VER_FILE_DESCRIPTION "List disks"
#define VER_MAJOR 1
#define VER_MINOR 3
#define VER_STRING2 "1.3"
#define VER_MINOR 4
#define VER_STRING2 "1.4"

#include "ver_defaults.h"

0 comments on commit 7dc3e4f

Please sign in to comment.