Skip to content

Commit 8071a96

Browse files
committed
Load blksz, lrecl, and date attributes
Signed-off-by: Timothy Johnson <[email protected]>
1 parent a312989 commit 8071a96

File tree

8 files changed

+212
-22
lines changed

8 files changed

+212
-22
lines changed

native/c/commands/ds.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ int handle_data_set_list(InvocationContext &context)
382382
fields.push_back(it->volser);
383383
fields.push_back(it->migr ? "true" : "false");
384384
fields.push_back(it->recfm);
385+
// TODO Add more attributes here
385386
}
386387
context.output_stream() << zut_format_as_csv(fields) << endl;
387388
fields.clear();
@@ -404,10 +405,18 @@ int handle_data_set_list(InvocationContext &context)
404405
entry->set("name", str(trimmed_name));
405406
if (attributes)
406407
{
408+
entry->set("cdate", str(it->cdate));
409+
entry->set("blksz", i64(it->blksz));
407410
entry->set("dsorg", str(it->dsorg));
408-
entry->set("volser", str(it->volser));
411+
entry->set("edate", str(it->edate));
412+
entry->set("extx", i64(it->extx));
413+
entry->set("lrecl", i64(it->lrecl));
409414
entry->set("migr", boolean(it->migr));
415+
entry->set("ovf", boolean(it->ovf));
416+
entry->set("rdate", str(it->rdate));
410417
entry->set("recfm", str(it->recfm));
418+
entry->set("sizex", i64(it->sizex));
419+
entry->set("volser", str(it->volser));
411420
}
412421
entries_array->push(entry);
413422
}

native/c/zds.cpp

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,111 @@ void load_recfm_from_dscb(const DSCBFormat1 *dscb, string *recfm)
744744
}
745745
}
746746

