@@ -84,99 +84,98 @@ zx_status_t RamNandCtl::Create(fbl::RefPtr<RamNandCtl>* out) {
84
84
}
85
85
86
86
__EXPORT
87
- zx_status_t RamNand::Create (const fuchsia_hardware_nand_RamNandInfo* config,
88
- std::optional<RamNand>* out) {
89
- fbl::unique_fd control (open (kBasePath , O_RDWR));
90
-
91
- zx::channel ctl_svc;
92
- zx_status_t st = fdio_get_service_handle (control.release (), ctl_svc.reset_and_get_address ());
93
- if (st != ZX_OK) {
94
- return st;
87
+ zx_status_t RamNandCtl::CreateRamNand (const fuchsia_hardware_nand_RamNandInfo* config,
88
+ std::optional<RamNand>* out) {
89
+ fdio_t * io = fdio_unsafe_fd_to_io (fd ().get ());
90
+ if (io == NULL ) {
91
+ fprintf (stderr, " Could not get fdio object\n " );
92
+ return ZX_ERR_INTERNAL;
95
93
}
94
+ zx_handle_t ctl_svc = fdio_unsafe_borrow_channel (io);
96
95
97
96
char name[fuchsia_hardware_nand_NAME_LEN + 1 ];
98
97
size_t out_name_size;
99
98
zx_status_t status;
100
- st = fuchsia_hardware_nand_RamNandCtlCreateDevice (ctl_svc.get (), config, &status, name,
101
- fuchsia_hardware_nand_NAME_LEN, &out_name_size);
99
+ zx_status_t st = fuchsia_hardware_nand_RamNandCtlCreateDevice (
100
+ ctl_svc, config, &status, name, fuchsia_hardware_nand_NAME_LEN, &out_name_size);
101
+ fdio_unsafe_release (io);
102
102
if (st != ZX_OK || status != ZX_OK) {
103
103
st = st != ZX_OK ? st : status;
104
104
fprintf (stderr, " Could not create ram_nand device, %d\n " , st);
105
105
return st;
106
106
}
107
107
name[out_name_size] = ' \0 ' ;
108
+
109
+ // TODO(fxbug.dev/33003): We should be able to open relative to ctl->fd(), but
110
+ // due to a bug, we have to be relative to devfs_root instead.
108
111
fbl::StringBuffer<PATH_MAX> path;
109
- path.Append (kBasePath );
110
- path.Append (" /" );
112
+ path.Append (" sys/platform/00:00:2e/nand-ctl/" );
111
113
path.Append (name);
114
+ fprintf (stderr, " Trying to open (%s)\n " , path.c_str ());
112
115
113
- fbl::unique_fd ram_nand_ctl (open (kBasePath , O_RDONLY | O_DIRECTORY));
114
- if (!ram_nand_ctl) {
115
- fprintf (stderr, " Could not open ram_nand_ctl" );
116
- return ZX_ERR_INTERNAL;
117
- }
118
-
119
- fbl::unique_fd ram_nand;
120
- st = WaitForFile (ram_nand_ctl, name, &ram_nand);
116
+ fbl::unique_fd fd;
117
+ st = devmgr_integration_test::RecursiveWaitForFile (devfs_root (), path.c_str (), &fd);
121
118
if (st != ZX_OK) {
122
- fprintf (stderr, " Could not open ram_nand\n " );
123
119
return st;
124
120
}
125
121
126
- *out = RamNand (std::move (ram_nand), path. ToString (), fbl::String (name ));
122
+ *out = RamNand (std::move (fd ));
127
123
return ZX_OK;
128
124
}
129
125
130
126
__EXPORT
131
- zx_status_t RamNand::Create (fbl::RefPtr<RamNandCtl> ctl,
132
- const fuchsia_hardware_nand_RamNandInfo* config,
127
+ zx_status_t RamNandCtl::CreateWithRamNand (const fuchsia_hardware_nand_RamNandInfo* config,
128
+ std::optional<RamNand>* out) {
129
+ fbl::RefPtr<RamNandCtl> ctl;
130
+ zx_status_t st = RamNandCtl::Create (&ctl);
131
+ if (st != ZX_OK) {
132
+ return st;
133
+ }
134
+ return ctl->CreateRamNand (config, out);
135
+ }
136
+
137
+ __EXPORT
138
+ zx_status_t RamNand::Create (const fuchsia_hardware_nand_RamNandInfo* config,
133
139
std::optional<RamNand>* out) {
134
- fdio_t * io = fdio_unsafe_fd_to_io (ctl->fd ().get ());
135
- if (io == NULL ) {
136
- fprintf (stderr, " Could not get fdio object\n " );
137
- return ZX_ERR_INTERNAL;
140
+ fbl::unique_fd control (open (kBasePath , O_RDWR));
141
+
142
+ zx::channel ctl_svc;
143
+ zx_status_t st = fdio_get_service_handle (control.release (), ctl_svc.reset_and_get_address ());
144
+ if (st != ZX_OK) {
145
+ return st;
138
146
}
139
- zx_handle_t ctl_svc = fdio_unsafe_borrow_channel (io);
140
147
141
148
char name[fuchsia_hardware_nand_NAME_LEN + 1 ];
142
149
size_t out_name_size;
143
150
zx_status_t status;
144
- zx_status_t st = fuchsia_hardware_nand_RamNandCtlCreateDevice (
145
- ctl_svc, config, &status, name, fuchsia_hardware_nand_NAME_LEN, &out_name_size);
146
- fdio_unsafe_release (io);
151
+ st = fuchsia_hardware_nand_RamNandCtlCreateDevice (ctl_svc.get (), config, &status, name,
152
+ fuchsia_hardware_nand_NAME_LEN, &out_name_size);
147
153
if (st != ZX_OK || status != ZX_OK) {
148
154
st = st != ZX_OK ? st : status;
149
155
fprintf (stderr, " Could not create ram_nand device, %d\n " , st);
150
156
return st;
151
157
}
152
158
name[out_name_size] = ' \0 ' ;
153
-
154
- // TODO(fxbug.dev/33003): We should be able to open relative to ctl->fd(), but
155
- // due to a bug, we have to be relative to devfs_root instead.
156
159
fbl::StringBuffer<PATH_MAX> path;
157
- path.Append (" sys/platform/00:00:2e/nand-ctl/" );
160
+ path.Append (kBasePath );
161
+ path.Append (" /" );
158
162
path.Append (name);
159
- fprintf (stderr, " Trying to open (%s)\n " , path.c_str ());
160
163
161
- fbl::unique_fd fd ;
162
- st = devmgr_integration_test::RecursiveWaitForFile (ctl-> devfs_root (), path. c_str (), &fd);
163
- if (st != ZX_OK) {
164
- return st ;
164
+ fbl::unique_fd ram_nand_ctl ( open ( kBasePath , O_RDONLY | O_DIRECTORY)) ;
165
+ if (!ram_nand_ctl) {
166
+ fprintf (stderr, " Could not open ram_nand_ctl " );
167
+ return ZX_ERR_INTERNAL ;
165
168
}
166
169
167
- *out = RamNand (std::move (fd), std::move (ctl));
168
- return ZX_OK;
169
- }
170
-
171
- __EXPORT
172
- zx_status_t RamNand::CreateIsolated (const fuchsia_hardware_nand_RamNandInfo* config,
173
- std::optional<RamNand>* out) {
174
- fbl::RefPtr<RamNandCtl> ctl;
175
- zx_status_t st = RamNandCtl::Create (&ctl);
170
+ fbl::unique_fd ram_nand;
171
+ st = WaitForFile (ram_nand_ctl, name, &ram_nand);
176
172
if (st != ZX_OK) {
173
+ fprintf (stderr, " Could not open ram_nand\n " );
177
174
return st;
178
175
}
179
- return Create (std::move (ctl), config, out);
176
+
177
+ *out = RamNand (std::move (ram_nand), path.ToString (), fbl::String (name));
178
+ return ZX_OK;
180
179
}
181
180
182
181
__EXPORT
0 commit comments