@@ -6,6 +6,7 @@ const fatfs = @import("zfat");
6
6
7
7
const block_size = 512 ;
8
8
const max_path_len = 8192 ; // this should be enough
9
+ const max_label_len = 11 ; // see http://elm-chan.org/fsw/ff/doc/setlabel.html
9
10
10
11
const FAT = @This ();
11
12
@@ -128,21 +129,35 @@ fn render(self: *FAT, stream: *dim.BinaryStream) dim.Content.RenderError!void {
128
129
};
129
130
130
131
const ops = self .ops .items ;
131
- if (ops .len > 0 ) {
132
- filesystem .mount ("0:" , true ) catch | err | switch (err ) {
133
- error .NotEnabled = > @panic ("bug in zfat" ),
134
- error .DiskErr = > return error .IoError ,
135
- error .NotReady = > @panic ("bug in zfat disk wrapper" ),
136
- error .InvalidDrive = > @panic ("bug in AtomicOps" ),
137
- error .NoFilesystem = > @panic ("bug in zfat" ),
138
- };
139
132
140
- const wrapper = AtomicOps {};
133
+ filesystem .mount ("0:" , true ) catch | err | switch (err ) {
134
+ error .NotEnabled = > @panic ("bug in zfat" ),
135
+ error .DiskErr = > return error .IoError ,
136
+ error .NotReady = > @panic ("bug in zfat disk wrapper" ),
137
+ error .InvalidDrive = > @panic ("bug in AtomicOps" ),
138
+ error .NoFilesystem = > @panic ("bug in zfat" ),
139
+ };
141
140
142
- for (ops ) | op | {
143
- try op .execute (wrapper );
141
+ if (self .label ) | label | {
142
+ if (label .len <= max_label_len ) {
143
+ var label_buffer : [max_label_len + 3 :0 ]u8 = undefined ;
144
+ const buf = std .fmt .bufPrintZ (& label_buffer , "0:{s}" , .{label }) catch @panic ("buffer too small" );
145
+
146
+ _ = fatfs .api .setlabel (buf .ptr );
147
+ } else {
148
+ std .log .err ("label \" {}\" is {} characters long, but only up to {} are permitted." , .{
149
+ std .zig .fmtEscapes (label ),
150
+ label .len ,
151
+ max_label_len ,
152
+ });
144
153
}
145
154
}
155
+
156
+ const wrapper = AtomicOps {};
157
+
158
+ for (ops ) | op | {
159
+ try op .execute (wrapper );
160
+ }
146
161
}
147
162
148
163
const FatType = enum {
0 commit comments