747+
void load_date_from_dscb(const char *date_in, string *date_out)
748+
{
749+
// Date is in 'YDD' format (3 bytes): Year offset and day of year
750+
// If all zeros, date is not maintained
751+
unsigned char year_offset = static_cast<unsigned char>(date_in[0]);
752+
unsigned char day_high = static_cast<unsigned char>(date_in[1]);
753+
unsigned char day_low = static_cast<unsigned char>(date_in[2]);
754+
755+
// Check if date is zero (not maintained)
756+
if (year_offset == 0 && day_high == 0 && day_low == 0)
757+
{
758+
*date_out = "";
759+
return;
760+
}
761+
762+
// Parse year: add 1900 to the year offset
763+
int year = 1900 + year_offset;
764+
765+
// Parse day of year from 2-byte value (big-endian)
766+
int day_of_year = (day_high << 8) | day_low;
767+
768+
// Convert day of year to month/day
769+
static const int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
770+
771+
// Check for leap year
772+
bool is_leap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
773+
774+
int month = 1;
775+
int day = day_of_year;
776+
777+
for (int i = 0; i < 12 && day > days_in_month[i]; i++)
778+
{
779+
int days_this_month = days_in_month[i];
780+
if (i == 1 && is_leap) // February in leap year
781+
days_this_month = 29;
782+
783+
day -= days_this_month;
784+
month++;
785+
}
786+
787+
// Format as "YYYY/MM/DD"
788+
char buffer[11];
789+
sprintf(buffer, "%04d/%02d/%02d", year, month, day);
790+
*date_out = buffer;
791+
}
792+
793+
void load_size_from_dscb(const DSCBFormat1 *dscb, ZDSEntry &entry)
794+
{
795+
// extx: Number of extents on this volume
796+
entry.extx = dscb->ds1noepv;
797+
798+
// Parse the extent information from ds1exnts (3 extents, 10 bytes each)
799+
// Each extent has: type(1), seq(1), lower_limit(4), upper_limit(4)
800+
const char *extent_data = dscb->ds1exnts;
801+
int total_tracks = 0;
802+
bool has_overflow = false;
803+
804+
for (int i = 0; i < 3; i++)
805+
{
806+
const char *extent = extent_data + (i * 10);
807+
uint8_t extent_type = static_cast<uint8_t>(extent[0]);
808+
809+
// Check if this is a valid extent (not X'00')
810+
if (extent_type == 0x00)
811+
break;
812+
813+
// Check for overflow extent (ISAM X'02')
814+
if (extent_type & 0x02)
815+
{
816+
has_overflow = true;
817+
}
818+
819+
// Parse lower limit CCHH (4 bytes)
820+
uint16_t lower_cyl_low = (static_cast<unsigned char>(extent[2]) << 8) |
821+
static_cast<unsigned char>(extent[3]);
822+
uint16_t lower_cyl_high = (static_cast<unsigned char>(extent[4]) >> 4) & 0x0F;
823+
uint16_t lower_head = ((static_cast<unsigned char>(extent[4]) & 0x0F) << 8) |
824+
static_cast<unsigned char>(extent[5]);
825+
826+
// Parse upper limit CCHH (4 bytes)
827+
uint16_t upper_cyl_low = (static_cast<unsigned char>(extent[6]) << 8) |
828+
static_cast<unsigned char>(extent[7]);
829+
uint16_t upper_cyl_high = (static_cast<unsigned char>(extent[8]) >> 4) & 0x0F;
830+
uint16_t upper_head = ((static_cast<unsigned char>(extent[8]) & 0x0F) << 8) |
831+
static_cast<unsigned char>(extent[9]);
832+
833+
// Calculate full cylinder numbers (28-bit)
834+
uint32_t lower_cyl = (lower_cyl_high << 16) | lower_cyl_low;
835+
uint32_t upper_cyl = (upper_cyl_high << 16) | upper_cyl_low;
836+
837+
// Calculate tracks in this extent
838+
if (upper_cyl >= lower_cyl)
839+
{
840+
int tracks_in_extent = ((upper_cyl - lower_cyl) * 15) + (upper_head - lower_head) + 1;
841+
total_tracks += tracks_in_extent;
842+
}
843+
}
844+
845+
// sizex: Total tracks allocated
846+
entry.sizex = total_tracks;
847+
848+
// ovf: Overflow indicator
849+
entry.ovf = has_overflow;
850+
}
851+
747852
void zds_get_attrs_from_dscb(ZDS *zds, ZDSEntry &entry)
748853
{
749854
auto *dscb = (DSCBFormat1 *)__malloc31(sizeof(DSCBFormat1));
@@ -759,6 +864,14 @@ void zds_get_attrs_from_dscb(ZDS *zds, ZDSEntry &entry)
759864
{
760865
load_dsorg_from_dscb(dscb, &entry.dsorg);
761866
load_recfm_from_dscb(dscb, &entry.recfm);
867+
entry.blksz = (static_cast<unsigned char>(dscb->ds1blkl[0]) << 8) |
868+
static_cast<unsigned char>(dscb->ds1blkl[1]);
869+
entry.lrecl = (static_cast<unsigned char>(dscb->ds1lrecl[0]) << 8) |
870+
static_cast<unsigned char>(dscb->ds1lrecl[1]);
871+
load_date_from_dscb(dscb->ds1credt, &entry.cdate);
872+
load_date_from_dscb(dscb->ds1expdt, &entry.edate);
873+
load_date_from_dscb(dscb->ds1refd, &entry.rdate);
874+
load_size_from_dscb(dscb, entry);
762875
}
763876
else
764877
{

native/c/zds.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ struct ZDSMem
2727
struct ZDSEntry
2828
{
2929
std::string name;
30+
int blksz;
31+
std::string cdate;
3032
std::string dsorg;
31-
std::string volser;
32-
std::string recfm;
33+
std::string edate;
34+
int extx;
35+
int lrecl;
3336
bool migr;
37+
bool ovf;
38+
std::string rdate;
39+
std::string recfm;
40+
int sizex;
41+
std::string volser;
3442
};
3543

3644
typedef struct

native/zowed/schemas/requests.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/**
2-
* This program and the accompanying materials are made available under the terms of the
3-
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4-
* https://www.eclipse.org/legal/epl-v20.html
5-
*
6-
* SPDX-License-Identifier: EPL-2.0
7-
*
8-
* Copyright Contributors to the Zowe Project.
9-
*
1+
/**
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
1010
*/
1111

1212
// Code generated by generateTypes.ts. DO NOT EDIT.

native/zowed/schemas/responses.hpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/**
2-
* This program and the accompanying materials are made available under the terms of the
3-
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4-
* https://www.eclipse.org/legal/epl-v20.html
5-
*
6-
* SPDX-License-Identifier: EPL-2.0
7-
*
8-
* Copyright Contributors to the Zowe Project.
9-
*
1+
/**
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
1010
*/
1111

1212
// Code generated by generateTypes.ts. DO NOT EDIT.
@@ -22,7 +22,17 @@ ZJSON_SCHEMA(Dataset,
2222
FIELD_OPTIONAL(dsorg, STRING),
2323
FIELD_OPTIONAL(volser, STRING),
2424
FIELD_OPTIONAL(migr, BOOL),
25-
FIELD_OPTIONAL(recfm, STRING)
25+
FIELD_OPTIONAL(recfm, STRING),
26+
FIELD_OPTIONAL(blksz, NUMBER),
27+
FIELD_OPTIONAL(cdate, STRING),
28+
FIELD_OPTIONAL(edate, STRING),
29+
FIELD_OPTIONAL(extx, NUMBER),
30+
FIELD_OPTIONAL(lrecl, NUMBER),
31+
FIELD_OPTIONAL(ovf, BOOL),
32+
FIELD_OPTIONAL(rdate, STRING),
33+
FIELD_OPTIONAL(sizex, NUMBER),
34+
FIELD_OPTIONAL(spacu, STRING),
35+
FIELD_OPTIONAL(used, NUMBER)
2636
);
2737

2838
struct DsMember {};

packages/cli/src/list/data-set/DataSet.definition.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ export const ListDataSetDefinition: ICommandDefinition = {
5050
required: true,
5151
},
5252
],
53+
options: [
54+
{
55+
name: "attributes",
56+
aliases: ["a"],
57+
description: "Fetch attributes of the data sets being listed.",
58+
type: "boolean",
59+
},
60+
],
5361
profile: { optional: ["ssh"] },
5462
outputFormatOptions: true,
5563
};

packages/cli/src/list/data-set/DataSet.handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class ListDataSetsHandler extends SshBaseHandler {
1919
try {
2020
response = await client.ds.listDatasets({
2121
pattern: params.arguments.pattern,
22+
attributes: params.arguments.attributes,
2223
});
2324
} catch (err) {
2425
const errText = (err instanceof ImperativeError ? err.additionalDetails : err.toString()).replace(
@@ -37,6 +38,7 @@ export default class ListDataSetsHandler extends SshBaseHandler {
3738
response.returnedRows,
3839
params.arguments.pattern,
3940
);
41+
params.response.data.setObj(response.items);
4042
params.response.format.output({
4143
output: response.items,
4244
format: "table",

packages/sdk/src/doc/rpc/common.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,46 @@ export interface Dataset {
109109
* Record format
110110
*/
111111
recfm?: string;
112+
/**
113+
* Block size
114+
*/
115+
blksz?: number;
116+
/**
117+
* Creation date
118+
*/
119+
cdate?: string;
120+
/**
121+
* Expiration date
122+
*/
123+
edate?: string;
124+
/**
125+
* Number of extents
126+
*/
127+
extx?: number;
128+
/**
129+
* Logical record length
130+
*/
131+
lrecl?: number;
132+
/**
133+
* Overflow indicator
134+
*/
135+
ovf?: boolean;
136+
/**
137+
* Last referenced date
138+
*/
139+
rdate?: string;
140+
/**
141+
* Size in extents
142+
*/
143+
sizex?: number;
144+
/**
145+
* Space allocation units
146+
*/
147+
spacu?: string;
148+
/**
149+
* Amount of space used
150+
*/
151+
used?: number;
112152
}
113153

114154
export interface DatasetAttributes {

0 commit comments

Comments
 (0)